Changes between Initial Version and Version 1 of RMS:Territories


Ignore:
Timestamp:
Feb 23, 2008, 4:18:59 AM (16 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • RMS:Territories

    v1 v1  
     1== territory(parentArea) ==
     2This is the constructor. It defines the parent area.
     3== divide(int) ==
     4This method equally divides the territory a specified number of times.
     5== next() ==
     6This method increments to the next divided area.
     7== isValid() ==
     8This method returns whether or not there are more divided areas to iterate through: true/false.
     9== reset() ==
     10This method resets to the first divided area.
     11== retrieve(int) ==
     12This method returns an area object of a specified divided area.
     13
     14Here is a sample code of how to implement territories:
     15
     16{{{
     17  1:
     18  2: terr = new territory(MAP);
     19  3: terr.divide(player.num);
     20  4: terr.create;
     21  5:
     22  6: prov = new array(player.num);
     23  7:
     24  8: for(terr.reset;terr.isValid;terr.next)
     25  9: {
     26 10:    prov[terr.current] = new territory(terr.retrieve);
     27 11:    prov[terr.current].divide(4);
     28 12:    prov[terr.current].create;
     29 13: }
     30 14:
     31 15: function attrition()
     32 16: {
     33 17:    for(i=0;i < player.num;i++)
     34 18:    {
     35 19:        for(x=0;x < player.num;x++)
     36 20:        {
     37 21:            if(playerinarea(i, terr.retrieve(x)) && x != i)
     38 22:            {
     39 23:                playerAttrit(i, terr.retrieve(x), 20);
     40 24:            }
     41 25:            else
     42 26:            {
     43 27:                playerAttrit(i, terr.retrieve(x));
     44 28:            }
     45 29:        }
     46 30:    }
     47 31: }
     48 32:
     49 33: trigAttrition = new trigger("attrition");
     50 34: trigAttrition.enable;
     51}}}
     52
     53 * Line 2 creates a territory object within the whole map area
     54 * Line 3 divides the territory by the number of players
     55 * Line 4 registers the territory
     56 * Line 6 defines an array, an item for each player
     57 * Line 8 defines a loop that uses the territory's iterator to go through each divided territory
     58 * Line 10 creates a new territory object for each divided territory (provinces)
     59 * Line 11 divides each territory by 4
     60 * Line 12 registeres each territory
     61 * 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.