centerprints now are managed independently per line
[divverent/nexuiz.git] / data / qcsrc / server / campaign.qc
1 // campaign cvars:
2 //   _campaign_index: index of CURRENT map
3 //   g_campaign_index: index of current LAST map (saved)
4 //   g_campaign_skill: bot skill offset
5
6 float campaign_level;
7 float campaign_won;
8
9 void(string s) CampaignBailout =
10 {
11         cvar_set("g_campaign", "0");
12         bprint(strcat("campaign initialization failed: ", s, "\n"));
13         //error(strcat("campaign initialization failed: ", s, "\n"));
14         return;
15 }
16
17 void() CampaignPreInit =
18 {
19         float baseskill;
20         string title;
21         campaign_level = cvar("_campaign_index");
22         CampaignFile_Load(campaign_level, 2);
23         if(campaign_entries < 1)
24                 return CampaignBailout("unknown map");
25         cvar_set("bot_number", ftos(campaign_bots[0]));
26
27         baseskill = cvar("g_campaign_skill");
28         baseskill = baseskill + campaign_botskill[0];
29         if(baseskill < 0)
30                 baseskill = 0;
31         cvar_set("skill", ftos(baseskill));
32
33         cvar_set("sv_public", "0");
34         cvar_set("pausable", "1");
35
36         title = campaign_shortdesc[0];
37         title = strzone(strcat("Level ", ftos(campaign_level + 1), ": ", title));
38         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"));
39         strunzone(title);
40 }
41
42 string GetMapname();
43 void() CampaignPostInit =
44 {
45         // now some sanity checks
46         string thismapname, wantedmapname;
47         thismapname = GetMapname();
48         wantedmapname = campaign_gametype[0];
49         wantedmapname = strcat(wantedmapname, "_", campaign_mapname[0]);
50         if(wantedmapname != thismapname)
51                 return CampaignBailout(strcat("wrong map: ", wantedmapname, " != ", thismapname));
52         cvar_set("fraglimit", ftos(campaign_fraglimit[0]));
53         cvar_set("timelimit", "0");
54 }
55
56 void() CampaignPreIntermission =
57 {
58         entity head;
59         float won;
60         float lost;
61
62         won = 0;
63
64         head = findchain(classname, "player");
65         while(head)
66         {
67                 if(clienttype(head) == CLIENTTYPE_REAL)
68                 {
69                         if(head.winning)
70                                 won = won + 1;
71                         else
72                                 lost = lost + 1;
73                 }
74                 head = head.chain;
75         }
76
77         if(won == 1 && lost == 0)
78         {
79                 campaign_won = 1;
80                 bprint("The current level has been WON.\n");
81                 // sound!
82         }
83         else
84         {
85                 campaign_won = 0;
86                 bprint("The current level has been LOST.\n");
87                 // sound!
88         }
89
90         if(campaign_won)
91         {
92                 if(campaign_entries < 2)
93                 {
94                         //localcmd("set g_campaign_index 0\n");
95                         // don't reset...
96                         localcmd("set g_campaign_won 1\n");
97                 }
98                 else if(campaign_level == cvar("g_campaign_index"))
99                 {
100                         // advance level
101                         localcmd("set g_campaign_index ");
102                         localcmd(ftos(campaign_level + 1));
103                         localcmd("\n");
104                 }
105         }
106 }
107
108 void() CampaignPostIntermission =
109 {
110         // NOTE: campaign_won is 0 or 1, that is, points to the next level
111
112         if(campaign_won && campaign_entries < 2)
113         {
114                 // last map won!
115                 localcmd("togglemenu\n");
116                 CampaignFile_Unload();
117                 return;
118         }
119
120         CampaignSetup(campaign_won);
121         CampaignFile_Unload();
122         strunzone(campaign_message);
123 }
124
125
126
127 void(float n) CampaignLevelWarp =
128 {
129         if(!cvar("sv_cheats"))
130                 return;
131         CampaignFile_Unload();
132         CampaignFile_Load(n, 1);
133         if(campaign_entries)
134                 CampaignSetup(0);
135         else
136                 error("Sorry, cheater. You are NOT WELCOME.");
137         CampaignFile_Unload();
138 }