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)
143 FOREACH_ENTITY_STRING(targetname, this.target,
145 if(it.classname == "target_objective")
147 if(this.enemy == NULL)
150 objerror(this, "more than one objective as target - fix the map!");
155 if(this.enemy == NULL)
156 objerror(this, "no objective as target - fix the map!");
159 bool assault_decreaser_sprite_visible(entity this, entity player, entity view)
161 if(this.assault_decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
167 void target_objective_decrease_activate(entity this)
171 FOREACH_ENTITY_STRING(target, this.targetname,
173 if(it.assault_sprite != NULL)
175 WaypointSprite_Disown(it.assault_sprite, waypointsprite_deadlifetime);
176 if(it.classname == "func_assault_destructible")
177 it.sprite = NULL; // TODO: just unsetting it?!
180 spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (it.absmin + it.absmax), it, assault_sprite, RADARICON_OBJECTIVE);
181 spr.assault_decreaser = this;
182 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
183 spr.classname = "sprite_waypoint";
184 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
185 if(it.classname == "func_assault_destructible")
187 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
188 WaypointSprite_UpdateMaxHealth(spr, it.max_health);
189 WaypointSprite_UpdateHealth(spr, it.health);
193 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
197 void target_objective_decrease_findtarget(entity this)
199 assault_setenemytoobjective(this);
202 void target_assault_roundend_reset(entity this)
204 //print("round end reset\n");
205 ++this.cnt; // up round counter
206 this.winning = false; // up round
209 void target_assault_roundend_use(entity this, entity actor, entity trigger)
211 this.winning = 1; // round has been won by attackers
214 void assault_roundstart_use(entity this, entity actor, entity trigger)
216 SUB_UseTargets(this, this, trigger);
218 //(Re)spawn all turrets
219 FOREACH_ENTITY_CLASS("turret_main", true, LAMBDA(
221 if(it.team == NUM_TEAM_1)
222 it.team = NUM_TEAM_2;
224 it.team = NUM_TEAM_1;
226 // Doubles as teamchange
230 void assault_roundstart_use_this(entity this)
232 assault_roundstart_use(this, NULL, NULL);
235 void assault_wall_think(entity this)
237 if(this.enemy.health < 0)
240 this.solid = SOLID_NOT;
244 this.model = this.mdl;
245 this.solid = SOLID_BSP;
248 this.nextthink = time + 0.2;
252 // reset objectives, toggle spawnpoints, reset triggers, ...
253 void vehicles_clearreturn(entity veh);
254 void vehicles_spawn(entity this);
255 void assault_new_round(entity this)
257 //bprint("ASSAULT: new round\n");
259 // Eject players from vehicles
260 FOREACH_CLIENT(IS_PLAYER(it) && it.vehicle, vehicles_exit(it.vehicle, VHEF_RELEASE));
262 FOREACH_ENTITY_FLAGS(vehicle_flags, VHF_ISVEHICLE, LAMBDA(
263 vehicles_clearreturn(it);
268 this.winning = this.winning + 1;
270 // swap attacker/defender roles
271 if(assault_attacker_team == NUM_TEAM_1)
272 assault_attacker_team = NUM_TEAM_2;
274 assault_attacker_team = NUM_TEAM_1;
276 FOREACH_ENTITY(IS_NOT_A_CLIENT(it), LAMBDA(
277 if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
278 else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
281 // reset the level with a countdown
282 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
283 ReadyRestart_force(); // sets game_starttime
286 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
287 // they win. Otherwise the defending team wins once the timelimit passes.
288 int WinningCondition_Assault()
290 WinningConditionHelper(NULL); // set worldstatus
292 int status = WINNING_NO;
293 // as the timelimit has not yet passed just assume the defending team will win
294 if(assault_attacker_team == NUM_TEAM_1)
296 SetWinners(team, NUM_TEAM_2);
300 SetWinners(team, NUM_TEAM_1);
304 ent = find(NULL, classname, "target_assault_roundend");
307 if(ent.winning) // round end has been triggered by attacking team
309 bprint("ASSAULT: round completed...\n");
310 SetWinners(team, assault_attacker_team);
312 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
314 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
316 status = WINNING_YES;
320 assault_new_round(ent);
329 spawnfunc(info_player_attacker)
331 if (!g_assault) { remove(this); return; }
333 this.team = NUM_TEAM_1; // red, gets swapped every round
334 spawnfunc_info_player_deathmatch(this);
337 spawnfunc(info_player_defender)
339 if (!g_assault) { remove(this); return; }
341 this.team = NUM_TEAM_2; // blue, gets swapped every round
342 spawnfunc_info_player_deathmatch(this);
345 spawnfunc(target_objective)
347 if (!g_assault) { remove(this); return; }
349 this.classname = "target_objective";
350 this.use = assault_objective_use;
351 this.reset = assault_objective_reset;
353 this.spawn_evalfunc = target_objective_spawn_evalfunc;
356 spawnfunc(target_objective_decrease)
358 if (!g_assault) { remove(this); return; }
360 this.classname = "target_objective_decrease";
365 this.use = assault_objective_decrease_use;
366 this.health = ASSAULT_VALUE_INACTIVE;
367 this.max_health = ASSAULT_VALUE_INACTIVE;
370 InitializeEntity(this, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
373 // destructible walls that can be used to trigger target_objective_decrease
374 spawnfunc(func_breakable);
375 spawnfunc(func_assault_destructible)
377 if (!g_assault) { remove(this); return; }
380 this.classname = "func_assault_destructible";
382 if(assault_attacker_team == NUM_TEAM_1)
383 this.team = NUM_TEAM_2;
385 this.team = NUM_TEAM_1;
387 spawnfunc_func_breakable(this);
390 spawnfunc(func_assault_wall)
392 if (!g_assault) { remove(this); return; }
394 this.classname = "func_assault_wall";
395 this.mdl = this.model;
396 _setmodel(this, this.mdl);
397 this.solid = SOLID_BSP;
398 setthink(this, assault_wall_think);
399 this.nextthink = time;
400 InitializeEntity(this, assault_setenemytoobjective, INITPRIO_FINDTARGET);
403 spawnfunc(target_assault_roundend)
405 if (!g_assault) { remove(this); return; }
407 this.winning = 0; // round not yet won by attackers
408 this.classname = "target_assault_roundend";
409 this.use = target_assault_roundend_use;
410 this.cnt = 0; // first round
411 this.reset = target_assault_roundend_reset;
414 spawnfunc(target_assault_roundstart)
416 if (!g_assault) { remove(this); return; }
418 assault_attacker_team = NUM_TEAM_1;
419 this.classname = "target_assault_roundstart";
420 this.use = assault_roundstart_use;
421 this.reset2 = assault_roundstart_use_this;
422 InitializeEntity(this, assault_roundstart_use_this, INITPRIO_FINDTARGET);
426 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
429 float radius, bestvalue;
433 ad = findchain(classname, "func_assault_destructible");
435 for (; ad; ad = ad.chain)
444 FOREACH_ENTITY_STRING(targetname, ad.target,
446 if(it.classname == "target_objective_decrease")
448 if(it.enemy.health > 0 && it.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();