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