1 #include "gamemode_assault.qh"
2 #ifndef GAMEMODE_ASSAULT_H
3 #define GAMEMODE_ASSAULT_H
5 void assault_ScoreRules();
7 REGISTER_MUTATOR(as, false)
10 have_team_spawns = -1; // request team spawns
14 if (time > 1) // game loads at time 1
15 error("This is a game type and it cannot be added at runtime.");
19 MUTATOR_ONROLLBACK_OR_REMOVE
21 // we actually cannot roll back assault_Initialize here
22 // BUT: we don't need to! If this gets called, adding always
28 LOG_INFO("This is a game type and it cannot be removed at runtime.");
36 .entity assault_decreaser;
37 .entity assault_sprite;
40 const int HAVOCBOT_AST_ROLE_NONE = 0;
41 const int HAVOCBOT_AST_ROLE_DEFENSE = 2;
42 const int HAVOCBOT_AST_ROLE_OFFENSE = 4;
44 .int havocbot_role_flags;
45 .float havocbot_attack_time;
47 .void(entity this) havocbot_role;
48 .void(entity this) havocbot_previous_role;
50 void(entity this) havocbot_role_ast_defense;
51 void(entity this) havocbot_role_ast_offense;
52 .entity havocbot_ast_target;
54 void(entity bot) havocbot_ast_reset_role;
56 void(entity this, float ratingscale, vector org, float sradius) havocbot_goalrating_items;
57 void(entity this, float ratingscale, vector org, float sradius) havocbot_goalrating_enemyplayers;
60 const float ST_ASSAULT_OBJECTIVES = 1;
61 const float SP_ASSAULT_OBJECTIVES = 4;
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 WITH(entity, self, 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()
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()
212 assault_setenemytoobjective();
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()
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 WITH(entity, self, it, turret_respawn());
245 void assault_wall_think()
247 if(self.enemy.health < 0)
250 self.solid = SOLID_NOT;
254 self.model = self.mdl;
255 self.solid = SOLID_BSP;
258 self.nextthink = time + 0.2;
262 // reset objectives, toggle spawnpoints, reset triggers, ...
263 void vehicles_clearreturn(entity veh);
264 void vehicles_spawn();
265 void assault_new_round()
267 //bprint("ASSAULT: new round\n");
269 // Eject players from vehicles
270 FOREACH_CLIENT(IS_PLAYER(it) && it.vehicle, LAMBDA(WITH(entity, self, it, vehicles_exit(VHEF_RELEASE))));
272 FOREACH_ENTITY_FLAGS(vehicle_flags, VHF_ISVEHICLE, LAMBDA(
274 vehicles_clearreturn(self);
281 self.winning = self.winning + 1;
283 // swap attacker/defender roles
284 if(assault_attacker_team == NUM_TEAM_1)
285 assault_attacker_team = NUM_TEAM_2;
287 assault_attacker_team = NUM_TEAM_1;
289 FOREACH_ENTITY(IS_NOT_A_CLIENT(it), LAMBDA(
290 if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
291 else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
294 // reset the level with a countdown
295 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
296 ReadyRestart_force(); // sets game_starttime
299 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
300 // they win. Otherwise the defending team wins once the timelimit passes.
301 int WinningCondition_Assault()
304 WinningConditionHelper(); // set worldstatus
306 int status = WINNING_NO;
307 // as the timelimit has not yet passed just assume the defending team will win
308 if(assault_attacker_team == NUM_TEAM_1)
310 SetWinners(team, NUM_TEAM_2);
314 SetWinners(team, NUM_TEAM_1);
318 ent = find(world, classname, "target_assault_roundend");
321 if(ent.winning) // round end has been triggered by attacking team
323 bprint("ASSAULT: round completed...\n");
324 SetWinners(team, assault_attacker_team);
326 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
328 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
330 status = WINNING_YES;
334 WITH(entity, self, ent, assault_new_round());
343 spawnfunc(info_player_attacker)
345 if (!g_assault) { remove(self); return; }
347 self.team = NUM_TEAM_1; // red, gets swapped every round
348 spawnfunc_info_player_deathmatch(this);
351 spawnfunc(info_player_defender)
353 if (!g_assault) { remove(self); return; }
355 self.team = NUM_TEAM_2; // blue, gets swapped every round
356 spawnfunc_info_player_deathmatch(this);
359 spawnfunc(target_objective)
361 if (!g_assault) { remove(this); return; }
363 this.classname = "target_objective";
364 this.use = assault_objective_use;
365 this.reset = assault_objective_reset;
367 this.spawn_evalfunc = target_objective_spawn_evalfunc;
370 spawnfunc(target_objective_decrease)
372 if (!g_assault) { remove(self); return; }
374 self.classname = "target_objective_decrease";
379 self.use = assault_objective_decrease_use;
380 self.health = ASSAULT_VALUE_INACTIVE;
381 self.max_health = ASSAULT_VALUE_INACTIVE;
384 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
387 // destructible walls that can be used to trigger target_objective_decrease
388 spawnfunc(func_breakable);
389 spawnfunc(func_assault_destructible)
391 if (!g_assault) { remove(self); return; }
394 self.classname = "func_assault_destructible";
396 if(assault_attacker_team == NUM_TEAM_1)
397 self.team = NUM_TEAM_2;
399 self.team = NUM_TEAM_1;
401 spawnfunc_func_breakable(this);
404 spawnfunc(func_assault_wall)
406 if (!g_assault) { remove(self); return; }
408 self.classname = "func_assault_wall";
409 self.mdl = self.model;
410 _setmodel(self, self.mdl);
411 self.solid = SOLID_BSP;
412 self.think = assault_wall_think;
413 self.nextthink = time;
414 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
417 spawnfunc(target_assault_roundend)
419 if (!g_assault) { remove(self); return; }
421 self.winning = 0; // round not yet won by attackers
422 self.classname = "target_assault_roundend";
423 self.use = target_assault_roundend_use;
424 self.cnt = 0; // first round
425 self.reset = target_assault_roundend_reset;
428 spawnfunc(target_assault_roundstart)
430 if (!g_assault) { remove(self); return; }
432 assault_attacker_team = NUM_TEAM_1;
433 self.classname = "target_assault_roundstart";
434 self.use = assault_roundstart_use;
435 self.reset2 = assault_roundstart_use;
436 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
440 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
442 entity ad, best, wp, tod;
443 float radius, found, bestvalue;
446 ad = findchain(classname, "func_assault_destructible");
448 for (; ad; ad = ad.chain)
457 for(tod = world; (tod = find(tod, targetname, ad.target)); )
459 if(tod.classname == "target_objective_decrease")
461 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
463 // dprint(etos(ad),"\n");
472 /// dprint("target not found\n");
475 /// dprint("target #", etos(ad), " found\n");
478 p = 0.5 * (ad.absmin + ad.absmax);
479 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
480 // te_knightspike(p);
481 // te_lightning2(world, '0 0 0', p);
483 // Find and rate waypoints around it
486 bestvalue = 99999999999;
487 for(radius=0; radius<1500 && !found; radius+=500)
489 for(wp=findradius(p, radius); wp; wp=wp.chain)
491 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
492 if(wp.classname=="waypoint")
493 if(checkpvs(wp.origin, ad))
507 /// dprint("waypoints around target were found\n");
508 // te_lightning2(world, '0 0 0', best.origin);
509 // te_knightspike(best.origin);
511 navigation_routerating(this, best, ratingscale, 4000);
514 this.havocbot_attack_time = 0;
516 if(checkpvs(this.view_ofs,ad))
517 if(checkpvs(this.view_ofs,best))
519 // dprint("increasing attack time for this target\n");
520 this.havocbot_attack_time = time + 2;
526 void havocbot_role_ast_offense(entity this)
530 this.havocbot_attack_time = 0;
531 havocbot_ast_reset_role(this);
535 // Set the role timeout if necessary
536 if (!this.havocbot_role_timeout)
537 this.havocbot_role_timeout = time + 120;
539 if (time > this.havocbot_role_timeout)
541 havocbot_ast_reset_role(this);
545 if(this.havocbot_attack_time>time)
548 if (this.bot_strategytime < time)
550 navigation_goalrating_start(this);
551 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
552 havocbot_goalrating_ast_targets(this, 20000);
553 havocbot_goalrating_items(this, 15000, this.origin, 10000);
554 navigation_goalrating_end(this);
556 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
560 void havocbot_role_ast_defense(entity this)
564 this.havocbot_attack_time = 0;
565 havocbot_ast_reset_role(this);
569 // Set the role timeout if necessary
570 if (!this.havocbot_role_timeout)
571 this.havocbot_role_timeout = time + 120;
573 if (time > this.havocbot_role_timeout)
575 havocbot_ast_reset_role(this);
579 if(this.havocbot_attack_time>time)
582 if (this.bot_strategytime < time)
584 navigation_goalrating_start(this);
585 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 3000);
586 havocbot_goalrating_ast_targets(this, 20000);
587 havocbot_goalrating_items(this, 15000, this.origin, 10000);
588 navigation_goalrating_end(this);
590 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
594 void havocbot_role_ast_setrole(entity this, float role)
598 case HAVOCBOT_AST_ROLE_DEFENSE:
599 this.havocbot_role = havocbot_role_ast_defense;
600 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
601 this.havocbot_role_timeout = 0;
603 case HAVOCBOT_AST_ROLE_OFFENSE:
604 this.havocbot_role = havocbot_role_ast_offense;
605 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
606 this.havocbot_role_timeout = 0;
611 void havocbot_ast_reset_role(entity this)
616 if(this.team == assault_attacker_team)
617 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_OFFENSE);
619 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_DEFENSE);
623 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
625 if(self.team == assault_attacker_team)
626 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
628 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
633 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
635 if(!self.team || self.team == MAX_SHOT_DISTANCE)
636 self.team = 5; // this gets reversed when match starts?
641 MUTATOR_HOOKFUNCTION(as, VehicleSpawn)
643 self.nextthink = time + 0.5;
648 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
650 havocbot_ast_reset_role(self);
654 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
656 return (frag_victim.classname == "func_assault_destructible");
659 MUTATOR_HOOKFUNCTION(as, GetTeamCount)
661 // assault always has 2 teams
666 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
668 ret_float = WinningCondition_Assault();
672 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
674 // no assault warmups
679 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
682 switch(self.classname)
684 case "info_player_team1":
685 case "info_player_team2":
686 case "info_player_team3":
687 case "info_player_team4":
695 void assault_ScoreRules()
697 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
698 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
699 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
700 ScoreRules_basics_end();