1 /* ======================================================================= */
3 /* ======================================================================= */
6 // Locations or Agents are both of type generic_object. Generic_objects may
7 // have states, and are responsible for updating their states appropriately
8 // when their step() functions are executed.
10 extern void init_registry(void);
11 extern void step_everybody(void);
15 int where_in_registry;
17 generic_object(); // enter generic_object into ObjectRegistry
18 // We never copy generic_objects, so we don't need a copy constructor.
19 ~generic_object(void); // delete from ObjectRegistry
20 // Simulation steps, accomodate different kinds of time
21 virtual void compute_next_state(void) { }
22 virtual void step(void) { }
25 // =======================================================================
27 // Locations can be regular (like a field of squares or hexagons) or
28 // irregular. Regular locations have 2-D or 3-D positions represented
29 // by integers. Locations are never copied; no need for copy constructors.
31 const int max_num_directions = 6; // handles both cubes and hexagons
33 class location: public generic_object
35 // Any kind of location needs a physical position, but for a regular
36 // location, this may be implicit, and for an irregular location, it
37 // should be custom-defined.
39 // Any kind of location needs a private list of neighbors, but for a
40 // regular location, this may be implicit.
47 class irregular_location: public location
51 irregular_location(double xi, double yi, double zi)
52 { x = xi; y = yi; z = zi; }
53 ~irregular_location();
56 class discrete_location: public location
59 class location *neighbors[max_num_directions];
60 void clear_neighbors(void);
62 discrete_location(int xi, int yi, int zi):
64 { clear_neighbors(); }
65 ~discrete_location(void);
66 void assign_neighbor(int direction, location *x)
67 { neighbors[direction] = x; }
70 // =======================================================================
72 // Agents are generic_objects with locations, who can move. Examples in
73 // Pacman would be the protagonist, the monsters, and the monsters' ghosts.
75 class agent: public generic_object