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 for (entity e = NULL; (e = find(e, target, this.targetname)); )
15 if (e.classname == "target_objective_decrease")
17 target_objective_decrease_activate(e);
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 FOREACH_ENTITY_STRING(targetname, this.target,
79 if(it.classname == "target_objective")
81 if(this.enemy == NULL)
84 objerror(this, "more than one objective as target - fix the map!");
89 if(this.enemy == NULL)
90 objerror(this, "no objective as target - fix the map!");
93 bool assault_decreaser_sprite_visible(entity this, entity player, entity view)
95 if(this.assault_decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
101 void target_objective_decrease_activate(entity this)
105 FOREACH_ENTITY_STRING(target, this.targetname,
107 if(it.assault_sprite != NULL)
109 WaypointSprite_Disown(it.assault_sprite, waypointsprite_deadlifetime);
110 if(it.classname == "func_assault_destructible")
111 it.sprite = NULL; // TODO: just unsetting it?!
114 spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (it.absmin + it.absmax), it, assault_sprite, RADARICON_OBJECTIVE);
115 spr.assault_decreaser = this;
116 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
117 spr.classname = "sprite_waypoint";
118 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
119 if(it.classname == "func_assault_destructible")
121 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
122 WaypointSprite_UpdateMaxHealth(spr, it.max_health);
123 WaypointSprite_UpdateHealth(spr, it.health);
127 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
131 void target_objective_decrease_findtarget(entity this)
133 assault_setenemytoobjective(this);
136 void target_assault_roundend_reset(entity this)
138 //print("round end reset\n");
139 ++this.cnt; // up round counter
140 this.winning = false; // up round
143 void target_assault_roundend_use(entity this, entity actor, entity trigger)
145 this.winning = 1; // round has been won by attackers
148 void assault_roundstart_use(entity this, entity actor, entity trigger)
150 SUB_UseTargets(this, this, trigger);
152 //(Re)spawn all turrets
153 FOREACH_ENTITY_CLASS("turret_main", true, LAMBDA(
155 if(it.team == NUM_TEAM_1)
156 it.team = NUM_TEAM_2;
158 it.team = NUM_TEAM_1;
160 // Doubles as teamchange
164 void assault_roundstart_use_this(entity this)
166 assault_roundstart_use(this, NULL, NULL);
169 void assault_wall_think(entity this)
171 if(this.enemy.health < 0)
174 this.solid = SOLID_NOT;
178 this.model = this.mdl;
179 this.solid = SOLID_BSP;
182 this.nextthink = time + 0.2;
186 // reset objectives, toggle spawnpoints, reset triggers, ...
187 void vehicles_clearreturn(entity veh);
188 void vehicles_spawn(entity this);
189 void assault_new_round(entity this)
191 //bprint("ASSAULT: new round\n");
193 // Eject players from vehicles
194 FOREACH_CLIENT(IS_PLAYER(it) && it.vehicle, vehicles_exit(it.vehicle, VHEF_RELEASE));
196 IL_EACH(g_vehicles, true,
198 vehicles_clearreturn(it);
203 this.winning = this.winning + 1;
205 // swap attacker/defender roles
206 if(assault_attacker_team == NUM_TEAM_1)
207 assault_attacker_team = NUM_TEAM_2;
209 assault_attacker_team = NUM_TEAM_1;
211 FOREACH_ENTITY_FLOAT(pure_data, false,
216 if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
217 else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
220 // reset the level with a countdown
221 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
222 ReadyRestart_force(); // sets game_starttime
225 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
226 // they win. Otherwise the defending team wins once the timelimit passes.
227 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 assault_new_round(ent);
268 spawnfunc(info_player_attacker)
270 if (!g_assault) { delete(this); return; }
272 this.team = NUM_TEAM_1; // red, gets swapped every round
273 spawnfunc_info_player_deathmatch(this);
276 spawnfunc(info_player_defender)
278 if (!g_assault) { delete(this); return; }
280 this.team = NUM_TEAM_2; // blue, gets swapped every round
281 spawnfunc_info_player_deathmatch(this);
284 spawnfunc(target_objective)
286 if (!g_assault) { delete(this); return; }
288 this.classname = "target_objective";
289 this.use = assault_objective_use;
290 this.reset = assault_objective_reset;
292 this.spawn_evalfunc = target_objective_spawn_evalfunc;
295 spawnfunc(target_objective_decrease)
297 if (!g_assault) { delete(this); return; }
299 this.classname = "target_objective_decrease";
304 this.use = assault_objective_decrease_use;
305 this.health = ASSAULT_VALUE_INACTIVE;
306 this.max_health = ASSAULT_VALUE_INACTIVE;
309 InitializeEntity(this, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
312 // destructible walls that can be used to trigger target_objective_decrease
313 spawnfunc(func_breakable);
314 spawnfunc(func_assault_destructible)
316 if (!g_assault) { delete(this); return; }
319 this.classname = "func_assault_destructible";
321 if(assault_attacker_team == NUM_TEAM_1)
322 this.team = NUM_TEAM_2;
324 this.team = NUM_TEAM_1;
326 spawnfunc_func_breakable(this);
329 spawnfunc(func_assault_wall)
331 if (!g_assault) { delete(this); return; }
333 this.classname = "func_assault_wall";
334 this.mdl = this.model;
335 _setmodel(this, this.mdl);
336 this.solid = SOLID_BSP;
337 setthink(this, assault_wall_think);
338 this.nextthink = time;
339 InitializeEntity(this, assault_setenemytoobjective, INITPRIO_FINDTARGET);
342 spawnfunc(target_assault_roundend)
344 if (!g_assault) { delete(this); return; }
346 this.winning = 0; // round not yet won by attackers
347 this.classname = "target_assault_roundend";
348 this.use = target_assault_roundend_use;
349 this.cnt = 0; // first round
350 this.reset = target_assault_roundend_reset;
353 spawnfunc(target_assault_roundstart)
355 if (!g_assault) { delete(this); return; }
357 assault_attacker_team = NUM_TEAM_1;
358 this.classname = "target_assault_roundstart";
359 this.use = assault_roundstart_use;
360 this.reset2 = assault_roundstart_use_this;
361 InitializeEntity(this, assault_roundstart_use_this, INITPRIO_FINDTARGET);
365 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
367 FOREACH_ENTITY_CLASS("func_assault_destructible", it.bot_attack,
373 FOREACH_ENTITY_STRING(targetname, it.target,
375 if(it.classname != "target_objective_decrease")
378 if(it.enemy.health > 0 && it.enemy.health < ASSAULT_VALUE_INACTIVE)
388 vector p = 0.5 * (it.absmin + it.absmax);
390 // Find and rate waypoints around it
393 float bestvalue = 99999999999;
395 for(float radius = 0; radius < 1500 && !found; radius += 500)
397 FOREACH_ENTITY_RADIUS(p, radius, it.classname == "waypoint" && !(it.wpflags & WAYPOINTFLAG_GENERATED),
399 if(checkpvs(it.origin, des))
402 if(it.cnt < bestvalue)
413 /// dprint("waypoints around target were found\n");
414 // te_lightning2(NULL, '0 0 0', best.origin);
415 // te_knightspike(best.origin);
417 navigation_routerating(this, best, ratingscale, 4000);
420 this.havocbot_attack_time = 0;
422 if(checkpvs(this.view_ofs,it))
423 if(checkpvs(this.view_ofs,best))
425 // dprint("increasing attack time for this target\n");
426 this.havocbot_attack_time = time + 2;
432 void havocbot_role_ast_offense(entity this)
436 this.havocbot_attack_time = 0;
437 havocbot_ast_reset_role(this);
441 // Set the role timeout if necessary
442 if (!this.havocbot_role_timeout)
443 this.havocbot_role_timeout = time + 120;
445 if (time > this.havocbot_role_timeout)
447 havocbot_ast_reset_role(this);
451 if(this.havocbot_attack_time>time)
454 if (this.bot_strategytime < time)
456 navigation_goalrating_start(this);
457 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
458 havocbot_goalrating_ast_targets(this, 20000);
459 havocbot_goalrating_items(this, 15000, this.origin, 10000);
460 navigation_goalrating_end(this);
462 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
466 void havocbot_role_ast_defense(entity this)
470 this.havocbot_attack_time = 0;
471 havocbot_ast_reset_role(this);
475 // Set the role timeout if necessary
476 if (!this.havocbot_role_timeout)
477 this.havocbot_role_timeout = time + 120;
479 if (time > this.havocbot_role_timeout)
481 havocbot_ast_reset_role(this);
485 if(this.havocbot_attack_time>time)
488 if (this.bot_strategytime < time)
490 navigation_goalrating_start(this);
491 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 3000);
492 havocbot_goalrating_ast_targets(this, 20000);
493 havocbot_goalrating_items(this, 15000, this.origin, 10000);
494 navigation_goalrating_end(this);
496 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
500 void havocbot_role_ast_setrole(entity this, float role)
504 case HAVOCBOT_AST_ROLE_DEFENSE:
505 this.havocbot_role = havocbot_role_ast_defense;
506 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
507 this.havocbot_role_timeout = 0;
509 case HAVOCBOT_AST_ROLE_OFFENSE:
510 this.havocbot_role = havocbot_role_ast_offense;
511 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
512 this.havocbot_role_timeout = 0;
517 void havocbot_ast_reset_role(entity this)
522 if(this.team == assault_attacker_team)
523 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_OFFENSE);
525 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_DEFENSE);
529 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
531 entity player = M_ARGV(0, entity);
533 if(player.team == assault_attacker_team)
534 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
536 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
539 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
541 entity turret = M_ARGV(0, entity);
543 if(!turret.team || turret.team == MAX_SHOT_DISTANCE)
544 turret.team = 5; // this gets reversed when match starts?
547 MUTATOR_HOOKFUNCTION(as, VehicleSpawn)
549 entity veh = M_ARGV(0, entity);
551 veh.nextthink = time + 0.5;
554 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
556 entity bot = M_ARGV(0, entity);
558 havocbot_ast_reset_role(bot);
562 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
564 entity frag_victim = M_ARGV(0, entity);
566 return (frag_victim.classname == "func_assault_destructible");
569 MUTATOR_HOOKFUNCTION(as, GetTeamCount)
571 // assault always has 2 teams
576 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
578 M_ARGV(0, float) = WinningCondition_Assault();
582 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
584 // no assault warmups
588 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
590 entity ent = M_ARGV(0, entity);
592 switch(ent.classname)
594 case "info_player_team1":
595 case "info_player_team2":
596 case "info_player_team3":
597 case "info_player_team4":
603 void assault_ScoreRules()
607 teams |= BIT(1); // always red vs blue
609 ScoreRules_basics(teams, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
610 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
611 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
612 ScoreRules_basics_end();