object $elevator parents $path;
var $elevator current_location = $place_level_1;
var $elevator command_queue = [];
var $elevator destinations = [$place_level_1, $place_level_2, $place_level_3 ];
$path_level_1_to_lift
.press_cmd()
$elevator.command($place_level_1,'open)
$elevator
.command()
arg place, command
if (current_location == place)
.open_path(sender(), $elevator, place);
else {
command_queue = .add(command_queue,
$path_level_1_to_lift
.press_cmd()
$elevator.command($place_level_1,'open)
$elevator
.command()
arg place, command
if (current_location == place)
.open_path(sender(), $elevator, place);
else {
command_queue = .add(command_queue, [place, command}
$scheduler.add_task(5,'run_lift); // schedule task
}
.run_lift()
// move lift
// current_location = next in destinations list;
// check to see if destination on command_queue matches current location
// then open doors and delete command from queue
// if not reschedule task or if commands are still on queue
$scheduler.add_task(5,'run_lift);
[/code]
Sorry this is off the top of my head and I haven't used Cold core in a while
but I hope this gives you some ideas.
BTW, this IS a great mud coding quiz question. :-)
;var p, new; if(!(| valid($elevator) |)) { new = $place.spawn(); new.set_objname('elevator);}
;|as $elevator<$root>;manager = $quasar;
;|as $elevator<$root>;flags = ['variables, 'methods, 'code, 'core, 'fertile];
;|as $elevator<$root>;created_on = 1363940577;
;|as $elevator<$root>;inited = 1;
@av $elevator,task_id = -1
;|as $elevator<$elevator>;task_id = -1;
@av $elevator,lift_hints = #[]
;|as $elevator<$elevator>;lift_hints = #[];
@av $elevator,stop_queue = []
;|as $elevator<$elevator>;stop_queue = [];
;|as $elevator<$dmi_data>;descriptions = #[];
;|as $elevator<$has_commands>;shortcuts = #[];
;|as $elevator<$has_commands>;remote = #[["@reset", [["@reset", "*", "@reset <this>", 'reset_cmd, #[[1, ['this, []]]]]]]];
;|as $elevator<$has_commands>;local = #[["dest?ination", [["dest?ination", "*", "dest?ination <any>", 'dest_cmd, #[[1, ['any, []]]]]]], ["@set-lift-hint|@slh|@lift-hint", [["@set-lift-hint|@slh|@lift-hint", "* to|is *", "@set-lift-hint|@slh|@lift-hint <any> to|is <any>", 'set_lift_hint_cmd, #[[1, ['any, []]], [3, ['any, []]]]]]]];
;|as $elevator<$has_name>;name = ['prop, "Generic Elevator", "Generic Elevator"];
;|as $elevator<$described>;prose = [];
;|as $elevator<$location>;contents = [];
;|as $elevator<$place>;entrances = [];
;|as $elevator<$place>;exits = [];
;|as $elevator<$place>;realm = $realm_of_creation;
;|as $elevator<$command_cache>;commands = #[["dest", [["dest?ination", $elevator]]], ["desti", [["dest?ination", $elevator]]], ["destin", [["dest?ination", $elevator]]], ["destina", [["dest?ination", $elevator]]], ["destinat", [["dest?ination", $elevator]]], ["destinati", [["dest?ination", $elevator]]], ["destinatio", [["dest?ination", $elevator]]], ["destination", [["dest?ination", $elevator]]], ["@set-lift-hint", [["@set-lift-hint|@slh|@lift-hint", $elevator]]], ["@slh", [["@set-lift-hint|@slh|@lift-hint", $elevator]]], ["@lift-hint", [["@set-lift-hint|@slh|@lift-hint", $elevator]]]];
;|as $elevator<$command_cache>;shortcuts = [];
;|as $elevator<$command_cache>;modules = [];
@program $elevator.reset_cmd() +access=pub
arg cmdstr, cmd, what;
var out, tmp;
// Kill any travel task
(| $scheduler.del_task(task_id) |);
// Reset the queue and task_id
stop_queue = [];
task_id = 0;
// Validate the exit out
out = (| (.exits())[1] |);
if (!out || !valid(out) || !out.is($exit))
return ">> The exit leading of the lift is either missing or bad. You need to recreate it.";
tmp = (| (.entrances())[1] |);
if (!tmp || !valid(tmp) || !tmp.is($exit)) {
user().tell(">> This elevator doesn't seem to have any valid entrances. Skipping this step.");
} else {
// Link the exit to the first room in the entrances list
(> out.relink(tmp.source()) <);
// Reset the lock
(> out.set_lock((<$true_lock_frob, #[]>)) <);
}
return ">> Your lift has been reset. Have a nice day!";
.
@program $elevator.lift_dest() +access=pub
return (> (.exits())[1].dest() <);
.
@program $elevator.prose() +access=pub
arg @no_default;
var ret;
ret = [pass(@no_default)];
// This next bit prevents the destinations stuff from being added to the room desc when you are trying to edit the actual room desc.
if (caller() != $described)
ret = [@ret, "", .dests()];
return ret;
.
@program $elevator.dests() +access=pub
var x, ways, out, d;
// Returns a formatted list of destinations for appending to the room description.
// TODO: could this maybe be converted into a generator instead?
if (!(ways = .entrances()))
return "[This lift is not connected to anything]";
out = [];
for x in [1 .. listlen(ways)] {
d = (| lift_hints[ways[x]].to_english(",") |) || "";
out = [@out, (ways[x].source() == .lift_dest() ? ">" : " ") + tostr(x).right(2) + " " + ways[x].source().name().left(20).ansi("c") + ": " + d];
}
out = [@out, "", "Use \"dest?ination <# or name>\" to make a selection"];
return out;
.
@program $elevator.dest_cmd() +access=pub
arg cmdstr, cmd, str;
var o, e;
// Save so we only have to call .entrances() once
e = .entrances();
o = .match_destination(str);
if (!o || !valid(o))
return "No such destination.";
if (o.source() == .lift_dest())
return "The computer says, \"The lift is already there.\"";
.announce(user().name() + " (to computer) says, \"" + o.source().name() + "\".");
(> .queue_stop(o) <);
.
@program $elevator.queue_stop() +access=pub
arg dest;
if (!(dest in stop_queue || []))
stop_queue = [@stop_queue || [], dest];
if (!(task_id in tasks()))
$scheduler.add_task(1, 'travel_task);
.
@program $elevator.match_destination() +access=pub
arg str;
var obj, found, i;
if (str.is_numeric()) {
i = toint(str);
if (i > 0 && i <= listlen(.entrances()))
return (.entrances())[i];
else
return 0;
}
found = [];
for obj in (.entrances()) {
if (obj.source().match_name(str))
found += [obj];
if (!found && .match_lift_hint(obj, str))
found += [obj];
}
if (listlen(found) == 1)
return found[1];
return 0;
.
@program $elevator.match_lift_hint() +access=pub
arg ele, str;
var m, a, hints;
if (!str)
return 0;
hints = (| lift_hints[ele] |) || [];
if (!hints)
return 0;
for a in (hints || []) {
if ((m = match_begin(a, str)))
return m;
}
return 0;
.
@program $elevator.parse_lift_hints() +access=pub
arg value, @args;
var objs, o;
objs = [];
for o in (value.explode(",")) {
o = o.trim();
if (o)
objs = setadd(objs, o);
}
return objs;
.
@program $elevator.set_lift_hints() +access=pub
arg name, definer, value, @args;
set_var('lift_hints, value);
.
@program $elevator.set_lift_hint_cmd() +access=pub
arg cmstr, cmd, this, prep, iobjstr;
var target, out, line, x;
target = .match_destination(this);
if (!target)
return ">> No such destination.";
if (!iobjstr)
return ">> You must give at least one argument.";
out = [];
for x in (iobjstr.explode(","))
out = [@out, x.trim()];
if (!out)
return ">> I couldn't parse any destinations from what you gave me.";
(> (lift_hints = dict_add(lift_hints || #[], target, out)) <);
return ">> You set the lift hints for " + target.namef('xref) + " to: " + out.join(",") + ".";
.
@program $elevator.lift_hints() +access=pub
return lift_hints || #[];
.
@program $elevator.travel_task() +access=pub
var tmp, out, wdelay, sdelay;
out = (> (.exits())[1] <);
if (!out || !out.is($exit))
throw(~etype, "Object is not an $exit.");
task_id = task_id();
sdelay = 5;
wdelay = 5;
while (stop_queue != []) {
.announce("The doors slide shut and the lift begins to move.");
tmp = stop_queue[1];
out.dest().announce("The lift doors slide shut.");
out.set_lock((<$false_lock_frob, #[]>));
$scheduler.sleep(wdelay);
if (stop_queue.length() == 1)
stop_queue = [];
else
stop_queue = stop_queue.subrange(2);
$scheduler.sleep(sdelay);
tmp.source().announce("The lift has arrived on this level.");
.announce("The lift comes to a stop and the doors slide open at " + tmp.source().name() + ".");
(> out.relink(tmp.source()) <);
(> out.set_lock((<$true_lock_frob, #[]>)) <);
if (stop_queue != [])
$scheduler.sleep(5);
}
.
@program $elevator.initialize_elevator() +access=pub
stop_queue = [];
task_id = -1;
lift_hints = #[];
.
@program $elevator.acceptable() +access=pub
arg actor, mover, room;
// Allow the destination to deny the move.
if (.lift_dest() != room) {
actor.tell("You call the lift.");
actor.location().announce(tostr(actor.name() + " calls the lift."), actor);
.queue_stop(mover);
return 0;
}
return 1;
.
I am new to programming these types of games but I know a little C++. I have a test server set up as I try to figure out how to do basic things.
my situation right now is that I am trying to make an elevator which would travel through several rooms I have created. I have been told I need to create a dynamic door to achieve this but I do not know how to go about that. Can some one please tell me step-by-step how to proceed? I know some of you might find this basic but I really don't even know how to edit an object like a door so it for example closes automatically. So when I say step-by-step I really mean it.
Thanks in advance for any help.