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, by |
---|
8 | * Jonathan Clark, or by Sam Hocevar. |
---|
9 | */ |
---|
10 | |
---|
11 | #ifndef __CHARACTERZ_HPP_ |
---|
12 | #define __CHARACTERZ_HPP_ |
---|
13 | |
---|
14 | #include <string.h> |
---|
15 | |
---|
16 | #include "seq.h" |
---|
17 | //#include "sound.h" |
---|
18 | #include "ability.h" |
---|
19 | #include "event.h" |
---|
20 | #include <stdarg.h> |
---|
21 | #include <time.h> |
---|
22 | |
---|
23 | |
---|
24 | enum character_state |
---|
25 | { |
---|
26 | dead, |
---|
27 | dieing, |
---|
28 | stopped, |
---|
29 | start_run_jump, run_jump, run_jump_fall, end_run_jump, |
---|
30 | flinch_up, flinch_down, |
---|
31 | morph_pose, |
---|
32 | running |
---|
33 | }; |
---|
34 | |
---|
35 | #define MAX_STATE (running+1) |
---|
36 | extern char const *state_names[]; |
---|
37 | |
---|
38 | class named_field |
---|
39 | { |
---|
40 | public : |
---|
41 | char *real_name; |
---|
42 | char *descript_name; |
---|
43 | named_field(char *real, char *fake) |
---|
44 | { real_name = strdup(real); |
---|
45 | descript_name = strdup(fake); |
---|
46 | } |
---|
47 | ~named_field() { free(real_name); free(descript_name); } |
---|
48 | } ; |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | // all cflags default is 0 |
---|
53 | #define TOTAL_CFLAGS 11 |
---|
54 | enum { CFLAG_HURT_ALL, // if object hurts all characters, not just player |
---|
55 | CFLAG_IS_WEAPON, // if object is a collectable weapon (should have a logo) |
---|
56 | CFLAG_STOPPABLE, // if object can be stopped by any other object |
---|
57 | CFLAG_CAN_BLOCK, // if object can block other object |
---|
58 | CFLAG_HURTABLE, |
---|
59 | CFLAG_PUSHABLE, // can push other pushable characters |
---|
60 | CFLAG_UNLISTABLE, // if object should appear in object list during edit mode |
---|
61 | CFLAG_ADD_FRONT, |
---|
62 | CFLAG_CACHED_IN, |
---|
63 | CFLAG_NEED_CACHE_IN, |
---|
64 | CFLAG_UNACTIVE_SHIELD // if object is not active (i.e. link 0 aistate==0) |
---|
65 | // then objects will not draw a damage when hitting it |
---|
66 | }; |
---|
67 | extern char const *cflag_names[TOTAL_CFLAGS]; |
---|
68 | |
---|
69 | // all object functions default to NULL |
---|
70 | #define TOTAL_OFUNS 11 |
---|
71 | enum { OFUN_AI, // objects ai function called by the mover, should call (tick) |
---|
72 | OFUN_MOVER, // objects move function, gets x y and but |
---|
73 | OFUN_DRAW, |
---|
74 | OFUN_MAP_DRAW, |
---|
75 | OFUN_DAMAGE, // called when the object receives damage |
---|
76 | OFUN_NEXT_STATE, // called at the end of an object sequence |
---|
77 | OFUN_USER_FUN, // can by called (user_fun x y z) |
---|
78 | OFUN_CONSTRUCTOR, // called when object is created, dev & play modes |
---|
79 | OFUN_RELOAD, // called when the object is loaded from disk (not save games) |
---|
80 | OFUN_GET_CACHE_LIST, // called on level load, should return list (a . b) a is character id, and b is other ids |
---|
81 | OFUN_CHANGE_TYPE |
---|
82 | } ; |
---|
83 | extern char const *ofun_names[TOTAL_OFUNS]; |
---|
84 | |
---|
85 | |
---|
86 | class CharacterType |
---|
87 | { |
---|
88 | public: |
---|
89 | CharacterType(LList *args, LSymbol *name); // lisp object describes object |
---|
90 | ~CharacterType(); |
---|
91 | |
---|
92 | uint16_t ts,tiv,tv; // total states, total index vars, total local vars |
---|
93 | sequence **seq; // [0..ts-1] |
---|
94 | LSymbol **seq_syms; // symbol describing what this state is [0..ts-1] |
---|
95 | |
---|
96 | LSymbol **vars; // symbol describing variable names [0..tiv-1] |
---|
97 | short *var_index; // index into local var [0..tiv-1] |
---|
98 | |
---|
99 | void add_var(void *symbol, void *name); |
---|
100 | int add_state(LObject *symbol); // returns index into seq to use |
---|
101 | int abil[TOTAL_ABILITIES]; |
---|
102 | void *fun_table[TOTAL_OFUNS]; // pointers to lisp function for this object |
---|
103 | int logo,morph_mask,morph_power; |
---|
104 | long rangex,rangey,draw_rangex,draw_rangey; // range off screen before character is skipped |
---|
105 | |
---|
106 | uint16_t cflags; |
---|
107 | void *get_fun(int name) { return fun_table[name]; } |
---|
108 | int get_cflag(int name) { return cflags&(1<<name); } |
---|
109 | void set_cflag(int name, int x) { if (x) cflags|=(1<<name); else cflags&=~(1<<name); } |
---|
110 | int total_fields; // used by game editor to replace field names |
---|
111 | named_field **fields; |
---|
112 | |
---|
113 | sequence *get_sequence(character_state s); |
---|
114 | void add_sequence(character_state which, sequence *new_seq); |
---|
115 | int has_sequence(character_state s) { return s<ts && (seq[s]!=NULL); } |
---|
116 | int cache_in(); // returns false if out of cache memory |
---|
117 | void check_sizes(); |
---|
118 | long isa_var_name(char *name); |
---|
119 | } ; |
---|
120 | |
---|
121 | extern CharacterType **figures; |
---|
122 | int flinch_state(character_state state); |
---|
123 | |
---|
124 | void *def_char(void *args); |
---|
125 | |
---|
126 | extern int total_weapons; |
---|
127 | extern int *weapon_types; // maps 0..total_weapons into 'real' weapon type |
---|
128 | |
---|
129 | #endif |
---|
130 | |
---|
131 | |
---|
132 | |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | |
---|
143 | |
---|
144 | |
---|
145 | |
---|
146 | |
---|
147 | |
---|