1 #include "gamemode_assault.qh"
2 #ifndef GAMEMODE_ASSAULT_H
3 #define GAMEMODE_ASSAULT_H
5 void assault_ScoreRules();
6 void ActivateTeamplay();
8 REGISTER_MUTATOR(as, false)
11 have_team_spawns = -1; // request team spawns
15 if (time > 1) // game loads at time 1
16 error("This is a game type and it cannot be added at runtime.");
20 MUTATOR_ONROLLBACK_OR_REMOVE
22 // we actually cannot roll back assault_Initialize here
23 // BUT: we don't need to! If this gets called, adding always
29 LOG_INFO("This is a game type and it cannot be removed at runtime.");
37 .entity assault_decreaser;
38 .entity assault_sprite;
41 const int HAVOCBOT_AST_ROLE_NONE = 0;
42 const int HAVOCBOT_AST_ROLE_DEFENSE = 2;
43 const int HAVOCBOT_AST_ROLE_OFFENSE = 4;
45 .int havocbot_role_flags;
46 .float havocbot_attack_time;
48 .void(entity this) havocbot_role;
49 .void(entity this) havocbot_previous_role;
51 void(entity this) havocbot_role_ast_defense;
52 void(entity this) havocbot_role_ast_offense;
53 .entity havocbot_ast_target;
55 void(entity bot) havocbot_ast_reset_role;
57 void(entity this, float ratingscale, vector org, float sradius) havocbot_goalrating_items;
58 void(entity this, float ratingscale, vector org, float sradius) havocbot_goalrating_enemyplayers;
61 const float ST_ASSAULT_OBJECTIVES = 1;
62 const float SP_ASSAULT_OBJECTIVES = 4;
64 // predefined spawnfuncs
65 void target_objective_decrease_activate();
72 void assault_objective_use()
76 //print("^2Activated objective ", self.targetname, "=", etos(self), "\n");
77 //print("Activator is ", activator.classname, "\n");
79 for (entity e = world; (e = find(e, target, this.targetname)); )
81 if (e.classname == "target_objective_decrease")
83 WITHSELF(e, target_objective_decrease_activate());
90 vector target_objective_spawn_evalfunc(entity player, entity spot, vector current)
92 if(self.health < 0 || self.health >= ASSAULT_VALUE_INACTIVE)
97 // reset this objective. Used when spawning an objective
98 // and when a new round starts
99 void assault_objective_reset(entity this)
101 this.health = ASSAULT_VALUE_INACTIVE;
104 // decrease the health of targeted objectives
105 void assault_objective_decrease_use()
107 if(activator.team != assault_attacker_team)
109 // wrong team triggered decrease
113 if(other.assault_sprite)
115 WaypointSprite_Disown(other.assault_sprite, waypointsprite_deadlifetime);
116 if(other.classname == "func_assault_destructible")
117 other.sprite = world;
120 return; // already activated! cannot activate again!
122 if(self.enemy.health < ASSAULT_VALUE_INACTIVE)
124 if(self.enemy.health - self.dmg > 0.5)
126 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.dmg);
127 self.enemy.health = self.enemy.health - self.dmg;
131 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.enemy.health);
132 PlayerTeamScore_Add(activator, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
133 self.enemy.health = -1;
139 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(centerprint(it, self.message)));
141 oldactivator = activator;
144 activator = oldactivator;
150 void assault_setenemytoobjective(entity this)
153 for(objective = world; (objective = find(objective, targetname, self.target)); )
155 if(objective.classname == "target_objective")
157 if(self.enemy == world)
158 self.enemy = objective;
160 objerror("more than one objective as target - fix the map!");
165 if(self.enemy == world)
166 objerror("no objective as target - fix the map!");
169 float assault_decreaser_sprite_visible(entity e)
173 decreaser = self.assault_decreaser;
175 if(decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
181 void target_objective_decrease_activate()
185 for(ent = world; (ent = find(ent, target, self.targetname)); )
187 if(ent.assault_sprite != world)
189 WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
190 if(ent.classname == "func_assault_destructible")
194 spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE);
195 spr.assault_decreaser = self;
196 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
197 spr.classname = "sprite_waypoint";
198 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
199 if(ent.classname == "func_assault_destructible")
201 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
202 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
203 WaypointSprite_UpdateHealth(spr, ent.health);
207 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
211 void target_objective_decrease_findtarget(entity this)
213 assault_setenemytoobjective(this);
216 void target_assault_roundend_reset(entity this)
218 //print("round end reset\n");
219 ++this.cnt; // up round counter
220 this.winning = false; // up round
223 void target_assault_roundend_use()
225 self.winning = 1; // round has been won by attackers
228 void assault_roundstart_use(entity this)
233 //(Re)spawn all turrets
234 FOREACH_ENTITY_CLASS("turret_main", true, LAMBDA(
236 if(it.team == NUM_TEAM_1)
237 it.team = NUM_TEAM_2;
239 it.team = NUM_TEAM_1;
241 // Dubbles as teamchange
242 WITHSELF(it, turret_respawn());
245 void assault_roundstart_use_self()
248 assault_roundstart_use(this);
251 void assault_wall_think()
253 if(self.enemy.health < 0)
256 self.solid = SOLID_NOT;
260 self.model = self.mdl;
261 self.solid = SOLID_BSP;
264 self.nextthink = time + 0.2;
268 // reset objectives, toggle spawnpoints, reset triggers, ...
269 void vehicles_clearreturn(entity veh);
270 void vehicles_spawn();
271 void assault_new_round()
273 //bprint("ASSAULT: new round\n");
275 // Eject players from vehicles
276 FOREACH_CLIENT(IS_PLAYER(it) && it.vehicle, WITHSELF(it, vehicles_exit(VHEF_RELEASE)));
278 FOREACH_ENTITY_FLAGS(vehicle_flags, VHF_ISVEHICLE, LAMBDA(
280 vehicles_clearreturn(self);
287 self.winning = self.winning + 1;
289 // swap attacker/defender roles
290 if(assault_attacker_team == NUM_TEAM_1)
291 assault_attacker_team = NUM_TEAM_2;
293 assault_attacker_team = NUM_TEAM_1;
295 FOREACH_ENTITY(IS_NOT_A_CLIENT(it), LAMBDA(
296 if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
297 else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
300 // reset the level with a countdown
301 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
302 ReadyRestart_force(); // sets game_starttime
305 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
306 // they win. Otherwise the defending team wins once the timelimit passes.
307 int WinningCondition_Assault()
310 WinningConditionHelper(); // set worldstatus
312 int status = WINNING_NO;
313 // as the timelimit has not yet passed just assume the defending team will win
314 if(assault_attacker_team == NUM_TEAM_1)
316 SetWinners(team, NUM_TEAM_2);
320 SetWinners(team, NUM_TEAM_1);
324 ent = find(world, classname, "target_assault_roundend");
327 if(ent.winning) // round end has been triggered by attacking team
329 bprint("ASSAULT: round completed...\n");
330 SetWinners(team, assault_attacker_team);
332 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
334 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
336 status = WINNING_YES;
340 WITHSELF(ent, assault_new_round());
349 spawnfunc(info_player_attacker)
351 if (!g_assault) { remove(self); return; }
353 self.team = NUM_TEAM_1; // red, gets swapped every round
354 spawnfunc_info_player_deathmatch(this);
357 spawnfunc(info_player_defender)
359 if (!g_assault) { remove(self); return; }
361 self.team = NUM_TEAM_2; // blue, gets swapped every round
362 spawnfunc_info_player_deathmatch(this);
365 spawnfunc(target_objective)
367 if (!g_assault) { remove(this); return; }
369 this.classname = "target_objective";
370 this.use = assault_objective_use;
371 this.reset = assault_objective_reset;
373 this.spawn_evalfunc = target_objective_spawn_evalfunc;
376 spawnfunc(target_objective_decrease)
378 if (!g_assault) { remove(self); return; }
380 self.classname = "target_objective_decrease";
385 self.use = assault_objective_decrease_use;
386 self.health = ASSAULT_VALUE_INACTIVE;
387 self.max_health = ASSAULT_VALUE_INACTIVE;
390 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
393 // destructible walls that can be used to trigger target_objective_decrease
394 spawnfunc(func_breakable);
395 spawnfunc(func_assault_destructible)
397 if (!g_assault) { remove(self); return; }
400 self.classname = "func_assault_destructible";
402 if(assault_attacker_team == NUM_TEAM_1)
403 self.team = NUM_TEAM_2;
405 self.team = NUM_TEAM_1;
407 spawnfunc_func_breakable(this);
410 spawnfunc(func_assault_wall)
412 if (!g_assault) { remove(self); return; }
414 self.classname = "func_assault_wall";
415 self.mdl = self.model;
416 _setmodel(self, self.mdl);
417 self.solid = SOLID_BSP;
418 self.think = assault_wall_think;
419 self.nextthink = time;
420 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
423 spawnfunc(target_assault_roundend)
425 if (!g_assault) { remove(self); return; }
427 self.winning = 0; // round not yet won by attackers
428 self.classname = "target_assault_roundend";
429 self.use = target_assault_roundend_use;
430 self.cnt = 0; // first round
431 self.reset = target_assault_roundend_reset;
434 spawnfunc(target_assault_roundstart)
436 if (!g_assault) { remove(self); return; }
438 assault_attacker_team = NUM_TEAM_1;
439 self.classname = "target_assault_roundstart";
440 self.use = assault_roundstart_use_self;
441 self.reset2 = assault_roundstart_use_self;
442 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
446 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
448 entity ad, best, wp, tod;
449 float radius, found, bestvalue;
452 ad = findchain(classname, "func_assault_destructible");
454 for (; ad; ad = ad.chain)
463 for(tod = world; (tod = find(tod, targetname, ad.target)); )
465 if(tod.classname == "target_objective_decrease")
467 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
469 // dprint(etos(ad),"\n");
478 /// dprint("target not found\n");
481 /// dprint("target #", etos(ad), " found\n");
484 p = 0.5 * (ad.absmin + ad.absmax);
485 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
486 // te_knightspike(p);
487 // te_lightning2(world, '0 0 0', p);
489 // Find and rate waypoints around it
492 bestvalue = 99999999999;
493 for(radius=0; radius<1500 && !found; radius+=500)
495 for(wp=findradius(p, radius); wp; wp=wp.chain)
497 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
498 if(wp.classname=="waypoint")
499 if(checkpvs(wp.origin, ad))
513 /// dprint("waypoints around target were found\n");
514 // te_lightning2(world, '0 0 0', best.origin);
515 // te_knightspike(best.origin);
517 navigation_routerating(this, best, ratingscale, 4000);
520 this.havocbot_attack_time = 0;
522 if(checkpvs(this.view_ofs,ad))
523 if(checkpvs(this.view_ofs,best))
525 // dprint("increasing attack time for this target\n");
526 this.havocbot_attack_time = time + 2;
532 void havocbot_role_ast_offense(entity this)
536 this.havocbot_attack_time = 0;
537 havocbot_ast_reset_role(this);
541 // Set the role timeout if necessary
542 if (!this.havocbot_role_timeout)
543 this.havocbot_role_timeout = time + 120;
545 if (time > this.havocbot_role_timeout)
547 havocbot_ast_reset_role(this);
551 if(this.havocbot_attack_time>time)
554 if (this.bot_strategytime < time)
556 navigation_goalrating_start(this);
557 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
558 havocbot_goalrating_ast_targets(this, 20000);
559 havocbot_goalrating_items(this, 15000, this.origin, 10000);
560 navigation_goalrating_end(this);
562 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
566 void havocbot_role_ast_defense(entity this)
570 this.havocbot_attack_time = 0;
571 havocbot_ast_reset_role(this);
575 // Set the role timeout if necessary
576 if (!this.havocbot_role_timeout)
577 this.havocbot_role_timeout = time + 120;
579 if (time > this.havocbot_role_timeout)
581 havocbot_ast_reset_role(this);
585 if(this.havocbot_attack_time>time)
588 if (this.bot_strategytime < time)
590 navigation_goalrating_start(this);
591 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 3000);
592 havocbot_goalrating_ast_targets(this, 20000);
593 havocbot_goalrating_items(this, 15000, this.origin, 10000);
594 navigation_goalrating_end(this);
596 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
600 void havocbot_role_ast_setrole(entity this, float role)
604 case HAVOCBOT_AST_ROLE_DEFENSE:
605 this.havocbot_role = havocbot_role_ast_defense;
606 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
607 this.havocbot_role_timeout = 0;
609 case HAVOCBOT_AST_ROLE_OFFENSE:
610 this.havocbot_role = havocbot_role_ast_offense;
611 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
612 this.havocbot_role_timeout = 0;
617 void havocbot_ast_reset_role(entity this)
622 if(this.team == assault_attacker_team)
623 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_OFFENSE);
625 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_DEFENSE);
629 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
631 if(self.team == assault_attacker_team)
632 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
634 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
639 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
641 if(!self.team || self.team == MAX_SHOT_DISTANCE)
642 self.team = 5; // this gets reversed when match starts?
647 MUTATOR_HOOKFUNCTION(as, VehicleSpawn)
649 self.nextthink = time + 0.5;
654 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
656 havocbot_ast_reset_role(self);
660 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
662 return (frag_victim.classname == "func_assault_destructible");
665 MUTATOR_HOOKFUNCTION(as, GetTeamCount)
667 // assault always has 2 teams
672 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
674 ret_float = WinningCondition_Assault();
678 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
680 // no assault warmups
685 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
688 switch(self.classname)
690 case "info_player_team1":
691 case "info_player_team2":
692 case "info_player_team3":
693 case "info_player_team4":
701 void assault_ScoreRules()
703 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
704 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
705 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
706 ScoreRules_basics_end();