1 #include "gamemode_assault.qh"
4 #define AS_ROUND_DELAY 5
7 void assault_objective_use(entity this, entity actor, entity trigger)
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 if(this.health < 0 || this.health >= ASSAULT_VALUE_INACTIVE)
27 // reset this objective. Used when spawning an objective
28 // and when a new round starts
29 void assault_objective_reset(entity this)
31 this.health = ASSAULT_VALUE_INACTIVE;
34 // decrease the health of targeted objectives
35 void assault_objective_decrease_use(entity this, entity actor, entity trigger)
37 if(actor.team != assault_attacker_team)
39 // wrong team triggered decrease
43 if(trigger.assault_sprite)
45 WaypointSprite_Disown(trigger.assault_sprite, waypointsprite_deadlifetime);
46 if(trigger.classname == "func_assault_destructible")
47 trigger.sprite = NULL; // TODO: just unsetting it?!
50 return; // already activated! cannot activate again!
52 if(this.enemy.health < ASSAULT_VALUE_INACTIVE)
54 if(this.enemy.health - this.dmg > 0.5)
56 PlayerTeamScore_Add(actor, SP_SCORE, ST_SCORE, this.dmg);
57 this.enemy.health = this.enemy.health - this.dmg;
61 PlayerTeamScore_Add(actor, SP_SCORE, ST_SCORE, this.enemy.health);
62 PlayerTeamScore_Add(actor, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
63 this.enemy.health = -1;
65 if(this.enemy.message)
66 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(centerprint(it, this.enemy.message)));
68 SUB_UseTargets(this.enemy, this, trigger);
73 void assault_setenemytoobjective(entity this)
75 IL_EACH(g_assault_objectives, it.targetname == this.target,
77 if(this.enemy == NULL)
80 objerror(this, "more than one objective as target - fix the map!");
84 if(this.enemy == NULL)
85 objerror(this, "no objective as target - fix the map!");
88 bool assault_decreaser_sprite_visible(entity this, entity player, entity view)
90 if(this.assault_decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
96 void target_objective_decrease_activate(entity this)
100 FOREACH_ENTITY_STRING(target, this.targetname,
102 if(it.assault_sprite != NULL)
104 WaypointSprite_Disown(it.assault_sprite, waypointsprite_deadlifetime);
105 if(it.classname == "func_assault_destructible")
106 it.sprite = NULL; // TODO: just unsetting it?!
109 spr = WaypointSprite_SpawnFixed(WP_AssaultDefend, 0.5 * (it.absmin + it.absmax), it, assault_sprite, RADARICON_OBJECTIVE);
110 spr.assault_decreaser = this;
111 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
112 spr.classname = "sprite_waypoint";
113 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
114 if(it.classname == "func_assault_destructible")
116 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
117 WaypointSprite_UpdateMaxHealth(spr, it.max_health);
118 WaypointSprite_UpdateHealth(spr, it.health);
122 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
126 void target_objective_decrease_findtarget(entity this)
128 assault_setenemytoobjective(this);
131 void target_assault_roundend_reset(entity this)
133 //print("round end reset\n");
134 ++this.cnt; // up round counter
135 this.winning = false; // up round
138 void target_assault_roundend_use(entity this, entity actor, entity trigger)
140 this.winning = 1; // round has been won by attackers
143 void assault_roundstart_use(entity this, entity actor, entity trigger)
145 SUB_UseTargets(this, this, trigger);
147 //(Re)spawn all turrets
148 IL_EACH(g_turrets, true,
151 if(it.team == NUM_TEAM_1)
152 it.team = NUM_TEAM_2;
154 it.team = NUM_TEAM_1;
156 // Doubles as teamchange
160 void assault_roundstart_use_this(entity this)
162 assault_roundstart_use(this, NULL, NULL);
165 void assault_wall_think(entity this)
167 if(this.enemy.health < 0)
170 this.solid = SOLID_NOT;
174 this.model = this.mdl;
175 this.solid = SOLID_BSP;
178 this.nextthink = time + 0.2;
182 // reset objectives, toggle spawnpoints, reset triggers, ...
183 void assault_new_round(entity this)
185 //bprint("ASSAULT: new round\n");
188 this.winning = this.winning + 1;
190 // swap attacker/defender roles
191 if(assault_attacker_team == NUM_TEAM_1)
192 assault_attacker_team = NUM_TEAM_2;
194 assault_attacker_team = NUM_TEAM_1;
196 FOREACH_ENTITY_FLOAT(pure_data, false,
201 if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
202 else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
205 // reset the level with a countdown
206 cvar_set("timelimit", ftos(ceil(time - AS_ROUND_DELAY - game_starttime) / 60));
207 ReadyRestart_force(); // sets game_starttime
212 void as_round_think()
215 assault_new_round(as_round.ent_winning);
220 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
221 // they win. Otherwise the defending team wins once the timelimit passes.
222 int WinningCondition_Assault()
227 WinningConditionHelper(NULL); // set worldstatus
229 int status = WINNING_NO;
230 // as the timelimit has not yet passed just assume the defending team will win
231 if(assault_attacker_team == NUM_TEAM_1)
233 SetWinners(team, NUM_TEAM_2);
237 SetWinners(team, NUM_TEAM_1);
241 ent = find(NULL, classname, "target_assault_roundend");
244 if(ent.winning) // round end has been triggered by attacking team
246 bprint("Assault: round completed.\n");
247 SetWinners(team, assault_attacker_team);
249 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
251 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
253 status = WINNING_YES;
257 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ASSAULT_OBJ_DESTROYED, ceil(time - game_starttime));
258 as_round = new(as_round);
259 as_round.think = as_round_think;
260 as_round.ent_winning = ent;
261 as_round.nextthink = time + AS_ROUND_DELAY;
264 // make sure timelimit isn't hit while the game is blocked
265 if(autocvar_timelimit > 0)
266 if(time + AS_ROUND_DELAY >= game_starttime + autocvar_timelimit * 60)
267 cvar_set("timelimit", ftos(autocvar_timelimit + AS_ROUND_DELAY / 60));
276 spawnfunc(info_player_attacker)
278 if (!g_assault) { delete(this); return; }
280 this.team = NUM_TEAM_1; // red, gets swapped every round
281 spawnfunc_info_player_deathmatch(this);
284 spawnfunc(info_player_defender)
286 if (!g_assault) { delete(this); return; }
288 this.team = NUM_TEAM_2; // blue, gets swapped every round
289 spawnfunc_info_player_deathmatch(this);
292 spawnfunc(target_objective)
294 if (!g_assault) { delete(this); return; }
296 this.classname = "target_objective";
297 IL_PUSH(g_assault_objectives, this);
298 this.use = assault_objective_use;
299 this.reset = assault_objective_reset;
301 this.spawn_evalfunc = target_objective_spawn_evalfunc;
304 spawnfunc(target_objective_decrease)
306 if (!g_assault) { delete(this); return; }
308 this.classname = "target_objective_decrease";
309 IL_PUSH(g_assault_objectivedecreasers, this);
314 this.use = assault_objective_decrease_use;
315 this.health = ASSAULT_VALUE_INACTIVE;
316 this.max_health = ASSAULT_VALUE_INACTIVE;
319 InitializeEntity(this, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
322 // destructible walls that can be used to trigger target_objective_decrease
323 spawnfunc(func_breakable);
324 spawnfunc(func_assault_destructible)
326 if (!g_assault) { delete(this); return; }
329 this.classname = "func_assault_destructible";
330 IL_PUSH(g_assault_destructibles, this);
332 if(assault_attacker_team == NUM_TEAM_1)
333 this.team = NUM_TEAM_2;
335 this.team = NUM_TEAM_1;
337 spawnfunc_func_breakable(this);
340 spawnfunc(func_assault_wall)
342 if (!g_assault) { delete(this); return; }
344 this.classname = "func_assault_wall";
345 this.mdl = this.model;
346 _setmodel(this, this.mdl);
347 this.solid = SOLID_BSP;
348 setthink(this, assault_wall_think);
349 this.nextthink = time;
350 InitializeEntity(this, assault_setenemytoobjective, INITPRIO_FINDTARGET);
353 spawnfunc(target_assault_roundend)
355 if (!g_assault) { delete(this); return; }
357 this.winning = 0; // round not yet won by attackers
358 this.classname = "target_assault_roundend";
359 this.use = target_assault_roundend_use;
360 this.cnt = 0; // first round
361 this.reset = target_assault_roundend_reset;
364 spawnfunc(target_assault_roundstart)
366 if (!g_assault) { delete(this); return; }
368 assault_attacker_team = NUM_TEAM_1;
369 this.classname = "target_assault_roundstart";
370 this.use = assault_roundstart_use;
371 this.reset2 = assault_roundstart_use_this;
372 InitializeEntity(this, assault_roundstart_use_this, INITPRIO_FINDTARGET);
376 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
378 IL_EACH(g_assault_destructibles, it.bot_attack,
385 IL_EACH(g_assault_objectivedecreasers, it.targetname == destr.target,
387 if(it.enemy.health > 0 && it.enemy.health < ASSAULT_VALUE_INACTIVE)
397 vector p = 0.5 * (it.absmin + it.absmax);
399 // Find and rate waypoints around it
402 float bestvalue = 99999999999;
404 for(float radius = 0; radius < 1500 && !found; radius += 500)
406 FOREACH_ENTITY_RADIUS(p, radius, it.classname == "waypoint" && !(it.wpflags & WAYPOINTFLAG_GENERATED),
408 if(checkpvs(it.origin, des))
411 if(it.cnt < bestvalue)
422 /// dprint("waypoints around target were found\n");
423 // te_lightning2(NULL, '0 0 0', best.origin);
424 // te_knightspike(best.origin);
426 navigation_routerating(this, best, ratingscale, 4000);
429 this.havocbot_attack_time = 0;
431 if(checkpvs(this.view_ofs,it))
432 if(checkpvs(this.view_ofs,best))
434 // dprint("increasing attack time for this target\n");
435 this.havocbot_attack_time = time + 2;
441 void havocbot_role_ast_offense(entity this)
445 this.havocbot_attack_time = 0;
446 havocbot_ast_reset_role(this);
450 // Set the role timeout if necessary
451 if (!this.havocbot_role_timeout)
452 this.havocbot_role_timeout = time + 120;
454 if (time > this.havocbot_role_timeout)
456 havocbot_ast_reset_role(this);
460 if(this.havocbot_attack_time>time)
463 if (this.bot_strategytime < time)
465 navigation_goalrating_start(this);
466 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
467 havocbot_goalrating_ast_targets(this, 20000);
468 havocbot_goalrating_items(this, 15000, this.origin, 10000);
469 navigation_goalrating_end(this);
471 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
475 void havocbot_role_ast_defense(entity this)
479 this.havocbot_attack_time = 0;
480 havocbot_ast_reset_role(this);
484 // Set the role timeout if necessary
485 if (!this.havocbot_role_timeout)
486 this.havocbot_role_timeout = time + 120;
488 if (time > this.havocbot_role_timeout)
490 havocbot_ast_reset_role(this);
494 if(this.havocbot_attack_time>time)
497 if (this.bot_strategytime < time)
499 navigation_goalrating_start(this);
500 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 3000);
501 havocbot_goalrating_ast_targets(this, 20000);
502 havocbot_goalrating_items(this, 15000, this.origin, 10000);
503 navigation_goalrating_end(this);
505 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
509 void havocbot_role_ast_setrole(entity this, float role)
513 case HAVOCBOT_AST_ROLE_DEFENSE:
514 this.havocbot_role = havocbot_role_ast_defense;
515 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
516 this.havocbot_role_timeout = 0;
518 case HAVOCBOT_AST_ROLE_OFFENSE:
519 this.havocbot_role = havocbot_role_ast_offense;
520 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
521 this.havocbot_role_timeout = 0;
526 void havocbot_ast_reset_role(entity this)
531 if(this.team == assault_attacker_team)
532 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_OFFENSE);
534 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_DEFENSE);
538 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
540 entity player = M_ARGV(0, entity);
542 if(player.team == assault_attacker_team)
543 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
545 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
548 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
550 entity turret = M_ARGV(0, entity);
552 if(!turret.team || turret.team == MAX_SHOT_DISTANCE)
553 turret.team = 5; // this gets reversed when match starts?
556 MUTATOR_HOOKFUNCTION(as, VehicleInit)
558 entity veh = M_ARGV(0, entity);
560 veh.nextthink = time + 0.5;
563 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
565 entity bot = M_ARGV(0, entity);
567 havocbot_ast_reset_role(bot);
571 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
573 entity frag_victim = M_ARGV(0, entity);
575 return (frag_victim.classname == "func_assault_destructible");
578 MUTATOR_HOOKFUNCTION(as, CheckAllowedTeams)
580 // assault always has 2 teams
585 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
587 M_ARGV(0, float) = WinningCondition_Assault();
591 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
593 // no assault warmups
597 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
599 entity ent = M_ARGV(0, entity);
601 switch(ent.classname)
603 case "info_player_team1":
604 case "info_player_team2":
605 case "info_player_team3":
606 case "info_player_team4":
611 MUTATOR_HOOKFUNCTION(as, ReadyRestart_Deny)
613 // readyrestart not supported (yet)
618 void assault_ScoreRules()
622 teams |= BIT(1); // always red vs blue
624 ScoreRules_basics(teams, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
625 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
626 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
627 ScoreRules_basics_end();