]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/campaign_file.qc
Fix FL_WEAPON flag overlapping FL_JUMPRELEASED. This unintentional change was introdu...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / campaign_file.qc
1 #include "campaign_file.qh"
2
3 #if defined(CSQC)
4 #elif defined(MENUQC)
5 #elif defined(SVQC)
6         #include <common/util.qh>
7         #include <common/campaign_common.qh>
8 #endif
9
10 // CampaignFileLoad(offset, n)
11 // - Loads campaign level data (up to n entries starting at offset)
12 //   into the globals
13 // - Returns the number of entries successfully read
14 float CampaignFile_Load(int offset, float n)
15 {
16         float fh;
17         float lineno;
18         float entlen;
19         float i;
20         string l, a;
21         string fn;
22
23         if(n > CAMPAIGN_MAX_ENTRIES)
24                 n = CAMPAIGN_MAX_ENTRIES;
25
26         campaign_offset = offset;
27         campaign_entries = 0;
28         campaign_title = string_null;
29
30         fn = language_filename(strcat("maps/campaign", campaign_name, ".txt"));
31         fh = fopen(fn, FILE_READ);
32         if(fh >= 0)
33         {
34                 for(lineno = 0; (l = fgets(fh)); )
35                 {
36                         if(strlen(l) == 0)
37                                 continue; // empty line
38                         if(substring(l, 0, 11) == "//campaign:")
39                                 campaign_title = substring(l, 11, strlen(l) - 11);
40                         if(substring(l, 0, 2) == "//")
41                                 continue; // comment
42                         if(substring(l, 0, 12) == "\"//campaign:")
43                                 campaign_title = substring(l, 12, strlen(l) - 13);
44                         if(substring(l, 0, 3) == "\"//")
45                                 continue; // comment
46                         if(lineno >= offset)
47                         {
48                                 entlen = tokenize(l); // using insane tokenizer for CSV
49
50 #define CAMPAIGN_GETARG \
51         a = argv(++i); \
52         if(a == ",") \
53                 a = ""; \
54         else \
55                 ++i
56
57                                 i = -1; // starts at -1 so I don't need postincrement; that is, i points to BEFORE the current arg!
58                                 CAMPAIGN_GETARG; campaign_gametype[campaign_entries] = strzone(a);
59                                 CAMPAIGN_GETARG; campaign_mapname[campaign_entries] = strzone(a);
60                                 CAMPAIGN_GETARG; campaign_bots[campaign_entries] = stof(a);
61                                 CAMPAIGN_GETARG; campaign_botskill[campaign_entries] = stof(a);
62                                 CAMPAIGN_GETARG; campaign_fraglimit[campaign_entries] = strzone(a);
63                                 CAMPAIGN_GETARG; campaign_timelimit[campaign_entries] = strzone(a);
64                                 CAMPAIGN_GETARG; campaign_mutators[campaign_entries] = strzone(a);
65                                 #ifdef SVQC
66                                 CAMPAIGN_GETARG;
67                                 CAMPAIGN_GETARG;
68                                 #else
69                                 CAMPAIGN_GETARG; campaign_shortdesc[campaign_entries] = strzone(a);
70                                 CAMPAIGN_GETARG; campaign_longdesc[campaign_entries] = strzone(strreplace("\\n", "\n", a));
71                                 #endif
72
73                                 if(i > entlen)
74                                         error("syntax error in campaign file: line has not enough fields");
75
76                                 campaign_entries = campaign_entries + 1;
77
78                                 if(campaign_entries >= n)
79                                         break;
80                         }
81                         lineno = lineno + 1;
82                 }
83                 fclose(fh);
84         }
85
86         campaign_title = strzone(campaign_title);
87
88         return campaign_entries;
89 }
90
91 void CampaignFile_Unload()
92 {
93         if(campaign_title)
94         {
95                 strfree(campaign_title);
96                 for(int i = 0; i < campaign_entries; ++i)
97                 {
98                         strfree(campaign_gametype[i]);
99                         strfree(campaign_mapname[i]);
100                         strfree(campaign_fraglimit[i]);
101                         strfree(campaign_timelimit[i]);
102                         strfree(campaign_mutators[i]);
103                         #ifndef SVQC
104                         strfree(campaign_shortdesc[i]);
105                         strfree(campaign_longdesc[i]);
106                         #endif
107                 }
108                 campaign_entries = 0;
109         }
110 }