source: abuse/trunk/src/level.h @ 494

Last change on this file since 494 was 494, checked in by Sam Hocevar, 11 years ago

style: remove trailing spaces, fix copyright statements.

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