]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/common/campaign_file.qc
changed ctf and domination scoring to individual player scoring, this
[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
13         if(n > CAMPAIGN_MAX_ENTRIES)
14                 n = CAMPAIGN_MAX_ENTRIES;
15
16         campaign_offset = offset;
17         campaign_entries = 0;
18
19         fh = fopen("maps/campaign.txt", FILE_READ);
20         if(fh >= 0)
21         {
22                 for(lineno = 0; (l = fgets(fh)); )
23                 {
24                         if(strlen(l) == 0)
25                                 continue; // empty line
26                         if(substring(l, 0, 2) == "//")
27                                 continue; // comment
28                         if(substring(l, 0, 3) == "\"//")
29                                 continue; // comment
30                         if(lineno >= offset)
31                         {
32                                 entlen = tokenize(l);
33
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.
43
44                                 i = 0;
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;
54
55                                 if(campaign_entries >= n)
56                                         break;
57                         }
58                         lineno = lineno + 1;
59                 }
60                 fclose(fh);
61         }
62
63         return campaign_entries;
64 }
65
66 void CampaignFile_Unload()
67 {
68         float i;
69         for(i = 0; i < campaign_entries; ++i)
70         {
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]);
76         }
77         campaign_entries = 0;
78 }