May 13th, 2002

  • catpad

AOS example

/* The assumption is that I am on WEST, the enemy is on EAST */

Staff {

   on start {
      create 20 p1,p2,p3 as Peasant;
      /* Send peasants to north, west, south */
      set dir = north;
      send 1 message "init_peasant" to p1;
      set dir = west;
      send 1 message "init_peasant" to p2;
      set dir = south;
      send 1 message "init_peasant" to p3;
      
      create 20 a1,a2,a3 as Attacker;
      send 1 "up" to d1,d2,d3;
      send 1 "down" to a1,a2,a3;
   }   	   	
   	
   on kill {
      select by initiator.type {
         on Peasant { 
            /* simply replace the peasant */
            create 20 initiator.name as Peasant;
            set dir = initiator.direction;
            send 1 message "init_peasant";
         }
      }
   }
 
  on message "enemy_agent_located" {
     /* summon Attackers to the initiator.location */
TODO
  }

  on message "enemy_staff_located" {
     /* summon Attackers to the initiator.location */
TODO
  }
      	
}

Agent Peasant {
	
   on message "init_peasant" {
      turn to initiator.dir;
      move 20;
      timer 10 "collect";
   }
   
   on timer "collect" {
      pump 5 to Staff;
      timer 10 "collect";
   }   
}



Agent Spy {
   
   on creation {   	
   	turn east;
   	shield 20;
   	move 20;
   	radar 20;
   	timer 5 "migrate";
   }
   
   on timer "migrate" {
   	/* After some time migrate to another location */
   	turn right;
   	move 20;
   	/* reset timer */
   	timer 5 "migrate";
   }
      
   on attack {
        /* Defend yourself by all means */
   	shield me.mana;
   }
   
   on radar {
      select by initiator.type {
         /* Only enemies are interesting for Spy */
         on enemy.Agent {
            send Staff.distance "enemy_agent_located" to Staff;
         }
         in enemy.Staff {
            send Staff.distance "enemy_staff_located" to Staff;         
         }
      }
   }
      
   on touch {
   }
   
}