schedule.h

Go to the documentation of this file.
00001 /*
00002  *  Schedule.h - Schedules for characters.
00003  *
00004  *  Copyright (C) 2000-2001  The Exult Team
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #ifndef SCHEDULE_H
00022 #define SCHEDULE_H  1
00023 
00024 #include "tiles.h"
00025 #include "vec.h"
00026 #include "lists.h"
00027 #include "singles.h"
00028 
00029 #ifdef WIN32
00030 #include <windows.h>
00031 #define Rectangle RECTX
00032 #endif
00033 
00034 class Game_object;
00035 class Actor;
00036 class Rectangle;
00037 class Actor_action;
00038 
00039 /*
00040  *  A Schedule controls the NPC it is assigned to.
00041  */
00042 class Schedule : public Game_singletons
00043   {
00044 protected:
00045   Actor *npc;     // Who this controls.
00046   Tile_coord blocked;   // Tile where actor was blocked.
00047   short prev_type;    // Actor's previous schedule.
00048   int street_maintenance_failures;// # times failed to find path.
00049   long street_maintenance_time; // Time (msecs) when last tried.
00050 public:
00051   Schedule(Actor *n);
00052   virtual ~Schedule()
00053     {  }
00054   int get_prev_type() const
00055     { return prev_type; }
00056   void set_blocked(Tile_coord b)
00057     { blocked = b; }
00058   enum Schedule_types {
00059     combat = 0, horiz_pace = 1,
00060     vert_pace = 2,  talk = 3,
00061     dance = 4,  eat = 5,
00062     farm = 6, tend_shop = 7,
00063     miner = 8,  hound = 9,
00064     stand = 10, loiter = 11,
00065     wander = 12,  blacksmith = 13,
00066     sleep = 14, wait = 15,
00067     sit = 16, graze = 17,
00068     bake = 18,  sew = 19,
00069     shy = 20, lab = 21,
00070     thief = 22, waiter = 23,
00071     special = 24, kid_games = 25,
00072     eat_at_inn = 26,duel = 27,
00073     preach = 28,  patrol = 29,
00074     desk_work = 30, follow_avatar = 31,
00075           // Our own:
00076     walk_to_schedule = 32,
00077     street_maintenance = 33
00078     };
00079           // Set actor to walk somewhere, then
00080           //   do something.
00081   static void set_action_sequence(Actor *actor, Tile_coord dest,
00082     Actor_action *when_there, bool from_off_screen = false,
00083               int delay = 0);
00084   int try_street_maintenance(); // Handle street-lamps, shutters.
00085   virtual void now_what() = 0;  // Npc calls this when it's done
00086           //   with its last task.
00087   virtual void im_dormant() // Npc calls this when it goes from
00088     {  }      //   being active to dormant.
00089   virtual void ending(int newtype)// Switching to another schedule.
00090     {  }
00091   virtual void set_weapon() // Set weapon info.
00092     {  }
00093           // Set where to sleep.
00094   virtual void set_bed(Game_object *b)
00095     {  }
00096           // Notify that schedule's obj. has
00097           //   been moved.
00098   virtual void notify_object_gone(Game_object *obj)
00099     {  }
00100           // For Usecode intrinsic.
00101   virtual int get_actual_type(Actor *npc);
00102   };
00103 
00104 /*
00105  *  Street maintenance (turn lamps on/off).
00106  */
00107 class Street_maintenance_schedule : public Schedule
00108   {
00109   Game_object *obj;   // Lamp/shutters.
00110   int shapenum, framenum;   // Save original shapenum.
00111   Actor_action *paction;    // Path to follow to get there.
00112 public:
00113   Street_maintenance_schedule(Actor *n, Actor_action *p, Game_object *o);
00114   virtual void now_what();
00115           // For Usecode intrinsic.
00116   virtual int get_actual_type(Actor *npc);
00117   };
00118 
00119 /*
00120  *  For following the Avatar (by party members):
00121  */
00122 class Follow_avatar_schedule : public Schedule
00123   {
00124   unsigned long next_path_time; // Next time we're allowed to use
00125           //   pathfinding to follow leader.
00126 public:
00127   Follow_avatar_schedule(Actor *n) : Schedule(n), next_path_time(0)
00128     {  }
00129   virtual void now_what();  // Now what should NPC do?
00130   };
00131 
00132 /*
00133  *  A 'do nothing' schedule.
00134  */
00135 class Wait_schedule : public Schedule
00136   {
00137 public:
00138   Wait_schedule(Actor *n) : Schedule(n)
00139     {  }
00140   virtual void now_what();  // Now what should NPC do?
00141   };
00142 
00143 /*
00144  *  A schedule for pacing between two points:
00145  */
00146 class Pace_schedule : public Schedule
00147   {
00148   Tile_coord p0;      // Point 0 tile coords.
00149   Tile_coord p1;      // Point 1 tile coords.
00150   char which;     // Which he's going to (0 or 1).
00151 public:
00152   Pace_schedule(Actor *n, Tile_coord pt0, Tile_coord pt1)
00153     : Schedule(n), p0(pt0), p1(pt1), which(0)
00154     {  }
00155           // Create common schedules:
00156   static Pace_schedule *create_horiz(Actor *n);
00157   static Pace_schedule *create_vert(Actor *n);
00158   virtual void now_what();  // Now what should NPC do?
00159   };
00160 
00161 /*
00162  *  A schedule for eating at an inn.
00163  */
00164 class Eat_at_inn_schedule : public Schedule
00165   {
00166 public:
00167   Eat_at_inn_schedule(Actor *n) : Schedule(n)
00168     {  }
00169   virtual void now_what();  // Now what should NPC do?
00170   };
00171 
00172 /*
00173  *  A schedule for preaching.
00174  */
00175 class Preach_schedule : public Schedule
00176   {
00177   enum {
00178     find_podium,
00179     at_podium,
00180     exhort,
00181     visit,
00182     talk_member,
00183     find_icon,
00184     pray
00185     } state;
00186 public:
00187   Preach_schedule(Actor *n) : Schedule(n), state(find_podium)
00188     {  }
00189   virtual void now_what();  // Now what should NPC do?
00190   };
00191 
00192 /*
00193  *  A schedule for patrolling along 'path' objects.
00194  */
00195 class Patrol_schedule : public Schedule
00196   {
00197   Game_object_vector paths; // Each 'path' object.
00198   int pathnum;      // # of next we're heading towards.
00199   int dir;      // 1 or -1;
00200   int failures;     // # of failures to find marker.
00201   bool sitting;     // Sat down for one of the paths.
00202   bool find_next;     // Search for next path object.
00203 public:
00204   Patrol_schedule(Actor *n)
00205     : Schedule(n), pathnum(-1), dir(1), failures(0),
00206       sitting(false), find_next(true)
00207     {  }
00208   virtual void now_what();  // Now what should NPC do?
00209   };
00210 
00211 /*
00212  *  Talk to avatar.
00213  */
00214 class Talk_schedule : public Schedule
00215   {
00216   int phase;      // 0=walk to Av., 1=talk, 2=done.
00217 public:
00218   Talk_schedule(Actor *n) : Schedule(n), phase(0)
00219     {  }
00220   virtual void now_what();  // Now what should NPC do?
00221   };
00222 
00223 /*
00224  *  Loiter within a rectangle.
00225  */
00226 class Loiter_schedule : public Schedule
00227   {
00228 protected:
00229   Tile_coord center;    // Center of rectangle.
00230   int dist;     // Distance in tiles to roam in each
00231           //   dir.
00232 public:
00233   Loiter_schedule(Actor *n, int d = 12);
00234   virtual void now_what();  // Now what should NPC do?
00235   };
00236 
00237 /*
00238  *  Kid games.
00239  */
00240 class Kid_games_schedule : public Loiter_schedule
00241   {
00242   Actor_queue kids;     // Other kids playing.
00243 public:
00244   Kid_games_schedule(Actor *n) : Loiter_schedule(n, 10)
00245     {  }
00246   virtual void now_what();  // Now what should NPC do?
00247   };
00248 
00249 /*
00250  *  Dance.
00251  */
00252 class Dance_schedule : public Loiter_schedule
00253   {
00254 public:
00255   Dance_schedule(Actor *n) : Loiter_schedule(n, 4)
00256     {  }
00257   virtual void now_what();  // Now what should NPC do?
00258   };
00259 
00260 /*
00261  *  Miner/farmer:
00262  */
00263 class Tool_schedule : public Loiter_schedule
00264   {
00265   int toolshape;      // Pick/scythe shape.
00266   Game_object *tool;
00267 public:
00268   Tool_schedule(Actor *n, int shnum) : Loiter_schedule(n, 12), 
00269           toolshape(shnum), tool(0)
00270     {  }
00271   virtual void now_what();  // Now what should NPC do?
00272   virtual void ending(int newtype);// Switching to another schedule.
00273   };
00274 
00275 /*
00276  *  Hound the Avatar.
00277  */
00278 class Hound_schedule : public Schedule
00279   {
00280 public:
00281   Hound_schedule(Actor *n) : Schedule(n)
00282     {  }
00283   virtual void now_what();  // Now what should NPC do?
00284   };
00285 
00286 /*
00287  *  Wander all over the place, using pathfinding.
00288  */
00289 class Wander_schedule : public Loiter_schedule
00290   {
00291 public:
00292   Wander_schedule(Actor *n) : Loiter_schedule(n, 128)
00293     {  }
00294   virtual void now_what();  // Now what should NPC do?
00295   };
00296 
00297 /*
00298  *  Sleep in a  bed.
00299  */
00300 class Sleep_schedule : public Schedule
00301   {
00302   Tile_coord floorloc;    // Where NPC was standing before.
00303   Game_object *bed;   // Bed being slept on, or 0.
00304   int state;
00305   int spread0, spread1;   // Range of bedspread frames.
00306 public:
00307   Sleep_schedule(Actor *n);
00308   virtual void now_what();  // Now what should NPC do?
00309   virtual void ending(int newtype);// Switching to another schedule.
00310           // Set where to sleep.
00311   virtual void set_bed(Game_object *b)
00312     { bed = b; state = 0; }
00313   };
00314 
00315 /*
00316  *  Sit in a chair.
00317  */
00318 class Sit_schedule : public Schedule
00319   {
00320   Game_object *chair;   // What to sit in.
00321   bool sat;     // True if we already sat down.
00322   bool did_barge_usecode;   // So we only call it once.
00323 public:
00324   Sit_schedule(Actor *n, Game_object *ch = 0);
00325   virtual void now_what();  // Now what should NPC do?
00326   static bool is_occupied(Game_object *chairobj, Actor *actor);
00327   static bool set_action(Actor *actor, Game_object *chairobj = 0,
00328         int delay = 0, Game_object **chair_found = 0);
00329   };
00330 
00331 /*
00332  *  Desk work - Just sit in front of desk.
00333  */
00334 class Desk_schedule : public Schedule
00335   {
00336   Game_object *chair;   // What to sit in.
00337 public:
00338   Desk_schedule(Actor *n);
00339   virtual void now_what();  // Now what should NPC do?
00340   };
00341 
00342 /*
00343  *  Shy away from Avatar.
00344  */
00345 class Shy_schedule : public Schedule
00346   {
00347 public:
00348   Shy_schedule(Actor *n) : Schedule(n)
00349     {  }
00350   virtual void now_what();  // Now what should NPC do?
00351   };
00352 
00353 /*
00354  *  Lab work.
00355  */
00356 class Lab_schedule : public Schedule
00357   {
00358   Game_object_vector tables;
00359   Game_object *chair;   // Chair to sit in.
00360   Game_object *book;    // Book to read.
00361   Game_object *cauldron;
00362   Tile_coord spot_on_table;
00363   enum {
00364     start,
00365     walk_to_cauldron,
00366     use_cauldron,
00367     sit_down,
00368     read_book,
00369     stand_up,
00370     walk_to_table,
00371     use_potion
00372   } state;
00373   void init();
00374 public:
00375   Lab_schedule(Actor *n);
00376   virtual void now_what();  // Now what should NPC do?
00377   };
00378 
00379 /*
00380  *  Wait tables.
00381  */
00382 class Waiter_schedule : public Schedule
00383   {
00384   int first;      // 1 if first 'what_next()' called.
00385   Tile_coord startpos;    // Starting position.
00386   Actor *customer;    // Current customer.
00387   Actor_queue customers;    // List of customers.
00388   Game_object_vector prep_tables;   // Prep. tables.
00389   Game_object_vector eating_tables;   // Tables with chairs around them.
00390   void get_customer();
00391   void find_tables(int shapenum);
00392   Game_object *find_serving_spot(Tile_coord& spot);
00393 public:
00394   Waiter_schedule(Actor *n);
00395   virtual void now_what();  // Now what should NPC do?
00396   virtual void ending(int newtype);// Switching to another schedule.
00397   };
00398 
00399 /*
00400  *  Sew/weave schedule.
00401  */
00402 class Sew_schedule : public Schedule
00403   {
00404   Game_object *bale;    // Bale of wool.
00405   Game_object *spinwheel;
00406   Game_object *chair;   // In front of spinning wheel.
00407   Game_object *spindle;   // Spindle of thread.
00408   Game_object *loom;
00409   Game_object *cloth;
00410   Game_object *work_table, *wares_table;
00411   int sew_clothes_cnt;
00412   enum {
00413     get_wool,
00414     sit_at_wheel,
00415     spin_wool,
00416     get_thread,
00417     weave_cloth,
00418     get_cloth,
00419     to_work_table,
00420     set_to_sew,
00421     sew_clothes,
00422     get_clothes,
00423     display_clothes,
00424     done
00425   } state;
00426 public:
00427   Sew_schedule(Actor *n);
00428   virtual void now_what();  // Now what should NPC do?
00429   virtual void ending(int newtype);// Switching to another schedule.
00430   };
00431 
00432 /*
00433  *  Bake schedule
00434  */
00435 class Bake_schedule : public Schedule
00436 {
00437   Game_object *oven;
00438   Game_object *worktable;
00439   Game_object *displaytable;
00440   Game_object *flourbag;
00441   Game_object *dough;
00442   Game_object *dough_in_oven;
00443   int baked_count;
00444   enum {
00445     to_flour,
00446     get_flour,
00447     to_table,
00448     make_dough,
00449     remove_from_oven,
00450     display_wares,
00451     get_dough,
00452     put_in_oven
00453   } state;
00454 public:
00455   Bake_schedule(Actor *n);
00456   virtual void now_what();
00457   virtual void ending(int newtype);
00458   virtual void notify_object_gone(Game_object *obj);
00459 };
00460 
00461 /*
00462  *  Blacksmith schedule
00463  */
00464 class Forge_schedule : public Schedule
00465 {
00466   Game_object *tongs;
00467   Game_object *hammer;
00468   Game_object *blank;
00469   Game_object *firepit;
00470   Game_object *anvil;
00471   Game_object *trough;
00472   Game_object *bellows;
00473   enum {
00474     put_sword_on_firepit,
00475     use_bellows,
00476     get_tongs,
00477     sword_on_anvil,
00478     get_hammer,
00479     use_hammer,
00480     walk_to_trough,
00481     fill_trough,
00482     get_tongs2,
00483     use_trough,
00484     done
00485   } state;
00486 public:
00487   Forge_schedule(Actor *n);
00488   virtual void now_what();  // Now what should NPC do?
00489   virtual void ending(int newtype); // Switching to another schedule
00490 };
00491 
00492 /*
00493  *  Walk to the destination for a new schedule.
00494  */
00495 class Walk_to_schedule : public Schedule
00496   {
00497   Tile_coord dest;    // Where we're going.
00498   int first_delay;    // Starting delay (1/1000's sec.)
00499   int new_schedule;   // Schedule to set when we get there.
00500   int retries;      // # failures at finding path.
00501   int legs;     // # times restarted walk.
00502           // Set to walk off screen.
00503   void walk_off_screen(Rectangle& screen, Tile_coord& goal);
00504 public:
00505   Walk_to_schedule(Actor *n, Tile_coord d, int new_sched,
00506               int delay = -1);
00507   virtual void now_what();  // Now what should NPC do?
00508   virtual void im_dormant();  // Just went dormant.
00509           // For Usecode intrinsic.
00510   virtual int get_actual_type(Actor *npc);
00511   };
00512 
00513 /*
00514  *  An NPC schedule change:
00515  */
00516 class Schedule_change
00517   {
00518   unsigned char time;   // Time*3hours when this takes effect.
00519   unsigned char type;   // Schedule_type value.
00520   unsigned char x, y;   // Location within superchunk.
00521   unsigned char superchunk; // 0-143.
00522 public:
00523   Schedule_change() : time(0), type(0), x(0), y(0), superchunk(0)
00524     {  }
00525   void set(unsigned char *ent); // Create from 4-byte entry.
00526   void get(unsigned char *ent); // Get 4-byte entry.
00527   void set(int ax, int ay, unsigned char stype, unsigned char stime);
00528   int get_type() const
00529     { return type; }
00530   int get_time() const
00531     { return time; }
00532   Tile_coord get_pos() const; // Get position chunk, tile.
00533   };
00534 
00535 #endif

Generated on Mon Jul 9 14:42:50 2007 for ExultEngine by  doxygen 1.5.1