Version 1 (modified by trac, 16 years ago) ( diff )

--

territory(parentArea)

This is the constructor. It defines the parent area.

divide(int)

This method equally divides the territory a specified number of times.

next()

This method increments to the next divided area.

isValid()

This method returns whether or not there are more divided areas to iterate through: true/false.

reset()

This method resets to the first divided area.

retrieve(int)

This method returns an area object of a specified divided area.

Here is a sample code of how to implement territories:

  1: 
  2: terr = new territory(MAP);
  3: terr.divide(player.num);
  4: terr.create;
  5: 
  6: prov = new array(player.num);
  7: 
  8: for(terr.reset;terr.isValid;terr.next)
  9: {
 10:    prov[terr.current] = new territory(terr.retrieve);
 11:    prov[terr.current].divide(4);
 12:    prov[terr.current].create;
 13: }
 14: 
 15: function attrition()
 16: {
 17:    for(i=0;i < player.num;i++)
 18:    {
 19:        for(x=0;x < player.num;x++)
 20:        {
 21:            if(playerinarea(i, terr.retrieve(x)) && x != i)
 22:            {
 23:                playerAttrit(i, terr.retrieve(x), 20);
 24:            }
 25:            else
 26:            {
 27:                playerAttrit(i, terr.retrieve(x));
 28:            }
 29:        }
 30:    }
 31: }
 32: 
 33: trigAttrition = new trigger("attrition");
 34: trigAttrition.enable;
  • Line 2 creates a territory object within the whole map area
  • Line 3 divides the territory by the number of players
  • Line 4 registers the territory
  • Line 6 defines an array, an item for each player
  • Line 8 defines a loop that uses the territory's iterator to go through each divided territory
  • Line 10 creates a new territory object for each divided territory (provinces)
  • Line 11 divides each territory by 4
  • Line 12 registeres each territory
  • Line 15-31 defines the trigger function for attrition. It loops through each player checking if a player finds his way into another player's territory and starts off the attrition effect. "&& x != i" makes sure it doesn't run the attrition on a player for being on his own territory. Calling the effect without an interval unregisters the attrition so as to cancel the effect.
Note: See TracWiki for help on using the wiki.