00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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>
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
00079
00080 class Game_window
00081 {
00082 static Game_window *game_window;
00083
00084 Dragging_info *dragging;
00085 Effects_manager *effects;
00086 Game_clock *clock;
00087 Game_map *map;
00088 Game_render *render;
00089 Gump_manager *gump_man;
00090 Party_manager *party_man;
00091 Image_window8 *win;
00092 Npc_proximity_handler *npc_prox;
00093 Palette *pal;
00094 Shape_manager *shape_man;
00095 Time_queue *tqueue;
00096 Time_sensitive *background_noise;
00097 Usecode_machine *usecode;
00098
00099 bool combat;
00100 bool focus;
00101 bool ice_dungeon;
00102 bool painted;
00103
00104 int skip_above_actor;
00105 unsigned int in_dungeon;
00106 int num_npcs1;
00107 int std_delay;
00108 long time_stopped;
00109 unsigned long special_light;
00110 int theft_warnings;
00111 short theft_cx, theft_cy;
00112
00113 Barge_object *moving_barge;
00114 Main_actor *main_actor;
00115 Actor *camera_actor;
00116 Actor_vector npcs;
00117 Exult_vector<Dead_body*> bodies;
00118 Deleted_objects *removed;
00119
00120 int scrolltx, scrollty;
00121 Rectangle scroll_bounds;
00122 Rectangle dirty;
00123
00124 char *save_names[10];
00125
00126 bool mouse3rd;
00127 bool fastmouse;
00128 bool double_click_closes_gumps;
00129 int text_bg;
00130 int step_tile_delta;
00131 bool allow_double_right_move;
00132
00133
00134 void set_scrolls(Tile_coord cent);
00135 void clear_world();
00136 void read_save_names();
00137 long check_time_stopped();
00138
00139 #ifdef RED_PLASMA
00140
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
00149
00150 int skip_lift;
00151
00152 bool paint_eggs;
00153 bool armageddon;
00154 bool walk_in_formation;
00155 int debug;
00156
00157
00158
00159 Game_window(int width = 0, int height = 0, int scale = 1,
00160 int scaler = 0);
00161 ~Game_window();
00162
00163 static Game_window *get_instance()
00164 { return game_window; }
00165 void abort(const char *msg, ...);
00166
00167
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
00175 { return scrolltx; }
00176 inline int get_scrollty() const
00177 { return scrollty; }
00178 inline Rectangle get_win_rect() const
00179 { return Rectangle(0, 0, win->get_width(), win->get_height());}
00180 Rectangle get_win_tile_rect()
00181 { return Rectangle(get_scrolltx(), get_scrollty(),
00182 (get_width() + c_tilesize - 1)/c_tilesize,
00183 (get_height() + c_tilesize - 1)/c_tilesize); }
00184
00185 Rectangle clip_to_win(Rectangle r)
00186 {
00187 Rectangle wr = get_win_rect();
00188 return (r.intersect(wr));
00189 }
00190
00191 void resized(unsigned int neww, unsigned int newh,
00192 unsigned int newsc, unsigned int newsclr);
00193 void get_focus();
00194 void lose_focus();
00195 inline bool have_focus() const
00196 { return focus; }
00197
00198
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
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
00237
00238 Map_patch_collection *get_map_patches();
00239
00240 bool locate_shape(int shapenum, bool upwards);
00241 void send_location();
00242
00243
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();
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
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
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()
00275 { return special_light != 0; }
00276
00277 void add_special_light(int minutes);
00278
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
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();
00296 void add_npc(Actor *npc, int num);
00297 inline int in_combat()
00298 { return combat; }
00299 void toggle_combat();
00300 inline bool get_frame_skipping()
00301 { return true; }
00302
00303 int get_party(Actor **list, int avatar_too = 0);
00304
00305 void add_nearby_npc(Npc_actor *npc);
00306 void remove_nearby_npc(Npc_actor *npc);
00307
00308 void get_nearby_npcs(Actor_queue& list);
00309
00310 void schedule_npcs(int hour3, int backwards = 0, bool repaint = true);
00311 void mend_npcs();
00312
00313 Actor *find_witness(Actor *& closest_npc);
00314 void theft();
00315 void call_guards(Actor *witness = 0);
00316 void attack_avatar(int num_guards = 0);
00317
00318
00319
00320 inline void set_painted()
00321 { painted = 1; }
00322 inline bool was_painted()
00323 { return painted; }
00324 bool show(bool force = false)
00325 {
00326 if (painted || force)
00327 {
00328 win->show();
00329 painted = false;
00330 return true;
00331 }
00332 return false;
00333 }
00334 void clear_dirty()
00335 { dirty.w = 0; }
00336
00337 void paint_map_at_tile(int x, int y, int w, int h,
00338 int toptx, int topty, int skip_above = 31);
00339
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();
00344
00345 void paint_dirty();
00346 void set_all_dirty()
00347 { dirty = Rectangle(0, 0, get_width(), get_height()); }
00348 void add_dirty(Rectangle r)
00349 { dirty = dirty.w > 0 ? dirty.add(r) : r; }
00350
00351
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
00366 void set_scrolls(int newscrolltx, int newscrollty);
00367 void center_view(Tile_coord t);
00368 void set_camera_actor(Actor *a);
00369 Actor *get_camera_actor()
00370 { return camera_actor; }
00371
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
00378 void show_game_location(int x, int y);
00379 #endif
00380
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
00387 Rectangle get_shape_rect(Game_object *obj);
00388
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
00394
00395 void write();
00396 void read();
00397 void write_gwin();
00398 void read_gwin();
00399 void write_map();
00400 void read_map();
00401 void reload_usecode();
00402 void init_actors();
00403 void init_files(bool cycle=true);
00404
00405
00406 void get_saveinfo( Shape_file *&map,
00407 SaveGame_Details *&details,
00408 SaveGame_Party *& party);
00409
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();
00426 inline char *get_save_name(int i) const
00427 { return save_names[i]; }
00428 void setup_game();
00429 void read_npcs();
00430 void write_npcs();
00431 void read_schedules();
00432 void write_schedules();
00433 void revert_schedules(Actor *);
00434
00435 void restore_gamedat(const char *fname);
00436 void restore_gamedat(int num);
00437
00438 void save_gamedat(const char *fname, const char *savename);
00439 void save_gamedat(int num, const char *savename);
00440
00441 static char *get_game_identity(const char *savename);
00442 bool init_gamedat(bool create);
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
00453
00454 void view_right();
00455 void view_left();
00456 void view_down();
00457 void view_up();
00458
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();
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);
00470
00471 Game_object *find_object(int x, int y);
00472
00473 void show_items(int x, int y, bool ctrl = false);
00474
00475 void paused_combat_select(int x, int y);
00476 ShapeID get_flat(int x, int y);
00477
00478 void delete_object(Game_object *obj);
00479
00480 void double_clicked(int x, int y);
00481 bool start_dragging(int x, int y);
00482 bool drag(int x, int y);
00483 bool drop_dragged(int x, int y, bool moved);
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
00488 Shape_file* create_mini_screenshot ();
00489
00490
00491
00492
00493 void emulate_cache(int oldx, int oldy, int newx, int newy);
00494
00495 bool emulate_is_move_allowed(int tx, int ty);
00496
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