Debian Codegraph @

src/cdogs/game_mode.c

raw symbols SCIP
1 /*
2 C-Dogs SDL
3 A port of the legendary (and fun) action/arcade cdogs.
4 Copyright (c) 2013-2017, 2019-2021 Cong Xu
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12 Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 POSSIBILITY OF SUCH DAMAGE.
27 */
28 #include "game_mode.h"
29
30 #include "campaigns.h"
31 #include "config.h"
32 #include "player.h"
33 #include "utils.h"
34
35 const char *GameModeStr(const GameMode g)
36 {
37 switch (g)
38 {
39 T2S(GAME_MODE_NORMAL, "Campaign");
40 T2S(GAME_MODE_DOGFIGHT, "Dogfight");
41 T2S(GAME_MODE_DEATHMATCH, "Deathmatch");
42 T2S(GAME_MODE_QUICK_PLAY, "Quick Play");
43 default:
44 return "";
45 }
46 }
47
48 bool IsIntroNeeded(const GameMode mode)
49 {
50 return mode == GAME_MODE_NORMAL;
51 }
52
53 bool IsGameOptionsNeeded(const GameMode mode)
54 {
55 // Clients can't set game options
56 if (gCampaign.IsClient)
57 return false;
58
59 switch (mode)
60 {
61 case GAME_MODE_NORMAL:
62 return !gCampaign.OptionsSet;
63 case GAME_MODE_DOGFIGHT:
64 return !gCampaign.OptionsSet;
65 case GAME_MODE_DEATHMATCH:
66 return true;
67 case GAME_MODE_QUICK_PLAY:
68 return !gCampaign.OptionsSet;
69 default:
70 CASSERT(false, "unknown game mode");
71 return false;
72 }
73 }
74
75 bool IsScoreNeeded(const GameMode mode)
76 {
77 return mode != GAME_MODE_DOGFIGHT && mode != GAME_MODE_DEATHMATCH;
78 }
79
80 bool HasObjectives(const GameMode mode)
81 {
82 return mode == GAME_MODE_NORMAL || mode == GAME_MODE_QUICK_PLAY;
83 }
84
85 bool IsAutoMapEnabled(const GameMode mode)
86 {
87 return mode != GAME_MODE_DOGFIGHT && mode != GAME_MODE_DEATHMATCH;
88 }
89
90 bool CanLevelSelect(const GameMode mode)
91 {
92 return mode == GAME_MODE_NORMAL;
93 }
94
95 bool IsMissionBriefingNeeded(const GameMode mode, const char *missionBriefing)
96 {
97 return HasObjectives(mode) && GetNumPlayers(PLAYER_ANY, false, true) > 0 &&
98 missionBriefing != NULL && strlen(missionBriefing) > 0;
99 }
100
101 bool AreKeysAllowed(const GameMode mode)
102 {
103 return mode == GAME_MODE_NORMAL || mode == GAME_MODE_QUICK_PLAY;
104 }
105
106 bool AreHealthPickupsAllowed(const GameMode mode)
107 {
108 return mode == GAME_MODE_NORMAL || mode == GAME_MODE_QUICK_PLAY;
109 }
110
111 bool IsMultiplayer(const GameMode mode)
112 {
113 return mode == GAME_MODE_DOGFIGHT || mode == GAME_MODE_DEATHMATCH;
114 }
115
116 bool IsPVP(const GameMode mode)
117 {
118 return mode == GAME_MODE_DOGFIGHT || mode == GAME_MODE_DEATHMATCH;
119 }
120
121 bool HasExit(const GameMode mode)
122 {
123 return mode != GAME_MODE_DOGFIGHT && mode != GAME_MODE_DEATHMATCH;
124 }
125
126 bool HasRounds(const GameMode mode)
127 {
128 return mode == GAME_MODE_DOGFIGHT;
129 }
130
131 int ModeMaxRoundsWon(const GameMode mode)
132 {
133 CASSERT(IsPVP(mode), "Game mode does not have any max rounds");
134 switch (mode)
135 {
136 case GAME_MODE_DOGFIGHT:
137 return ConfigGetInt(&gConfig, "Dogfight.FirstTo");
138 case GAME_MODE_DEATHMATCH:
139 return 1;
140 default:
141 CASSERT(false, "unknown game mode");
142 return 0;
143 }
144 }
145
146 bool ModeHasNPCs(const GameMode mode)
147 {
148 return mode != GAME_MODE_DOGFIGHT && mode != GAME_MODE_DEATHMATCH;
149 }