1 #include "gamemode_assault.qh"
3 #include <lib/float.qh>
6 #define AS_ROUND_DELAY 5
9 void assault_objective_use(entity this, entity actor, entity trigger)
13 //print("^2Activated objective ", this.targetname, "=", etos(this), "\n");
14 //print("Activator is ", actor.classname, "\n");
16 IL_EACH(g_assault_objectivedecreasers, it.target == this.targetname,
18 target_objective_decrease_activate(it);
22 vector target_objective_spawn_evalfunc(entity this, entity player, entity spot, vector current)
24 if(this.health < 0 || this.health >= ASSAULT_VALUE_INACTIVE)
29 // reset this objective. Used when spawning an objective
30 // and when a new round starts
31 void assault_objective_reset(entity this)
33 this.health = ASSAULT_VALUE_INACTIVE;
36 // decrease the health of targeted objectives
37 void assault_objective_decrease_use(entity this, entity actor, entity trigger)
39 if(actor.team != assault_attacker_team)
41 // wrong team triggered decrease
45 if(trigger.assault_sprite)
47 WaypointSprite_Disown(trigger.assault_sprite, waypointsprite_deadlifetime);
48 if(trigger.classname == "func_assault_destructible")
49 trigger.sprite = NULL; // TODO: just unsetting it?!
52 return; // already activated! cannot activate again!
54 if(this.enemy.health < ASSAULT_VALUE_INACTIVE)
56 if(this.enemy.health - this.dmg > 0.5)
58 PlayerTeamScore_Add(actor, SP_SCORE, ST_SCORE, this.dmg);
59 this.enemy.health = this.enemy.health - this.dmg;
63 PlayerTeamScore_Add(actor, SP_SCORE, ST_SCORE, this.enemy.health);
64 PlayerTeamScore_Add(actor, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
65 this.enemy.health = -1;
67 if(this.enemy.message)
68 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(centerprint(it, this.enemy.message)));
70 SUB_UseTargets(this.enemy, this, trigger);
75 void assault_setenemytoobjective(entity this)
77 IL_EACH(g_assault_objectives, it.targetname == this.target,
79 if(this.enemy == NULL)
82 objerror(this, "more than one objective as target - fix the map!");
86 if(this.enemy == NULL)
87 objerror(this, "no objective as target - fix the map!");
90 bool assault_decreaser_sprite_visible(entity this, entity player, entity view)
92 if(this.assault_decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
98 void target_objective_decrease_activate(entity this)
102 FOREACH_ENTITY_STRING(target, this.targetname,
104 if(it.assault_sprite != NULL)
106 WaypointSprite_Disown(it.assault_sprite, waypointsprite_deadlifetime);
107 if(it.classname == "func_assault_destructible")
108 it.sprite = NULL; // TODO: just unsetting it?!
111 spr = WaypointSprite_SpawnFixed(WP_AssaultDefend, 0.5 * (it.absmin + it.absmax), it, assault_sprite, RADARICON_OBJECTIVE);
112 spr.assault_decreaser = this;
113 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
114 spr.classname = "sprite_waypoint";
115 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
116 if(it.classname == "func_assault_destructible")
118 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
119 WaypointSprite_UpdateMaxHealth(spr, it.max_health);
120 WaypointSprite_UpdateHealth(spr, it.health);
124 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
128 void target_objective_decrease_findtarget(entity this)
130 assault_setenemytoobjective(this);
133 void target_assault_roundend_reset(entity this)
135 //print("round end reset\n");
136 ++this.cnt; // up round counter
137 this.winning = false; // up round
140 void target_assault_roundend_use(entity this, entity actor, entity trigger)
142 this.winning = 1; // round has been won by attackers
145 void assault_roundstart_use(entity this, entity actor, entity trigger)
147 SUB_UseTargets(this, this, trigger);
149 //(Re)spawn all turrets
150 IL_EACH(g_turrets, true,
153 if(it.team == NUM_TEAM_1)
154 it.team = NUM_TEAM_2;
156 it.team = NUM_TEAM_1;
158 // Doubles as teamchange
162 void assault_roundstart_use_this(entity this)
164 assault_roundstart_use(this, NULL, NULL);
167 void assault_wall_think(entity this)
169 if(this.enemy.health < 0)
172 this.solid = SOLID_NOT;
176 this.model = this.mdl;
177 this.solid = SOLID_BSP;
180 this.nextthink = time + 0.2;
184 // reset objectives, toggle spawnpoints, reset triggers, ...
185 void assault_new_round(entity this)
187 //bprint("ASSAULT: new round\n");
190 this.winning = this.winning + 1;
192 // swap attacker/defender roles
193 if(assault_attacker_team == NUM_TEAM_1)
194 assault_attacker_team = NUM_TEAM_2;
196 assault_attacker_team = NUM_TEAM_1;
198 FOREACH_ENTITY_FLOAT(pure_data, false,
203 if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
204 else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
207 // reset the level with a countdown
208 cvar_set("timelimit", ftos(ceil(time - AS_ROUND_DELAY - game_starttime) / 60));
209 ReadyRestart_force(); // sets game_starttime
214 void as_round_think()
216 game_stopped = false;
217 assault_new_round(as_round.ent_winning);
222 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
223 // they win. Otherwise the defending team wins once the timelimit passes.
224 int WinningCondition_Assault()
229 WinningConditionHelper(NULL); // set worldstatus
231 int status = WINNING_NO;
232 // as the timelimit has not yet passed just assume the defending team will win
233 if(assault_attacker_team == NUM_TEAM_1)
235 SetWinners(team, NUM_TEAM_2);
239 SetWinners(team, NUM_TEAM_1);
243 ent = find(NULL, classname, "target_assault_roundend");
246 if(ent.winning) // round end has been triggered by attacking team
248 bprint("Assault: round completed.\n");
249 SetWinners(team, assault_attacker_team);
251 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
253 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
255 status = WINNING_YES;
259 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ASSAULT_OBJ_DESTROYED, ceil(time - game_starttime));
260 as_round = new(as_round);
261 as_round.think = as_round_think;
262 as_round.ent_winning = ent;
263 as_round.nextthink = time + AS_ROUND_DELAY;
266 // make sure timelimit isn't hit while the game is blocked
267 if(autocvar_timelimit > 0)
268 if(time + AS_ROUND_DELAY >= game_starttime + autocvar_timelimit * 60)
269 cvar_set("timelimit", ftos(autocvar_timelimit + AS_ROUND_DELAY / 60));
278 spawnfunc(info_player_attacker)
280 if (!g_assault) { delete(this); return; }
282 this.team = NUM_TEAM_1; // red, gets swapped every round
283 spawnfunc_info_player_deathmatch(this);
286 spawnfunc(info_player_defender)
288 if (!g_assault) { delete(this); return; }
290 this.team = NUM_TEAM_2; // blue, gets swapped every round
291 spawnfunc_info_player_deathmatch(this);
294 spawnfunc(target_objective)
296 if (!g_assault) { delete(this); return; }
298 this.classname = "target_objective";
299 IL_PUSH(g_assault_objectives, this);
300 this.use = assault_objective_use;
301 this.reset = assault_objective_reset;
303 this.spawn_evalfunc = target_objective_spawn_evalfunc;
306 spawnfunc(target_objective_decrease)
308 if (!g_assault) { delete(this); return; }
310 this.classname = "target_objective_decrease";
311 IL_PUSH(g_assault_objectivedecreasers, this);
316 this.use = assault_objective_decrease_use;
317 this.health = ASSAULT_VALUE_INACTIVE;
318 this.max_health = ASSAULT_VALUE_INACTIVE;
321 InitializeEntity(this, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
324 // destructible walls that can be used to trigger target_objective_decrease
325 spawnfunc(func_breakable);
326 spawnfunc(func_assault_destructible)
328 if (!g_assault) { delete(this); return; }
331 this.classname = "func_assault_destructible";
332 IL_PUSH(g_assault_destructibles, this);
334 if(assault_attacker_team == NUM_TEAM_1)
335 this.team = NUM_TEAM_2;
337 this.team = NUM_TEAM_1;
339 spawnfunc_func_breakable(this);
342 spawnfunc(func_assault_wall)
344 if (!g_assault) { delete(this); return; }
346 this.classname = "func_assault_wall";
347 this.mdl = this.model;
348 _setmodel(this, this.mdl);
349 this.solid = SOLID_BSP;
350 setthink(this, assault_wall_think);
351 this.nextthink = time;
352 InitializeEntity(this, assault_setenemytoobjective, INITPRIO_FINDTARGET);
355 spawnfunc(target_assault_roundend)
357 if (!g_assault) { delete(this); return; }
359 this.winning = 0; // round not yet won by attackers
360 this.classname = "target_assault_roundend";
361 this.use = target_assault_roundend_use;
362 this.cnt = 0; // first round
363 this.reset = target_assault_roundend_reset;
366 spawnfunc(target_assault_roundstart)
368 if (!g_assault) { delete(this); return; }
370 assault_attacker_team = NUM_TEAM_1;
371 this.classname = "target_assault_roundstart";
372 this.use = assault_roundstart_use;
373 this.reset2 = assault_roundstart_use_this;
374 InitializeEntity(this, assault_roundstart_use_this, INITPRIO_FINDTARGET);
378 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
380 IL_EACH(g_assault_destructibles, it.bot_attack,
387 IL_EACH(g_assault_objectivedecreasers, it.targetname == destr.target,
389 if(it.enemy.health > 0 && it.enemy.health < ASSAULT_VALUE_INACTIVE)
399 vector p = 0.5 * (it.absmin + it.absmax);
401 // Find and rate waypoints around it
404 float bestvalue = 99999999999;
406 for(float radius = 0; radius < 1500 && !found; radius += 500)
408 FOREACH_ENTITY_RADIUS(p, radius, it.classname == "waypoint" && !(it.wpflags & WAYPOINTFLAG_GENERATED),
410 if(checkpvs(it.origin, des))
413 if(it.cnt < bestvalue)
424 /// dprint("waypoints around target were found\n");
425 // te_lightning2(NULL, '0 0 0', best.origin);
426 // te_knightspike(best.origin);
428 navigation_routerating(this, best, ratingscale, 4000);
431 this.havocbot_attack_time = 0;
433 if(checkpvs(this.view_ofs,it))
434 if(checkpvs(this.view_ofs,best))
436 // dprint("increasing attack time for this target\n");
437 this.havocbot_attack_time = time + 2;
443 void havocbot_role_ast_offense(entity this)
447 this.havocbot_attack_time = 0;
448 havocbot_ast_reset_role(this);
452 // Set the role timeout if necessary
453 if (!this.havocbot_role_timeout)
454 this.havocbot_role_timeout = time + 120;
456 if (time > this.havocbot_role_timeout)
458 havocbot_ast_reset_role(this);
462 if(this.havocbot_attack_time>time)
465 if (this.bot_strategytime < time)
467 navigation_goalrating_start(this);
468 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
469 havocbot_goalrating_ast_targets(this, 20000);
470 havocbot_goalrating_items(this, 15000, this.origin, 10000);
471 navigation_goalrating_end(this);
473 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
477 void havocbot_role_ast_defense(entity this)
481 this.havocbot_attack_time = 0;
482 havocbot_ast_reset_role(this);
486 // Set the role timeout if necessary
487 if (!this.havocbot_role_timeout)
488 this.havocbot_role_timeout = time + 120;
490 if (time > this.havocbot_role_timeout)
492 havocbot_ast_reset_role(this);
496 if(this.havocbot_attack_time>time)
499 if (this.bot_strategytime < time)
501 navigation_goalrating_start(this);
502 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 3000);
503 havocbot_goalrating_ast_targets(this, 20000);
504 havocbot_goalrating_items(this, 15000, this.origin, 10000);
505 navigation_goalrating_end(this);
507 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
511 void havocbot_role_ast_setrole(entity this, float role)
515 case HAVOCBOT_AST_ROLE_DEFENSE:
516 this.havocbot_role = havocbot_role_ast_defense;
517 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
518 this.havocbot_role_timeout = 0;
520 case HAVOCBOT_AST_ROLE_OFFENSE:
521 this.havocbot_role = havocbot_role_ast_offense;
522 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
523 this.havocbot_role_timeout = 0;
528 void havocbot_ast_reset_role(entity this)
533 if(this.team == assault_attacker_team)
534 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_OFFENSE);
536 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_DEFENSE);
540 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
542 entity player = M_ARGV(0, entity);
544 if(player.team == assault_attacker_team)
545 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
547 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
550 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
552 entity turret = M_ARGV(0, entity);
554 if(!turret.team || turret.team == FLOAT_MAX)
555 turret.team = 5; // this gets reversed when match starts?
558 MUTATOR_HOOKFUNCTION(as, VehicleInit)
560 entity veh = M_ARGV(0, entity);
562 veh.nextthink = time + 0.5;
565 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
567 entity bot = M_ARGV(0, entity);
569 havocbot_ast_reset_role(bot);
573 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
575 entity frag_victim = M_ARGV(0, entity);
577 return (frag_victim.classname == "func_assault_destructible");
580 MUTATOR_HOOKFUNCTION(as, CheckAllowedTeams)
582 // assault always has 2 teams
587 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
589 M_ARGV(0, float) = WinningCondition_Assault();
593 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
595 // no assault warmups
599 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
601 entity ent = M_ARGV(0, entity);
603 switch(ent.classname)
605 case "info_player_team1":
606 case "info_player_team2":
607 case "info_player_team3":
608 case "info_player_team4":
613 MUTATOR_HOOKFUNCTION(as, ReadyRestart_Deny)
615 // readyrestart not supported (yet)
620 void assault_ScoreRules()
624 teams |= BIT(1); // always red vs blue
626 ScoreRules_basics(teams, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
627 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
628 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
629 ScoreRules_basics_end();