• Advertisement
  • entries
    740
  • comments
    957
  • views
    730553

More Scheduling Goodness, Special Blocks Done

Sign in to follow this  

44 views

Schedule Manager 2.0

I've improved upon the schedule manager, here's the changes:
  • addObject now addFunction - Changed this to better clarify what this function is doing, and also because of the next item

  • Command execution - now you can call addCommand in order to schedule a one-line command to be carried out at the given time (example below)

  • Constructor/destructor - making use of onAdd and onRemove to handle some internal stuff (thanks bank!)
The coolest part is, of course, the ability to schedule commands now as well as functions. So for example if your player trips a trap that throws a flag and in 15 seconds you want that flag reset, instead of having to create a function to call to reset a single flag you can just do
Schedule.addCommand(false, 15000, "Trap.doorshut = true;");
Wheeee. Here's the updated code:


//---------------------------------------------------------------------------------------------
// File : schedule.cs
// Copyright : Blade Edge Software (C) 2006 - 2007
// Author : Drew Sikora
//---------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------
// Name : onAdd
// Class : Schedule
//
// Description : used to create the ScriptGroup that will hold all our appointments
//---------------------------------------------------------------------------------------------
function Schedule::onAdd(%this)
{
%this.appointments = new ScriptGroup();

} // end onAdd


//---------------------------------------------------------------------------------------------
// Name : onRemove
// Class : Schedule
//
// Description : in case you forget to call remove() with no arguments to delete all scheduled
// : events at the end of the game, this does it for you
//---------------------------------------------------------------------------------------------
function Schedule::onRemove(%this)
{
%this.appointments.remove();

} // end onRemove


new ScriptObject(Schedule);


//---------------------------------------------------------------------------------------------
// Name : addFunction
// Class : Schedule
//
// Arguments : repeat - whether the scheduled call repeats
// : [object] - the object this function belongs to
// : time - the time until the appointment is executed
// : funcName - the name of the function we will be calling
// : [argumentList] - the list of arguments to apply to ths function call
//
// Description : adds a new appointment to the schedule manager and stores the handle and appointment
// : data for later reference. Functions without objects should pass "" for %object
//---------------------------------------------------------------------------------------------
function Schedule::addFunction(%this, %repeat, %object, %time, %funcName, %argumentList)
{
%appointment = new ScriptObject()
{
id = %this.id++;
object = %object;
repeat = %repeat;
time = %time;
funcName = %funcName;
arguments = %argumentList;
handle = %this.schedule(%time, "call", %this.id);
};

// store appointment and return handle to caller
%this.appointments.add(%appointment);
return %appointment.handle;

} // end addFunction


//---------------------------------------------------------------------------------------------
// Name : addCommand
// Class : Schedule
//
// Arguments : repeat - whether the scheduled call repeats
// : time - the time until the appointment is executed
// : command - the command to execute
//
// Description : adds a new appointment to the schedule manager and stores the handle and appointment
// : data for later reference. Make sure all commands are terminated with a semi-colon
//---------------------------------------------------------------------------------------------
function Schedule::addCommand(%this, %repeat, %time, %command)
{
%appointment = new ScriptObject()
{
id = %this.id++;
repeat = %repeat;
time = %time;
command = %command;
handle = %this.schedule(%time, "call", %this.id);
};

// store appointment and return handle to caller
%this.appointments.add(%appointment);
return %appointment.handle;

} // end addCommand


//---------------------------------------------------------------------------------------------
// Name : remove
// Class : Schedule
//
// Arguments : [apptHandle] - the handle to the appointment we want to cancel/remove
//
// Description : removes an appointment from the schedule manager and cancels the scheduled event.
// : if apptHandle is unused, all appointments are deleted
//---------------------------------------------------------------------------------------------
function Schedule::remove(%this, %apptHandle)
{
// find the handle, cancel and remove it
for (%appt = 0; %appt < %this.appointments.getCount(); %appt++)
{
if ((%apptHandle !$= "") && (%this.appointments.getObject(%appt).handle == %apptHandle))
{
cancel(%this.appointments.getObject(%appt).handle);
%this.appointments.remove(%this.appointments.getObject(%appt));
break;
}
else if (%apptHandle $= "")
cancel(%this.appointments.getObject(%appt).handle);
}

if (%apptHandle $= "")
%this.appointments.delete();

} // end remove


//---------------------------------------------------------------------------------------------
// Name : pause
// Class : Schedule
//
// Arguments : isPaused - whether to pause (true) or unpause (false) all scheduled events
//
// Description : Cancels all scheduled events and stores their remaining time for reactivation
// : when game is unpaused
//---------------------------------------------------------------------------------------------
function Schedule::pause(%this, %isPaused)
{
if (%isPaused)
{
for (%appt = 0; %appt < %this.appointments.getCount(); %appt++)
{
%this.appointments.getObject(%appt).timeLeft = getEventTimeLeft(%this.appointments.getObject(%appt).handle);
cancel(%this.appointments.getObject(%appt).handle);
}
}
else
{
for (%appt = 0; %appt < %this.appointments.getCount(); %appt++)
{
%this.appointments.getObject(%appt).handle = %this.schedule(%this.appointments.getObject(%appt).timeLeft, "call", %this.appointments.getObject(%appt).id);
}
}

} // end pause


//---------------------------------------------------------------------------------------------
// Name : call
// Class : Schedule
//
// Arguments : id - the unique id assigned to this appointment
//
// Description : is called to carry out scheduled function call but also to loop the event or
// : remove it from our appointment group
//---------------------------------------------------------------------------------------------
function Schedule::call(%this, %id)
{
// find the appointment
for (%appt = 0; %appt < %this.appointments.getCount(); %appt++)
{
if (%this.appointments.getObject(%appt).id == %id)
{
// check for any arguments
if (%this.appointments.getObject(%appt).arguments !$= "")
{
// first argument has no comma or space
%args = getWord(%this.appointments.getObject(%appt).arguments, 0);

for(%arg = 1; %arg < getWordCount(%this.appointments.getObject(%appt).arguments); %arg++)
{
%args = %args @ "," SPC getWord(%this.appointments.getObject(%appt).arguments, %arg);
}
}

// write out the command or function call and execute
if (%this.appointments.getObject(%appt).funcName !$= "")
{
if (%this.appointments.getObject(%appt).object !$= "")
%call = %this.appointments.getObject(%appt).object @ ".";

%call = %call @ %this.appointments.getObject(%appt).funcName @ "(" @ %args @ ");";
}
else if (%this.appointments.getObject(%appt).command !$= "")
{
%call = %this.appointments.getObject(%appt).command;
}
eval(%call);

// renew appointment or delete?
if (%this.appointments.getObject(%appt).repeat)
%this.appointments.getObject(%appt).handle = %this.schedule(%this.appointments.getObject(%appt).time, "call", %this.appointments.getObject(%appt).id);
else
%this.appointments.remove(%this.appointments.getObject(%appt));

break;
}
}

} // end call


Special Blocks Complete

All the special blocks are now working in the game. The ones I implemented today are
  • Vampire Block - lands on the stack and converts the three adjacent blocks to that player's color

  • Swap Block - this block's use can be two-fold. First, you can use it to steal the special block your opponent is holding. Second, whether you steal a block or not your swap block appears in his special block holder, and stays there for 30 seconds. Since the player stuck with the swap block can't get another special block, it has a tactical use to prevent players from getting special blocks

  • Destruction Block - Lands on the stack and destroys every enemy block from the top to the bottom in a 3-column area (1 to each side of the center)

  • Mystery Block - Randomly morphs into any of the other special blocks when dropped

  • Randomizer Block - lands on the stack and changes the orientation of every block's discharge arrows
Next on the list

My next goal is implementing chain reactions, which let you reach down into the stack of blocks to affect enemies buried beneath. I already have some cool particle effects planned out for this, should be awesome. I'll also be adding particle effect explosions and other polish over the coming week, as well as breaking the game down into Timed and High Score game types with both Blitz and Direct game modes.

Phew, got a lot of work ahead of me...
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement