1 #include "gamemode_assault.qh"
6 void assault_objective_use(entity this, entity actor, entity trigger)
10 //print("^2Activated objective ", this.targetname, "=", etos(this), "\n");
11 //print("Activator is ", actor.classname, "\n");
13 IL_EACH(g_assault_objectivedecreasers, it.target == this.targetname,
15 target_objective_decrease_activate(it);
19 vector target_objective_spawn_evalfunc(entity this, entity player, entity spot, vector current)
21 if(this.health < 0 || this.health >= ASSAULT_VALUE_INACTIVE)
26 // reset this objective. Used when spawning an objective
27 // and when a new round starts
28 void assault_objective_reset(entity this)
30 this.health = ASSAULT_VALUE_INACTIVE;
33 // decrease the health of targeted objectives
34 void assault_objective_decrease_use(entity this, entity actor, entity trigger)
36 if(actor.team != assault_attacker_team)
38 // wrong team triggered decrease
42 if(trigger.assault_sprite)
44 WaypointSprite_Disown(trigger.assault_sprite, waypointsprite_deadlifetime);
45 if(trigger.classname == "func_assault_destructible")
46 trigger.sprite = NULL; // TODO: just unsetting it?!
49 return; // already activated! cannot activate again!
51 if(this.enemy.health < ASSAULT_VALUE_INACTIVE)
53 if(this.enemy.health - this.dmg > 0.5)
55 PlayerTeamScore_Add(actor, SP_SCORE, ST_SCORE, this.dmg);
56 this.enemy.health = this.enemy.health - this.dmg;
60 PlayerTeamScore_Add(actor, SP_SCORE, ST_SCORE, this.enemy.health);
61 PlayerTeamScore_Add(actor, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
62 this.enemy.health = -1;
64 if(this.enemy.message)
65 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(centerprint(it, this.enemy.message)));
67 SUB_UseTargets(this.enemy, this, trigger);
72 void assault_setenemytoobjective(entity this)
74 IL_EACH(g_assault_objectives, it.targetname == this.target,
76 if(this.enemy == NULL)
79 objerror(this, "more than one objective as target - fix the map!");
83 if(this.enemy == NULL)
84 objerror(this, "no objective as target - fix the map!");
87 bool assault_decreaser_sprite_visible(entity this, entity player, entity view)
89 if(this.assault_decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
95 void target_objective_decrease_activate(entity this)
99 FOREACH_ENTITY_STRING(target, this.targetname,
101 if(it.assault_sprite != NULL)
103 WaypointSprite_Disown(it.assault_sprite, waypointsprite_deadlifetime);
104 if(it.classname == "func_assault_destructible")
105 it.sprite = NULL; // TODO: just unsetting it?!
108 spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (it.absmin + it.absmax), it, assault_sprite, RADARICON_OBJECTIVE);
109 spr.assault_decreaser = this;
110 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
111 spr.classname = "sprite_waypoint";
112 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
113 if(it.classname == "func_assault_destructible")
115 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
116 WaypointSprite_UpdateMaxHealth(spr, it.max_health);
117 WaypointSprite_UpdateHealth(spr, it.health);
121 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
125 void target_objective_decrease_findtarget(entity this)
127 assault_setenemytoobjective(this);
130 void target_assault_roundend_reset(entity this)
132 //print("round end reset\n");
133 ++this.cnt; // up round counter
134 this.winning = false; // up round
137 void target_assault_roundend_use(entity this, entity actor, entity trigger)
139 this.winning = 1; // round has been won by attackers
142 void assault_roundstart_use(entity this, entity actor, entity trigger)
144 SUB_UseTargets(this, this, trigger);
146 //(Re)spawn all turrets
147 IL_EACH(g_turrets, true,
150 if(it.team == NUM_TEAM_1)
151 it.team = NUM_TEAM_2;
153 it.team = NUM_TEAM_1;
155 // Doubles as teamchange
159 void assault_roundstart_use_this(entity this)
161 assault_roundstart_use(this, NULL, NULL);
164 void assault_wall_think(entity this)
166 if(this.enemy.health < 0)
169 this.solid = SOLID_NOT;
173 this.model = this.mdl;
174 this.solid = SOLID_BSP;
177 this.nextthink = time + 0.2;
181 // reset objectives, toggle spawnpoints, reset triggers, ...
182 void vehicles_clearreturn(entity veh);
183 void vehicles_spawn(entity this);
184 void assault_new_round(entity this)
186 //bprint("ASSAULT: new round\n");
188 // Eject players from vehicles
189 FOREACH_CLIENT(IS_PLAYER(it) && it.vehicle, vehicles_exit(it.vehicle, VHEF_RELEASE));
191 IL_EACH(g_vehicles, true,
193 vehicles_clearreturn(it);
198 this.winning = this.winning + 1;
200 // swap attacker/defender roles
201 if(assault_attacker_team == NUM_TEAM_1)
202 assault_attacker_team = NUM_TEAM_2;
204 assault_attacker_team = NUM_TEAM_1;
206 FOREACH_ENTITY_FLOAT(pure_data, false,
211 if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
212 else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
215 // reset the level with a countdown
216 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
217 ReadyRestart_force(); // sets game_starttime
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()
224 WinningConditionHelper(NULL); // set worldstatus
226 int status = WINNING_NO;
227 // as the timelimit has not yet passed just assume the defending team will win
228 if(assault_attacker_team == NUM_TEAM_1)
230 SetWinners(team, NUM_TEAM_2);
234 SetWinners(team, NUM_TEAM_1);
238 ent = find(NULL, classname, "target_assault_roundend");
241 if(ent.winning) // round end has been triggered by attacking team
243 bprint("ASSAULT: round completed...\n");
244 SetWinners(team, assault_attacker_team);
246 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
248 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
250 status = WINNING_YES;
254 assault_new_round(ent);
263 spawnfunc(info_player_attacker)
265 if (!g_assault) { delete(this); return; }
267 this.team = NUM_TEAM_1; // red, gets swapped every round
268 spawnfunc_info_player_deathmatch(this);
271 spawnfunc(info_player_defender)
273 if (!g_assault) { delete(this); return; }
275 this.team = NUM_TEAM_2; // blue, gets swapped every round
276 spawnfunc_info_player_deathmatch(this);
279 spawnfunc(target_objective)
281 if (!g_assault) { delete(this); return; }
283 this.classname = "target_objective";
284 IL_PUSH(g_assault_objectives, this);
285 this.use = assault_objective_use;
286 this.reset = assault_objective_reset;
288 this.spawn_evalfunc = target_objective_spawn_evalfunc;
291 spawnfunc(target_objective_decrease)
293 if (!g_assault) { delete(this); return; }
295 this.classname = "target_objective_decrease";
296 IL_PUSH(g_assault_objectivedecreasers, this);
301 this.use = assault_objective_decrease_use;
302 this.health = ASSAULT_VALUE_INACTIVE;
303 this.max_health = ASSAULT_VALUE_INACTIVE;
306 InitializeEntity(this, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
309 // destructible walls that can be used to trigger target_objective_decrease
310 spawnfunc(func_breakable);
311 spawnfunc(func_assault_destructible)
313 if (!g_assault) { delete(this); return; }
316 this.classname = "func_assault_destructible";
317 IL_PUSH(g_assault_destructibles, this);
319 if(assault_attacker_team == NUM_TEAM_1)
320 this.team = NUM_TEAM_2;
322 this.team = NUM_TEAM_1;
324 spawnfunc_func_breakable(this);
327 spawnfunc(func_assault_wall)
329 if (!g_assault) { delete(this); return; }
331 this.classname = "func_assault_wall";
332 this.mdl = this.model;
333 _setmodel(this, this.mdl);
334 this.solid = SOLID_BSP;
335 setthink(this, assault_wall_think);
336 this.nextthink = time;
337 InitializeEntity(this, assault_setenemytoobjective, INITPRIO_FINDTARGET);
340 spawnfunc(target_assault_roundend)
342 if (!g_assault) { delete(this); return; }
344 this.winning = 0; // round not yet won by attackers
345 this.classname = "target_assault_roundend";
346 this.use = target_assault_roundend_use;
347 this.cnt = 0; // first round
348 this.reset = target_assault_roundend_reset;
351 spawnfunc(target_assault_roundstart)
353 if (!g_assault) { delete(this); return; }
355 assault_attacker_team = NUM_TEAM_1;
356 this.classname = "target_assault_roundstart";
357 this.use = assault_roundstart_use;
358 this.reset2 = assault_roundstart_use_this;
359 InitializeEntity(this, assault_roundstart_use_this, INITPRIO_FINDTARGET);
363 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
365 IL_EACH(g_assault_destructibles, it.bot_attack,
372 IL_EACH(g_assault_objectivedecreasers, it.targetname == destr.target,
374 if(it.enemy.health > 0 && it.enemy.health < ASSAULT_VALUE_INACTIVE)
384 vector p = 0.5 * (it.absmin + it.absmax);
386 // Find and rate waypoints around it
389 float bestvalue = 99999999999;
391 for(float radius = 0; radius < 1500 && !found; radius += 500)
393 FOREACH_ENTITY_RADIUS(p, radius, it.classname == "waypoint" && !(it.wpflags & WAYPOINTFLAG_GENERATED),
395 if(checkpvs(it.origin, des))
398 if(it.cnt < bestvalue)
409 /// dprint("waypoints around target were found\n");
410 // te_lightning2(NULL, '0 0 0', best.origin);
411 // te_knightspike(best.origin);
413 navigation_routerating(this, best, ratingscale, 4000);
416 this.havocbot_attack_time = 0;
418 if(checkpvs(this.view_ofs,it))
419 if(checkpvs(this.view_ofs,best))
421 // dprint("increasing attack time for this target\n");
422 this.havocbot_attack_time = time + 2;
428 void havocbot_role_ast_offense(entity this)
432 this.havocbot_attack_time = 0;
433 havocbot_ast_reset_role(this);
437 // Set the role timeout if necessary
438 if (!this.havocbot_role_timeout)
439 this.havocbot_role_timeout = time + 120;
441 if (time > this.havocbot_role_timeout)
443 havocbot_ast_reset_role(this);
447 if(this.havocbot_attack_time>time)
450 if (this.bot_strategytime < time)
452 navigation_goalrating_start(this);
453 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
454 havocbot_goalrating_ast_targets(this, 20000);
455 havocbot_goalrating_items(this, 15000, this.origin, 10000);
456 navigation_goalrating_end(this);
458 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
462 void havocbot_role_ast_defense(entity this)
466 this.havocbot_attack_time = 0;
467 havocbot_ast_reset_role(this);
471 // Set the role timeout if necessary
472 if (!this.havocbot_role_timeout)
473 this.havocbot_role_timeout = time + 120;
475 if (time > this.havocbot_role_timeout)
477 havocbot_ast_reset_role(this);
481 if(this.havocbot_attack_time>time)
484 if (this.bot_strategytime < time)
486 navigation_goalrating_start(this);
487 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 3000);
488 havocbot_goalrating_ast_targets(this, 20000);
489 havocbot_goalrating_items(this, 15000, this.origin, 10000);
490 navigation_goalrating_end(this);
492 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
496 void havocbot_role_ast_setrole(entity this, float role)
500 case HAVOCBOT_AST_ROLE_DEFENSE:
501 this.havocbot_role = havocbot_role_ast_defense;
502 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
503 this.havocbot_role_timeout = 0;
505 case HAVOCBOT_AST_ROLE_OFFENSE:
506 this.havocbot_role = havocbot_role_ast_offense;
507 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
508 this.havocbot_role_timeout = 0;
513 void havocbot_ast_reset_role(entity this)
518 if(this.team == assault_attacker_team)
519 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_OFFENSE);
521 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_DEFENSE);
525 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
527 entity player = M_ARGV(0, entity);
529 if(player.team == assault_attacker_team)
530 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
532 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
535 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
537 entity turret = M_ARGV(0, entity);
539 if(!turret.team || turret.team == MAX_SHOT_DISTANCE)
540 turret.team = 5; // this gets reversed when match starts?
543 MUTATOR_HOOKFUNCTION(as, VehicleSpawn)
545 entity veh = M_ARGV(0, entity);
547 veh.nextthink = time + 0.5;
550 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
552 entity bot = M_ARGV(0, entity);
554 havocbot_ast_reset_role(bot);
558 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
560 entity frag_victim = M_ARGV(0, entity);
562 return (frag_victim.classname == "func_assault_destructible");
565 MUTATOR_HOOKFUNCTION(as, GetTeamCount)
567 // assault always has 2 teams
572 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
574 M_ARGV(0, float) = WinningCondition_Assault();
578 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
580 // no assault warmups
584 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
586 entity ent = M_ARGV(0, entity);
588 switch(ent.classname)
590 case "info_player_team1":
591 case "info_player_team2":
592 case "info_player_team3":
593 case "info_player_team4":
599 void assault_ScoreRules()
603 teams |= BIT(1); // always red vs blue
605 ScoreRules_basics(teams, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
606 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
607 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
608 ScoreRules_basics_end();