Xonotic
changelevel.qc
Go to the documentation of this file.
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 
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
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 != "")
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
const int CHANGELEVEL_MULTIPLAYER
Definition: changelevel.qh:4
entity() spawn
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
spawnfunc(info_player_attacker)
Definition: sv_assault.qc:283
float spawnflags
Definition: progsdefs.qc:191
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
Gametype MapInfo_Type_FromString(string gtype, bool dowarn)
Definition: mapinfo.qc:589
void NextLevel()
Definition: world.qc:1276
entity gametype
Definition: main.qh:30
float count
Definition: powerups.qc:22
bool campaign_forcewin
Definition: campaign.qh:29
bool autocvar_g_campaign
Definition: campaign.qh:6
#define use
Definition: csprogsdefs.qh:50
void MapInfo_SwitchGameType(Gametype t)
Definition: mapinfo.qc:1178
#define IS_PLAYER(v)
Definition: utils.qh:9