Xonotic
campaign_file.qc File Reference
#include "campaign_file.qh"
+ Include dependency graph for campaign_file.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CAMPAIGN_GETARG
 

Functions

float CampaignFile_Load (int offset, float n)
 
void CampaignFile_Unload ()
 

Macro Definition Documentation

◆ CAMPAIGN_GETARG

#define CAMPAIGN_GETARG
Value:
a = argv(++i); \
if(a == ",") \
a = ""; \
else \
++i

Referenced by CampaignFile_Load().

Function Documentation

◆ CampaignFile_Load()

float CampaignFile_Load ( int  offset,
float  n 
)

Definition at line 14 of file campaign_file.qc.

References campaign_bots, campaign_botskill, campaign_entries, campaign_fraglimit, campaign_gametype, CAMPAIGN_GETARG, campaign_longdesc, campaign_mapname, CAMPAIGN_MAX_ENTRIES, campaign_mutators, campaign_name, campaign_offset, campaign_shortdesc, campaign_timelimit, campaign_title, error(), fclose(), fgets(), FILE_READ, fopen(), language_filename(), stof(), strcat(), string_null, strlen(), strzone(), substring(), and tokenize().

15 {
16  float fh;
17  float lineno;
18  float entlen;
19  float i;
20  string l, a;
21  string fn;
22 
23  if(n > CAMPAIGN_MAX_ENTRIES)
25 
26  campaign_offset = offset;
27  campaign_entries = 0;
29 
30  fn = language_filename(strcat("maps/campaign", campaign_name, ".txt"));
31  fh = fopen(fn, FILE_READ);
32  if(fh >= 0)
33  {
34  for(lineno = 0; (l = fgets(fh)); )
35  {
36  if(strlen(l) == 0)
37  continue; // empty line
38  if(substring(l, 0, 11) == "//campaign:")
39  campaign_title = substring(l, 11, strlen(l) - 11);
40  if(substring(l, 0, 2) == "//")
41  continue; // comment
42  if(substring(l, 0, 12) == "\"//campaign:")
43  campaign_title = substring(l, 12, strlen(l) - 13);
44  if(substring(l, 0, 3) == "\"//")
45  continue; // comment
46  if(lineno >= offset)
47  {
48  entlen = tokenize(l); // using insane tokenizer for CSV
49 
50 #define CAMPAIGN_GETARG \
51  a = argv(++i); \
52  if(a == ",") \
53  a = ""; \
54  else \
55  ++i
56 
57  i = -1; // starts at -1 so I don't need postincrement; that is, i points to BEFORE the current arg!
66  CAMPAIGN_GETARG; campaign_longdesc[campaign_entries] = strzone(strreplace("\\n", "\n", a));
67 
68  if(i > entlen)
69  error("syntax error in campaign file: line has not enough fields");
70 
72 
73  if(campaign_entries >= n)
74  break;
75  }
76  lineno = lineno + 1;
77  }
78  fclose(fh);
79  }
80 
82 
83  return campaign_entries;
84 }
#define CAMPAIGN_GETARG
string string_null
Definition: nil.qh:9
string campaign_name
string campaign_shortdesc[CAMPAIGN_MAX_ENTRIES]
const float FILE_READ
Definition: csprogsdefs.qc:231
string campaign_timelimit[CAMPAIGN_MAX_ENTRIES]
float campaign_botskill[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"))
float campaign_bots[CAMPAIGN_MAX_ENTRIES]
string campaign_mutators[CAMPAIGN_MAX_ENTRIES]
string campaign_title
int campaign_offset
int campaign_entries
#define CAMPAIGN_MAX_ENTRIES
ERASEABLE string language_filename(string s)
Definition: i18n.qh:14
string campaign_gametype[CAMPAIGN_MAX_ENTRIES]
string campaign_longdesc[CAMPAIGN_MAX_ENTRIES]
string campaign_mapname[CAMPAIGN_MAX_ENTRIES]
string campaign_fraglimit[CAMPAIGN_MAX_ENTRIES]
+ Here is the call graph for this function:

◆ CampaignFile_Unload()

void CampaignFile_Unload ( )

Definition at line 86 of file campaign_file.qc.

References campaign_entries, campaign_fraglimit, campaign_gametype, campaign_longdesc, campaign_mapname, campaign_mutators, campaign_shortdesc, campaign_timelimit, campaign_title, and strfree.

Referenced by CampaignLevelWarp(), CampaignPostIntermission(), CampaignPreInit(), and XonoticCampaignList_loadCvars().

87 {
88  if(campaign_title)
89  {
91  for(int i = 0; i < campaign_entries; ++i)
92  {
100  }
101  campaign_entries = 0;
102  }
103 }
string campaign_shortdesc[CAMPAIGN_MAX_ENTRIES]
string campaign_timelimit[CAMPAIGN_MAX_ENTRIES]
string campaign_mutators[CAMPAIGN_MAX_ENTRIES]
string campaign_title
int campaign_entries
string campaign_gametype[CAMPAIGN_MAX_ENTRIES]
string campaign_longdesc[CAMPAIGN_MAX_ENTRIES]
#define strfree(this)
Definition: string.qh:56
string campaign_mapname[CAMPAIGN_MAX_ENTRIES]
string campaign_fraglimit[CAMPAIGN_MAX_ENTRIES]
+ Here is the caller graph for this function: