1 #include "gamemode_assault.qh"
2 #ifndef GAMEMODE_ASSAULT_H
3 #define GAMEMODE_ASSAULT_H
5 void assault_ScoreRules();
6 void ActivateTeamplay();
8 REGISTER_MUTATOR(as, false)
11 have_team_spawns = -1; // request team spawns
15 if (time > 1) // game loads at time 1
16 error("This is a game type and it cannot be added at runtime.");
20 MUTATOR_ONROLLBACK_OR_REMOVE
22 // we actually cannot roll back assault_Initialize here
23 // BUT: we don't need to! If this gets called, adding always
29 LOG_INFO("This is a game type and it cannot be removed at runtime.");
37 .entity assault_decreaser;
38 .entity assault_sprite;
41 const int HAVOCBOT_AST_ROLE_NONE = 0;
42 const int HAVOCBOT_AST_ROLE_DEFENSE = 2;
43 const int HAVOCBOT_AST_ROLE_OFFENSE = 4;
45 .int havocbot_role_flags;
46 .float havocbot_attack_time;
48 .void(entity this) havocbot_role;
49 .void(entity this) havocbot_previous_role;
51 void(entity this) havocbot_role_ast_defense;
52 void(entity this) havocbot_role_ast_offense;
53 .entity havocbot_ast_target;
55 void(entity bot) havocbot_ast_reset_role;
57 void(entity this, float ratingscale, vector org, float sradius) havocbot_goalrating_items;
58 void(entity this, float ratingscale, vector org, float sradius) havocbot_goalrating_enemyplayers;
61 const float ST_ASSAULT_OBJECTIVES = 1;
62 const float SP_ASSAULT_OBJECTIVES = 4;
64 // predefined spawnfuncs
65 void target_objective_decrease_activate(entity this);
72 void assault_objective_use(entity this, entity actor, entity trigger)
76 //print("^2Activated objective ", this.targetname, "=", etos(this), "\n");
77 //print("Activator is ", actor.classname, "\n");
79 for (entity e = NULL; (e = find(e, target, this.targetname)); )
81 if (e.classname == "target_objective_decrease")
83 target_objective_decrease_activate(e);
88 vector target_objective_spawn_evalfunc(entity this, entity player, entity spot, vector current)
90 if(this.health < 0 || this.health >= ASSAULT_VALUE_INACTIVE)
95 // reset this objective. Used when spawning an objective
96 // and when a new round starts
97 void assault_objective_reset(entity this)
99 this.health = ASSAULT_VALUE_INACTIVE;
102 // decrease the health of targeted objectives
103 void assault_objective_decrease_use(entity this, entity actor, entity trigger)
105 if(actor.team != assault_attacker_team)
107 // wrong team triggered decrease
111 if(trigger.assault_sprite)
113 WaypointSprite_Disown(trigger.assault_sprite, waypointsprite_deadlifetime);
114 if(trigger.classname == "func_assault_destructible")
115 trigger.sprite = NULL; // TODO: just unsetting it?!
118 return; // already activated! cannot activate again!
120 if(this.enemy.health < ASSAULT_VALUE_INACTIVE)
122 if(this.enemy.health - this.dmg > 0.5)
124 PlayerTeamScore_Add(actor, SP_SCORE, ST_SCORE, this.dmg);
125 this.enemy.health = this.enemy.health - this.dmg;
129 PlayerTeamScore_Add(actor, SP_SCORE, ST_SCORE, this.enemy.health);
130 PlayerTeamScore_Add(actor, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
131 this.enemy.health = -1;
133 if(this.enemy.message)
134 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(centerprint(it, this.enemy.message)));
136 SUB_UseTargets(this.enemy, this, trigger);
141 void assault_setenemytoobjective(entity this)
144 for(objective = NULL; (objective = find(objective, targetname, this.target)); )
146 if(objective.classname == "target_objective")
148 if(this.enemy == NULL)
149 this.enemy = objective;
151 objerror(this, "more than one objective as target - fix the map!");
156 if(this.enemy == NULL)
157 objerror(this, "no objective as target - fix the map!");
160 bool assault_decreaser_sprite_visible(entity this, entity player, entity view)
162 if(this.assault_decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
168 void target_objective_decrease_activate(entity this)
172 for(ent = NULL; (ent = find(ent, target, this.targetname)); )
174 if(ent.assault_sprite != NULL)
176 WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
177 if(ent.classname == "func_assault_destructible")
178 ent.sprite = NULL; // TODO: just unsetting it?!
181 spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE);
182 spr.assault_decreaser = this;
183 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
184 spr.classname = "sprite_waypoint";
185 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
186 if(ent.classname == "func_assault_destructible")
188 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
189 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
190 WaypointSprite_UpdateHealth(spr, ent.health);
194 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
198 void target_objective_decrease_findtarget(entity this)
200 assault_setenemytoobjective(this);
203 void target_assault_roundend_reset(entity this)
205 //print("round end reset\n");
206 ++this.cnt; // up round counter
207 this.winning = false; // up round
210 void target_assault_roundend_use(entity this, entity actor, entity trigger)
212 this.winning = 1; // round has been won by attackers
215 void assault_roundstart_use(entity this, entity actor, entity trigger)
217 SUB_UseTargets(this, this, trigger);
219 //(Re)spawn all turrets
220 FOREACH_ENTITY_CLASS("turret_main", true, LAMBDA(
222 if(it.team == NUM_TEAM_1)
223 it.team = NUM_TEAM_2;
225 it.team = NUM_TEAM_1;
227 // Doubles as teamchange
231 void assault_roundstart_use_this(entity this)
233 assault_roundstart_use(this, NULL, NULL);
236 void assault_wall_think(entity this)
238 if(this.enemy.health < 0)
241 this.solid = SOLID_NOT;
245 this.model = this.mdl;
246 this.solid = SOLID_BSP;
249 this.nextthink = time + 0.2;
253 // reset objectives, toggle spawnpoints, reset triggers, ...
254 void vehicles_clearreturn(entity veh);
255 void vehicles_spawn(entity this);
256 void assault_new_round(entity this)
258 //bprint("ASSAULT: new round\n");
260 // Eject players from vehicles
261 FOREACH_CLIENT(IS_PLAYER(it) && it.vehicle, vehicles_exit(it.vehicle, VHEF_RELEASE));
263 FOREACH_ENTITY_FLAGS(vehicle_flags, VHF_ISVEHICLE, LAMBDA(
264 vehicles_clearreturn(it);
269 this.winning = this.winning + 1;
271 // swap attacker/defender roles
272 if(assault_attacker_team == NUM_TEAM_1)
273 assault_attacker_team = NUM_TEAM_2;
275 assault_attacker_team = NUM_TEAM_1;
277 FOREACH_ENTITY(IS_NOT_A_CLIENT(it), LAMBDA(
278 if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
279 else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
282 // reset the level with a countdown
283 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
284 ReadyRestart_force(); // sets game_starttime
287 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
288 // they win. Otherwise the defending team wins once the timelimit passes.
289 int WinningCondition_Assault()
291 WinningConditionHelper(NULL); // set worldstatus
293 int status = WINNING_NO;
294 // as the timelimit has not yet passed just assume the defending team will win
295 if(assault_attacker_team == NUM_TEAM_1)
297 SetWinners(team, NUM_TEAM_2);
301 SetWinners(team, NUM_TEAM_1);
305 ent = find(NULL, classname, "target_assault_roundend");
308 if(ent.winning) // round end has been triggered by attacking team
310 bprint("ASSAULT: round completed...\n");
311 SetWinners(team, assault_attacker_team);
313 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
315 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
317 status = WINNING_YES;
321 assault_new_round(ent);
330 spawnfunc(info_player_attacker)
332 if (!g_assault) { remove(this); return; }
334 this.team = NUM_TEAM_1; // red, gets swapped every round
335 spawnfunc_info_player_deathmatch(this);
338 spawnfunc(info_player_defender)
340 if (!g_assault) { remove(this); return; }
342 this.team = NUM_TEAM_2; // blue, gets swapped every round
343 spawnfunc_info_player_deathmatch(this);
346 spawnfunc(target_objective)
348 if (!g_assault) { remove(this); return; }
350 this.classname = "target_objective";
351 this.use = assault_objective_use;
352 this.reset = assault_objective_reset;
354 this.spawn_evalfunc = target_objective_spawn_evalfunc;
357 spawnfunc(target_objective_decrease)
359 if (!g_assault) { remove(this); return; }
361 this.classname = "target_objective_decrease";
366 this.use = assault_objective_decrease_use;
367 this.health = ASSAULT_VALUE_INACTIVE;
368 this.max_health = ASSAULT_VALUE_INACTIVE;
371 InitializeEntity(this, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
374 // destructible walls that can be used to trigger target_objective_decrease
375 spawnfunc(func_breakable);
376 spawnfunc(func_assault_destructible)
378 if (!g_assault) { remove(this); return; }
381 this.classname = "func_assault_destructible";
383 if(assault_attacker_team == NUM_TEAM_1)
384 this.team = NUM_TEAM_2;
386 this.team = NUM_TEAM_1;
388 spawnfunc_func_breakable(this);
391 spawnfunc(func_assault_wall)
393 if (!g_assault) { remove(this); return; }
395 this.classname = "func_assault_wall";
396 this.mdl = this.model;
397 _setmodel(this, this.mdl);
398 this.solid = SOLID_BSP;
399 setthink(this, assault_wall_think);
400 this.nextthink = time;
401 InitializeEntity(this, assault_setenemytoobjective, INITPRIO_FINDTARGET);
404 spawnfunc(target_assault_roundend)
406 if (!g_assault) { remove(this); return; }
408 this.winning = 0; // round not yet won by attackers
409 this.classname = "target_assault_roundend";
410 this.use = target_assault_roundend_use;
411 this.cnt = 0; // first round
412 this.reset = target_assault_roundend_reset;
415 spawnfunc(target_assault_roundstart)
417 if (!g_assault) { remove(this); return; }
419 assault_attacker_team = NUM_TEAM_1;
420 this.classname = "target_assault_roundstart";
421 this.use = assault_roundstart_use;
422 this.reset2 = assault_roundstart_use_this;
423 InitializeEntity(this, assault_roundstart_use_this, INITPRIO_FINDTARGET);
427 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
429 entity ad, best, wp, tod;
430 float radius, found, bestvalue;
433 ad = findchain(classname, "func_assault_destructible");
435 for (; ad; ad = ad.chain)
444 for(tod = NULL; (tod = find(tod, targetname, ad.target)); )
446 if(tod.classname == "target_objective_decrease")
448 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
450 // dprint(etos(ad),"\n");
459 /// dprint("target not found\n");
462 /// dprint("target #", etos(ad), " found\n");
465 p = 0.5 * (ad.absmin + ad.absmax);
466 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
467 // te_knightspike(p);
468 // te_lightning2(NULL, '0 0 0', p);
470 // Find and rate waypoints around it
473 bestvalue = 99999999999;
474 for(radius=0; radius<1500 && !found; radius+=500)
476 for(wp=findradius(p, radius); wp; wp=wp.chain)
478 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
479 if(wp.classname=="waypoint")
480 if(checkpvs(wp.origin, ad))
494 /// dprint("waypoints around target were found\n");
495 // te_lightning2(NULL, '0 0 0', best.origin);
496 // te_knightspike(best.origin);
498 navigation_routerating(this, best, ratingscale, 4000);
501 this.havocbot_attack_time = 0;
503 if(checkpvs(this.view_ofs,ad))
504 if(checkpvs(this.view_ofs,best))
506 // dprint("increasing attack time for this target\n");
507 this.havocbot_attack_time = time + 2;
513 void havocbot_role_ast_offense(entity this)
517 this.havocbot_attack_time = 0;
518 havocbot_ast_reset_role(this);
522 // Set the role timeout if necessary
523 if (!this.havocbot_role_timeout)
524 this.havocbot_role_timeout = time + 120;
526 if (time > this.havocbot_role_timeout)
528 havocbot_ast_reset_role(this);
532 if(this.havocbot_attack_time>time)
535 if (this.bot_strategytime < time)
537 navigation_goalrating_start(this);
538 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
539 havocbot_goalrating_ast_targets(this, 20000);
540 havocbot_goalrating_items(this, 15000, this.origin, 10000);
541 navigation_goalrating_end(this);
543 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
547 void havocbot_role_ast_defense(entity this)
551 this.havocbot_attack_time = 0;
552 havocbot_ast_reset_role(this);
556 // Set the role timeout if necessary
557 if (!this.havocbot_role_timeout)
558 this.havocbot_role_timeout = time + 120;
560 if (time > this.havocbot_role_timeout)
562 havocbot_ast_reset_role(this);
566 if(this.havocbot_attack_time>time)
569 if (this.bot_strategytime < time)
571 navigation_goalrating_start(this);
572 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 3000);
573 havocbot_goalrating_ast_targets(this, 20000);
574 havocbot_goalrating_items(this, 15000, this.origin, 10000);
575 navigation_goalrating_end(this);
577 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
581 void havocbot_role_ast_setrole(entity this, float role)
585 case HAVOCBOT_AST_ROLE_DEFENSE:
586 this.havocbot_role = havocbot_role_ast_defense;
587 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
588 this.havocbot_role_timeout = 0;
590 case HAVOCBOT_AST_ROLE_OFFENSE:
591 this.havocbot_role = havocbot_role_ast_offense;
592 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
593 this.havocbot_role_timeout = 0;
598 void havocbot_ast_reset_role(entity this)
603 if(this.team == assault_attacker_team)
604 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_OFFENSE);
606 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_DEFENSE);
610 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
612 entity player = M_ARGV(0, entity);
614 if(player.team == assault_attacker_team)
615 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
617 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
620 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
622 entity turret = M_ARGV(0, entity);
624 if(!turret.team || turret.team == MAX_SHOT_DISTANCE)
625 turret.team = 5; // this gets reversed when match starts?
628 MUTATOR_HOOKFUNCTION(as, VehicleSpawn)
630 entity veh = M_ARGV(0, entity);
632 veh.nextthink = time + 0.5;
635 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
637 entity bot = M_ARGV(0, entity);
639 havocbot_ast_reset_role(bot);
643 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
645 entity frag_victim = M_ARGV(0, entity);
647 return (frag_victim.classname == "func_assault_destructible");
650 MUTATOR_HOOKFUNCTION(as, GetTeamCount)
652 // assault always has 2 teams
657 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
659 M_ARGV(0, float) = WinningCondition_Assault();
663 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
665 // no assault warmups
669 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
671 entity ent = M_ARGV(0, entity);
673 switch(ent.classname)
675 case "info_player_team1":
676 case "info_player_team2":
677 case "info_player_team3":
678 case "info_player_team4":
684 void assault_ScoreRules()
686 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
687 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
688 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
689 ScoreRules_basics_end();