2 // _campaign_index: index of CURRENT map
3 // g_campaign_index: index of current LAST map (saved)
4 // g_campaign_skill: bot skill offset
9 void(string s) CampaignBailout =
11 cvar_set("g_campaign", "0");
12 bprint(strcat("campaign initialization failed: ", s, "\n"));
13 //error(strcat("campaign initialization failed: ", s, "\n"));
17 string fstrunzone(string s)
25 // NOTE: s may not be a tempstring here
26 string Campaign_wordwrap(string s, float l)
41 for(i = 0; i <= strlen(s); ++i)
43 if(i != strlen(s) && substring(s, i, 1) != " ")
46 word = substring(s, startidx, i - startidx);
52 t = strzone(strcat(t, "\n\n"));
55 else if(strlen(word) < lleft)
63 t = strzone(strcat(t, word));
64 lleft = lleft - strlen(word);
69 t = strzone(strcat(t, "\n", word));
70 lleft = l - strlen(word);
77 void() CampaignPreInit =
81 campaign_level = cvar("_campaign_index");
82 CampaignFile_Load(campaign_level, 2);
83 if(campaign_entries < 1)
84 return CampaignBailout("unknown map");
85 cvar_set("bot_number", ftos(campaign_bots[0]));
87 baseskill = cvar("g_campaign_skill");
88 baseskill = baseskill + campaign_botskill[0];
91 cvar_set("skill", ftos(baseskill));
93 cvar_set("sv_public", "0");
94 cvar_set("pausable", "1");
96 title = campaign_shortdesc[0];
97 campaign_message = strzone(strcat("\n\n\n\n\n\n\n\n\n\n^1\n", title, "\n^3\n", Campaign_wordwrap(campaign_longdesc[0], 50), "\n\n^1press jump to enter the game"));
101 void() CampaignPostInit =
103 // now some sanity checks
105 thismapname = GetMapname();
106 if(campaign_mapcfgname[0] != thismapname)
107 return CampaignBailout(strcat("wrong map: ", campaign_mapcfgname[0], " != ", thismapname));
108 cvar_set("fraglimit", ftos(campaign_fraglimit[0]));
109 cvar_set("timelimit", "0");
112 void() CampaignPreIntermission =
120 head = findchain(classname, "player");
123 if(clienttype(head) == CLIENTTYPE_REAL)
133 if(won == 1 && lost == 0)
136 bprint("The current level has been WON.\n");
142 bprint("The current level has been LOST.\n");
148 if(campaign_level == cvar("g_campaign_index"))
151 localcmd("set g_campaign_index ");
152 localcmd(ftos(campaign_level + 1));
155 if(campaign_entries < 2)
157 localcmd("set g_campaign_index 0\n");
158 localcmd("set g_campaign_won 1\n");
163 void() CampaignPostIntermission =
165 // NOTE: campaign_won is 0 or 1, that is, points to the next level
167 if(campaign_won && campaign_entries < 2)
170 localcmd("togglemenu\n");
171 CampaignFile_Unload();
175 CampaignSetup(campaign_won);
176 CampaignFile_Unload();
177 strunzone(campaign_message);
182 void(float n) CampaignLevelWarp =
184 if(!cvar("sv_cheats"))
186 CampaignFile_Unload();
187 CampaignFile_Load(n, 1);
191 error("Sorry, cheater. You are NOT WELCOME.");
192 CampaignFile_Unload();