1 // CampaignFileLoad(offset, n)
\r
2 // - Loads campaign level data (up to n entries starting at offset)
\r
4 // - Returns the number of entries successfully read
\r
5 float CampaignFile_Load(float offset, float n)
\r
14 if(n > CAMPAIGN_MAX_ENTRIES)
\r
15 n = CAMPAIGN_MAX_ENTRIES;
\r
17 campaign_offset = offset;
\r
18 campaign_entries = 0;
\r
19 campaign_title = string_null;
\r
21 fn = strcat("maps/campaign", campaign_name, ".txt");
\r
22 fh = fopen(fn, FILE_READ);
\r
25 for(lineno = 0; (l = fgets(fh)); )
\r
28 continue; // empty line
\r
29 if(substring(l, 0, 11) == "//campaign:")
\r
30 campaign_title = substring(l, 11, strlen(l) - 11);
\r
31 if(substring(l, 0, 2) == "//")
\r
32 continue; // comment
\r
33 if(substring(l, 0, 12) == "\"//campaign:")
\r
34 campaign_title = substring(l, 12, strlen(l) - 13);
\r
35 if(substring(l, 0, 3) == "\"//")
\r
36 continue; // comment
\r
37 if(lineno >= offset)
\r
39 entlen = tokenize(l); // using insane tokenizer for CSV
\r
41 #define CAMPAIGN_GETARG0 if(i >= entlen)
\r
42 #define CAMPAIGN_GETARG1 CAMPAIGN_GETARG0 error("syntax error in campaign file: line has not enough fields");
\r
43 #define CAMPAIGN_GETARG2 CAMPAIGN_GETARG1 a = argv(++i);
\r
44 #define CAMPAIGN_GETARG3 CAMPAIGN_GETARG2 if(a == ",")
\r
45 #define CAMPAIGN_GETARG4 CAMPAIGN_GETARG3 a = "";
\r
46 #define CAMPAIGN_GETARG5 CAMPAIGN_GETARG4 else
\r
47 #define CAMPAIGN_GETARG CAMPAIGN_GETARG5 ++i
\r
48 // What you're seeing here is what people will do when your compiler supports
\r
49 // C-style macros but no line continuations.
\r
51 i = -1; // starts at -1 so I don't need postincrement; that is, i points to BEFORE the current arg!
\r
52 CAMPAIGN_GETARG; campaign_gametype[campaign_entries] = strzone(a);
\r
53 CAMPAIGN_GETARG; campaign_mapname[campaign_entries] = strzone(a);
\r
54 CAMPAIGN_GETARG; campaign_bots[campaign_entries] = stof(a);
\r
55 CAMPAIGN_GETARG; campaign_botskill[campaign_entries] = stof(a);
\r
56 CAMPAIGN_GETARG; campaign_fraglimit[campaign_entries] = stof(a);
\r
57 CAMPAIGN_GETARG; campaign_mutators[campaign_entries] = strzone(a);
\r
58 CAMPAIGN_GETARG; campaign_shortdesc[campaign_entries] = strzone(a);
\r
59 CAMPAIGN_GETARG; campaign_longdesc[campaign_entries] = strzone(strreplace("\\n", "\n", a));
\r
60 campaign_entries = campaign_entries + 1;
\r
62 if(campaign_entries >= n)
\r
65 lineno = lineno + 1;
\r
70 campaign_title = strzone(campaign_title);
\r
72 return campaign_entries;
\r
75 void CampaignFile_Unload()
\r
80 strunzone(campaign_title);
\r
81 for(i = 0; i < campaign_entries; ++i)
\r
83 strunzone(campaign_gametype[i]);
\r
84 strunzone(campaign_mapname[i]);
\r
85 strunzone(campaign_mutators[i]);
\r
86 strunzone(campaign_shortdesc[i]);
\r
87 strunzone(campaign_longdesc[i]);
\r
89 campaign_entries = 0;
\r
90 campaign_title = string_null;
\r