5 #include "campaign_common.qh"
8 // CampaignFileLoad(offset, n)
9 // - Loads campaign level data (up to n entries starting at offset)
11 // - Returns the number of entries successfully read
12 float CampaignFile_Load(int offset, float n)
21 if(n > CAMPAIGN_MAX_ENTRIES)
22 n = CAMPAIGN_MAX_ENTRIES;
24 campaign_offset = offset;
26 campaign_title = string_null;
28 fn = language_filename(strcat("maps/campaign", campaign_name, ".txt"));
29 fh = fopen(fn, FILE_READ);
32 for(lineno = 0; (l = fgets(fh)); )
35 continue; // empty line
36 if(substring(l, 0, 11) == "//campaign:")
37 campaign_title = substring(l, 11, strlen(l) - 11);
38 if(substring(l, 0, 2) == "//")
40 if(substring(l, 0, 12) == "\"//campaign:")
41 campaign_title = substring(l, 12, strlen(l) - 13);
42 if(substring(l, 0, 3) == "\"//")
46 entlen = tokenize(l); // using insane tokenizer for CSV
48 #define CAMPAIGN_GETARG \
54 // What you're seeing here is what people will do when your compiler supports
55 // C-style macros but no line continuations.
57 i = -1; // starts at -1 so I don't need postincrement; that is, i points to BEFORE the current arg!
58 CAMPAIGN_GETARG; campaign_gametype[campaign_entries] = strzone(a);
59 CAMPAIGN_GETARG; campaign_mapname[campaign_entries] = strzone(a);
60 CAMPAIGN_GETARG; campaign_bots[campaign_entries] = stof(a);
61 CAMPAIGN_GETARG; campaign_botskill[campaign_entries] = stof(a);
62 CAMPAIGN_GETARG; campaign_fraglimit[campaign_entries] = stof(a);
63 CAMPAIGN_GETARG; campaign_timelimit[campaign_entries] = stof(a);
64 CAMPAIGN_GETARG; campaign_mutators[campaign_entries] = strzone(a);
65 CAMPAIGN_GETARG; campaign_shortdesc[campaign_entries] = strzone(a);
66 CAMPAIGN_GETARG; campaign_longdesc[campaign_entries] = strzone(strreplace("\\n", "\n", a));
69 error("syntax error in campaign file: line has not enough fields");
71 campaign_entries = campaign_entries + 1;
73 if(campaign_entries >= n)
81 campaign_title = strzone(campaign_title);
83 return campaign_entries;
86 void CampaignFile_Unload()
90 strunzone(campaign_title);
92 for(i = 0; i < campaign_entries; ++i)
94 strunzone(campaign_gametype[i]);
95 strunzone(campaign_mapname[i]);
96 strunzone(campaign_mutators[i]);
97 strunzone(campaign_shortdesc[i]);
98 strunzone(campaign_longdesc[i]);
100 campaign_entries = 0;
101 campaign_title = string_null;