From SRASWiki

Jump to: navigation, search


Engine Implementation


The engine has been built entirely in PHP. The engine pulls in an XML scenario file and constructs the game object. At the end of each turn a method is called which represents advancing in time. The page index.php creates the game object and stores it in a session, an initial tick is also performed. The flash is also embedded on this page. Upon pressing end turn in the flash game, the allocations are POSTED to the page flashPost.php which retrieves the game object from the session and calls the tick method with the posted allocations.


Class Diagram


This class contains the methods required in order to read the scenario xml into the engine and create the relevent objects. For example the loadNpcs() method reads all of the NPC's from the XML file and creates an NPC object for each of them. This object is then stored and returned in an Array. All of the methods work in the same way for:

  • loadNpcs()
  • loadPcs()
  • loadEvents()
  • scheduleEvents()


The game class is the class that represents the entire game environment. When the game is constructed the methods from setupData are used in order to create arrays of all the data required by the game. THe game class has several other methods detailed below:


This method spawns an event which occurs as a result of another event finishing. It requires two parameters:

  1. spawnArray - This is the associative array in the format Array("delay"=>10,"penalty"=>40,"eventId"=>"event10"). This array comes from the spawn object for an event.
  1. applyTo - This is the actor id of the person the spawn event should apply to.

This is a simple method to check if the supplied associative array contains no values. If any one of the values are equal to a null string("") then the method will return true.


This method reads the time given in the toProcess XML file and checks if it corresponds to the current engine time. If they do not match an error messaage is echoed.


This method loops through the currentEvents array and checks if the event has completed. If it has, the outcome (capable, incapable or expired) is determined and any spawn events created using the createSpawn method.


This method is called if an event has been completed. Four parameters are required:

  1. scheduledEvent - This is the scheduledEvent object of the event being completed
  2. key - This is the key of the event in the currentEvents array
  3. outcome - This is a string of the outcome of the event
  4. spawnArray - This is the associative array in the format Array("delay"=>10,"penalty"=>40,"eventId"=>"event10"). This array comes from the spawn object for an event.

This method collates the data and moves it from the currentEvents array to the completedEvents array for feedback purposes.


This method returns true if the given shceduledEvent is a terminating event.


This method checks all the events in future events and moves them into current events if they are scheduled to be executed at the current time


This file reads in the toProcess XML from the UI and reflects the moves made by a user in the engine. Two parameters are required:

  1. XmlToProcess - This is file path of the xmlToProcess file
  2. timeCheck - This is the boolean value, if false a timeCheck between the UI and engine will be carried out

This method is called at the end of each turn. It represents the progression of time in the engine and outputs an xml file toDraw. One parameter is required:

  1. xmlToProcess - This file path of the toProcess file from the UI.


This is an abstract class with the following properties:

  1. protected $id
  2. protected $name

In this implementation it is the parents to both #npc and #pc


This is the non playable character class. It inherits from the #actor class. It has the following property:

  1. private &npcHtmlData;


This is the playable character class, it inherits from the #actor class and has the following properties:

  • private $pcHtmlData;
  • private $available;
    • boolean field denoting if a playable character is currently occupied
  • private $rank;
    • integer value for the rank of the playable character
  • private $allocatedTo;


This class represents a event. It is the parent class of #scheduledEvent and has the following properties:

  • protected $id;
  • protected $displayText;
  • protected $defaultWindow;
  • protected $duration;
  • protected $resolution;
    • The required ranks in order to capable resolve the event
  • protected $spawn;
  • protected $terminating;


This class inherits from the #event class and has the following properties:

  • private $scheduledTime;
  • private $timeStarted;
  • private $applyTo;
  • private $expireTime;
  • private $window;
  • private $attendedBy = array();

It also has the following methods:


This method checks to see if the current event is complete and (using #capableSolution) the outcome of the event. It requires one parameter of the current engine time.


This method determines if an event has finished with a capable solution or not. Returns true if outcome is capable.


Decrements the time on the current duration


Recalls the playable characters from the current event (sets attendedBy back to an empty array).


This class represents the possible spawn events that an event can have. It has the following properties:

  • private $capable
  • private $incapable
  • private $expired

All of these three properties are arrays each holding the spawn event for that outcome.


This class contains the methods to write the toDraw XML file for inputting into the UI.

It has the following methods:


This method writes the XML for all of the npc's in NpcArray and their current statuses. Three parameters are required:

  1. xmlDoc - This is the DOMDocument
  2. rootnode - This is the rootnode to which the npcs will be added
  3. npcArray = This is the array of npcs to add to the xml

The same as above but for Pcs.


The same as above but for events.


Saves the xml to a specified file location


calls all of the above methods and writes the xml

Known Issues


There is an issue with the game if multiple people are playing the game simultaneously. User A presses end turn and a toDraw file is written, User B pressed end turn at a similar time and the data loaded in from toDraw will be from User A rather than User B. Two options to solve this problem are:

  1. Pass the session ID to the flash on index.php as a parameter in the html see here. The php can then append the session id to the xml file name and the flash with then only ever load the xml for its session. Problem: lots of xml files created.
  2. Echo the toDraw.xml out from the php rather than write it to a file. The flash can the retrieve this xml string using the URLLoader Object.

Sequence Diagram (OLD)

To see the diagram, go to this website and enter this code:

note over tick: invoke and receive data tick->paramArray: check for rtrumps paramArray->tick: return rtrump data activate tick note left of tick: evaluate rtrumps tick-->xmlStore: add resources deactivate tick tick->happeningNow[]: decrement happeningNow[]-->tick: return terminated events activate tick tick->Scenario Representation:generate implications for events Scenario Representation -> tick:return feedback and spawn tick->Feedback Diary: store feedback tick-->schedule:add spawn tick-->happeningNow[]:add spawn deactivate tick tick->paramArray:get event allocations paramArray->tick:return event allocations tick->happeningNow[]:update tick->schedule:get starting events schedule->tick: return starting events tick->happeningNow[]:add starting events tick->xmlStore: get HappeningNow and write out xmlStore->happeningNow[]: give me details happeningNow[]->xmlStore: return events note over xmlStore: write to XML

Personal tools