]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/target/changelevel.qc
Merge branch 'master' into Mario/weaponorder
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / target / changelevel.qc
1 #include "changelevel.qh"
2 #ifdef SVQC
3 .string chmap, gametype;
4 .entity chlevel_targ;
5
6 void target_changelevel_use(entity this, entity actor, entity trigger)
7 {
8         if(game_stopped)
9                 return;
10
11         if(this.spawnflags & CHANGELEVEL_MULTIPLAYER)
12         {
13                 // simply don't react if a non-player triggers it
14                 if(!IS_PLAYER(actor)) { return; }
15
16                 actor.chlevel_targ = this;
17
18                 int plnum = 0;
19                 int realplnum = 0;
20                 // let's not count bots
21                 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
22                         ++realplnum;
23                         if(it.chlevel_targ == this)
24                                 ++plnum;
25                 });
26                 if(plnum < ceil(realplnum * min(1, this.count))) // 70% of players
27                         return;
28         }
29
30         if(this.gametype != "")
31                 MapInfo_SwitchGameType(MapInfo_Type_FromString(this.gametype));
32
33         if (this.chmap == "")
34         {
35                 if(IS_REAL_CLIENT(actor) && autocvar_g_campaign) // only count it as a win if the player touched (TODO: bots ending stage/vehicles?)
36                         campaign_forcewin = true; // this counts as beating the map in a campaign stage!
37                 NextLevel();
38         }
39         else
40                 changelevel(this.chmap);
41 }
42
43 /*target_changelevel
44 Target to change/end level
45 KEYS:
46 chmap: map to switch to, leave empty for endmatch
47 gametype: gametype for the next map
48 count: fraction of real players that need to trigger this entity for levelchange
49 SPAWNFLAGS:
50 CHANGELEVEL_MULTIPLAYER: multiplayer support
51 */
52
53 spawnfunc(target_changelevel)
54 {
55         this.use = target_changelevel_use;
56
57         if(!this.count)
58         {
59                 this.count = 0.7;
60         }
61 }
62 #endif