source: abuse/tags/pd/macabuse/inc/level.hpp

Last change on this file was 49, checked in by Sam Hocevar, 15 years ago
  • Imported original public domain release, for future reference.
File size: 8.6 KB
Line 
1
2#ifndef __LEVEL_HPP_
3#define __LEVEL_HPP_
4
5#include "specs.hpp"
6#include "macs.hpp"
7#include "objects.hpp"
8#include "view.hpp"
9#include "id.hpp"
10#include "timing.hpp"
11
12#include <stdlib.h>
13#define ASPECT 4             // foreground scrolls 4 times faster than background
14
15
16// the following defines the area of activity for objects
17// when they are out of this are no processing occurs on them
18// region is specified from upper left corner of screen
19#define ACTIVE_LEFT 500
20#define ACTIVE_RIGHT (280+500)         
21#define ACTIVE_TOP 200
22#define ACTIVE_BOTTOM (180+200)
23#define fgvalue(y) ((y) & 0x3fff)
24#define above_tile(y) ((y) & 0x4000)
25#define bgvalue(y) (y)
26
27class area_controller
28{
29  public :
30  long x,y,w,h,active;
31  long ambient,view_xoff,view_yoff;
32  long ambient_speed, view_xoff_speed,view_yoff_speed;
33  area_controller *next;
34  area_controller(long X, long Y, long W, long H, area_controller *Next);
35} ;
36
37extern long last_tile_hit_x,last_tile_hit_y;
38extern int dev;
39class level        // contain map info and objects
40{
41  unsigned short *map_fg,        // just big 2d arrays
42                 *map_bg,
43                 bg_width,bg_height,
44                 fg_width,fg_height; 
45  char *Name,*first_name;
46  long total_objs;
47  game_object *first,*first_active,*last;
48
49  game_object **attack_list;                // list of characters for tick which can attack someone
50  int attack_list_size,attack_total;
51  void add_attacker(game_object *who);
52
53  game_object **target_list;                // list of characters for tick which can be attacked
54  int target_list_size,target_total;
55  void add_target(game_object *who);
56
57  game_object **block_list;                // list of characters who can block a character
58  int block_list_size,block_total;
59  void add_block(game_object *who);
60
61  void remove_block(game_object *who);
62  void remove_all_block(game_object *who);
63
64  game_object **all_block_list;            // list of characters who can block a character or can be hurt
65  int all_block_list_size,all_block_total;
66  void add_all_block(game_object *who);
67
68  double previous_time;      // previous time spent playing the level (i.e. previous to this load)
69  time_marker start_time;    // time spent playing this level during this sessions
70  ulong ctick;
71  int am_timing;             // flag set when timing is on so time can be transfered to previous time on save()
72
73public:
74  void start_timing();         // reset's start_time
75  void stop_timing();          // transfers all time from start_time till now to previous time
76  double time_taken();
77
78  char *original_name() { if (first_name) return first_name; else return Name; }
79  ulong tick_counter() { return ctick; }
80  void set_tick_counter(ulong x);
81  area_controller *area_list;
82 
83  void clear_active_list() { first_active=NULL; }
84  char *name() { return Name; }
85  game_object *attacker(game_object *who);
86  int is_attacker(game_object *who);
87  game_object *main_character();
88
89  game_object *first_object() { return first; }
90  game_object *first_active_object() { return first_active; }
91  unsigned short foreground_width() { return fg_width; }
92  unsigned short foreground_height() { return fg_height; }
93  unsigned short background_width() { return bg_width; }
94  unsigned short background_height() { return bg_height; }
95  int load_failed() { return map_fg==NULL; }
96  level(spec_directory *sd, bFILE *fp, char *lev_name);
97  void load_fail();             
98  level(int width, int height, char *name); 
99  int save(char *filename, int save_all);  // save_all includes player and view information (1 = success)
100  void set_name(char *name) { Name=strcpy((char *)jrealloc(Name,strlen(name)+1,"map name"),name); }
101  void set_size(int w, int h);
102  void remove_light(light_source *which);
103  void try_pushback(game_object *subject,game_object *target);
104  ~level();
105
106  int fg_raised(int x, int y) { CHECK(x>=0 && y>=0 && x<fg_width && y<fg_height);
107                                 return (*(map_fg+x+y*fg_width))&0x4000; }
108  void fg_set_raised(int x, int y, int r) { CHECK(x>=0 && y>=0 && x<fg_width && y<fg_height);
109                                            ushort v=(*(map_fg+x+y*fg_width))&(0xffff-0x4000);
110                                            if (r) (*(map_fg+x+y*fg_width))=v|0x4000;
111                                            else (*(map_fg+x+y*fg_width))=v;
112                                          }
113  void mark_seen(int x, int y) { CHECK(x>=0 && y>=0 && x<fg_width && y<fg_height);
114                                          (*(map_fg+x+y*fg_width))|=0x8000; }
115  void clear_fg(long x, long y) { *(map_fg+x+y*fg_width)&=0x7fff; }
116
117  unsigned short *get_fgline(int y) { CHECK(y>=0 && y<fg_height); return map_fg+y*fg_width; }
118  unsigned short *get_bgline(int y) { CHECK(y>=0 && y<bg_height); return map_bg+y*bg_width; }
119  unsigned short get_fg(int x, int y) { if (x>=0 && y>=0 && x<fg_width && y<fg_height)
120                                          return fgvalue(*(map_fg+x+y*fg_width));
121                                        else return 0;
122                                      }
123  unsigned short get_bg(int x, int y) { if (x>=0 && y>=0 && x<bg_width && y<bg_height)
124                                          return *(map_bg+x+y*bg_width);
125                                         else return 0;
126                                        }
127  void put_fg(int x, int y, unsigned short tile) { *(map_fg+x+y*fg_width)=tile; }   
128  void put_bg(int x, int y, unsigned short tile) { *(map_bg+x+y*bg_width)=tile; }
129  void draw_objects(view *v);
130  void interpolate_draw_objects(view *v);
131  void draw_areas(view *v);
132  int tick();                                // returns false if character is dead
133  void check_collisions();
134  void wall_push();
135  void add_object(game_object *new_guy);
136  void add_object_after(game_object *new_guy, game_object *who);
137  void delete_object(game_object *who);
138  void remove_object(game_object *who);      // unlinks the object from level, but doesn't delete it
139  void load_objects(spec_directory *sd, bFILE *fp);
140  void load_cache_info(spec_directory *sd, bFILE *fp);
141  void old_load_objects(spec_directory *sd, bFILE *fp);
142  void load_options(spec_directory *sd, bFILE *fp);
143  void write_objects(bFILE *fp, object_node *save_list);
144  void write_options(bFILE *fp);
145  void write_thumb_nail(bFILE *fp, image *im);
146  void write_cache_prof_info();
147  void restart();
148
149
150  void unactivate_all();
151  // forms all the objects in processing range into a linked list
152  int add_actives(long x1, long y1, long x2, long y2);  //returns total added
153  void pull_actives(game_object *o, game_object *&last_active, int &t);
154  int add_drawables(long x1, long y1, long x2, long y2);  //returns total added
155
156  game_object *find_object(long x, long y);
157
158  game_object *damage_intersect(long x1, long y1, long &x2, long &y2, game_object *exclude);
159  game_object *boundary_setback(game_object *subject, long x1, long y1, long &x2, long &y2);
160  game_object *all_boundary_setback(game_object *subject, long x1, long y1, long &x2, long &y2);
161  int crush(game_object *by_who, int xamount, int yamount);
162  int push_characters(game_object *by_who, int xamount, int yamount);  // return 0 if fail on any.
163  int platform_push(game_object *by_who, int xamount, int yamount);
164  void foreground_intersect(long x1, long y1, long &x2, long &y2);
165  void vforeground_intersect(long x1, long y1, long &y2);
166
167  void hurt_radius(long x, long y,long r, long m, game_object *from, game_object *exclude,
168                   int max_push);
169  void send_signal(long signal);
170  void next_focus();
171  void to_front(game_object *o);
172  void to_back(game_object *o);
173  game_object *find_closest(int x, int y, int type, game_object *who);
174  game_object *find_xclosest(int x, int y, int type, game_object *who);
175  game_object *find_xrange(int x, int y, int type, int xd);
176  game_object *find_self(game_object *me);
177
178
179  void write_links(bFILE *fp, object_node *save_list, object_node *exclude_list);
180  void load_links(bFILE *fp, spec_directory *sd, object_node *save_list, object_node *exclude_list);
181
182
183  game_object *find_type(int type, int skip);
184  void insert_players();   // inserts the players into the level
185
186
187  game_object *get_random_start(int min_player_dist, view *exclude);
188//  game_object *find_enemy(game_object *exclude1, game_object *exclude2);
189
190  bFILE *create_dir(char *filename, int save_all,
191                    object_node *save_list, object_node *exclude_list);
192  view *make_view_list(int nplayers);
193  long total_light_links(object_node *list);
194  long total_object_links(object_node *save_list);
195  game_object *find_object_in_area(long x, long y, long x1, long y1,
196                                   long x2, long y2, Cell *list, game_object *exclude);
197  game_object *find_object_in_angle(long x, long y, long start_angle, long end_angle,
198                                    void *list, game_object *exclude);
199  object_node *make_not_list(object_node *list);
200  int load_player_info(bFILE *fp, spec_directory *sd, object_node *save_list);
201  void write_player_info(bFILE *fp, object_node *save_list);
202  void write_object_info(char *filename);
203  void level_loaded_notify();
204} ;
205
206extern level *current_level;
207void pull_actives(game_object *o, game_object *&last_active, int &t);
208
209
210
211#endif
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
Note: See TracBrowser for help on using the repository browser.