2 // _campaign_index: index of CURRENT map
3 // _campaign_name: name of the current campaign
4 // g_campaign(name)_index: index of current LAST map (saved)
5 // g_campaign_skill: bot skill offset
9 string campaign_index_var;
10 float checkrules_equality;
12 void(string s) CampaignBailout =
14 cvar_set("g_campaign", "0");
15 ServerConsoleEcho(strcat("campaign initialization failed: ", s), TRUE);
19 void() CampaignPreInit =
23 campaign_level = cvar("_campaign_index");
24 campaign_name = strzone(cvar_string("_campaign_name"));
25 campaign_index_var = strzone(strcat("g_campaign", campaign_name, "_index"));
26 CampaignFile_Load(campaign_level, 2);
27 if(campaign_entries < 1)
28 return CampaignBailout("unknown map");
29 cvar_set("bot_number", ftos(campaign_bots[0]));
31 baseskill = cvar("g_campaign_skill");
32 baseskill = baseskill + campaign_botskill[0];
35 cvar_set("skill", ftos(baseskill));
37 cvar_set("sv_public", "0");
38 cvar_set("pausable", "1");
40 title = campaign_shortdesc[0];
41 title = strzone(strcat("Level ", ftos(campaign_level + 1), ": ", title));
42 campaign_message = strzone(strcat("\n\n\n\n\n\n\n\n\n\n^1\n", title, "\n^3\n", wordwrap(campaign_longdesc[0], 50), "\n\n^1press jump to enter the game"));
47 void() CampaignPostInit =
49 // now some sanity checks
50 string thismapname, wantedmapname;
51 thismapname = GetMapname();
52 wantedmapname = campaign_gametype[0];
53 wantedmapname = strcat(wantedmapname, "_", campaign_mapname[0]);
54 if(wantedmapname != thismapname)
55 return CampaignBailout(strcat("wrong map: ", wantedmapname, " != ", thismapname));
56 cvar_set("fraglimit", ftos(campaign_fraglimit[0]));
57 cvar_set("timelimit", "0");
60 void CampaignSaveCvar(string cvarname, float value)
67 registercvar(cvarname, ftos(value));
68 cvar_set(cvarname, ftos(value));
69 // note: cvarname must be remembered
71 fh = fopen("campaign.cfg", FILE_READ);
75 while((l = fgets(fh)))
77 cvarname = strcat1(cvarname);
78 contents = strcat1(contents);
84 if(argv(1) == cvarname)
86 contents = strcat(contents, "set ", argv(1), " ", argv(2), "\n");
90 contents = strcat(contents, "set ", cvarname, " ", ftos(value), "\n");
91 fh = fopen("campaign.cfg", FILE_WRITE);
98 error("Cannot write to campaign file");
102 void() CampaignPreIntermission =
107 local string savevar;
111 head = findchain(classname, "player");
114 if(clienttype(head) == CLIENTTYPE_REAL)
124 if(won == 1 && lost == 0 && checkrules_equality == 0)
127 bprint("The current level has been WON.\n");
133 bprint("The current level has been LOST.\n");
139 if(campaign_entries < 2)
142 savevar = strcat("g_campaign", campaign_name, "_won");
143 CampaignSaveCvar(savevar, 1);
145 else if(campaign_level == cvar(campaign_index_var))
148 CampaignSaveCvar(campaign_index_var, campaign_level + 1);
153 void() CampaignPostIntermission =
155 // NOTE: campaign_won is 0 or 1, that is, points to the next level
157 if(campaign_won && campaign_entries < 2)
160 localcmd("togglemenu\n");
161 CampaignFile_Unload();
165 CampaignSetup(campaign_won);
166 CampaignFile_Unload();
167 strunzone(campaign_message);
168 strunzone(campaign_index_var);
169 strunzone(campaign_name);
175 void(float n) CampaignLevelWarp =
179 CampaignFile_Unload();
180 CampaignFile_Load(n, 1);
184 error("Sorry, cheater. You are NOT WELCOME.");
185 CampaignFile_Unload();