1 /*
2 
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 #ifndef __PLAYER_H
20 #define __PLAYER_H
21 
22 /*
23  * $Source: r:/prj/cit/src/inc/RCS/player.h $
24  * $Revision: 1.95 $
25  * $Author: minman $
26  * $Date: 1994/09/06 21:17:30 $
27  *
28  *
29  */
30 
31 // Includes
32 #include "gamesys.h"
33 #include "objects.h"
34 #include "map.h"
35 
36 // Defines
37 #define DEGREES_OF_FREEDOM 6 // number of physics control axes.
38 
39 // Basic quantities, of MFD's, slots, buttons, functions
40 #define NUM_MFDS 2
41 #define MFD_NUM_VIRTUAL_SLOTS 5
42 #define MFD_NUM_REAL_SLOTS (MFD_NUM_VIRTUAL_SLOTS + NUM_MFDS)
43 #define MFD_NUM_FUNCS 32 // this oughta do for now.
44 
45 #define NUM_EMAIL_PROPER 47
46 #define NUM_LOG_LEVELS 14
47 #define LOGS_PER_LEVEL 16
48 #define NUM_DATA 23
49 
50 #define NUM_EMAIL (NUM_EMAIL_PROPER + NUM_DATA + NUM_LOG_LEVELS * LOGS_PER_LEVEL)
51 
52 #define NUM_DAMAGE_TYPES 8
53 
54 typedef uint8_t MFD_Status;
55 #define MFD_EMPTY   0
56 #define MFD_FLASH   1
57 #define MFD_ACTIVE  2
58 #define MFD_UNAVAIL 3
59 
60 #define DEFAULT_FATIGUE_REGEN 50
61 #define NUM_WEAPON_SLOTS 7
62 #define EMPTY_WEAPON_SLOT 0xFF
63 #define NUM_GENERAL_SLOTS 14
64 
65 typedef enum {
66     ACTIVE_WEAPON = 0,
67     ACTIVE_GRENADE = 1,
68     ACTIVE_DRUG = 2,
69     ACTIVE_CART = 3,
70     ACTIVE_HARDWARE = 4,
71     ACTIVE_COMBAT_SOFT = 5,
72     ACTIVE_DEFENSE_SOFT = 6,
73     ACTIVE_MISC_SOFT = 7,
74     ACTIVE_GENERAL = 8,
75     ACTIVE_EMAIL = 9,
76     NUM_ACTIVES = 10
77 } Actives;
78 
79 #define PLAYER_VERSION_NUMBER ((int)6)
80 
81 // Some questbitty stuff
82 #define NUM_QUESTBITS 512
83 #define QUESTBIT_GET(qnum) (player_struct.questbits[((qnum) / 8u)] & (1u << ((qnum) % 8u)))
84 #define QUESTBIT_ON(qnum)  (player_struct.questbits[((qnum) / 8u)] |= (1u << ((qnum) % 8u)))
85 #define QUESTBIT_OFF(qnum) (player_struct.questbits[((qnum) / 8u)] &= ~(1u << ((qnum) % 8u)))
86 
87 #define NUM_QUESTVARS 64
88 #define QUESTVAR_GET(qnum) (player_struct.questvars[(qnum)])
89 #define QUESTVAR_SET(qnum, x)                  \
90     do {                                       \
91         player_struct.questvars[(qnum)] = (x); \
92     } while (0)
93 
94 #define COMBAT_DIFF_INDEX 0
95 #define QUEST_DIFF_INDEX  1
96 #define PUZZLE_DIFF_INDEX 2
97 #define CYBER_DIFF_INDEX  3
98 
99 #define PLAYER_MAX_HP 255
100 
101 #define get_righto_hp(w) (*((&(player_struct.hit_points)) + w))
102 
103 typedef struct _weapon_slot {
104     ubyte type;    // type of weapon in slot or EMPTY_WEAPON_SLOT
105     ubyte subtype; // subtype of weapon
106     union {
107         ubyte ammo; // current number of rounds
108         ubyte heat; // how hot am I?
109     };
110     union {
111         ubyte ammo_type; // current ammo type.
112         ubyte setting;   // current charge setting.
113     };
114     ubyte make_info; // manufacturer
115 } weapon_slot;
116 
117 typedef struct _softs {
118     ubyte combat[NUM_COMBAT_SOFTS];
119     ubyte defense[NUM_DEFENSE_SOFTS];
120     ubyte misc[NUM_MISC_SOFTS];
121 } softs_data;
122 
123 // FIXME pragma
124 #pragma pack(push,1)
125 
126 typedef struct _Player {
127     // Static Game Data
128     char name[20];
129     char realspace_level; // this is the last realspace level we were in
130 
131     // Difficulty related stuff
132     byte difficulty[4];
133     ubyte level_diff_zorched[(NUM_LEVELS / 8) + 1]; // bitfield for levels -- 1 if difficulty dealt with yet, 0 else
134 
135     // system stuff
136     uint32_t game_time;
137     uint32_t last_second_update; // when was last do_stuff_every_second
138     uint32_t last_drug_update;
139     uint32_t last_ware_update;
140     uint32_t last_anim_check;
141     int queue_time;
142     int deltat;
143     byte detail_level;
144 
145     // World stuff
146     ubyte level;                           // current level
147     short initial_shodan_vals[NUM_LEVELS]; // initial shodan security levels
148     byte controls[DEGREES_OF_FREEDOM];     // physics controls
149     ObjID rep;                             // The player's object-system object
150     ObjLoc realspace_loc;                  // This is where the player will come back out of cspace into
151     int version_num;
152     ObjID inventory[NUM_GENERAL_SLOTS]; // general inventory
153 
154     // Random physics state.
155     ubyte posture;      // current posture (standing/stooped/prone)
156     uchar foot_planted; // Player's foot is planted
157     byte leanx, leany;  // leaning, -100-+100
158 
159     // not used - eye postion - lower in struct!!!!
160     fixang eye; // eye position
161 
162     // Gamesys stuff
163     ubyte hit_points;                        // I bet we will want these.
164     ubyte cspace_hp;                         // after hit_points so we can array ref this stuff
165     ushort hit_points_regen;                 // Rate at which hit points regenerate, per minute
166     ubyte hit_points_lost[NUM_DAMAGE_TYPES]; // Rate at which damage is taken, per minute
167     ushort bio_post_expose;                  // expose damage from bio squares long past.
168     ushort rad_post_expose;                  // expose damage from rad squares long past.
169     ubyte energy;                            // suit power charge
170     ubyte energy_spend;                      // rate of energy burn
171     ubyte energy_regen;                      // Rate at which suit recharges
172     uchar energy_out;                        // out of energy last check
173     short cspace_trips;
174     int cspace_time_base;
175     ubyte questbits[NUM_QUESTBITS / 8]; // Mask of which "quests" you have completed
176     short questvars[NUM_QUESTVARS];
177     uint32_t hud_modes;           // What hud functions are currently active?
178     uchar experience;          // Are you experienced?
179     int fatigue;               // how fatigued are you
180     ushort fatigue_spend;      // Current rate of fatigue expenditure in pts/sec
181     ushort fatigue_regen;      // Current rate of fatigue regeneration
182     ushort fatigue_regen_base; // base fatigue regen rate
183     ushort fatigue_regen_max;  // max fatigue regen rate
184     byte accuracy;
185     ubyte shield_absorb_rate; // % of damage shields absorb
186     ubyte shield_threshold;   // Level where shields turn off
187     ubyte light_value;        // current lamp setting
188 
189     // MFD State
190     ubyte mfd_virtual_slots[NUM_MFDS][MFD_NUM_VIRTUAL_SLOTS]; // ptrs to mfd_slot id's
191     MFD_Status mfd_slot_status[MFD_NUM_REAL_SLOTS];
192     ubyte mfd_all_slots[MFD_NUM_REAL_SLOTS]; // ptrs to mfd_func id's
193     ubyte mfd_func_status[MFD_NUM_FUNCS];    // ptrs to mfd_func flags
194     ubyte mfd_func_data[MFD_NUM_FUNCS][8];
195     ubyte mfd_current_slots[NUM_MFDS]; // ptrs to mfd's curr slots
196     ubyte mfd_empty_funcs[NUM_MFDS];   // ptrs to mfd's empty func
197     uchar mfd_access_puzzles[64];      // this is 4 times as much as that hardcoded 8 up there
198                                        // who knows how much we really need, hopefully in soon
199                                        // KLC - changed to 64
200     char mfd_save_slot[NUM_MFDS];
201 
202     // Inventory stuff, in general, a value of zero will indicate an empty slot
203     // indices are drug/grenade/ware "types"
204     ubyte hardwarez[NUM_HARDWAREZ]; // Which warez do we have? (level of each type?)
205     softs_data softs;
206     ubyte cartridges[NUM_AMMO_TYPES]; // Cartridges for each ammo type.
207     ubyte partial_clip[NUM_AMMO_TYPES];
208     ubyte drugs[NUM_DRUGZ];       // Quantity of each drug
209     ubyte grenades[NUM_GRENADEZ]; // Quantity of each grenade.
210 
211     uchar email[NUM_EMAIL];     // Which email messages do you have.
212     ubyte logs[NUM_LOG_LEVELS]; // on which levels do we have logs.
213 
214     // Weapons are arranged into "slots"
215     weapon_slot weapons[NUM_WEAPON_SLOTS]; // Which weapons do you have?
216 
217     // Inventory status
218     ubyte hardwarez_status[NUM_HARDWAREZ]; // Status of active wares (on/off, activation time, recharge time?)
219     struct _softs softs_status;
220     ubyte jumpjet_energy_fraction;              // fractional units of energy spent on jumpjets.
221     ubyte email_sender_counts[32];              // who has sent how many emails
222     byte drug_status[NUM_DRUGZ];                // Time left on active drugs, 0 if inactive
223     ubyte drug_intensity[NUM_DRUGZ];            // Intensity of active drugs, 0 if inactive
224     ushort grenades_time_setting[NUM_GRENADEZ]; // Time setting for each grenade
225 
226     // PLOT STUFF
227     ushort time2dest; // Time to destination (seconds)
228     ushort time2comp; // time to completion of current program (seconds)
229 
230     // Combat shtuff <tm>
231     ObjID curr_target; // creature currently "targeted"
232     uint32_t last_fire;   // last gametime the weapon fired.
233     ushort fire_rate;  // game time required between weapon fires.
234 
235     // Selectied items
236     ubyte actives[NUM_ACTIVES];
237 
238     // Other transitory state
239     ObjID save_obj_cursor; // saving object cursor when you change to cyberspace
240     ObjID panel_ref;       // Last panel utilized.  stuffed here for reference
241 
242     // Stats...
243     int num_victories;
244     int time_in_cspace;
245     int rounds_fired;
246     int num_hits;
247 
248     // Playtesting data
249     int num_deaths;
250 
251     // from this point on - data is taking the time_to_level space
252     int32_t eye_pos; // physics eye position
253 
254     // let's hope State stays at 12 fixes
255     fix edms_state[12];
256 
257     // the player's actively selected inventory category.
258     ubyte current_active;
259     ubyte active_bio_tracks;
260 
261     short current_email;
262 
263     char version[6];
264     uchar dead;
265 
266     ushort lean_filter_state;
267     ushort FREE_BITS_HERE;
268     uchar mfd_save_vis;
269 
270     uint32_t auto_fire_click;
271 
272     uint32_t posture_slam_state;
273 
274     uchar terseness;
275 
276     uint32_t last_bob; // not last paul, but last bob
277 
278     uchar pad[9];
279 } Player;
280 
281 #pragma pack(pop)
282 
283 #define PLAYER_OBJ     (player_struct.rep)
284 #define PLAYER_BIN_X   OBJ_LOC_BIN_X(objs[PLAYER_OBJ].loc)
285 #define PLAYER_BIN_Y   OBJ_LOC_BIN_Y(objs[PLAYER_OBJ].loc)
286 #define PLAYER_FINE_X  OBJ_LOC_FINE_X(objs[PLAYER_OBJ].loc)
287 #define PLAYER_FINE_Y  OBJ_LOC_FINE_Y(objs[PLAYER_OBJ].loc)
288 #define PLAYER_PHYSICS (objs[PLAYER_OBJ].info.ph)
289 #define player_physics PLAYER_PHYSICS
290 
291 // Prototypes
292 errtype init_player(Player *pplr);
293 errtype player_tele_to(int x, int y);
294 errtype player_create_initial(void);
295 errtype player_startup(void);
296 errtype player_shutdown(void);
297 ubyte set_player_energy_spend(ubyte new_val);
298 bool IsFullscreenWareOn(void);
299 
300 // Globals
301 #ifdef __PLAYER_SRC
302 Player player_struct;
303 Obj *player_dos_obj;
304 #else
305 extern Player player_struct;
306 extern Obj *player_dos_obj;
307 #endif
308 
309 #endif // __PLAYER_H
310