Debian Codegraph @

src/cdogs/actors.h

raw symbols SCIP
1 /*
2 C-Dogs SDL
3 A port of the legendary (and fun) action/arcade cdogs.
4 Copyright (C) 1995 Ronny Wester
5 Copyright (C) 2003 Jeremy Chin
6 Copyright (C) 2003-2007 Lucas Martin-King
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 This file incorporates work covered by the following copyright and
23 permission notice:
24
25 Copyright (c) 2013-2024 Cong Xu
26 All rights reserved.
27
28 Redistribution and use in source and binary forms, with or without
29 modification, are permitted provided that the following conditions are met:
30
31 Redistributions of source code must retain the above copyright notice, this
32 list of conditions and the following disclaimer.
33 Redistributions in binary form must reproduce the above copyright notice,
34 this list of conditions and the following disclaimer in the documentation
35 and/or other materials provided with the distribution.
36
37 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
38 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
41 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
47 POSSIBILITY OF SUCH DAMAGE.
48 */
49 #pragma once
50
51 #include "ai_context.h"
52 #include "animation.h"
53 #include "emitter.h"
54 #include "game_mode.h"
55 #include "grafx.h"
56 #include "mathc/mathc.h"
57 #include "pickup.h"
58 #include "player.h"
59 #include "thing.h"
60 #include "weapon.h"
61
62 #define ACTOR_W 14
63 #define ACTOR_H 10
64
65 #define FLAGS_HURTALWAYS (1 << 2)
66
67 // Computer characters only
68 #define FLAGS_DETOURING (1 << 5)
69 #define FLAGS_TRYRIGHT (1 << 6)
70 #define FLAGS_SLEEPING (1 << 7)
71 #define FLAGS_VISIBLE (1 << 8)
72 #define FLAGS_ASBESTOS (1 << 9) // Immune to fire
73 #define FLAGS_IMMUNITY (1 << 10) // Immune to poison
74 #define FLAGS_SEETHROUGH (1 << 11) // Almost transparent
75 #define FLAGS_DEAF (1 << 12)
76 #define FLAGS_ALL_SEEING (1 << 13)
77 #define FLAGS_UNLOCK_DOORS (1 << 14)
78 #define FLAGS_WAKING (1 << 15)
79
80 // Special flags
81 #define FLAGS_RUNS_AWAY (1 << 16) // Move directly away from player
82 #define FLAGS_GOOD_GUY (1 << 17) // Shots cannot hurt player
83 #define FLAGS_PRISONER (1 << 18) // Won't move until touched by player
84 #define FLAGS_INVULNERABLE (1 << 19)
85 #define FLAGS_FOLLOWER (1 << 20) // Follows player
86 #define FLAGS_PENALTY (1 << 21) // Big score penalty if shot
87 #define FLAGS_VICTIM (1 << 22) // Can be shot by everyone
88 #define FLAGS_SNEAKY (1 << 23) // Always shoot back when player shoots
89 #define FLAGS_SLEEPALWAYS (1 << 24)
90 #define FLAGS_AWAKEALWAYS (1 << 25)
91 #define FLAGS_RESCUED (1 << 26) // Run towards exit
92 #define FLAGS_MOVE_AND_SHOOT (1 << 27) // Can move and shoot at the same time
93
94 typedef enum
95 {
96 ACTORACTION_MOVING,
97 ACTORACTION_EXITING
98 } ActorAction;
99
100 typedef struct Actor
101 {
102 struct vec2 Pos;
103 // Vector that the player is attempting to move in, based on input
104 struct vec2 MoveVel;
105 direction_e direction;
106 // Rotation used to draw the actor, which will lag behind the actual
107 // rotation in order to show smooth rotation
108 float DrawRadians;
109 Animation anim;
110 int stateCounter;
111 int lastCmd;
112 // Whether the player ran into something whilst trying to move
113 // In this situation, we interrupt dead reckoning and resend the position
114 bool hasCollided;
115 // Whether the last special command was performed with a direction
116 // This differentiates between a special command and weapon switch
117 bool specialCmdDir;
118 // If the actor wants to pick up everything, even those that need to be
119 // manually picked up using special input
120 bool PickupAll;
121 // Flag to specify whether this actor is over a special pickup,
122 // such as weapons which will replace the current weapon.
123 // If the player presses switch when in this state, instead of switching
124 // weapons, pick up.
125 bool CanPickupSpecial;
126
127 // -1 if human character (get from player data), otherwise index into
128 // CharacterStore OtherChars
129 int charId;
130 int PlayerUID; // -1 unless a human player
131 int uid; // unique ID across all actors
132 int pilotUID; // the actor that controls this
133 // (same as uid for normal actors)
134 int vehicleUID; // -1 unless piloting a vehicle
135 Weapon guns[MAX_WEAPONS];
136 CArray ammo; // of int
137 int gunIndex;
138 int lastGunIdx;
139
140 int health;
141 // A counter for player death
142 // If 0, player is alive
143 // If >0 but less than deathPics, player is "dying" and this variable
144 // is used as the frame in the death animation
145 int dead;
146 int flamed;
147 int poisoned;
148 int petrified;
149 int confused;
150 int flags;
151
152 int turns;
153
154 int slideLock;
155 // For damage text
156 int accumulatedDamage;
157 int damageCooldownTicks;
158 // Facial expression when melee or taking damage
159 int grimaceCounter;
160
161 // What to say (text label appears above actor) and how long to say it
162 char Chatter[256];
163 int ChatterCounter;
164
165 Emitter barrelSmoke;
166 Emitter healEffect;
167
168 // Gore emitters
169 Emitter blood1;
170 Emitter blood2;
171 Emitter blood3;
172 int bleedCounter;
173
174 color_t footprintMask;
175 int footprintCounter;
176
177 bool hasShot;
178
179 // Whether actor is in a pickup menu and their current selection
180 struct
181 {
182 const Pickup *pickup;
183 const PickupEffect *effect;
184 int index;
185 } pickupMenu;
186
187 // Signals to other AIs what this actor is doing
188 ActorAction action;
189 AIContext *aiContext;
190 Thing thing;
191 bool isInUse;
192 } TActor;
193
194 // Store all actors in-line in an array
195 // Destroying actors does not modify the array, only switches
196 // a boolean flag isInUse to denote whether this instance is
197 // in use.
198 // Actors should be identified by index
199 // There is a small chance of invalidating pointers if
200 // actors are added and the array must be resized.
201 // Therefore do not hold actor pointers and reuse.
202 extern CArray gActors; // of TActor
203
204 void ActorSetState(TActor *actor, const ActorAnimation state);
205 void UpdateActorState(TActor *actor, int ticks);
206 void ActorMove(const NActorMove am);
207 int CommandActor(TActor *actor, int cmd, int ticks);
208 void SlideActor(TActor *actor, int cmd);
209 void UpdateAllActors(const int ticks);
210 void ActorsPilotVehicles(void);
211 void ActorHeal(TActor *actor, const int amount, const bool exceedMax);
212 void InjureActor(TActor *actor, int injury);
213
214 void ActorAddAmmo(TActor *actor, const int ammoId, const int amount);
215 // Whether the actor has a gun that uses this ammo
216 bool ActorUsesAmmo(const TActor *actor, const int ammoId);
217 void ActorReplaceGun(const NActorReplaceGun rg);
218 void ActorSetAIState(TActor *actor, const AIState s);
219 void ActorPilot(const NActorPilot ap);
220
221 void ActorsInit(void);
222 void ActorsTerminate(void);
223 int ActorsGetNextUID(void);
224 int ActorsGetFreeIndex(void);
225 TActor *ActorAdd(NActorAdd aa);
226 void ActorDestroy(TActor *a);
227
228 TActor *ActorGetByUID(const int uid);
229 const Character *ActorGetCharacter(const TActor *a);
230 #define ACTOR_GET_GUN(a) (&(a)->guns[(a)->gunIndex])
231 #define ACTOR_GET_GRENADE(a) (&(a)->guns[MAX_GUNS])
232 #define ACTOR_GET_WEAPON(a) \
233 (ACTOR_GET_GUN(a)->Gun != NULL ? ACTOR_GET_GUN(a) : ACTOR_GET_GRENADE(a))
234 struct vec2 ActorGetAverageWeaponMuzzleOffset(const TActor *a);
235 struct vec2 ActorGetMuzzleOffset(
236 const TActor *a, const Weapon *w, const int barrel);
237 // Returns -1 if gun does not use ammo
238 int ActorWeaponGetAmmo(
239 const TActor *a, const WeaponClass *wc, const int barrel);
240 // Returns -1 if no barrels can fire
241 int ActorGetCanFireBarrel(const TActor *a, const Weapon *w);
242 bool ActorCanSwitchToWeapon(const TActor *a, const int slot);
243 bool ActorTrySwitchWeapon(const TActor *a);
244 // Returns -1 if actor doesn't have gun
245 int ActorFindGun(const TActor *a, const WeaponClass *wc);
246 int ActorGetNumWeapons(const TActor *a);
247 int ActorGetNumGuns(const TActor *a);
248 int ActorGetNumGrenades(const TActor *a);
249 void ActorSwitchGun(const NActorSwitchGun sg);
250 void ActorPickupGun(const TActor *a, const WeaponClass *wc);
251 bool ActorIsImmune(const TActor *actor, const special_damage_e damage);
252 bool ActorTakesDamage(const TActor *actor, const special_damage_e damage);
253 void ActorHit(const NThingDamage d);
254 bool ActorIsInvulnerable(
255 const TActor *a, const int flags, const int playerUID, const GameMode mode,
256 const special_damage_e special);
257
258 int ActorGetMaxHeal(const TActor *a, const bool exceedMax);
259 int ActorGetHealthPercent(const TActor *a);
260 bool ActorIsLowHealth(const TActor *a);
261 bool ActorIsGrimacing(const TActor *a);
262
263 bool ActorIsLocalPlayer(const int uid);
264 void ActorPersistPlayerWeaponsAndAmmo(const TActor *a);