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)
13 if(n > CAMPAIGN_MAX_ENTRIES)
14 n = CAMPAIGN_MAX_ENTRIES;
16 campaign_offset = offset;
19 fh = fopen("maps/campaign.txt", FILE_READ);
22 for(lineno = 0; (l = fgets(fh)); )
25 continue; // empty line
26 if(substring(l, 0, 2) == "//")
28 if(substring(l, 0, 3) == "\"//")
34 #define CAMPAIGN_GETARG0 if(i >= entlen)
35 #define CAMPAIGN_GETARG1 CAMPAIGN_GETARG0 error("syntax error in campaign file: line has not enough fields");
36 #define CAMPAIGN_GETARG2 CAMPAIGN_GETARG1 a = argv(i++);
37 #define CAMPAIGN_GETARG3 CAMPAIGN_GETARG2 if(a == ",")
38 #define CAMPAIGN_GETARG4 CAMPAIGN_GETARG3 a = "";
39 #define CAMPAIGN_GETARG5 CAMPAIGN_GETARG4 else
40 #define CAMPAIGN_GETARG CAMPAIGN_GETARG5 ++i
41 // What you're seeing here is what people will do when your compiler supports
42 // C-style macros but no line continuations.
45 CAMPAIGN_GETARG; campaign_gametype[campaign_entries] = strzone(a);
46 CAMPAIGN_GETARG; campaign_mapname[campaign_entries] = strzone(a);
47 CAMPAIGN_GETARG; campaign_bots[campaign_entries] = stof(a);
48 CAMPAIGN_GETARG; campaign_botskill[campaign_entries] = stof(a);
49 CAMPAIGN_GETARG; campaign_fraglimit[campaign_entries] = stof(a);
50 CAMPAIGN_GETARG; campaign_mutators[campaign_entries] = strzone(a);
51 CAMPAIGN_GETARG; campaign_shortdesc[campaign_entries] = strzone(a);
52 CAMPAIGN_GETARG; campaign_longdesc[campaign_entries] = strzone(a);
53 campaign_entries = campaign_entries + 1;
55 if(campaign_entries >= n)
63 return campaign_entries;
66 void CampaignFile_Unload()
69 for(i = 0; i < campaign_entries; ++i)
71 strunzone(campaign_gametype[i]);
72 strunzone(campaign_mapname[i]);
73 strunzone(campaign_mutators[i]);
74 strunzone(campaign_shortdesc[i]);
75 strunzone(campaign_longdesc[i]);
81 // stuff to handle the campaign_longdesc field
82 string fstrunzone(string s)
90 // NOTE: s may not be a tempstring here
91 string Campaign_wordwrap(string s, float l)
106 for(i = 0; i <= strlen(s); ++i)
108 if(i != strlen(s) && substring(s, i, 1) != " ")
111 word = substring(s, startidx, i - startidx);
117 t = strzone(strcat(t, "\n\n"));
120 else if(!l || (strlen(word) < lleft))
128 t = strzone(strcat(t, word));
129 lleft = lleft - strlen(word);
134 t = strzone(strcat(t, "\n", word));
135 lleft = l - strlen(word);