1 #ifndef __WEAPONS_H
2 #define __WEAPONS_H
3 
4 /*
5 	weapons2.h
6 
7 	Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
8 	and the "Aleph One" developers.
9 
10 	This program is free software; you can redistribute it and/or modify
11 	it under the terms of the GNU General Public License as published by
12 	the Free Software Foundation; either version 3 of the License, or
13 	(at your option) any later version.
14 
15 	This program is distributed in the hope that it will be useful,
16 	but WITHOUT ANY WARRANTY; without even the implied warranty of
17 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 	GNU General Public License for more details.
19 
20 	This license is contained in the file "COPYING",
21 	which is included with this source code; it is available online at
22 	http://www.gnu.org/licenses/gpl.html
23 
24 	Saturday, May 13, 1995 4:41:42 PM- rdm created.
25 
26 Feb 4, 2000 (Loren Petrich):
27 	Added SMG stuff
28 
29 Feb 6, 2000 (Loren Petrich):
30 	Added access to size of weapon-definition structure and to the number of weapon types
31 
32 May 26, 2000 (Loren Petrich):
33 	Added XML support for configuring various weapon features
34 
35 Aug 31, 2000 (Loren Petrich):
36 	Added stuff for unpacking and packing
37 */
38 
39 #include "cstypes.h"
40 
41 /* enums for player.c */
42 enum { /* Weapons */
43 	_weapon_fist,
44 	_weapon_pistol,
45 	_weapon_plasma_pistol,
46 	_weapon_assault_rifle,
47 	_weapon_missile_launcher,
48 	_weapon_flamethrower,
49 	_weapon_alien_shotgun,
50 	_weapon_shotgun,
51 	_weapon_ball, // or something
52 	// LP addition:
53 	_weapon_smg,
54 	MAXIMUM_NUMBER_OF_WEAPONS,
55 
56 	_weapon_doublefisted_pistols= MAXIMUM_NUMBER_OF_WEAPONS, /* This is a pseudo-weapon */
57 	_weapon_doublefisted_shotguns,
58 	PLAYER_TORSO_SHAPE_COUNT
59 };
60 
61 enum {
62 	_shape_weapon_idle,
63 	_shape_weapon_charging,
64 	_shape_weapon_firing,
65         PLAYER_TORSO_WEAPON_ACTION_COUNT	// ZZZ: added this one
66 };
67 
68 enum {
69 	_primary_weapon,
70 	_secondary_weapon,
71 	NUMBER_OF_TRIGGERS
72 };
73 
74 enum /* weapon display positioning modes */
75 {
76 	_position_low, /* position==0 is invisible, position==FIXED_ONE is sticking out from left/bottom */
77 	_position_center, /* position==0 is off left/bottom, position==FIXED_ONE is off top/right */
78 	_position_high /* position==0 is invisible, position==FIXED_ONE is sticking out from right/top
79 		(mirrored, whether you like it or not) */
80 };
81 
82 /* ----------------- structures */
83 
84 struct weapon_display_information
85 {
86 	// Has sequence info for 3D-model weapon display
87 	short collection, shape_index, low_level_shape_index;
88 
89 	_fixed vertical_position, horizontal_position;
90 	short vertical_positioning_mode, horizontal_positioning_mode;
91 	short transfer_mode;
92 	_fixed transfer_phase;
93 
94 	bool flip_horizontal, flip_vertical;
95 
96 	// Needed for animated models: which frame in an individual sequence (0, 1, 2, ...)
97 	short Frame, NextFrame;
98 
99 	// Needed for animated models: which tick in a frame, and total ticks per frame
100 	short Phase, Ticks;
101 };
102 
103 // SB: This needs to be accessed in lua_script.cpp
104 
105 enum
106 {
107 	MAXIMUM_SHELL_CASINGS= 4
108 };
109 
110 struct trigger_data {
111 short state, phase;
112 short rounds_loaded;
113 short shots_fired, shots_hit;
114 short ticks_since_last_shot; /* used to play shell casing sound, and to calculate arc for shell casing drawing... */
115 short ticks_firing; /* How long have we been firing? (only valid for automatics) */
116 uint16 sequence; /* what step of the animation are we in? (NOT guaranteed to be in sync!) */
117 };
118 
119 struct weapon_data {
120 	short weapon_type; /* stored here to make life easier.. */
121 	uint16 flags;
122 	uint16 unused; /* non zero-> weapon is powered up */
123 	struct trigger_data triggers[NUMBER_OF_TRIGGERS];
124 };
125 
126 struct shell_casing_data
127 {
128 	short type;
129 	short frame;
130 
131 	uint16 flags;
132 
133 	_fixed x, y;
134 	_fixed vx, vy;
135 };
136 
137 struct player_weapon_data {
138 	short current_weapon;
139 	short desired_weapon;
140 	struct weapon_data weapons[MAXIMUM_NUMBER_OF_WEAPONS];
141 	struct shell_casing_data shell_casings[MAXIMUM_SHELL_CASINGS];
142 };
143 
144 // For external access:
145 const int SIZEOF_weapon_definition = 134;
146 
147 const int SIZEOF_player_weapon_data = 472;
148 
149 /* ----------------- prototypes */
150 /* called once at startup */
151 void initialize_weapon_manager(void);
152 
153 /* Initialize the weapons for a completely new game. */
154 void initialize_player_weapons_for_new_game(short player_index);
155 
156 /* initialize the given players weapons-> called after creating a player */
157 void initialize_player_weapons(short player_index);
158 
159 // Old external-access stuff: superseded by the packing and unpacking routines below
160 void *get_weapon_array(void);
161 int32 calculate_weapon_array_length(void);
162 
163 /* while this returns true, keep calling.. */
164 bool get_weapon_display_information(short *count,
165 	struct weapon_display_information *data);
166 
167 /* When the player runs over an item, check for reloads, etc. */
168 void process_new_item_for_reloading(short player_index, short item_type);
169 
170 /* Update the given player's weapons */
171 void update_player_weapons(short player_index, uint32 action_flags);
172 
173 /* Mark the weapon collections for loading or unloading.. */
174 void mark_weapon_collections(bool loading);
175 
176 /* Called when a player dies to discharge the weapons that they have charged up. */
177 void discharge_charged_weapons(short player_index);
178 
179 /* Called on entry to a level, and will change weapons if this one doesn't work */
180 /*  in the given environment. */
181 void check_player_weapons_for_environment_change(void);
182 
183 /* Tell me when one of my projectiles hits, and return the weapon_identifier I passed */
184 /*  to new_projectile... */
185 void player_hit_target(short player_index, short weapon_identifier);
186 
187 /* for drawing the player */
188 void get_player_weapon_mode_and_type(short player_index, short *shape_weapon_type,
189 	short *shape_mode);
190 
191 /* For the game window to update properly */
192 short get_player_desired_weapon(short player_index);
193 
194 /* This is pinned to the maximum I think I can hold.. */
195 short get_player_weapon_ammo_count(short player_index, short which_weapon, short which_trigger);
196 
197 short get_player_weapon_ammo_maximum(short player_index, short which_weapon, short which_trigger);
198 int16 get_player_weapon_ammo_type(short player_index, short which_weapon, short which_trigger);
199 bool get_player_weapon_drawn(short player_index, short which_weapon, short which_trigger);
200 
201 #ifdef DEBUG
202 void debug_print_weapon_status(void);
203 #endif
204 
205 // LP: to pack and unpack this data;
206 // these do not make the definitions visible to the outside world
207 
208 uint8 *unpack_player_weapon_data(uint8 *Stream, size_t Count);
209 uint8 *pack_player_weapon_data(uint8 *Stream, size_t Count);
210 uint8 *unpack_weapon_definition(uint8 *Stream, size_t Count);
211 uint8 *pack_weapon_definition(uint8 *Stream, size_t Count);
212 uint8* unpack_m1_weapon_definition(uint8* Stream, size_t Count);
213 void init_weapon_definitions();
214 
215 // LP additions: get number of weapon types;
216 size_t get_number_of_weapon_types();
217 
218 class InfoTree;
219 void parse_mml_weapons(const InfoTree& root);
220 void reset_mml_weapons();
221 
222 #endif
223 
224