Debian Codegraph @

src/cdogs/game_events.h

raw symbols SCIP
1 /*
2 C-Dogs SDL
3 A port of the legendary (and fun) action/arcade cdogs.
4
5 Copyright (c) 2013-2019, 2021, 2023 Cong Xu
6 All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11 Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
13 Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
28 */
29 #pragma once
30
31 #include "c_array.h"
32 #include "character.h"
33 #include "particle.h"
34 #include "player.h"
35 #include "proto/msg.pb.h"
36
37
38 // Game events represent anything that is created within the game but is
39 // required by outside systems, e.g. sound events
40 // This is to prevent the game from depending on these external systems
41
42 typedef enum
43 {
44 GAME_EVENT_NONE,
45
46 // Net initialisation messages
47 GAME_EVENT_CLIENT_CONNECT,
48 GAME_EVENT_CLIENT_ID,
49 GAME_EVENT_CAMPAIGN_DEF,
50 GAME_EVENT_PLAYER_DATA,
51 GAME_EVENT_PLAYER_REMOVE,
52 GAME_EVENT_TILE_SET,
53
54 GAME_EVENT_THING_DAMAGE,
55 GAME_EVENT_MAP_OBJECT_ADD,
56 GAME_EVENT_MAP_OBJECT_REMOVE,
57 GAME_EVENT_CLIENT_READY,
58 GAME_EVENT_NET_GAME_START,
59
60 GAME_EVENT_CONFIG,
61 GAME_EVENT_SCORE,
62 GAME_EVENT_SOUND_AT,
63 GAME_EVENT_SCREEN_SHAKE,
64 GAME_EVENT_SET_MESSAGE,
65
66 // Use to signal start of game; useless for single player,
67 // but for networked games it's used to set game ticks 0
68 GAME_EVENT_GAME_START,
69 GAME_EVENT_GAME_BEGIN,
70
71 GAME_EVENT_ACTOR_ADD,
72 GAME_EVENT_ACTOR_MOVE,
73 GAME_EVENT_ACTOR_STATE,
74 GAME_EVENT_ACTOR_DIR,
75 GAME_EVENT_ACTOR_SLIDE,
76 GAME_EVENT_ACTOR_IMPULSE,
77 GAME_EVENT_ACTOR_SWITCH_GUN,
78 GAME_EVENT_ACTOR_PICKUP_ALL,
79 GAME_EVENT_ACTOR_REPLACE_GUN,
80 GAME_EVENT_ACTOR_HEAL,
81 GAME_EVENT_ACTOR_ADD_AMMO,
82 GAME_EVENT_ACTOR_USE_AMMO,
83 GAME_EVENT_ACTOR_DIE,
84 GAME_EVENT_PLAYER_ADD_LIVES,
85 GAME_EVENT_ACTOR_MELEE,
86 GAME_EVENT_ACTOR_PILOT,
87
88 GAME_EVENT_ADD_PICKUP,
89 GAME_EVENT_REMOVE_PICKUP,
90
91 GAME_EVENT_BULLET_BOUNCE,
92 GAME_EVENT_REMOVE_BULLET,
93 GAME_EVENT_PARTICLE_REMOVE,
94 GAME_EVENT_GUN_FIRE,
95 GAME_EVENT_GUN_RELOAD,
96 GAME_EVENT_GUN_STATE,
97 GAME_EVENT_ADD_BULLET,
98 GAME_EVENT_ADD_PARTICLE,
99 GAME_EVENT_TRIGGER,
100 GAME_EVENT_EXPLORE_TILES,
101 GAME_EVENT_RESCUE_CHARACTER,
102 GAME_EVENT_OBJECTIVE_UPDATE,
103 GAME_EVENT_ADD_KEYS,
104 GAME_EVENT_DOOR_TOGGLE,
105
106 // Can complete mission
107 GAME_EVENT_MISSION_COMPLETE,
108
109 // Left pickup area
110 GAME_EVENT_MISSION_INCOMPLETE,
111 // In pickup area
112 GAME_EVENT_MISSION_PICKUP,
113 GAME_EVENT_MISSION_END
114 } GameEventType;
115
116 // Which game events should be passed along to server or client
117 typedef struct
118 {
119 GameEventType Type;
120 // Whether this message is sent by server to clients
121 bool Broadcast;
122 // Whether clients send this message to the server
123 bool Submit;
124 // Whether to simply enqueue as game event; otherwise processed by handler
125 bool Enqueue;
126 // Whether to broadcast these events only after game start
127 bool GameStart;
128 const pb_msgdesc_t *Fields;
129 } GameEventEntry;
130 GameEventEntry GameEventGetEntry(const GameEventType e);
131
132 typedef struct
133 {
134 GameEventType Type;
135 int Delay;
136 union
137 {
138 NPlayerData PlayerData;
139 NPlayerRemove PlayerRemove;
140 NTileSet TileSet;
141 NThingDamage ThingDamage;
142 NMapObjectAdd MapObjectAdd;
143 NMapObjectRemove MapObjectRemove;
144 NConfig Config;
145 NScore Score;
146 NSound SoundAt;
147 struct
148 {
149 int Amount;
150 bool CameraSubjectOnly;
151 int ActorUID;
152 } Shake;
153 struct
154 {
155 char Message[256];
156 int Ticks;
157 } SetMessage;
158 NGameBegin GameBegin;
159 NActorAdd ActorAdd;
160 NActorMove ActorMove;
161 NActorState ActorState;
162 NActorDir ActorDir;
163 NActorSlide ActorSlide;
164 NActorImpulse ActorImpulse;
165 NActorSwitchGun ActorSwitchGun;
166 NActorPickupAll ActorPickupAll;
167 NActorReplaceGun ActorReplaceGun;
168 NActorHeal Heal;
169 NActorAddAmmo AddAmmo;
170 NActorUseAmmo UseAmmo;
171 NActorDie ActorDie;
172 NPlayerAddLives PlayerAddLives;
173 NActorMelee Melee;
174 NActorPilot Pilot;
175 NAddPickup AddPickup;
176 NRemovePickup RemovePickup;
177 struct
178 {
179 int UID;
180 int Count;
181 } ObjectSetCounter;
182 NBulletBounce BulletBounce;
183 NRemoveBullet RemoveBullet;
184 int ParticleRemoveId;
185 NGunFire GunFire;
186 NGunReload GunReload;
187 NGunState GunState;
188 NAddBullet AddBullet;
189 AddParticle AddParticle;
190 NTrigger TriggerEvent;
191 NExploreTiles ExploreTiles;
192 NRescueCharacter Rescue;
193 NObjectiveUpdate ObjectiveUpdate;
194 NAddKeys AddKeys;
195 NDoorToggle DoorToggle;
196 NMissionComplete MissionComplete;
197 NMissionEnd MissionEnd;
198 } u;
199 } GameEvent;
200
201 extern CArray gGameEvents; // of GameEvent
202
203 #define GAME_OVER_DELAY (FPS_FRAMELIMIT * 2)
204
205 void GameEventsInit(CArray *store);
206 void GameEventsTerminate(CArray *store);
207 void GameEventsEnqueue(CArray *store, GameEvent e);
208 void GameEventsClear(CArray *store);
209
210 GameEvent GameEventNew(GameEventType type);
211 GameEvent GameEventNewActorAdd(const struct vec2 pos, const Character *c, const PlayerData *p);