Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
campaign_file.qc
Go to the documentation of this file.
1#include "campaign_file.qh"
2
3#if defined(CSQC)
4#elif defined(MENUQC)
5#elif defined(SVQC)
6 #include <common/util.qh>
8#endif
9
10// CampaignFileLoad(offset, n)
11// - Loads campaign level data (up to n entries starting at offset)
12// into the globals
13// - Returns the number of entries successfully read
14float CampaignFile_Load(int offset, float n)
15{
16 float fh;
17 float lineno;
18 float entlen;
19 float i;
20 string l, a;
21 string fn;
22
25
26 campaign_offset = offset;
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!
65 #ifdef SVQC
68 #else
69 CAMPAIGN_GETARG; campaign_shortdesc[campaign_entries] = strzone(a);
70 CAMPAIGN_GETARG; campaign_longdesc[campaign_entries] = strzone(strreplace("\\n", "\n", a));
71 #endif
72
73 if(i > entlen)
74 error("syntax error in campaign file: line has not enough fields");
75
77
78 if(campaign_entries >= n)
79 break;
80 }
81 lineno = lineno + 1;
82 }
83 fclose(fh);
84 }
85
87
88 return campaign_entries;
89}
90
92{
94 {
96 for(int i = 0; i < campaign_entries; ++i)
97 {
103 #ifndef SVQC
104 strfree(campaign_shortdesc[i]);
105 strfree(campaign_longdesc[i]);
106 #endif
107 }
109 }
110}
string campaign_mutators[CAMPAIGN_MAX_ENTRIES]
int campaign_offset
string campaign_title
string campaign_name
float campaign_bots[CAMPAIGN_MAX_ENTRIES]
float campaign_botskill[CAMPAIGN_MAX_ENTRIES]
string campaign_gametype[CAMPAIGN_MAX_ENTRIES]
#define CAMPAIGN_MAX_ENTRIES
string campaign_fraglimit[CAMPAIGN_MAX_ENTRIES]
string campaign_mapname[CAMPAIGN_MAX_ENTRIES]
int campaign_entries
string campaign_timelimit[CAMPAIGN_MAX_ENTRIES]
float CampaignFile_Load(int offset, float n)
#define CAMPAIGN_GETARG
void CampaignFile_Unload()
const float FILE_READ
#define strlen
ERASEABLE string language_filename(string s)
Definition i18n.qh:14
string fgets(float fhandle)
void fclose(float fhandle)
float stof(string val,...)
string substring(string s, float start, float length)
float fopen(string filename, float mode)
float tokenize(string s)
string strzone(string s)
string string_null
Definition nil.qh:9
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define error
Definition pre.qh:6
#define strfree(this)
Definition string.qh:59