gamemap.h

Go to the documentation of this file.
00001 /*
00002  *  gamemap.h - Game map data.
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 GAMEMAP_H
00023 #define GAMEMAP_H
00024 
00025 #include "exult_constants.h"
00026 #include "vec.h"
00027 #include "flags.h"
00028 #ifndef ALPHA_LINUX_CXX
00029 #  include <cassert>
00030 #endif
00031 #include <string> // STL string
00032 #include <iostream>
00033 #include <fstream>
00034 
00035 class Map_chunk;
00036 class Chunk_terrain;
00037 class Map_patch_collection;
00038 class Ireg_game_object;
00039 class Ifix_game_object;
00040 class Egg_object;
00041 class Shape_info;
00042 class Shapes_vga_file;
00043 class DataSource;
00044 
00045 /*
00046  *  The game map:
00047  */
00048 class Game_map
00049   {
00050           // Flat chunk areas:
00051   Exult_vector<Chunk_terrain *> chunk_terrains;
00052   bool read_all_terrain;    // True if we've read them all.
00053   bool map_modified;    // True if any map changes from
00054           //   map-editing.
00055           // Chunk_terrain index for each chunk:
00056   short terrain_map[c_num_chunks][c_num_chunks];
00057           // A list of objects in each chunk:
00058   Map_chunk *objects[c_num_chunks][c_num_chunks];
00059   bool schunk_read[144];    // Flag for reading in each "ifix".
00060   bool schunk_modified[144];  // Flag for modified "ifix".
00061   char *schunk_cache[144];
00062   int  schunk_cache_sizes[144];
00063   std::ifstream *chunks;    // "u7chunks" file.
00064   Map_patch_collection *map_patches;
00065 
00066   Map_chunk *create_chunk(int cx, int cy);
00067   Chunk_terrain *read_terrain(int chunk_num);
00068 
00069   void cache_out_schunk(int schunk);
00070 public:
00071   Game_map();
00072   ~Game_map();
00073   void init();      // Set up map.
00074   void clear();     // Clear out old map.
00075   void read_map_data();   // Read in 'ifix', 'ireg', etc.
00076   inline short get_terrain_num(int cx, int cy) const
00077     { return terrain_map[cx][cy]; }
00078   inline Map_patch_collection *get_map_patches()
00079     { return map_patches; }
00080   void set_map_modified()
00081     { map_modified = true; }
00082   bool was_map_modified() const
00083     { return map_modified; }
00084   bool is_chunk_read(int cx, int cy)
00085     { return cx < c_num_chunks && cy < c_num_chunks &&
00086       schunk_read[12*(cy/c_chunks_per_schunk) +
00087             cx/c_chunks_per_schunk]; }
00088   void set_ifix_modified(int cx, int cy)
00089     { 
00090     map_modified = true;
00091     schunk_modified[12*(cy/c_chunks_per_schunk) +
00092           cx/c_chunks_per_schunk] = true;
00093     }
00094           // Get/create objs. list for a chunk.
00095   Map_chunk *get_chunk(int cx, int cy)
00096     {
00097     assert((cx >= 0) && (cx < c_num_chunks) && 
00098             (cy >= 0) && (cy < c_num_chunks));
00099     Map_chunk *list = objects[cx][cy];
00100     return list ? list : create_chunk(cx, cy);
00101     }
00102   Map_chunk *get_chunk_safely(int cx, int cy)
00103     {
00104     Map_chunk *list;
00105     return (cx >= 0 && cx < c_num_chunks && 
00106       cy >= 0 && cy < c_num_chunks ? 
00107       ((list = objects[cx][cy]) != 0 ? list : 
00108             create_chunk(cx, cy)) : 0);
00109     }
00110           // Get "map" superchunk objs/scenery.
00111   void get_map_objects(int schunk);
00112           // Get "chunk" objects/scenery.
00113   void get_chunk_objects(int cx, int cy);
00114   void get_all_terrain();   // Read in all terrains.
00115           // Get desired terrain.
00116   Chunk_terrain *get_terrain(int tnum)
00117     {
00118     Chunk_terrain *ter = chunk_terrains[tnum];
00119     return ter ? ter : read_terrain(tnum);
00120     }
00121   inline int get_num_chunk_terrains() const
00122     { return chunk_terrains.size(); }
00123           // Set new terrain chunk.
00124   void set_chunk_terrain(int cx, int cy, int chunknum);
00125           // Get ifixxxx/iregxx name.
00126   static char *get_schunk_file_name(char *prefix,
00127             int schunk, char *fname);
00128   void write_static();    // Write to 'static' directory.
00129           // Write (static) map objects.
00130   void write_ifix_objects(int schunk);
00131           // Get "ifix" objects for a superchunk.
00132   void get_ifix_objects(int schunk);
00133           // Get "ifix" objs. for given chunk.
00134   void get_ifix_chunk_objects(DataSource* ifix, long filepos, int cnt,
00135               int cx, int cy);
00136           // Write scheduled script for obj.
00137   static void write_scheduled(DataSource* ireg, Game_object *obj,
00138             bool write_mark = false);
00139   void write_ireg();    // Write modified ireg files.
00140           // Write moveable objects to file.
00141   void write_ireg_objects(int schunk);
00142           // Write moveable objects to datasource.
00143   void write_ireg_objects(int schunk, DataSource *ireg);
00144           // Get moveable objects.
00145   void get_ireg_objects(int schunk);
00146           // Read scheduled script(s) for obj.
00147   void read_special_ireg(DataSource* ireg, Game_object *obj);
00148   void read_ireg_objects(DataSource* ireg, int scx, int scy,
00149           Game_object *container = 0,
00150       unsigned long flags = (1<<Obj_flags::okay_to_take));
00151   Ireg_game_object *create_ireg_object(Shape_info& info, int shnum, 
00152       int frnum, int tilex, int tiley, int lift);
00153   Ireg_game_object *create_ireg_object(int shnum, int frnum);
00154   Ifix_game_object *create_ifix_object(int shnum, int frnum);
00155           // Get all superchunk objects.
00156   void get_superchunk_objects(int schunk);
00157           // Locate chunk with desired terrain.
00158   bool locate_terrain(int tnum, int& cx, int& cy, bool upwards = false);
00159   bool swap_terrains(int tnum); // Swap adjacent terrain #'s.
00160           // Insert new terrain after 'tnum'.
00161   bool insert_terrain(int tnum, bool dup = false);
00162   bool delete_terrain(int tnum);
00163   void commit_terrain_edits();  // End terrain-editing mode.
00164   void abort_terrain_edits();
00165           // Search entire game for unused.
00166   void find_unused_shapes(unsigned char *found, int foundlen);
00167           // Locate shape (for EStudio).
00168   Game_object *locate_shape(int shapenum, bool upwards, 
00169               Game_object *start);
00170           // Do a cache out. (cx, cy) is the center
00171   void cache_out(int cx, int cy);
00172   };
00173 
00174 #endif

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