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;
63 // predefined spawnfuncs
64 void target_objective_decrease_activate();
71 void assault_objective_use()
75 //print("^2Activated objective ", self.targetname, "=", etos(self), "\n");
76 //print("Activator is ", activator.classname, "\n");
78 for (entity e = world; (e = find(e, target, this.targetname)); )
80 if (e.classname == "target_objective_decrease")
82 WITHSELF(e, target_objective_decrease_activate());
89 vector target_objective_spawn_evalfunc(entity player, entity spot, vector current)
91 if(self.health < 0 || self.health >= ASSAULT_VALUE_INACTIVE)
96 // reset this objective. Used when spawning an objective
97 // and when a new round starts
98 void assault_objective_reset(entity this)
100 this.health = ASSAULT_VALUE_INACTIVE;
103 // decrease the health of targeted objectives
104 void assault_objective_decrease_use()
106 if(activator.team != assault_attacker_team)
108 // wrong team triggered decrease
112 if(other.assault_sprite)
114 WaypointSprite_Disown(other.assault_sprite, waypointsprite_deadlifetime);
115 if(other.classname == "func_assault_destructible")
116 other.sprite = world;
119 return; // already activated! cannot activate again!
121 if(self.enemy.health < ASSAULT_VALUE_INACTIVE)
123 if(self.enemy.health - self.dmg > 0.5)
125 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.dmg);
126 self.enemy.health = self.enemy.health - self.dmg;
130 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.enemy.health);
131 PlayerTeamScore_Add(activator, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
132 self.enemy.health = -1;
138 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(centerprint(it, self.message)));
140 oldactivator = activator;
143 activator = oldactivator;
149 void assault_setenemytoobjective(entity this)
152 for(objective = world; (objective = find(objective, targetname, self.target)); )
154 if(objective.classname == "target_objective")
156 if(self.enemy == world)
157 self.enemy = objective;
159 objerror("more than one objective as target - fix the map!");
164 if(self.enemy == world)
165 objerror("no objective as target - fix the map!");
168 float assault_decreaser_sprite_visible(entity e)
172 decreaser = self.assault_decreaser;
174 if(decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
180 void target_objective_decrease_activate()
184 for(ent = world; (ent = find(ent, target, self.targetname)); )
186 if(ent.assault_sprite != world)
188 WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
189 if(ent.classname == "func_assault_destructible")
193 spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE);
194 spr.assault_decreaser = self;
195 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
196 spr.classname = "sprite_waypoint";
197 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
198 if(ent.classname == "func_assault_destructible")
200 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
201 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
202 WaypointSprite_UpdateHealth(spr, ent.health);
206 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
210 void target_objective_decrease_findtarget(entity this)
212 assault_setenemytoobjective(this);
215 void target_assault_roundend_reset(entity this)
217 //print("round end reset\n");
218 ++this.cnt; // up round counter
219 this.winning = false; // up round
222 void target_assault_roundend_use()
224 self.winning = 1; // round has been won by attackers
227 void assault_roundstart_use(entity this)
232 //(Re)spawn all turrets
233 FOREACH_ENTITY_CLASS("turret_main", true, LAMBDA(
235 if(it.team == NUM_TEAM_1)
236 it.team = NUM_TEAM_2;
238 it.team = NUM_TEAM_1;
240 // Dubbles as teamchange
241 WITHSELF(it, turret_respawn());
244 void assault_roundstart_use_self()
247 assault_roundstart_use(this);
250 void assault_wall_think()
252 if(self.enemy.health < 0)
255 self.solid = SOLID_NOT;
259 self.model = self.mdl;
260 self.solid = SOLID_BSP;
263 self.nextthink = time + 0.2;
267 // reset objectives, toggle spawnpoints, reset triggers, ...
268 void vehicles_clearreturn(entity veh);
269 void vehicles_spawn();
270 void assault_new_round()
272 //bprint("ASSAULT: new round\n");
274 // Eject players from vehicles
275 FOREACH_CLIENT(IS_PLAYER(it) && it.vehicle, WITHSELF(it, vehicles_exit(VHEF_RELEASE)));
277 FOREACH_ENTITY_FLAGS(vehicle_flags, VHF_ISVEHICLE, LAMBDA(
279 vehicles_clearreturn(self);
286 self.winning = self.winning + 1;
288 // swap attacker/defender roles
289 if(assault_attacker_team == NUM_TEAM_1)
290 assault_attacker_team = NUM_TEAM_2;
292 assault_attacker_team = NUM_TEAM_1;
294 FOREACH_ENTITY(IS_NOT_A_CLIENT(it), LAMBDA(
295 if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
296 else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
299 // reset the level with a countdown
300 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
301 ReadyRestart_force(); // sets game_starttime
304 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
305 // they win. Otherwise the defending team wins once the timelimit passes.
306 int WinningCondition_Assault()
309 WinningConditionHelper(); // set worldstatus
311 int status = WINNING_NO;
312 // as the timelimit has not yet passed just assume the defending team will win
313 if(assault_attacker_team == NUM_TEAM_1)
315 SetWinners(team, NUM_TEAM_2);
319 SetWinners(team, NUM_TEAM_1);
323 ent = find(world, classname, "target_assault_roundend");
326 if(ent.winning) // round end has been triggered by attacking team
328 bprint("ASSAULT: round completed...\n");
329 SetWinners(team, assault_attacker_team);
331 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
333 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
335 status = WINNING_YES;
339 WITHSELF(ent, assault_new_round());
348 spawnfunc(info_player_attacker)
350 if (!g_assault) { remove(self); return; }
352 self.team = NUM_TEAM_1; // red, gets swapped every round
353 spawnfunc_info_player_deathmatch(this);
356 spawnfunc(info_player_defender)
358 if (!g_assault) { remove(self); return; }
360 self.team = NUM_TEAM_2; // blue, gets swapped every round
361 spawnfunc_info_player_deathmatch(this);
364 spawnfunc(target_objective)
366 if (!g_assault) { remove(this); return; }
368 this.classname = "target_objective";
369 this.use = assault_objective_use;
370 this.reset = assault_objective_reset;
372 this.spawn_evalfunc = target_objective_spawn_evalfunc;
375 spawnfunc(target_objective_decrease)
377 if (!g_assault) { remove(self); return; }
379 self.classname = "target_objective_decrease";
384 self.use = assault_objective_decrease_use;
385 self.health = ASSAULT_VALUE_INACTIVE;
386 self.max_health = ASSAULT_VALUE_INACTIVE;
389 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
392 // destructible walls that can be used to trigger target_objective_decrease
393 spawnfunc(func_breakable);
394 spawnfunc(func_assault_destructible)
396 if (!g_assault) { remove(self); return; }
399 self.classname = "func_assault_destructible";
401 if(assault_attacker_team == NUM_TEAM_1)
402 self.team = NUM_TEAM_2;
404 self.team = NUM_TEAM_1;
406 spawnfunc_func_breakable(this);
409 spawnfunc(func_assault_wall)
411 if (!g_assault) { remove(self); return; }
413 self.classname = "func_assault_wall";
414 self.mdl = self.model;
415 _setmodel(self, self.mdl);
416 self.solid = SOLID_BSP;
417 self.think = assault_wall_think;
418 self.nextthink = time;
419 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
422 spawnfunc(target_assault_roundend)
424 if (!g_assault) { remove(self); return; }
426 self.winning = 0; // round not yet won by attackers
427 self.classname = "target_assault_roundend";
428 self.use = target_assault_roundend_use;
429 self.cnt = 0; // first round
430 self.reset = target_assault_roundend_reset;
433 spawnfunc(target_assault_roundstart)
435 if (!g_assault) { remove(self); return; }
437 assault_attacker_team = NUM_TEAM_1;
438 self.classname = "target_assault_roundstart";
439 self.use = assault_roundstart_use_self;
440 self.reset2 = assault_roundstart_use_self;
441 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
445 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
447 entity ad, best, wp, tod;
448 float radius, found, bestvalue;
451 ad = findchain(classname, "func_assault_destructible");
453 for (; ad; ad = ad.chain)
462 for(tod = world; (tod = find(tod, targetname, ad.target)); )
464 if(tod.classname == "target_objective_decrease")
466 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
468 // dprint(etos(ad),"\n");
477 /// dprint("target not found\n");
480 /// dprint("target #", etos(ad), " found\n");
483 p = 0.5 * (ad.absmin + ad.absmax);
484 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
485 // te_knightspike(p);
486 // te_lightning2(world, '0 0 0', p);
488 // Find and rate waypoints around it
491 bestvalue = 99999999999;
492 for(radius=0; radius<1500 && !found; radius+=500)
494 for(wp=findradius(p, radius); wp; wp=wp.chain)
496 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
497 if(wp.classname=="waypoint")
498 if(checkpvs(wp.origin, ad))
512 /// dprint("waypoints around target were found\n");
513 // te_lightning2(world, '0 0 0', best.origin);
514 // te_knightspike(best.origin);
516 navigation_routerating(this, best, ratingscale, 4000);
519 this.havocbot_attack_time = 0;
521 if(checkpvs(this.view_ofs,ad))
522 if(checkpvs(this.view_ofs,best))
524 // dprint("increasing attack time for this target\n");
525 this.havocbot_attack_time = time + 2;
531 void havocbot_role_ast_offense(entity this)
535 this.havocbot_attack_time = 0;
536 havocbot_ast_reset_role(this);
540 // Set the role timeout if necessary
541 if (!this.havocbot_role_timeout)
542 this.havocbot_role_timeout = time + 120;
544 if (time > this.havocbot_role_timeout)
546 havocbot_ast_reset_role(this);
550 if(this.havocbot_attack_time>time)
553 if (this.bot_strategytime < time)
555 navigation_goalrating_start(this);
556 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
557 havocbot_goalrating_ast_targets(this, 20000);
558 havocbot_goalrating_items(this, 15000, this.origin, 10000);
559 navigation_goalrating_end(this);
561 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
565 void havocbot_role_ast_defense(entity this)
569 this.havocbot_attack_time = 0;
570 havocbot_ast_reset_role(this);
574 // Set the role timeout if necessary
575 if (!this.havocbot_role_timeout)
576 this.havocbot_role_timeout = time + 120;
578 if (time > this.havocbot_role_timeout)
580 havocbot_ast_reset_role(this);
584 if(this.havocbot_attack_time>time)
587 if (this.bot_strategytime < time)
589 navigation_goalrating_start(this);
590 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 3000);
591 havocbot_goalrating_ast_targets(this, 20000);
592 havocbot_goalrating_items(this, 15000, this.origin, 10000);
593 navigation_goalrating_end(this);
595 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
599 void havocbot_role_ast_setrole(entity this, float role)
603 case HAVOCBOT_AST_ROLE_DEFENSE:
604 this.havocbot_role = havocbot_role_ast_defense;
605 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
606 this.havocbot_role_timeout = 0;
608 case HAVOCBOT_AST_ROLE_OFFENSE:
609 this.havocbot_role = havocbot_role_ast_offense;
610 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
611 this.havocbot_role_timeout = 0;
616 void havocbot_ast_reset_role(entity this)
621 if(this.team == assault_attacker_team)
622 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_OFFENSE);
624 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_DEFENSE);
628 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
630 if(self.team == assault_attacker_team)
631 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
633 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
638 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
640 if(!self.team || self.team == MAX_SHOT_DISTANCE)
641 self.team = 5; // this gets reversed when match starts?
646 MUTATOR_HOOKFUNCTION(as, VehicleSpawn)
648 self.nextthink = time + 0.5;
653 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
655 havocbot_ast_reset_role(self);
659 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
661 return (frag_victim.classname == "func_assault_destructible");
664 MUTATOR_HOOKFUNCTION(as, GetTeamCount)
666 // assault always has 2 teams
671 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
673 ret_float = WinningCondition_Assault();
677 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
679 // no assault warmups
684 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
687 switch(self.classname)
689 case "info_player_team1":
690 case "info_player_team2":
691 case "info_player_team3":
692 case "info_player_team4":
700 void assault_ScoreRules()
702 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
703 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
704 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
705 ScoreRules_basics_end();