1 /* 2 C-Dogs SDL 3 A port of the legendary (and fun) action/arcade cdogs. 4 5 Copyright (c) 2013-2019, 2021 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 "proto/msg.pb.h" 35 36 37 // Game events represent anything that is created within the game but is 38 // required by outside systems, e.g. sound events 39 // This is to prevent the game from depending on these external systems 40 41 typedef enum 42 { 43 GAME_EVENT_NONE, 44 45 // Net initialisation messages 46 GAME_EVENT_CLIENT_CONNECT, 47 GAME_EVENT_CLIENT_ID, 48 GAME_EVENT_CAMPAIGN_DEF, 49 GAME_EVENT_PLAYER_DATA, 50 GAME_EVENT_PLAYER_REMOVE, 51 GAME_EVENT_TILE_SET, 52 53 GAME_EVENT_THING_DAMAGE, 54 GAME_EVENT_MAP_OBJECT_ADD, 55 GAME_EVENT_MAP_OBJECT_REMOVE, 56 GAME_EVENT_CLIENT_READY, 57 GAME_EVENT_NET_GAME_START, 58 59 GAME_EVENT_CONFIG, 60 GAME_EVENT_SCORE, 61 GAME_EVENT_SOUND_AT, 62 GAME_EVENT_SCREEN_SHAKE, 63 GAME_EVENT_SET_MESSAGE, 64 65 // Use to signal start of game; useless for single player, 66 // but for networked games it's used to set game ticks 0 67 GAME_EVENT_GAME_START, 68 GAME_EVENT_GAME_BEGIN, 69 70 GAME_EVENT_ACTOR_ADD, 71 GAME_EVENT_ACTOR_MOVE, 72 GAME_EVENT_ACTOR_STATE, 73 GAME_EVENT_ACTOR_DIR, 74 GAME_EVENT_ACTOR_SLIDE, 75 GAME_EVENT_ACTOR_IMPULSE, 76 GAME_EVENT_ACTOR_SWITCH_GUN, 77 GAME_EVENT_ACTOR_PICKUP_ALL, 78 GAME_EVENT_ACTOR_REPLACE_GUN, 79 GAME_EVENT_ACTOR_HEAL, 80 GAME_EVENT_ACTOR_ADD_AMMO, 81 GAME_EVENT_ACTOR_USE_AMMO, 82 GAME_EVENT_ACTOR_DIE, 83 GAME_EVENT_ACTOR_MELEE, 84 GAME_EVENT_ACTOR_PILOT, 85 86 GAME_EVENT_ADD_PICKUP, 87 GAME_EVENT_REMOVE_PICKUP, 88 89 GAME_EVENT_BULLET_BOUNCE, 90 GAME_EVENT_REMOVE_BULLET, 91 GAME_EVENT_PARTICLE_REMOVE, 92 GAME_EVENT_GUN_FIRE, 93 GAME_EVENT_GUN_RELOAD, 94 GAME_EVENT_GUN_STATE, 95 GAME_EVENT_ADD_BULLET, 96 GAME_EVENT_ADD_PARTICLE, 97 GAME_EVENT_TRIGGER, 98 GAME_EVENT_EXPLORE_TILES, 99 GAME_EVENT_RESCUE_CHARACTER, 100 GAME_EVENT_OBJECTIVE_UPDATE, 101 GAME_EVENT_ADD_KEYS, 102 103 // Can complete mission 104 GAME_EVENT_MISSION_COMPLETE, 105 106 // Left pickup area 107 GAME_EVENT_MISSION_INCOMPLETE, 108 // In pickup area 109 GAME_EVENT_MISSION_PICKUP, 110 GAME_EVENT_MISSION_END 111 } GameEventType; 112 113 // Which game events should be passed along to server or client 114 typedef struct 115 { 116 GameEventType Type; 117 // Whether this message is sent by server to clients 118 bool Broadcast; 119 // Whether clients send this message to the server 120 bool Submit; 121 // Whether to simply enqueue as game event; otherwise processed by handler 122 bool Enqueue; 123 // Whether to broadcast these events only after game start 124 bool GameStart; 125 const pb_msgdesc_t *Fields; 126 } GameEventEntry; 127 GameEventEntry GameEventGetEntry(const GameEventType e); 128 129 typedef struct 130 { 131 GameEventType Type; 132 int Delay; 133 union 134 { 135 NPlayerData PlayerData; 136 NPlayerRemove PlayerRemove; 137 NTileSet TileSet; 138 NThingDamage ThingDamage; 139 NMapObjectAdd MapObjectAdd; 140 NMapObjectRemove MapObjectRemove; 141 NConfig Config; 142 NScore Score; 143 NSound SoundAt; 144 struct 145 { 146 int Amount; 147 bool CameraSubjectOnly; 148 int ActorUID; 149 } Shake; 150 struct 151 { 152 char Message[256]; 153 int Ticks; 154 } SetMessage; 155 NGameBegin GameBegin; 156 NActorAdd ActorAdd; 157 NActorMove ActorMove; 158 NActorState ActorState; 159 NActorDir ActorDir; 160 NActorSlide ActorSlide; 161 NActorImpulse ActorImpulse; 162 NActorSwitchGun ActorSwitchGun; 163 NActorPickupAll ActorPickupAll; 164 NActorReplaceGun ActorReplaceGun; 165 NActorHeal Heal; 166 NActorAddAmmo AddAmmo; 167 NActorUseAmmo UseAmmo; 168 NActorDie ActorDie; 169 NActorMelee Melee; 170 NActorPilot Pilot; 171 NAddPickup AddPickup; 172 NRemovePickup RemovePickup; 173 struct 174 { 175 int UID; 176 int Count; 177 } ObjectSetCounter; 178 NBulletBounce BulletBounce; 179 NRemoveBullet RemoveBullet; 180 int ParticleRemoveId; 181 NGunFire GunFire; 182 NGunReload GunReload; 183 NGunState GunState; 184 NAddBullet AddBullet; 185 AddParticle AddParticle; 186 NTrigger TriggerEvent; 187 NExploreTiles ExploreTiles; 188 NRescueCharacter Rescue; 189 NObjectiveUpdate ObjectiveUpdate; 190 NAddKeys AddKeys; 191 NMissionComplete MissionComplete; 192 NMissionEnd MissionEnd; 193 } u; 194 } GameEvent; 195 196 extern CArray gGameEvents; // of GameEvent 197 198 #define GAME_OVER_DELAY (FPS_FRAMELIMIT * 2) 199 200 void GameEventsInit(CArray *store); 201 void GameEventsTerminate(CArray *store); 202 void GameEventsEnqueue(CArray *store, GameEvent e); 203 void GameEventsClear(CArray *store); 204 205 GameEvent GameEventNew(GameEventType type); 206 GameEvent GameEventNewActorAdd(const struct vec2 pos, const Character *c, const bool isNPC); 207