source: golgotha/src/golg/map.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 10.0 KB
RevLine 
[80]1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#ifndef __MAP_HPP_
10#define __MAP_HPP_
11
12
13#include "arch.hh"
14#include "error/error.hh"
15#include "g1_limits.hh"
16#include "player_type.hh"
17#include "time/time.hh"
18#include "g1_vert.hh"
19#include "g1_object.hh"
20#include "reference.hh"
21#include "global_id.hh"
22
23class g1_map_cell_class;
24class g1_map_vertex_class;
25class g1_draw_context_class;
26class g1_obj_conscell_class;
27class g1_solid_class;
28class g1_bullet_class;
29class g1_solid_class;
30class g1_saver_class;
31class g1_loader_class;
32class g1_path_manager_class;
33class g1_visible_projection;
34class g1_quad_object_class;
35class g1_movie_flow_class;
36class g1_light_object_class;
37class i4_str;
38class i4_polygon_class;
39struct g1_visible_cell;
40class i4_pal_handle_class;
41class g1_astar_map_solver_class;
42class g1_takeover_pad_class;
43//class g1_critical_graph_class;
44typedef g1_typed_reference_class<g1_takeover_pad_class> g1_takeover_pad_ref;
45
46// these bit flags are passed into save & load for a map
47// this can be used to merge in sections of another map or reduce the amount
48// of undo info need to be saved and loaded
49enum {
50  G1_MAP_CELLS=(1<<0),
51  G1_MAP_VERTS=(1<<1),
52  G1_MAP_OBJECTS=(1<<2),
53  G1_MAP_MOVIE=(1<<3),
54  G1_MAP_PLAYERS=(1<<4),
55  G1_MAP_TICK=(1<<5),
56  G1_MAP_GRAPH=(1<<6),
57  G1_MAP_LIGHTS=(1<<7),
58  G1_MAP_SKY=(1<<8),
59  G1_MAP_VARS=(1<<9),
60  G1_MAP_VIEW_POSITIONS=(1<<11),
61  G1_MAP_RES_FILENAME=(1<<12),
62  G1_LAST_THING,
63  G1_MAP_ALL=(G1_LAST_THING-1)*2-1,
64
65  G1_MAP_SELECTED_VERTS=(1<<13)  // not part of G1_MAP_ALL because G1_MAP_VERTS encompases
66};
67
68
69enum {
70  G1_RECALC_RADAR_VIEW         = (1<<0),
71  G1_RECALC_PAD_LIST           = (1<<1),
72//   G1_RECALC_BLOCK_MAPS         = (1<<2),
73//   G1_RECALC_CRITICAL_DATA      = (1<<3),
74  G1_RECALC_WATER_VERTS        = (1<<4),  // determines which verts are drawn with wave motion
75  G1_RECALC_STATIC_LIGHT       = (1<<5)  // determines how much directional light hits each cell
76};
77
78
79class g1_map_class
80{
81private:
82  friend class g1_map_view_class;
83  friend class g1_editor_class;
84
85  friend i4_bool g1_load_level(const i4_const_str &filename,
86                               int reload_textures_and_models,
87                               w32 exclude_flags);
88
89//  friend class g1_critical_map_maker_class; 
90  friend class g1_object_controller_class;
91
92  void save_objects(g1_saver_class *out);
93
94  w32 recalc;       // bits telling what need recalculating set by add_undo in editor
95  w32 w,h;
96
97  g1_map_cell_class *cells;       // 2d array (w*h) of tile type, rotation, blocking status
98  g1_map_vertex_class *verts;    // 2d array ((w+1)*(h+1)) of height and lighting info of corners
99
100//   g1_block_map_class block[G1_GRADE_LEVELS];    // blockage maps for different slopes
101//   g1_collision_map_class collide; // collision map for objects
102
103//   g1_critical_graph_class *critical_graph;
104
105  enum { THINK_QUE_SIZE=G1_MAX_OBJECTS };
106  g1_object_class *think_que[THINK_QUE_SIZE];
107  w32 think_head, think_tail;
108
109 
110  void delete_map_view();
111
112  g1_object_class **load_objects(g1_loader_class *fp, w32 &tobjs);
113
114  // returns sections actually loaded
115  w32 load(g1_loader_class *fp, w32 sections);
116
117  i4_bool load_sky(g1_loader_class *fp);
118  void save_sky(g1_saver_class *fp);
119
120//   void save_critical_map(g1_saver_class *f);
121//   void load_critical_map(g1_loader_class *f);
122
123  g1_astar_map_solver_class *solver;
124  g1_path_manager_class *path_manager;
125 
126
127  // this is a hook so the level editor can draw selected verts
128  typedef void (*cell_draw_function_type)(sw32 x, sw32 y, void *context);
129  cell_draw_function_type post_cell_draw;
130  void *post_cell_draw_context;
131
132  i4_str *filename;
133
134  void init_lod();
135  void calc_map_lod(g1_object_controller_class *);
136
137  i4_bool movie_in_progress;
138
139public:
140  // only use this if you know what you are doing
141  void change_map(int w, int h, g1_map_cell_class *cells, g1_map_vertex_class *vertex);
142 
143  i4_str *sky_name;
144
145  void recalc_static_stuff();
146
147  void remove_from_think_list(g1_object_class *o);
148
149  void mark_for_recalc(w32 flags) { recalc |= flags; }
150
151//   g1_block_map_class *get_block_map(w8 grade) const { return (g1_block_map_class*)&block[grade]; }
152
153  i4_bool playing_movie() { return movie_in_progress; } 
154
155  i4_const_str get_filename();
156  void set_filename(const i4_const_str &fname);
157   
158
159  void set_post_cell_draw_function(cell_draw_function_type fun, void *context)
160  {
161    post_cell_draw=fun;
162    post_cell_draw_context=context;
163  }
164
165
166  i4_bool start_movie();
167  void stop_movie();
168  i4_bool advance_movie_with_time();
169
170  g1_movie_flow_class *current_movie;
171
172  g1_movie_flow_class *get_current_movie() { return current_movie; }
173
174  w32 get_tick();
175  i4_time_class tick_time; 
176
177  w16 width()  const { return w; }
178  w16 height() const { return h; }
179
180  class range_iterator
181  {
182  protected:
183    sw32 left, right, top, bottom, ix, iy;
184    g1_map_cell_class *cell;
185    g1_object_chain_class *chain;
186    w32 object_mask_flags, type_mask_flags;
187  public:
188    void begin(float x, float y, float range);
189    void mask(w32 _object_mask_flags, w32 _type_mask_flags=0xffffffff)
190    {
191      object_mask_flags = _object_mask_flags;
192      type_mask_flags = _type_mask_flags;
193    }
194    void safe_restart();
195    i4_bool end();
196    void next();
197
198    g1_object_class *get() const;
199
200    g1_object_class *operator*() { return get(); }
201    range_iterator& operator++() { next(); return *this;}
202    range_iterator& operator++(int) { next(); return *this;}
203  };
204
205  sw32 get_objects_in_range(float x, float y, float range,
206                            g1_object_class *dest_array[], w32 array_size,
207                            w32 object_mask_flags=0xffffffff, w32 type_mask_flags=0xffffffff);
208                           
209
210  g1_map_cell_class *cell(w16 x, w16 y) const;
211  g1_map_cell_class *cell(w32 offset) const;
212  g1_map_vertex_class *vertex(w16 x, w16 y) const;
213
214  void request_think(g1_object_class *obj)
215  {
216    think_que[think_head]=obj;
217
218    think_head++;
219    if (think_head>=THINK_QUE_SIZE)
220      think_head=0;
221   
222    if (think_head==think_tail)
223      i4_error("g1_map_class::request_think - thinkers exceeded maximum");
224  }
225
226  void request_remove(g1_object_class *obj);
227
228  void add_object(g1_object_chain_class &c, w32 x, w32 y);
229  void remove_object(g1_object_chain_class &c);
230
231
232  void remove_object_type(g1_object_type type);
233
234  g1_map_class(const i4_const_str &fname);
235
236//   void make_block_maps();
237
238  void draw(g1_draw_context_class *context,
239            i4_float player_x,
240            i4_float player_y,
241            i4_float player_z,
242            i4_angle player_angle);
243
244  void draw_cells(g1_draw_context_class  *context,
245                  g1_visible_cell *cell_list,
246                  int t_visible_cells);
247
248
249  void fast_draw_cells(g1_draw_context_class  *context);
250//                        g1_visible_cell *cell_list,
251//                        int t_visible_cells);
252
253
254  void think_objects();
255
256
257  // check so see if an object can move to the position x,y blocking is not checked
258  // against solids on the same team.
259  // returns 1 if hit object, -1 if hit building, and 0 if nothing
260  int check_non_player_collision(g1_player_type player_num,
261                                 const i4_3d_vector &point,
262                                 i4_3d_vector &ray,
263                                 g1_object_class*& hit) const;
264
265  int check_terrain_location(i4_float x, i4_float y, i4_float z,
266                             i4_float occupancy_radius,
267                             w8 grade, w8 dir) const;
268
269  void save(g1_saver_class *out, w32 sections);
270
271  g1_object_class *find_object_by_id(w32 object_id, g1_player_type prefered_team);
272
273  // this is not stank specific!
274  i4_bool find_path(i4_float start_x, i4_float start_y,
275                    i4_float dest_x, i4_float dest_y,
276                    i4_float *points, w16 &t_nodes);
277
278  // all objects in this area will receive damage falling off with distance
279  void damage_range(g1_object_class *obj,
280                    i4_float x, i4_float y, i4_float z,
281                    i4_float range, w16 damage, i4_float falloff=0);
282
283//   g1_critical_graph_class *get_critical_graph() { return critical_graph; }
284
285  i4_float terrain_height(i4_float x, i4_float y) const;
286  i4_float map_height(i4_float x, i4_float y, i4_float z) const;
287
288  void calc_terrain_normal(i4_float x, i4_float y, i4_3d_vector &normal);
289  void calc_pitch_and_roll(i4_float x, i4_float y, i4_float z, i4_float &pitch, i4_float &roll);
290
291  void calc_height_pitch_roll(i4_float x, i4_float y, i4_float z,
292                              i4_float &height, i4_float &pitch, i4_float &roll);
293                             
294
295  sw32 make_object_list(g1_object_class **buffer, sw32 buf_size);  // returns total added
296  sw32 make_selected_objects_list(w32 *buffer, sw32 buf_size);  // return total added (saved id's)
297
298  void change_vert_height(sw32 x, sw32 y, w8 new_height);
299
300  // how much light illuminates an object at this position
301  void get_illumination_light(i4_float x, i4_float y, i4_float &r, i4_float &g, i4_float &b);
302
303  void reload();
304
305  // returns the total number of cells that can be seen
306  int calc_visible(i4_transform_class &t,
307                   i4_polygon_class *area_poly,
308                   g1_visible_cell *buffer, w32 buf_elements,
309                   i4_float xscale, i4_float yscale);           // how much to scale x & y members of vertexes
310
311
312  i4_float min_terrain_height(w16 x, w16 y);
313
314  ~g1_map_class();
315} ;
316
317
318#endif
319
320
Note: See TracBrowser for help on using the repository browser.