]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mapobjects/target/changelevel.qc
Merge branch 'master' into martin-t/defaults
[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(this.spawnflags & CHANGELEVEL_MULTIPLAYER)
9         {
10                 // simply don't react if a non-player triggers it
11                 if(!IS_PLAYER(actor)) { return; }
12
13                 actor.chlevel_targ = this;
14
15                 int plnum = 0;
16                 int realplnum = 0;
17                 // let's not count bots
18                 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
19                         ++realplnum;
20                         if(it.chlevel_targ == this)
21                                 ++plnum;
22                 });
23                 if(plnum < ceil(realplnum * min(1, this.count))) // 70% of players
24                         return;
25         }
26
27         if(this.gametype != "")
28                 MapInfo_SwitchGameType(MapInfo_Type_FromString(this.gametype));
29
30         if (this.chmap == "")
31                 localcmd("endmatch\n");
32         else
33                 localcmd(strcat("changelevel ", this.chmap, "\n"));
34 }
35
36 /*target_changelevel
37 Target to change/end level
38 KEYS:
39 chmap: map to switch to, leave empty for endmatch
40 gametype: gametype for the next map
41 count: fraction of real players that need to trigger this entity for levelchange
42 SPAWNFLAGS:
43 CHANGELEVEL_MULTIPLAYER: multiplayer support
44 */
45
46 spawnfunc(target_changelevel)
47 {
48         this.use = target_changelevel_use;
49
50         if(!this.count)
51         {
52                 this.count = 0.7;
53         }
54 }
55 #endif