A Sensible Approach to a Self-Contained Vehicle (of Type Object/Room)

Good day.
The game I am developing involves making use of a Vehicle object to move distances that are described as too laborious to travel on foot.
I have begun implementing the Vehicle as such:

<object name="car">
      <inherit name="switchable" />
      <linkcolour>DimGrey</linkcolour>
      <alias>Car</alias>
      <isroom />
      <attr name="grid_fill">SlateGray</attr>
      <attr name="grid_label">Car</attr>
      <displayverbs type="stringlist">
        <value>Look At</value>
        <value>Start</value>
      </displayverbs>
      <usestandardverblist />
      <inventoryverbs type="stringlist" />
      <drop type="boolean">false</drop>
      <price type="int">5000</price>
      <look type="string"></look>
      <feature_switchable />
      <cannotswitchon>You need the key.</cannotswitchon>
      <grid_parent_offset_auto />
      <dropdestination type="object">car</dropdestination>
      <start type="script">
        if (Contains (car.parent, player)) {
          if (Contains (player, player_car_key)) {
            this.switchedon = true
            list add (car.displayverbs, "Stop")
            list remove (car.displayverbs, "Start")
            MoveObject (player_car_key, car)
            PrintCentered ("With a thrash and a dull hum your car surprisingly springs to life.")
          }
          else {
            msg ("You need the key.")
          }
        }
      </start>
      <stop type="script">
        if (Contains (car, player_car_key)) {
          this.switchedon = false
          list add (car.displayverbs, "Start")
          list remove (car.displayverbs, "Stop")
          MoveObject (player_car_key, player)
          PrintCentered ("We all tend towards zero energy, and so does your car. It seems relieved that you finally turned it off.")
        }
      </stop>
      <enter type="script">
      </enter>
      <beforeenter type="script">
        this.visited = true
      </beforeenter>
      <exit name="out_car" to="car">
        <lockmessage>Your car is locked.</lockmessage>
        <runscript />
        <attr name="grid_length" type="int">0</attr>
        <script type="script">
          MoveObject (player, car.parent)
        </script>
      </exit>
    </object>
    <exit name="into_car" alias="in" to="car">
      <inherit name="indirection" />
      <lockmessage>Your car is locked.</lockmessage>
    </exit>
  </object>

In-game, the functionality is a bit off.
Ideally the player should not be able to start the car until they are inside, but currently they are able to start and stop the car only when they are outside of it.
How can I make it so that the start and stop verbs will display only when inside the car?
Will this involve modifying the display verbs?

Thanks in advance,
igo


The problem here is that if you're inside the car, you can't see it.

One option would be to have an object with the alias 'car' that's inside the car. So you have one object for the outside of the car, and one object for the inside. The outside would have a description of the outside, and maybe a verb "get in" or something. The inside has a description of the inside of the car (or its 'look' script just does ShowRoomDescription()), and the start/stop verbs.

You might want to make the inside-of-car object a scenery object, so it doesn't show up on the 'places-and-objects' list, but have the description include "I am in my {object:inside_car}." so that the player has somewhere to click on it.


For one of my games, I approached this kind of thing differently, setting a backdrop scope script list add (items, game.pov.parent). This means that you can use an object's verbs while inside it. If you want to go down that route, you could maybe modify ShowRoomDescription() to make the "You are in" line an object link. But then you'd probably be able to look at the room/object from inside, so you'd have to modify the lookat command so that if the object looked at contains the player, it shows the room description instead.


(initial WIP: work in progress, as this is a big/difficult challenge for me, but good challenge-project for me too, but I'll need some time in trying to hopefully be able to complete it at some point, but posting it here for now, if anyone wants some ideas from it)


<object name="airplane_object">

  <inherit name="closed_vehicle_type" />

</object>

<object name="boat_object">

  <inherit name="open_vehicle_type" />

</object>

<object name="train_object">

  <inherit name="closed_vehicle_type" />

</object>

<object name="car_object">

  <inherit name="closed_vehicle_type" />

</object>

<object name="motorcycle_object">

  <inherit name="open_vehicle_type" />

</object>

<object name="bicycle_object">

  <inherit name="open_vehicle_type" />

</object>

<type name="motorized_type">

  <attr name="ignition" type="script">
    // requires (if want implementation of) correct 'key' item/Object (otherwise, the 'motorized_type' isn't needed, as you can just use the 'travel' Script Attribute of the 'vehicle_type' Object Type) 
  </attr>

</type>

<type name="closed_vehicle_type">

  <inherit name="container_closed" />
  <inherit name="container_lockable" />

  <inherit name="vehicle_type" />

</type>

<type name="open_vehicle_type">

  <inherit name="surface" />

  <inherit name="vehicle_type" />

</type>

<type name="vehicle_type">

  <attr name="embark" type="script">
  </attr>

  <attr name="disembark" type="script">
  </attr>

  <attr name="travel" type="script">
  </attr>

  <travel_objectlist_attribute type="objectlist">
  </travel_objectlist_attribute>

</type>

<verb name="ignition_verb">

  <property>ignition</property>
  <pattern>ignition</pattern>

</verb>

<verb name="embark_verb">

  <property>embark</property>
  <pattern>embark</pattern>

</verb>

<verb name="disembark_verb">

  <property>disembark</property>
  <pattern>disembark</pattern>

</verb>

<verb name="travel_verb">

  <property>travel</property>

  <pattern>travel</pattern>

  <template>TEMPLATE</template>

  <unresolved>That destination doesn't exist or isn't yet visited by you!</unresolved>

  <response>You can't travel to that!</response>
  
  <script>
    if (HasAttribute (this, "travel_objectlist_attribute")) {
      if (DoesInherit (game.pov.parent, "vehicle_type")) {
        game.pov_parent_object_attribute = game.pov.parent
      } else {
        game.pov_parent_object_attribute = game.pov
      }
      on ready {
        if (ListContains (this.travel_objectlist_attribute, game.pov_parent_object_attribute.parent)) {
          list remove (this.travel_objectlist_attribute, game.pov_parent_object_attribute.parent)
        }
        on ready {
          game.scripting_parent_object_attribute = this
          show menu ("Destination?", this.travel_objectlist_attribute, true) {
            list add (game.scripting_parent_object_attribute.travel_objectlist_attribute, game.pov_parent_object_attribute.parent)
            game.scripting_parent_object_attribute = null
            if (not result = null) {
              game.pov_parent_object_attribute.parent = result
            }
            on ready {
              game.pov_parent_object_attribute = null // since this attribute is holding the reference/pointer to the 'game.pov' (which is itself a reference/point to the 'player' Object) or 'game.pov.parent' (which is itself a reference/point to the 'vehicle' Object), is this setting the, 'player' or 'vehicle', Object to null (deleting the Object? And/or worse, creating a: dangling pointer or memory leak, ??? Or does it not effect the stored address, aka: doesn't delete the Object, no dangling pointer nor memory leak, ???)
            }
          }
        }
      }
    } else {
      msg ("ERROR: the Object doesn't have required the 'travel_objectlist_attribute' Objectlist Attribute")
    }
  </script>

</verb>

This is great. Thanks to both of you.
I'll begin implementing @mrangel's solution.
@hegemonkhan it was a pleasure to look at your code! I may experiment with aspects of yours in later attempts.


Log in to post a reply.

Support

Forums