Xonotic
campaign.qc File Reference
#include "campaign.qh"
#include <common/campaign_common.qh>
#include <common/mapinfo.qh>
#include <common/stats.qh>
#include <common/weapons/_all.qh>
#include <server/cheats.qh>
#include <server/intermission.qh>
#include <server/world.qh>
+ Include dependency graph for campaign.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int Campaign_GetLevelNum ()
 
string Campaign_GetMessage ()
 
float Campaign_Invalid ()
 
float CampaignBailout (string s)
 
void CampaignLevelWarp (float n)
 
void CampaignPostInit ()
 
void CampaignPostIntermission ()
 
void CampaignPreInit ()
 
void CampaignPreIntermission ()
 
void CampaignSaveCvar (string cvarname, float value)
 

Variables

string campaign_index_var
 
float campaign_level
 
float campaign_won
 

Function Documentation

◆ Campaign_GetLevelNum()

int Campaign_GetLevelNum ( )

Definition at line 44 of file campaign.qc.

References campaign_level.

Referenced by PrintWelcomeMessage().

45 {
46  return campaign_level + 1;
47 }
float campaign_level
Definition: campaign.qc:17
+ Here is the caller graph for this function:

◆ Campaign_GetMessage()

string Campaign_GetMessage ( )

Definition at line 49 of file campaign.qc.

References campaign_longdesc, campaign_shortdesc, and strcat().

Referenced by PrintWelcomeMessage().

50 {
51  return strcat(campaign_shortdesc[0], "\n^3\n", campaign_longdesc[0]);
52 }
string campaign_shortdesc[CAMPAIGN_MAX_ENTRIES]
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
string campaign_longdesc[CAMPAIGN_MAX_ENTRIES]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Campaign_Invalid()

float Campaign_Invalid ( )

Definition at line 31 of file campaign.qc.

References campaign_gametype, campaign_mapname, CampaignBailout(), GetMapname(), MapInfo_CurrentGametype(), MapInfo_Type_FromString(), and strcat().

Referenced by CampaignPostInit(), and CampaignPreInit().

32 {
33  string thismapname, wantedmapname;
34  thismapname = GetMapname();
35  wantedmapname = campaign_gametype[0];
36  if(MapInfo_CurrentGametype() != MapInfo_Type_FromString(wantedmapname, false))
37  return CampaignBailout("wrong game type!");
38  wantedmapname = campaign_mapname[0];
39  if(wantedmapname != thismapname)
40  return CampaignBailout(strcat("wrong map: ", wantedmapname, " != ", thismapname));
41  return 0;
42 }
float CampaignBailout(string s)
Definition: campaign.qc:22
string GetMapname()
Definition: intermission.qc:18
Gametype MapInfo_Type_FromString(string gtype, bool dowarn)
Definition: mapinfo.qc:589
Gametype MapInfo_CurrentGametype()
Definition: mapinfo.qc:1150
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
string campaign_gametype[CAMPAIGN_MAX_ENTRIES]
string campaign_mapname[CAMPAIGN_MAX_ENTRIES]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CampaignBailout()

float CampaignBailout ( string  s)

Definition at line 22 of file campaign.qc.

References autocvar__campaign_testrun, cvar_set(), error(), and LOG_INFO.

Referenced by Campaign_Invalid(), and CampaignPreInit().

23 {
24  cvar_set("g_campaign", "0");
25  LOG_INFO("^4campaign initialization failed: ", s);
27  error("CAMPAIGN FAIL AHAHAHAHAHAHAHAHAH))");
28  return 1;
29 }
bool autocvar__campaign_testrun
Definition: campaign.qh:3
#define LOG_INFO(...)
Definition: log.qh:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CampaignLevelWarp()

void CampaignLevelWarp ( float  n)

Definition at line 266 of file campaign.qc.

References campaign_entries, campaign_level, CampaignFile_Load(), CampaignFile_Unload(), CampaignSetup(), and error().

Referenced by GameCommand_warp().

267 {
268  if(n < 0)
269  n = campaign_level + 1;
271  CampaignFile_Load(n, 1);
272  if(campaign_entries)
273  CampaignSetup(0);
274  else
275  error("Sorry, cheater. You are NOT WELCOME.");
277 }
void CampaignSetup(int n)
int campaign_entries
float campaign_level
Definition: campaign.qc:17
float CampaignFile_Load(float offset, float entries)
void CampaignFile_Unload()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CampaignPostInit()

void CampaignPostInit ( )

Definition at line 105 of file campaign.qc.

References argv(), autocvar__campaign_testrun, campaign_fraglimit, Campaign_Invalid(), campaign_timelimit, cvar_set(), and tokenizebyseparator.

Referenced by spawnfunc().

106 {
107  // now some sanity checks
108  if(Campaign_Invalid())
109  return;
111  {
112  cvar_set("fraglimit", "0");
113  cvar_set("leadlimit", "0");
114  cvar_set("timelimit", "0.01");
115  }
116  else
117  {
118  // "default" uses implicit values, "" or "0" means no limit
120  if(argv(0) != "default") {
121  cvar_set("fraglimit", argv(0));
122  }
123  if(argv(1) != "default") {
124  cvar_set("leadlimit", argv(1));
125  }
126  if(campaign_timelimit[0] != "default") {
127  cvar_set("timelimit", campaign_timelimit[0]);
128  }
129  }
130 }
float Campaign_Invalid()
Definition: campaign.qc:31
string campaign_timelimit[CAMPAIGN_MAX_ENTRIES]
bool autocvar__campaign_testrun
Definition: campaign.qh:3
#define tokenizebyseparator
Definition: dpextensions.qh:21
string campaign_fraglimit[CAMPAIGN_MAX_ENTRIES]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CampaignPostIntermission()

void CampaignPostIntermission ( )

Definition at line 244 of file campaign.qc.

References campaign_entries, campaign_index_var, campaign_name, campaign_won, CampaignFile_Unload(), CampaignSetup(), localcmd, LOG_DEBUG, and strunzone().

Referenced by DoNextMapOverride().

245 {
246  // NOTE: campaign_won is 0 or 1, that is, points to the next level
247 
248  if(campaign_won && campaign_entries < 2)
249  {
250  // last map won!
251  LOG_DEBUG("^2test run: campaign looks GOOD");
252  localcmd("togglemenu 1\n");
254  return;
255  }
256 
261  campaign_name = "";
262 }
string campaign_name
float campaign_won
Definition: campaign.qc:18
string campaign_index_var
Definition: campaign.qc:19
void CampaignSetup(int n)
int campaign_entries
void CampaignFile_Unload()
#define LOG_DEBUG(...)
Definition: log.qh:85
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CampaignPreInit()

void CampaignPreInit ( )

Definition at line 54 of file campaign.qc.

References _MapInfo_Parse_Settemp(), argv(), autocvar__campaign_index, autocvar__campaign_name, autocvar_g_campaign_skill, autocvar_sv_cheats, campaign_bots, campaign_botskill, campaign_entries, campaign_forcewin, campaign_gametype, campaign_index_var, Campaign_Invalid(), campaign_level, campaign_mutators, campaign_name, CampaignBailout(), CampaignFile_Load(), CampaignFile_Unload(), cvar_set(), cvar_settemp(), ftos(), MAPINFO_SETTEMP_ACL_USER, MapInfo_SwitchGameType(), MapInfo_Type_FromString(), mapname, max(), strcat(), strzone(), and tokenizebyseparator.

Referenced by spawnfunc().

55 {
56  float baseskill;
59  campaign_index_var = strzone(strcat("g_campaign", campaign_name, "_index"));
61 
62  if(campaign_entries < 1)
63  {
64  CampaignBailout("unknown map");
65  return;
66  }
67 
69  {
72  CampaignBailout("JOLLY CHEATS AHAHAHAHAHAHAH))");
73  return;
74  }
75 
76  baseskill = max(0, autocvar_g_campaign_skill + campaign_botskill[0]);
77  campaign_forcewin = false;
78 
79  cvar_set("sv_public", "0");
80  cvar_set("pausable", "1");
81 
82  string cvar_campaignwrapper_list = strcat("; ", campaign_mutators[0], "; ");
83  int argc = tokenizebyseparator(cvar_campaignwrapper_list, "; ");
84  if(argc > 0)
85  {
86  for(int j = 0; j < argc; ++j)
87  {
88  string arg = argv(j);
89  if(arg == "") continue;
91  }
92  }
93 
94  cvar_settemp("g_campaign", "1");
95  cvar_settemp("g_dm", "0");
96  cvar_settemp("skill", ftos(baseskill));
97  cvar_settemp("bot_number", ftos(campaign_bots[0]));
98 
100 
101  if(Campaign_Invalid())
102  return;
103 }
float CampaignBailout(string s)
Definition: campaign.qc:22
float Campaign_Invalid()
Definition: campaign.qc:31
string campaign_name
string campaign_index_var
Definition: campaign.qc:19
float cvar_settemp(string tmp_cvar, string tmp_value)
Definition: util.qc:696
float campaign_botskill[CAMPAIGN_MAX_ENTRIES]
string mapname
Definition: csprogsdefs.qc:26
Gametype MapInfo_Type_FromString(string gtype, bool dowarn)
Definition: mapinfo.qc:589
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
int autocvar_g_campaign_skill
Definition: campaign.qh:8
float campaign_bots[CAMPAIGN_MAX_ENTRIES]
string campaign_mutators[CAMPAIGN_MAX_ENTRIES]
int autocvar_sv_cheats
Definition: cheats.qh:5
int campaign_entries
float campaign_level
Definition: campaign.qc:17
int autocvar__campaign_index
Definition: campaign.qh:4
string campaign_gametype[CAMPAIGN_MAX_ENTRIES]
#define tokenizebyseparator
Definition: dpextensions.qh:21
bool campaign_forcewin
Definition: campaign.qh:29
#define MAPINFO_SETTEMP_ACL_USER
Definition: mapinfo.qh:205
float CampaignFile_Load(float offset, float entries)
void CampaignFile_Unload()
void MapInfo_SwitchGameType(Gametype t)
Definition: mapinfo.qc:1178
void _MapInfo_Parse_Settemp(string pFilename, string acl, float type, string s, float recurse)
Definition: mapinfo.qc:627
string autocvar__campaign_name
Definition: campaign.qh:5
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CampaignPreIntermission()

void CampaignPreIntermission ( )

Definition at line 172 of file campaign.qc.

References autocvar__campaign_testrun, bprint(), campaign_entries, campaign_forcewin, campaign_index_var, campaign_level, campaign_name, campaign_won, CampaignSaveCvar(), cheatcount_total, checkrules_equality, cvar(), FOREACH_CLIENT, IS_PLAYER, IS_REAL_CLIENT, strcat(), and time.

Referenced by NextLevel().

173 {
174  int won = 0;
175  int lost = 0;
176  string savevar;
177 
179  if(it.winning)
180  won += 1;
181  else
182  lost += 1;
183  });
184 
186  {
187  campaign_won = 1;
188  bprint("Campaign test run, advancing level.\n");
189  }
190  else if(campaign_forcewin)
191  {
192  campaign_won = 1;
193  bprint("The current level has been WON.\n");
194  }
195  else if(won == 1 && lost == 0 && checkrules_equality == 0)
196  {
197  if(autocvar_timelimit != 0 && autocvar_fraglimit != 0 && time > autocvar_timelimit * 60) // checks if the timelimit has expired.
198  {
199  campaign_won = 0;
200  bprint("Time's up! The current level has been LOST.\n");
201  // sound!
202  }
203  else
204  {
205  campaign_won = 1;
206  bprint("The current level has been WON.\n");
207  // sound!
208  }
209  }
210  else if(autocvar_timelimit != 0 && time > autocvar_timelimit * 60)
211  {
212  campaign_won = 0;
213  bprint("Time's up! The current level has been LOST.\n");
214  // sound!
215  }
216  else
217  {
218  campaign_won = 0;
219  bprint("The current level has been LOST.\n");
220  // sound!
221  }
222 
224  {
226  {
227  if(campaign_entries < 2)
228  {
229  // I have won
230  savevar = strcat("g_campaign", campaign_name, "_won");
231  CampaignSaveCvar(savevar, 1);
232  // advance level (for menu to show it right)
234  }
235  else
236  {
237  // advance level
239  }
240  }
241  }
242 }
string campaign_name
float campaign_won
Definition: campaign.qc:18
string campaign_index_var
Definition: campaign.qc:19
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
bool autocvar__campaign_testrun
Definition: campaign.qh:3
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
float cheatcount_total
Definition: cheats.qh:10
int campaign_entries
float campaign_level
Definition: campaign.qc:17
void CampaignSaveCvar(string cvarname, float value)
Definition: campaign.qc:132
bool campaign_forcewin
Definition: campaign.qh:29
float checkrules_equality
Definition: world.qh:31
float time
Definition: csprogsdefs.qc:16
#define IS_PLAYER(v)
Definition: utils.qh:9
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CampaignSaveCvar()

void CampaignSaveCvar ( string  cvarname,
float  value 
)

Definition at line 132 of file campaign.qc.

References argv(), cvar_set(), error(), fclose(), fgets(), FILE_READ, FILE_WRITE, fopen(), fputs(), ftos(), registercvar(), strcat(), and tokenize_console.

Referenced by CampaignPreIntermission().

133 {
134  float fh;
135  float len;
136  string contents;
137  string l;
138 
139  registercvar(cvarname, ftos(value));
140  cvar_set(cvarname, ftos(value));
141  // note: cvarname must be remembered
142 
143  fh = fopen("campaign.cfg", FILE_READ);
144  contents = "";
145  if(fh >= 0)
146  {
147  while((l = fgets(fh)))
148  {
149  len = tokenize_console(l);
150  if(len != 3)
151  continue;
152  if(argv(0) != "set")
153  continue;
154  if(argv(1) == cvarname)
155  continue;
156  contents = strcat(contents, "set ", argv(1), " ", argv(2), "\n");
157  }
158  fclose(fh);
159  }
160  contents = strcat(contents, "set ", cvarname, " ", ftos(value), "\n");
161  fh = fopen("campaign.cfg", FILE_WRITE);
162  if(fh >= 0)
163  {
164  fputs(fh, contents);
165  }
166  else
167  {
168  error("Cannot write to campaign file");
169  }
170 }
const float FILE_READ
Definition: csprogsdefs.qc:231
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define tokenize_console
Definition: dpextensions.qh:24
const float FILE_WRITE
Definition: csprogsdefs.qc:233
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ campaign_index_var

string campaign_index_var

Definition at line 19 of file campaign.qc.

Referenced by CampaignPostIntermission(), CampaignPreInit(), and CampaignPreIntermission().

◆ campaign_level

float campaign_level

◆ campaign_won

float campaign_won

Definition at line 18 of file campaign.qc.

Referenced by CampaignPostIntermission(), and CampaignPreIntermission().