gamewin.h

Go to the documentation of this file.
00001 /*
00002  *  gamewin.h - X-windows Ultima7 map browser.
00003  *
00004  *  Copyright (C) 1998-1999  Jeffrey S. Freedman
00005  *  Copyright (C) 2000-2001  The Exult Team
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020  */
00021 
00022 #ifndef GAMEWIN_H
00023 #define GAMEWIN_H
00024 
00025 #include "flags.h"
00026 #include "iwin8.h"
00027 #include "lists.h"
00028 #include "rect.h"
00029 #include "tiles.h"
00030 #include "vgafile.h"
00031 
00032 #include <string> // STL string
00033 #include "vec.h"
00034 
00035 #define RED_PLASMA  1
00036 
00037 #ifdef RED_PLASMA
00038 #define CYCLE_RED_PLASMA()  cycle_load_palette()
00039 #else
00040 #define CYCLE_RED_PLASMA()
00041 #endif
00042 
00043 class Actor;
00044 class Barge_object;
00045 class Map_chunk;
00046 class Chunk_terrain;
00047 class Egg_object;
00048 class Font;
00049 class Game_object;
00050 class Game_clock;
00051 class Time_sensitive;
00052 class Gump;
00053 class Gump_button;
00054 class Ireg_game_object;
00055 class Dead_body;
00056 class Main_actor;
00057 class Npc_actor;
00058 class Npc_face_info;
00059 class Npc_proximity_handler;
00060 class Palette;
00061 class Time_queue;
00062 class Usecode_machine;
00063 class Deleted_objects;
00064 class Gump_manager;
00065 struct SaveGame_Details;
00066 struct SaveGame_Party;
00067 class Map_patch_collection;
00068 class Dragging_info;
00069 class Game_map;
00070 class Shape_manager;
00071 class Party_manager;
00072 class ShapeID;
00073 class Shape_info;
00074 class Game_render;
00075 class Effects_manager;
00076 
00077 /*
00078  *  The main game window:
00079  */
00080 class Game_window
00081   {
00082   static Game_window *game_window;// There's just one.
00083     // Game component classes:
00084   Dragging_info *dragging;  // Dragging info:
00085   Effects_manager *effects; // Manages special effects.
00086   Game_clock *clock;    // Keeps track of time.
00087   Game_map *map;      // Holds all terrain.
00088   Game_render *render;    // Helps with rendering.
00089   Gump_manager *gump_man;   // Open containers on screen.
00090   Party_manager *party_man; // Keeps party list.
00091   Image_window8 *win;   // Window to display into.
00092   Npc_proximity_handler *npc_prox;// Handles nearby NPC's.
00093   Palette *pal;
00094   Shape_manager *shape_man; // Manages shape file.
00095   Time_queue *tqueue;   // Time-based queue.
00096   Time_sensitive *background_noise;
00097   Usecode_machine *usecode; // Drives game plot.
00098     // Game state flags:
00099   bool combat;      // true if in combat.
00100   bool focus;     // Do we have focus?
00101   bool ice_dungeon;   // true if inside ice dungeon
00102   bool painted;     // true if we updated image buffer.
00103     // Game state values:
00104   int skip_above_actor;   // Level above actor to skip rendering.
00105   unsigned int in_dungeon;  // true if inside a dungeon.
00106   int num_npcs1;      // Number of type1 NPC's.
00107   int std_delay;      // Standard delay between frames.
00108   long time_stopped;    // For 'stop time' spell.
00109   unsigned long special_light;  // Game minute when light spell ends.
00110   int theft_warnings;   // # times warned in current chunk.
00111   short theft_cx, theft_cy; // Chunk where warnings occurred.
00112     // Gameplay objects:
00113   Barge_object *moving_barge; // ->cart/ship that's moving, or 0.
00114   Main_actor *main_actor;   // Main sprite to move around.
00115   Actor *camera_actor;    // What to center view around.
00116   Actor_vector npcs;    // Array of NPC's + the Avatar.
00117   Exult_vector<Dead_body*> bodies;// Corresponding Dead_body's.
00118   Deleted_objects *removed; // List of 'removed' objects.
00119     // Rendering info:
00120   int scrolltx, scrollty;   // Top-left tile of screen.
00121   Rectangle scroll_bounds;  // Walking outside this scrolls.
00122   Rectangle dirty;    // Dirty rectangle.
00123     // Savegames:
00124   char *save_names[10];   // Names of saved games.
00125     // Options:
00126   bool mouse3rd;      // use third (middle) mouse button
00127   bool fastmouse;
00128   bool double_click_closes_gumps;
00129   int text_bg;      // draw a dark background behind text
00130   int step_tile_delta;  // multiplier for the delta in start_actor_alt
00131   bool allow_double_right_move; // If moving with right click is allowed
00132 
00133     // Private methods:
00134   void set_scrolls(Tile_coord cent);
00135   void clear_world();   // Clear out world's contents.
00136   void read_save_names();   // Read in saved-game names.
00137   long check_time_stopped();
00138 
00139 #ifdef RED_PLASMA
00140   // Red plasma animation during game load
00141   uint32 load_palette_timer;
00142     int plasma_start_color, plasma_cycle_range;
00143 #endif
00144   
00145 public:
00146   friend class Game_render;
00147   /*
00148    *  Public flags and gameplay options:
00149    */
00150   int skip_lift;      // Skip objects with lift >= this.  0
00151           //   means 'terrain-editing' mode.
00152   bool paint_eggs;
00153   bool armageddon;    // Spell was cast.
00154   bool walk_in_formation;   // Use Party_manager for walking.
00155   int debug;
00156   /*
00157    *  Class maintenance:
00158    */
00159   Game_window(int width = 0, int height = 0, int scale = 1, 
00160               int scaler = 0);
00161   ~Game_window();
00162           // Get the one game window.
00163   static Game_window *get_instance()
00164     { return game_window; }
00165   void abort(const char *msg, ...); // Fatal error.
00166   /*
00167    *  Display:
00168    */
00169   void clear_screen(bool update = false);
00170   int get_width() const
00171     { return win->get_width(); }
00172   int get_height() const
00173     { return win->get_height(); }
00174   inline int get_scrolltx() const   // Get window offsets in tiles.
00175     { return scrolltx; }
00176   inline int get_scrollty() const
00177     { return scrollty; }
00178   inline Rectangle get_win_rect() const // Get window's rectangle.
00179     { return Rectangle(0, 0, win->get_width(), win->get_height());}
00180   Rectangle get_win_tile_rect() // Get it in tiles, rounding up.
00181     { return Rectangle(get_scrolltx(), get_scrollty(),
00182       (get_width() + c_tilesize - 1)/c_tilesize,
00183       (get_height() + c_tilesize - 1)/c_tilesize); }
00184           // Clip rectangle to window's.
00185   Rectangle clip_to_win(Rectangle r)
00186     {
00187     Rectangle wr = get_win_rect();
00188     return (r.intersect(wr));
00189     }
00190           // Resize event occurred.
00191   void resized(unsigned int neww, unsigned int newh,
00192         unsigned int newsc, unsigned int newsclr);
00193   void get_focus();   // Get/lose focus.
00194   void lose_focus();
00195   inline bool have_focus() const
00196     { return focus; }
00197   /*
00198    *  Game options:
00199    */
00200   bool get_mouse3rd() const
00201     { return mouse3rd; }
00202   void set_mouse3rd(bool m)
00203     { mouse3rd = m; }
00204   bool get_fastmouse() const
00205     { return get_win()->is_fullscreen() ? fastmouse : false; }
00206   void set_fastmouse(bool f)
00207     { fastmouse = f; }
00208   bool get_double_click_closes_gumps() const
00209     { return double_click_closes_gumps; }
00210   void set_double_click_closes_gumps(bool d)
00211     { double_click_closes_gumps = d; }
00212   int get_text_bg() const
00213     { return text_bg; }
00214   void set_text_bg(int t)
00215     { text_bg = t; }
00216   /*
00217    *  Game components:
00218    */
00219   inline Game_map *get_map() const
00220     { return map; }
00221   inline Usecode_machine *get_usecode() const
00222     { return usecode; }
00223   inline Image_window8 *get_win() const
00224     { return win; }
00225   inline Time_queue *get_tqueue() const
00226     { return tqueue; }
00227   Palette *get_pal()
00228     { return pal; }
00229   Effects_manager *get_effects()
00230     { return effects; }
00231   inline Gump_manager *get_gump_man() { return gump_man; }
00232   inline Party_manager *get_party_man() { return party_man; }
00233   inline Npc_proximity_handler *get_npc_prox()  { return npc_prox; }
00234   Game_clock *get_clock () { return clock; }
00235   /*
00236    *  ExultStudio support:
00237    */
00238   Map_patch_collection *get_map_patches();
00239           // Locate shape (for EStudio).
00240   bool locate_shape(int shapenum, bool upwards);
00241   void send_location();   // Send our location to EStudio.
00242   /*
00243    *  Gameplay data:
00244    */
00245   inline Barge_object *get_moving_barge() const
00246     { return moving_barge; }
00247   void set_moving_barge(Barge_object *b);
00248   bool is_moving();   // Is Avatar (or barge) moving?
00249   inline Main_actor *get_main_actor() const
00250     { return main_actor; }
00251   bool is_main_actor_inside()
00252     { return skip_above_actor < 31 ; }
00253           // Returns if skip_above_actor changed!
00254   bool set_above_main_actor(int lift)
00255     {
00256     if (skip_above_actor == lift) return false;
00257     skip_above_actor = lift;
00258     return true;
00259     }
00260   int get_render_skip_lift() const  // Skip rendering here.
00261     { return skip_above_actor < skip_lift ?
00262           skip_above_actor : skip_lift; }
00263   bool main_actor_dont_move();
00264   inline bool set_in_dungeon(unsigned int lift)
00265     { 
00266     if (in_dungeon == lift)
00267       return false;
00268     in_dungeon = lift;
00269     return true;
00270     }
00271   inline void set_ice_dungeon(bool ice) { ice_dungeon = ice; }
00272   inline unsigned int is_in_dungeon()
00273     { return in_dungeon; }
00274   inline bool is_special_light()  // Light spell in effect?
00275     { return special_light != 0; }
00276           // Light spell.
00277   void add_special_light(int minutes);
00278           // Handle 'stop time' spell.
00279   void set_time_stopped(long ticks);
00280   long is_time_stopped()
00281     { return !time_stopped ? 0 : check_time_stopped(); }
00282   int get_std_delay() const // Get/set animation frame delay.
00283     { return std_delay; }
00284   void set_std_delay(int msecs)
00285     { std_delay = msecs; }
00286   inline Actor *get_npc(long npc_num) const
00287     { return (npc_num >= 0 && npc_num < (int)npcs.size()) ? 
00288         npcs[npc_num] : 0; }
00289   void set_body(int npc_num, Dead_body *body)
00290     { bodies.put(npc_num, body); }
00291   Dead_body *get_body(int npc_num)
00292     { return bodies[npc_num]; }
00293   int get_num_npcs()
00294     { return npcs.size(); }
00295   int get_unused_npc();   // Find first unused NPC #.
00296   void add_npc(Actor *npc, int num);  // Add new one.
00297   inline int in_combat()    // In combat mode?
00298     { return combat; }
00299   void toggle_combat();
00300   inline bool get_frame_skipping()  // This needs doing
00301     { return true; }
00302           // Get ->party members.
00303   int get_party(Actor **list, int avatar_too = 0);
00304           // Add npc to 'nearby' list.
00305   void add_nearby_npc(Npc_actor *npc);
00306   void remove_nearby_npc(Npc_actor *npc);
00307           // Get all nearby NPC's.
00308   void get_nearby_npcs(Actor_queue& list);
00309           // Update NPCs' schedules.
00310   void schedule_npcs(int hour3, int backwards = 0, bool repaint = true);
00311   void mend_npcs();   // Restore HP's each hour.
00312           // Find witness to Avatar's 'crime'.
00313   Actor *find_witness(Actor *& closest_npc);
00314   void theft();     // Handle thievery.
00315   void call_guards(Actor *witness = 0);
00316   void attack_avatar(int num_guards = 0);
00317   /*
00318    *  Rendering:
00319    */
00320   inline void set_painted() // Force blit.
00321     { painted = 1; }
00322   inline bool was_painted()
00323     { return painted; }
00324   bool show(bool force = false) // Returns true if blit occurred.
00325     {
00326     if (painted || force)
00327       {
00328       win->show();
00329       painted = false;
00330       return true;
00331       }
00332     return false;
00333     }
00334   void clear_dirty()    // Clear dirty rectangle.
00335     { dirty.w = 0; }
00336           // Paint scene at given tile.
00337   void paint_map_at_tile(int x, int y, int w, int h,
00338         int toptx, int topty, int skip_above = 31);
00339           // Paint area of image.
00340   void paint(int x, int y, int w, int h);
00341   void paint(Rectangle& r)
00342     { paint(r.x, r.y, r.w, r.h); }
00343   void paint();     // Paint whole image.
00344           // Paint 'dirty' rectangle.
00345   void paint_dirty();
00346   void set_all_dirty()    // Whole window.
00347     { dirty = Rectangle(0, 0, get_width(), get_height()); }
00348   void add_dirty(Rectangle r) // Add rectangle to dirty area.
00349     { dirty = dirty.w > 0 ? dirty.add(r) : r; }
00350           // Add dirty rect. for obj. Rets. false
00351           //   if not on screen.
00352   bool add_dirty(Game_object *obj)
00353     {
00354     Rectangle rect = get_shape_rect(obj);
00355     rect.enlarge(5);
00356     rect = clip_to_win(rect);
00357     if (rect.w > 0 && rect.h > 0)
00358       {
00359       add_dirty(rect);
00360       return true;
00361       }
00362     else
00363       return false;
00364     }
00365           // Set view (upper-left).
00366   void set_scrolls(int newscrolltx, int newscrollty);
00367   void center_view(Tile_coord t); // Center view around t.
00368   void set_camera_actor(Actor *a);
00369   Actor *get_camera_actor()
00370     { return camera_actor; }
00371           // Scroll if necessary.
00372   bool scroll_if_needed(Tile_coord t);
00373   bool scroll_if_needed(Actor *a, Tile_coord t)
00374     { if (a == camera_actor) return scroll_if_needed(t); 
00375               else return false; }
00376 #if 1
00377           // Show abs. location of mouse.
00378   void show_game_location(int x, int y);
00379 #endif
00380           // Get screen area of shape at pt.
00381   Rectangle get_shape_rect(const Shape_frame *s, int x, int y) const
00382     {
00383     return Rectangle(x - s->xleft, y - s->yabove,
00384         s->get_width(), s->get_height());
00385     }
00386           // Get screen area used by object.
00387   Rectangle get_shape_rect(Game_object *obj);
00388           // Get screen loc. of object.
00389   void get_shape_location(Game_object *obj, int& x, int& y);
00390   void get_shape_location(Tile_coord t, int& x, int& y);
00391   void plasma(int w, int h, int x, int y, int startc, int endc);
00392   /*
00393    *  Save/restore/startup:
00394    */
00395   void write();     // Write out to 'gamedat'.
00396   void read();      // Read in 'gamedat'.
00397   void write_gwin();    // Write gamedat/gamewin.dat.
00398   void read_gwin();   // Read gamedat/gamewin.dat.
00399   void write_map();   // Write map data to <PATCH> dir.
00400   void read_map();    // Reread initial game map.
00401   void reload_usecode();    // Reread (patched) usecode.
00402   void init_actors();   // Place actors in the world.
00403   void init_files(bool cycle=true); // Load all files
00404 
00405     // From Gamedat
00406   void get_saveinfo( Shape_file *&map,
00407       SaveGame_Details *&details,
00408       SaveGame_Party *& party);
00409     // From Savegame
00410   bool get_saveinfo(int num, char *&name,
00411       Shape_file *&map,
00412       SaveGame_Details *&details,
00413       SaveGame_Party *& party);
00414   void read_saveinfo(DataSource *in,
00415       SaveGame_Details *&details,
00416       SaveGame_Party *& party);
00417 #ifdef HAVE_ZIP_SUPPORT
00418 private:
00419   bool get_saveinfo_zip(const char *fname, char *&name,
00420       Shape_file *&map,
00421       SaveGame_Details *&details,
00422       SaveGame_Party *& party);
00423 public:
00424 #endif
00425   void write_saveinfo();    // Write the save info to gamedat
00426   inline char *get_save_name(int i) const // Get ->saved-game name.
00427     { return save_names[i]; }
00428   void setup_game();    // Prepare for game
00429   void read_npcs();   // Read in npc's.
00430   void write_npcs();    // Write them back.
00431   void read_schedules();    // Read npc's schedules.
00432   void write_schedules();   // Write npc's schedules.
00433   void revert_schedules(Actor *); // Reset a npc's schedule.
00434           // Explode a savegame into "gamedat".
00435   void restore_gamedat(const char *fname);
00436   void restore_gamedat(int num);
00437           // Save "gamedat".
00438   void save_gamedat(const char *fname, const char *savename);
00439   void save_gamedat(int num, const char *savename);
00440           // Get IDENTITY string.
00441   static char *get_game_identity(const char *savename);
00442   bool init_gamedat(bool create); // Initialize gamedat directory
00443 #ifdef HAVE_ZIP_SUPPORT
00444 private:
00445   bool save_gamedat_zip(const char *fname, const char *savename);
00446   bool Restore_level2 (void *unzipfile);
00447   bool restore_gamedat_zip(const char *fname);
00448   static char *get_game_identity_zip(const char *savename);
00449 public:
00450 #endif
00451   /*
00452    *  Game control:
00453    */
00454   void view_right();    // Move view 1 chunk to right.
00455   void view_left();   // Move view left by 1 chunk.
00456   void view_down();   // Move view down.
00457   void view_up();     // Move view up.
00458           // Start moving actor.
00459   void start_actor_alt (int winx, int winy, int speed);
00460   void start_actor(int winx, int winy, int speed = 125);
00461   void start_actor_along_path(int winx, int winy, int speed = 125);
00462   void stop_actor();    // Stop main actor.
00463   inline void set_step_tile_delta(int size) { step_tile_delta = size; }
00464   inline int get_step_tile_delta() { return step_tile_delta; };
00465   inline void set_allow_double_right_move(bool a) { allow_double_right_move = a; }
00466   inline bool get_allow_double_right_move() { return allow_double_right_move; }
00467   void teleport_party(Tile_coord t, bool skip_eggs = false);
00468   bool activate_item(int shnum, int frnum=c_any_framenum,
00469          int qual=c_any_qual); // Activate item in party.
00470           // Find object (x, y) is in.
00471   Game_object *find_object(int x, int y);
00472           // Show names of items clicked on.
00473   void show_items(int x, int y, bool ctrl = false);
00474           // Right-click while combat paused.
00475   void paused_combat_select(int x, int y);
00476   ShapeID get_flat(int x, int y); // Return terrain (x, y) is in.
00477           // Schedule object for deletion.
00478   void delete_object(Game_object *obj);
00479           // Handle a double-click in window.
00480   void double_clicked(int x, int y);
00481   bool start_dragging(int x, int y);
00482   bool drag(int x, int y);  // During dragging.
00483   bool drop_dragged(int x, int y, bool moved);// Done dragging.
00484   bool is_dragging() const { return dragging != 0; }
00485   bool drop_at_lift(Game_object *to_drop, int x, int y, int at_lift);
00486   Gump *get_dragging_gump();
00487   // Create a mini-screenshot (96x60)
00488   Shape_file* create_mini_screenshot ();
00489   /*
00490    *  Chunk-caching:
00491    */
00492   // Old Style Caching Emulation. Called if player has changed chunks
00493   void emulate_cache(int oldx, int oldy, int newx, int newy);
00494   // Is a specific move by a monster or item allowed
00495   bool emulate_is_move_allowed(int tx, int ty);
00496   // Swapping a superchunk to disk emulation
00497   void emulate_swapout (int scx, int scy);
00498 
00499 
00500 #ifdef RED_PLASMA
00501   void setup_load_palette();
00502   void cycle_load_palette();
00503 #endif
00504   };
00505 #endif

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