source: abuse/tags/pd/abuse/inc/level.hpp @ 604

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