1 #include "sv_assault.qh"
4 #define AS_ROUND_DELAY 5
7 void assault_objective_use(entity this, entity actor, entity trigger)
10 SetResourceExplicit(this, RES_HEALTH, 100);
11 //print("^2Activated objective ", this.targetname, "=", etos(this), "\n");
12 //print("Activator is ", actor.classname, "\n");
14 IL_EACH(g_assault_objectivedecreasers, it.target == this.targetname,
16 target_objective_decrease_activate(it);
20 vector target_objective_spawn_evalfunc(entity this, entity player, entity spot, vector current)
22 float hlth = GetResource(this, RES_HEALTH);
23 if (hlth < 0 || hlth >= ASSAULT_VALUE_INACTIVE)
28 // reset this objective. Used when spawning an objective
29 // and when a new round starts
30 void assault_objective_reset(entity this)
32 SetResourceExplicit(this, RES_HEALTH, ASSAULT_VALUE_INACTIVE);
35 // decrease the health of targeted objectives
36 void assault_objective_decrease_use(entity this, entity actor, entity trigger)
38 if(actor.team != assault_attacker_team)
40 // wrong team triggered decrease
44 if(trigger.assault_sprite)
46 WaypointSprite_Disown(trigger.assault_sprite, waypointsprite_deadlifetime);
47 if(trigger.classname == "func_assault_destructible")
48 trigger.sprite = NULL; // TODO: just unsetting it?!
51 return; // already activated! cannot activate again!
53 float hlth = GetResource(this.enemy, RES_HEALTH);
54 if (hlth < ASSAULT_VALUE_INACTIVE)
56 if (hlth - this.dmg > 0.5)
58 GameRules_scoring_add_team(actor, SCORE, this.dmg);
59 TakeResource(this.enemy, RES_HEALTH, this.dmg);
63 GameRules_scoring_add_team(actor, SCORE, hlth);
64 GameRules_scoring_add_team(actor, ASSAULT_OBJECTIVES, 1);
65 SetResourceExplicit(this.enemy, RES_HEALTH, -1);
67 if(this.enemy.message)
68 FOREACH_CLIENT(IS_PLAYER(it), { 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(GetResource(this.assault_decreaser.enemy, RES_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, GetResource(it, RES_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(GetResource(this.enemy, RES_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 IL_EACH(g_saved_team, !IS_CLIENT(it),
200 if(it.team_saved == NUM_TEAM_1)
201 it.team_saved = NUM_TEAM_2;
202 else if(it.team_saved == NUM_TEAM_2)
203 it.team_saved = NUM_TEAM_1;
206 // reset the level with a countdown
207 cvar_set("timelimit", ftos(ceil(time - AS_ROUND_DELAY - game_starttime) / 60));
208 ReadyRestart_force(); // sets game_starttime
213 void as_round_think()
215 game_stopped = false;
216 assault_new_round(as_round.ent_winning);
221 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
222 // they win. Otherwise the defending team wins once the timelimit passes.
223 int WinningCondition_Assault()
228 WinningConditionHelper(NULL); // set worldstatus
230 int status = WINNING_NO;
231 // as the timelimit has not yet passed just assume the defending team will win
232 if(assault_attacker_team == NUM_TEAM_1)
234 SetWinners(team, NUM_TEAM_2);
238 SetWinners(team, NUM_TEAM_1);
242 ent = find(NULL, classname, "target_assault_roundend");
245 if(ent.winning) // round end has been triggered by attacking team
247 bprint("Assault: round completed.\n");
248 SetWinners(team, assault_attacker_team);
250 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
252 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
254 status = WINNING_YES;
258 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ASSAULT_OBJ_DESTROYED, ceil(time - game_starttime));
259 as_round = new(as_round);
260 as_round.think = as_round_think;
261 as_round.ent_winning = ent;
262 as_round.nextthink = time + AS_ROUND_DELAY;
265 // make sure timelimit isn't hit while the game is blocked
266 if(autocvar_timelimit > 0)
267 if(time + AS_ROUND_DELAY >= game_starttime + autocvar_timelimit * 60)
268 cvar_set("timelimit", ftos(autocvar_timelimit + AS_ROUND_DELAY / 60));
277 spawnfunc(info_player_attacker)
279 if (!g_assault) { delete(this); return; }
281 this.team = NUM_TEAM_1; // red, gets swapped every round
282 spawnfunc_info_player_deathmatch(this);
285 spawnfunc(info_player_defender)
287 if (!g_assault) { delete(this); return; }
289 this.team = NUM_TEAM_2; // blue, gets swapped every round
290 spawnfunc_info_player_deathmatch(this);
293 spawnfunc(target_objective)
295 if (!g_assault) { delete(this); return; }
297 this.classname = "target_objective";
298 IL_PUSH(g_assault_objectives, this);
299 this.use = assault_objective_use;
300 this.reset = assault_objective_reset;
302 this.spawn_evalfunc = target_objective_spawn_evalfunc;
305 spawnfunc(target_objective_decrease)
307 if (!g_assault) { delete(this); return; }
309 this.classname = "target_objective_decrease";
310 IL_PUSH(g_assault_objectivedecreasers, this);
315 this.use = assault_objective_decrease_use;
316 SetResourceExplicit(this, RES_HEALTH, ASSAULT_VALUE_INACTIVE);
317 this.max_health = ASSAULT_VALUE_INACTIVE;
320 InitializeEntity(this, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
323 // destructible walls that can be used to trigger target_objective_decrease
324 bool destructible_heal(entity targ, entity inflictor, float amount, float limit)
326 float true_limit = ((limit != RES_LIMIT_NONE) ? limit : targ.max_health);
327 float hlth = GetResource(targ, RES_HEALTH);
328 if (hlth <= 0 || hlth >= true_limit)
331 GiveResourceWithLimit(targ, RES_HEALTH, amount, true_limit);
334 WaypointSprite_UpdateHealth(targ.sprite, GetResource(targ, RES_HEALTH));
336 func_breakable_colormod(targ);
340 spawnfunc(func_breakable);
341 spawnfunc(func_assault_destructible)
343 if (!g_assault) { delete(this); return; }
346 this.classname = "func_assault_destructible";
347 this.event_heal = destructible_heal;
348 IL_PUSH(g_assault_destructibles, this);
350 if(assault_attacker_team == NUM_TEAM_1)
351 this.team = NUM_TEAM_2;
353 this.team = NUM_TEAM_1;
355 spawnfunc_func_breakable(this);
358 spawnfunc(func_assault_wall)
360 if (!g_assault) { delete(this); return; }
362 this.classname = "func_assault_wall";
363 this.mdl = this.model;
364 _setmodel(this, this.mdl);
365 this.solid = SOLID_BSP;
366 setthink(this, assault_wall_think);
367 this.nextthink = time;
368 InitializeEntity(this, assault_setenemytoobjective, INITPRIO_FINDTARGET);
371 spawnfunc(target_assault_roundend)
373 if (!g_assault) { delete(this); return; }
375 this.winning = 0; // round not yet won by attackers
376 this.classname = "target_assault_roundend";
377 this.use = target_assault_roundend_use;
378 this.cnt = 0; // first round
379 this.reset = target_assault_roundend_reset;
382 spawnfunc(target_assault_roundstart)
384 if (!g_assault) { delete(this); return; }
386 assault_attacker_team = NUM_TEAM_1;
387 this.classname = "target_assault_roundstart";
388 this.use = assault_roundstart_use;
389 this.reset2 = assault_roundstart_use_this;
390 InitializeEntity(this, assault_roundstart_use_this, INITPRIO_FINDTARGET);
394 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
396 IL_EACH(g_assault_destructibles, it.bot_attack,
403 IL_EACH(g_assault_objectivedecreasers, it.targetname == destr.target,
405 float hlth = GetResource(it.enemy, RES_HEALTH);
406 if (hlth > 0 && hlth < ASSAULT_VALUE_INACTIVE)
416 vector p = 0.5 * (it.absmin + it.absmax);
418 // Find and rate waypoints around it
421 float bestvalue = FLOAT_MAX;
423 for (float radius = 500; radius <= 1500 && !found; radius += 500)
425 FOREACH_ENTITY_RADIUS(p, radius, it.classname == "waypoint" && !(it.wpflags & WAYPOINTFLAG_GENERATED),
427 if(checkpvs(it.origin, des))
430 if(it.cnt < bestvalue)
441 /// dprint("waypoints around target were found\n");
442 // te_lightning2(NULL, '0 0 0', best.origin);
443 // te_knightspike(best.origin);
445 navigation_routerating(this, best, ratingscale, 4000);
448 this.havocbot_attack_time = 0;
450 if(checkpvs(this.origin + this.view_ofs, it))
451 if(checkpvs(this.origin + this.view_ofs, best))
453 // dprint("increasing attack time for this target\n");
454 this.havocbot_attack_time = time + 2;
460 void havocbot_role_ast_offense(entity this)
464 this.havocbot_attack_time = 0;
465 havocbot_ast_reset_role(this);
469 // Set the role timeout if necessary
470 if (!this.havocbot_role_timeout)
471 this.havocbot_role_timeout = time + 120;
473 if (time > this.havocbot_role_timeout)
475 havocbot_ast_reset_role(this);
479 if(this.havocbot_attack_time>time)
482 if (navigation_goalrating_timeout(this))
485 navigation_goalrating_start(this);
486 havocbot_goalrating_enemyplayers(this, 10000, this.origin, 650);
487 havocbot_goalrating_ast_targets(this, 20000);
488 havocbot_goalrating_items(this, 30000, this.origin, 10000);
489 navigation_goalrating_end(this);
491 navigation_goalrating_timeout_set(this);
495 void havocbot_role_ast_defense(entity this)
499 this.havocbot_attack_time = 0;
500 havocbot_ast_reset_role(this);
504 // Set the role timeout if necessary
505 if (!this.havocbot_role_timeout)
506 this.havocbot_role_timeout = time + 120;
508 if (time > this.havocbot_role_timeout)
510 havocbot_ast_reset_role(this);
514 if(this.havocbot_attack_time>time)
517 if (navigation_goalrating_timeout(this))
520 navigation_goalrating_start(this);
521 havocbot_goalrating_enemyplayers(this, 10000, this.origin, 3000);
522 havocbot_goalrating_ast_targets(this, 20000);
523 havocbot_goalrating_items(this, 30000, this.origin, 10000);
524 navigation_goalrating_end(this);
526 navigation_goalrating_timeout_set(this);
530 void havocbot_role_ast_setrole(entity this, float role)
534 case HAVOCBOT_AST_ROLE_DEFENSE:
535 this.havocbot_role = havocbot_role_ast_defense;
536 this.havocbot_role_timeout = 0;
538 case HAVOCBOT_AST_ROLE_OFFENSE:
539 this.havocbot_role = havocbot_role_ast_offense;
540 this.havocbot_role_timeout = 0;
545 void havocbot_ast_reset_role(entity this)
550 if(this.team == assault_attacker_team)
551 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_OFFENSE);
553 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_DEFENSE);
557 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
559 entity player = M_ARGV(0, entity);
561 if(player.team == assault_attacker_team)
562 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
564 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
567 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
569 entity turret = M_ARGV(0, entity);
571 if(!turret.team || turret.team == FLOAT_MAX)
572 turret.team = assault_attacker_team; // this gets reversed when match starts (assault_roundstart_use)
575 MUTATOR_HOOKFUNCTION(as, VehicleInit)
577 entity veh = M_ARGV(0, entity);
579 veh.nextthink = time + 0.5;
582 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
584 entity bot = M_ARGV(0, entity);
586 havocbot_ast_reset_role(bot);
590 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
592 entity frag_victim = M_ARGV(0, entity);
594 return (frag_victim.classname == "func_assault_destructible");
597 MUTATOR_HOOKFUNCTION(as, TeamBalance_CheckAllowedTeams)
599 // assault always has 2 teams
600 M_ARGV(0, float) = BIT(0) | BIT(1);
604 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
606 M_ARGV(0, float) = WinningCondition_Assault();
610 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
614 sv_ready_restart_after_countdown = 0;
617 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
619 entity ent = M_ARGV(0, entity);
621 switch(ent.classname)
623 case "info_player_team1":
624 case "info_player_team2":
625 case "info_player_team3":
626 case "info_player_team4":
631 MUTATOR_HOOKFUNCTION(as, ReadyRestart_Deny)
633 // readyrestart not supported (yet)