4 #include "../dpdefs/progsdefs.qh"
5 #include "../dpdefs/dpextensions.qh"
7 #include "campaign_common.qh"
10 // CampaignFileLoad(offset, n)
11 // - Loads campaign level data (up to n entries starting at offset)
13 // - Returns the number of entries successfully read
14 float CampaignFile_Load(int offset, float n)
23 if(n > CAMPAIGN_MAX_ENTRIES)
24 n = CAMPAIGN_MAX_ENTRIES;
26 campaign_offset = offset;
28 campaign_title = string_null;
30 fn = language_filename(strcat("maps/campaign", campaign_name, ".txt"));
31 fh = fopen(fn, FILE_READ);
34 for(lineno = 0; (l = fgets(fh)); )
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) == "//")
42 if(substring(l, 0, 12) == "\"//campaign:")
43 campaign_title = substring(l, 12, strlen(l) - 13);
44 if(substring(l, 0, 3) == "\"//")
48 entlen = tokenize(l); // using insane tokenizer for CSV
50 #define CAMPAIGN_GETARG \
56 // What you're seeing here is what people will do when your compiler supports
57 // C-style macros but no line continuations.
59 i = -1; // starts at -1 so I don't need postincrement; that is, i points to BEFORE the current arg!
60 CAMPAIGN_GETARG; campaign_gametype[campaign_entries] = strzone(a);
61 CAMPAIGN_GETARG; campaign_mapname[campaign_entries] = strzone(a);
62 CAMPAIGN_GETARG; campaign_bots[campaign_entries] = stof(a);
63 CAMPAIGN_GETARG; campaign_botskill[campaign_entries] = stof(a);
64 CAMPAIGN_GETARG; campaign_fraglimit[campaign_entries] = stof(a);
65 CAMPAIGN_GETARG; campaign_timelimit[campaign_entries] = stof(a);
66 CAMPAIGN_GETARG; campaign_mutators[campaign_entries] = strzone(a);
67 CAMPAIGN_GETARG; campaign_shortdesc[campaign_entries] = strzone(a);
68 CAMPAIGN_GETARG; campaign_longdesc[campaign_entries] = strzone(strreplace("\\n", "\n", a));
71 error("syntax error in campaign file: line has not enough fields");
73 campaign_entries = campaign_entries + 1;
75 if(campaign_entries >= n)
83 campaign_title = strzone(campaign_title);
85 return campaign_entries;
88 void CampaignFile_Unload()
92 strunzone(campaign_title);
94 for(i = 0; i < campaign_entries; ++i)
96 strunzone(campaign_gametype[i]);
97 strunzone(campaign_mapname[i]);
98 strunzone(campaign_mutators[i]);
99 strunzone(campaign_shortdesc[i]);
100 strunzone(campaign_longdesc[i]);
102 campaign_entries = 0;
103 campaign_title = string_null;