]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/menu/custom/campaign.qc
cmd info (something) prints the content of sv_info_(something), for server admins...
[divverent/nexuiz.git] / data / qcsrc / menu / custom / campaign.qc
1 string campaign_index_var;
2
3 void Campaign_Init()
4 {
5         campaign_name = strzone(cvar_string("g_campaign_name"));
6         campaign_index_var = strzone(strcat("g_campaign", campaign_name, "_index"));
7         CampaignFile_Load(0, CAMPAIGN_MAX_ENTRIES);
8 }
9
10 void Campaign_Shutdown()
11 {
12         CampaignFile_Unload();
13         strunzone(campaign_index_var);
14         strunzone(campaign_name);
15         campaign_name = "";
16 }
17
18 void Campaign_DumpLevels()
19 {
20         float i;
21         float imax;
22         imax = cvar(campaign_index_var) - campaign_offset;
23         if(imax >= campaign_entries)
24                 imax = campaign_entries - 1;
25         for(i = 0; i <= imax; ++i)
26         {
27                 print("Level ");
28                 print(ftos(i + campaign_offset));
29                 print(": ");
30                 print(campaign_gametype[i]);
31                 print("_");
32                 print(campaign_mapname[i]);
33                 print(" - ");
34                 print(campaign_shortdesc[i]);
35                 print("\n");
36         }
37         print("\n");
38 }
39
40 void Campaign_JumpLevel(float n)
41 {
42         float current;
43         // 1. current level?
44         current = cvar(campaign_index_var);
45         if(n > current)
46                 n = current;
47         if(n < 0)
48                 n = current;
49
50         n = n - campaign_offset;
51         if(n >= 0 && n < campaign_entries)
52                 CampaignSetup(n);
53 }
54
55 float campaign_entry_index;
56
57 void() Nex_Action_Campaign_Start =
58 {
59         Campaign_JumpLevel(campaign_entry_index);
60
61         // force the menu to hide
62         m_hide();
63 };
64
65 void() Nex_Action_Campaign_Update =
66 {
67         local entity item;
68         local string desc;
69         local float handle;
70         local string line;
71
72         handle = fopen(strcat("maps/campaign", campaign_name, ".txt"), FILE_READ);
73         if(handle >= 0) {
74                 while (line = fgets(handle)) {
75                         if(substring(line, 0, 12) == "\"//campaign:") {
76                                 desc = substring(line, 12, (strlen(line) - (12 + 1)));
77                                 break;
78                         } else {
79                                 continue;
80                         }
81                 }
82         }
83         fclose(handle);
84
85         item = Menu_GetItem("ShortDescriptionCampaign");
86         desc = strcat("Campaign: ", desc);
87         String_EntitySet(item, text, desc);
88
89         item = Menu_GetItem("ShortDescriptionEntry");
90         desc = campaign_shortdesc[campaign_entry_index];
91         desc = strcat("Level ", ftos(campaign_entry_index + 1), ": ", desc);
92         String_EntitySet(item, text, desc);
93
94         item = Menu_GetItem("LongDescriptionEntry");
95         desc = wordwrap(campaign_longdesc[campaign_entry_index], item.wrap - 1);
96         String_EntitySet(item, text, desc);
97
98         item = Menu_GetItem("PictureEntry");
99         String_EntitySet(item, picture, strcat("maps/",campaign_mapname[campaign_entry_index], ".jpg"));
100 };
101
102 void(float index) Nex_Action_Campaign_Find_Entry =
103 {
104         campaign_entry_index+=index;
105         if (campaign_entry_index < 0) campaign_entry_index = min((campaign_entries - 1), cvar(campaign_index_var));
106         if (campaign_entry_index > min((campaign_entries - 1), cvar(campaign_index_var))) campaign_entry_index = 0;
107 }
108
109 void() Nex_Action_Campaign_Prev_Entry =
110 {
111         Nex_Action_Campaign_Find_Entry(-1);
112         Nex_Action_Campaign_Update();
113 };
114
115 void() Nex_Action_Campaign_Next_Entry =
116 {
117         Nex_Action_Campaign_Find_Entry(1);
118         Nex_Action_Campaign_Update();
119 };
120
121 void() Nex_Action_Campaign_Init =
122 {
123         Campaign_Init();
124
125         campaign_entry_index = cvar(campaign_index_var);
126         Nex_Action_Campaign_Find_Entry(0); // set campaign_index_var back into range if too high or low
127
128         Nex_Action_Campaign_Update();
129 };
130
131 void(float index) Nex_Action_Campaign_Find_Campaign =
132 {
133         local float handle;
134         local float count;
135         float i;
136         local string filename;
137         handle = search_begin("maps/campaign*.txt", true, true);
138         if(handle >= 0) {
139                 count = search_getsize(handle);
140                 for (i = 0; i < count; i++) {
141                         filename = search_getfilename(handle, i);
142                         if (filename == strcat("maps/campaign", campaign_name, ".txt")) {
143                                 index+=i;
144                                 if (index < 0) index = (count - 1);
145                                 if (index > (count - 1)) index = 0;
146                                 filename = search_getfilename(handle, index);
147                                 break;
148                         }
149                 }
150                 count = strlen(filename);
151                 cvar_set("g_campaign_name", substring(filename, 13, (count - (13 + 4))));
152         }
153         search_end(handle);
154         Nex_Action_Campaign_Init();
155 }
156
157 void() Nex_Action_Campaign_Prev_Campaign =
158 {
159         Nex_Action_Campaign_Find_Campaign(-1);
160         Nex_Action_Campaign_Update();
161 };
162
163 void() Nex_Action_Campaign_Next_Campaign =
164 {
165         Nex_Action_Campaign_Find_Campaign(1);
166         Nex_Action_Campaign_Update();
167 };