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() havocbot_role;
48 .void() havocbot_previous_role;
50 void() havocbot_role_ast_defense;
51 void() havocbot_role_ast_offense;
52 .entity havocbot_ast_target;
54 void(entity bot) havocbot_ast_reset_role;
56 void(float ratingscale, vector org, float sradius) havocbot_goalrating_items;
57 void(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()
303 WinningConditionHelper(); // set worldstatus
305 int status = WINNING_NO;
306 // as the timelimit has not yet passed just assume the defending team will win
307 if(assault_attacker_team == NUM_TEAM_1)
309 SetWinners(team, NUM_TEAM_2);
313 SetWinners(team, NUM_TEAM_1);
317 ent = find(world, classname, "target_assault_roundend");
320 if(ent.winning) // round end has been triggered by attacking team
322 bprint("ASSAULT: round completed...\n");
323 SetWinners(team, assault_attacker_team);
325 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
327 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
329 status = WINNING_YES;
333 WITH(entity, self, ent, assault_new_round());
342 spawnfunc(info_player_attacker)
344 if (!g_assault) { remove(self); return; }
346 self.team = NUM_TEAM_1; // red, gets swapped every round
347 spawnfunc_info_player_deathmatch(this);
350 spawnfunc(info_player_defender)
352 if (!g_assault) { remove(self); return; }
354 self.team = NUM_TEAM_2; // blue, gets swapped every round
355 spawnfunc_info_player_deathmatch(this);
358 spawnfunc(target_objective)
360 if (!g_assault) { remove(this); return; }
362 this.classname = "target_objective";
363 this.use = assault_objective_use;
364 this.reset = assault_objective_reset;
366 this.spawn_evalfunc = target_objective_spawn_evalfunc;
369 spawnfunc(target_objective_decrease)
371 if (!g_assault) { remove(self); return; }
373 self.classname = "target_objective_decrease";
378 self.use = assault_objective_decrease_use;
379 self.health = ASSAULT_VALUE_INACTIVE;
380 self.max_health = ASSAULT_VALUE_INACTIVE;
383 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
386 // destructible walls that can be used to trigger target_objective_decrease
387 spawnfunc(func_breakable);
388 spawnfunc(func_assault_destructible)
390 if (!g_assault) { remove(self); return; }
393 self.classname = "func_assault_destructible";
395 if(assault_attacker_team == NUM_TEAM_1)
396 self.team = NUM_TEAM_2;
398 self.team = NUM_TEAM_1;
400 spawnfunc_func_breakable(this);
403 spawnfunc(func_assault_wall)
405 if (!g_assault) { remove(self); return; }
407 self.classname = "func_assault_wall";
408 self.mdl = self.model;
409 _setmodel(self, self.mdl);
410 self.solid = SOLID_BSP;
411 self.think = assault_wall_think;
412 self.nextthink = time;
413 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
416 spawnfunc(target_assault_roundend)
418 if (!g_assault) { remove(self); return; }
420 self.winning = 0; // round not yet won by attackers
421 self.classname = "target_assault_roundend";
422 self.use = target_assault_roundend_use;
423 self.cnt = 0; // first round
424 self.reset = target_assault_roundend_reset;
427 spawnfunc(target_assault_roundstart)
429 if (!g_assault) { remove(self); return; }
431 assault_attacker_team = NUM_TEAM_1;
432 self.classname = "target_assault_roundstart";
433 self.use = assault_roundstart_use;
434 self.reset2 = assault_roundstart_use;
435 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
439 void havocbot_goalrating_ast_targets(float ratingscale)
441 entity ad, best, wp, tod;
442 float radius, found, bestvalue;
445 ad = findchain(classname, "func_assault_destructible");
447 for (; ad; ad = ad.chain)
456 for(tod = world; (tod = find(tod, targetname, ad.target)); )
458 if(tod.classname == "target_objective_decrease")
460 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
462 // dprint(etos(ad),"\n");
471 /// dprint("target not found\n");
474 /// dprint("target #", etos(ad), " found\n");
477 p = 0.5 * (ad.absmin + ad.absmax);
478 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
479 // te_knightspike(p);
480 // te_lightning2(world, '0 0 0', p);
482 // Find and rate waypoints around it
485 bestvalue = 99999999999;
486 for(radius=0; radius<1500 && !found; radius+=500)
488 for(wp=findradius(p, radius); wp; wp=wp.chain)
490 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
491 if(wp.classname=="waypoint")
492 if(checkpvs(wp.origin, ad))
506 /// dprint("waypoints around target were found\n");
507 // te_lightning2(world, '0 0 0', best.origin);
508 // te_knightspike(best.origin);
510 navigation_routerating(best, ratingscale, 4000);
513 self.havocbot_attack_time = 0;
515 if(checkpvs(self.view_ofs,ad))
516 if(checkpvs(self.view_ofs,best))
518 // dprint("increasing attack time for this target\n");
519 self.havocbot_attack_time = time + 2;
525 void havocbot_role_ast_offense()
529 self.havocbot_attack_time = 0;
530 havocbot_ast_reset_role(self);
534 // Set the role timeout if necessary
535 if (!self.havocbot_role_timeout)
536 self.havocbot_role_timeout = time + 120;
538 if (time > self.havocbot_role_timeout)
540 havocbot_ast_reset_role(self);
544 if(self.havocbot_attack_time>time)
547 if (self.bot_strategytime < time)
549 navigation_goalrating_start();
550 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
551 havocbot_goalrating_ast_targets(20000);
552 havocbot_goalrating_items(15000, self.origin, 10000);
553 navigation_goalrating_end();
555 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
559 void havocbot_role_ast_defense()
563 self.havocbot_attack_time = 0;
564 havocbot_ast_reset_role(self);
568 // Set the role timeout if necessary
569 if (!self.havocbot_role_timeout)
570 self.havocbot_role_timeout = time + 120;
572 if (time > self.havocbot_role_timeout)
574 havocbot_ast_reset_role(self);
578 if(self.havocbot_attack_time>time)
581 if (self.bot_strategytime < time)
583 navigation_goalrating_start();
584 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
585 havocbot_goalrating_ast_targets(20000);
586 havocbot_goalrating_items(15000, self.origin, 10000);
587 navigation_goalrating_end();
589 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
593 void havocbot_role_ast_setrole(entity bot, float role)
597 case HAVOCBOT_AST_ROLE_DEFENSE:
598 bot.havocbot_role = havocbot_role_ast_defense;
599 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
600 bot.havocbot_role_timeout = 0;
602 case HAVOCBOT_AST_ROLE_OFFENSE:
603 bot.havocbot_role = havocbot_role_ast_offense;
604 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
605 bot.havocbot_role_timeout = 0;
610 void havocbot_ast_reset_role(entity bot)
615 if(bot.team == assault_attacker_team)
616 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
618 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
622 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
624 if(self.team == assault_attacker_team)
625 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
627 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
632 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
634 if(!self.team || self.team == MAX_SHOT_DISTANCE)
635 self.team = 5; // this gets reversed when match starts?
640 MUTATOR_HOOKFUNCTION(as, VehicleSpawn)
642 self.nextthink = time + 0.5;
647 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
649 havocbot_ast_reset_role(self);
653 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
655 return (frag_victim.classname == "func_assault_destructible");
658 MUTATOR_HOOKFUNCTION(as, GetTeamCount)
660 // assault always has 2 teams
665 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
667 ret_float = WinningCondition_Assault();
671 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
673 // no assault warmups
678 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
680 switch(self.classname)
682 case "info_player_team1":
683 case "info_player_team2":
684 case "info_player_team3":
685 case "info_player_team4":
693 void assault_ScoreRules()
695 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
696 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
697 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
698 ScoreRules_basics_end();