]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/common/campaign_file.qc
bugfix target_spawn, and change docs to match it
[divverent/nexuiz.git] / data / qcsrc / common / campaign_file.qc
1 // CampaignFileLoad(offset, n)
2 // - Loads campaign level data (up to n entries starting at offset)
3 //   into the globals
4 // - Returns the number of entries successfully read
5 float CampaignFile_Load(float offset, float n)
6 {
7         float fh;
8         float lineno;
9         float entlen;
10         float i;
11         string l, a;
12         string fn;
13
14         if(n > CAMPAIGN_MAX_ENTRIES)
15                 n = CAMPAIGN_MAX_ENTRIES;
16
17         campaign_offset = offset;
18         campaign_entries = 0;
19
20         fn = strcat("maps/campaign", campaign_name, ".txt");
21         fh = fopen(fn, FILE_READ);
22         if(fh >= 0)
23         {
24                 for(lineno = 0; (l = fgets(fh)); )
25                 {
26                         if(strlen(l) == 0)
27                                 continue; // empty line
28                         if(substring(l, 0, 2) == "//")
29                                 continue; // comment
30                         if(substring(l, 0, 3) == "\"//")
31                                 continue; // comment
32                         if(lineno >= offset)
33                         {
34                                 entlen = tokenize_insane(l); // using insane tokenizer for CSV
35
36 #define CAMPAIGN_GETARG0                  if(i >= entlen)
37 #define CAMPAIGN_GETARG1 CAMPAIGN_GETARG0     error("syntax error in campaign file: line has not enough fields");
38 #define CAMPAIGN_GETARG2 CAMPAIGN_GETARG1 a = argv(++i);
39 #define CAMPAIGN_GETARG3 CAMPAIGN_GETARG2 if(a == ",")
40 #define CAMPAIGN_GETARG4 CAMPAIGN_GETARG3     a = "";
41 #define CAMPAIGN_GETARG5 CAMPAIGN_GETARG4 else
42 #define CAMPAIGN_GETARG  CAMPAIGN_GETARG5     ++i
43 // What you're seeing here is what people will do when your compiler supports
44 // C-style macros but no line continuations.
45
46                                 i = -1; // starts at -1 so I don't need postincrement; that is, i points to BEFORE the current arg!
47                                 CAMPAIGN_GETARG; campaign_gametype[campaign_entries] = strzone(a);
48                                 CAMPAIGN_GETARG; campaign_mapname[campaign_entries] = strzone(a);
49                                 CAMPAIGN_GETARG; campaign_bots[campaign_entries] = stof(a);
50                                 CAMPAIGN_GETARG; campaign_botskill[campaign_entries] = stof(a);
51                                 CAMPAIGN_GETARG; campaign_fraglimit[campaign_entries] = stof(a);
52                                 CAMPAIGN_GETARG; campaign_mutators[campaign_entries] = strzone(a);
53                                 CAMPAIGN_GETARG; campaign_shortdesc[campaign_entries] = strzone(a);
54                                 CAMPAIGN_GETARG; campaign_longdesc[campaign_entries] = strzone(a);
55                                 campaign_entries = campaign_entries + 1;
56
57                                 if(campaign_entries >= n)
58                                         break;
59                         }
60                         lineno = lineno + 1;
61                 }
62                 fclose(fh);
63         }
64
65         return campaign_entries;
66 }
67
68 void CampaignFile_Unload()
69 {
70         float i;
71         for(i = 0; i < campaign_entries; ++i)
72         {
73                 strunzone(campaign_gametype[i]);
74                 strunzone(campaign_mapname[i]);
75                 strunzone(campaign_mutators[i]);
76                 strunzone(campaign_shortdesc[i]);
77                 strunzone(campaign_longdesc[i]);
78         }
79         campaign_entries = 0;
80 }