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_FLOAT(pure_data, false,
281 if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
282 else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
285 // reset the level with a countdown
286 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
287 ReadyRestart_force(); // sets game_starttime
290 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
291 // they win. Otherwise the defending team wins once the timelimit passes.
292 int WinningCondition_Assault()
294 WinningConditionHelper(NULL); // set worldstatus
296 int status = WINNING_NO;
297 // as the timelimit has not yet passed just assume the defending team will win
298 if(assault_attacker_team == NUM_TEAM_1)
300 SetWinners(team, NUM_TEAM_2);
304 SetWinners(team, NUM_TEAM_1);
308 ent = find(NULL, classname, "target_assault_roundend");
311 if(ent.winning) // round end has been triggered by attacking team
313 bprint("ASSAULT: round completed...\n");
314 SetWinners(team, assault_attacker_team);
316 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
318 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
320 status = WINNING_YES;
324 assault_new_round(ent);
333 spawnfunc(info_player_attacker)
335 if (!g_assault) { remove(this); return; }
337 this.team = NUM_TEAM_1; // red, gets swapped every round
338 spawnfunc_info_player_deathmatch(this);
341 spawnfunc(info_player_defender)
343 if (!g_assault) { remove(this); return; }
345 this.team = NUM_TEAM_2; // blue, gets swapped every round
346 spawnfunc_info_player_deathmatch(this);
349 spawnfunc(target_objective)
351 if (!g_assault) { remove(this); return; }
353 this.classname = "target_objective";
354 this.use = assault_objective_use;
355 this.reset = assault_objective_reset;
357 this.spawn_evalfunc = target_objective_spawn_evalfunc;
360 spawnfunc(target_objective_decrease)
362 if (!g_assault) { remove(this); return; }
364 this.classname = "target_objective_decrease";
369 this.use = assault_objective_decrease_use;
370 this.health = ASSAULT_VALUE_INACTIVE;
371 this.max_health = ASSAULT_VALUE_INACTIVE;
374 InitializeEntity(this, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
377 // destructible walls that can be used to trigger target_objective_decrease
378 spawnfunc(func_breakable);
379 spawnfunc(func_assault_destructible)
381 if (!g_assault) { remove(this); return; }
384 this.classname = "func_assault_destructible";
386 if(assault_attacker_team == NUM_TEAM_1)
387 this.team = NUM_TEAM_2;
389 this.team = NUM_TEAM_1;
391 spawnfunc_func_breakable(this);
394 spawnfunc(func_assault_wall)
396 if (!g_assault) { remove(this); return; }
398 this.classname = "func_assault_wall";
399 this.mdl = this.model;
400 _setmodel(this, this.mdl);
401 this.solid = SOLID_BSP;
402 setthink(this, assault_wall_think);
403 this.nextthink = time;
404 InitializeEntity(this, assault_setenemytoobjective, INITPRIO_FINDTARGET);
407 spawnfunc(target_assault_roundend)
409 if (!g_assault) { remove(this); return; }
411 this.winning = 0; // round not yet won by attackers
412 this.classname = "target_assault_roundend";
413 this.use = target_assault_roundend_use;
414 this.cnt = 0; // first round
415 this.reset = target_assault_roundend_reset;
418 spawnfunc(target_assault_roundstart)
420 if (!g_assault) { remove(this); return; }
422 assault_attacker_team = NUM_TEAM_1;
423 this.classname = "target_assault_roundstart";
424 this.use = assault_roundstart_use;
425 this.reset2 = assault_roundstart_use_this;
426 InitializeEntity(this, assault_roundstart_use_this, INITPRIO_FINDTARGET);
430 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
433 float radius, bestvalue;
437 ad = findchain(classname, "func_assault_destructible");
439 for (; ad; ad = ad.chain)
448 FOREACH_ENTITY_STRING(targetname, ad.target,
450 if(it.classname == "target_objective_decrease")
452 if(it.enemy.health > 0 && it.enemy.health < ASSAULT_VALUE_INACTIVE)
454 // dprint(etos(ad),"\n");
463 /// dprint("target not found\n");
466 /// dprint("target #", etos(ad), " found\n");
469 p = 0.5 * (ad.absmin + ad.absmax);
470 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
471 // te_knightspike(p);
472 // te_lightning2(NULL, '0 0 0', p);
474 // Find and rate waypoints around it
477 bestvalue = 99999999999;
478 for(radius=0; radius<1500 && !found; radius+=500)
480 for(wp=findradius(p, radius); wp; wp=wp.chain)
482 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
483 if(wp.classname=="waypoint")
484 if(checkpvs(wp.origin, ad))
498 /// dprint("waypoints around target were found\n");
499 // te_lightning2(NULL, '0 0 0', best.origin);
500 // te_knightspike(best.origin);
502 navigation_routerating(this, best, ratingscale, 4000);
505 this.havocbot_attack_time = 0;
507 if(checkpvs(this.view_ofs,ad))
508 if(checkpvs(this.view_ofs,best))
510 // dprint("increasing attack time for this target\n");
511 this.havocbot_attack_time = time + 2;
517 void havocbot_role_ast_offense(entity this)
521 this.havocbot_attack_time = 0;
522 havocbot_ast_reset_role(this);
526 // Set the role timeout if necessary
527 if (!this.havocbot_role_timeout)
528 this.havocbot_role_timeout = time + 120;
530 if (time > this.havocbot_role_timeout)
532 havocbot_ast_reset_role(this);
536 if(this.havocbot_attack_time>time)
539 if (this.bot_strategytime < time)
541 navigation_goalrating_start(this);
542 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
543 havocbot_goalrating_ast_targets(this, 20000);
544 havocbot_goalrating_items(this, 15000, this.origin, 10000);
545 navigation_goalrating_end(this);
547 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
551 void havocbot_role_ast_defense(entity this)
555 this.havocbot_attack_time = 0;
556 havocbot_ast_reset_role(this);
560 // Set the role timeout if necessary
561 if (!this.havocbot_role_timeout)
562 this.havocbot_role_timeout = time + 120;
564 if (time > this.havocbot_role_timeout)
566 havocbot_ast_reset_role(this);
570 if(this.havocbot_attack_time>time)
573 if (this.bot_strategytime < time)
575 navigation_goalrating_start(this);
576 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 3000);
577 havocbot_goalrating_ast_targets(this, 20000);
578 havocbot_goalrating_items(this, 15000, this.origin, 10000);
579 navigation_goalrating_end(this);
581 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
585 void havocbot_role_ast_setrole(entity this, float role)
589 case HAVOCBOT_AST_ROLE_DEFENSE:
590 this.havocbot_role = havocbot_role_ast_defense;
591 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
592 this.havocbot_role_timeout = 0;
594 case HAVOCBOT_AST_ROLE_OFFENSE:
595 this.havocbot_role = havocbot_role_ast_offense;
596 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
597 this.havocbot_role_timeout = 0;
602 void havocbot_ast_reset_role(entity this)
607 if(this.team == assault_attacker_team)
608 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_OFFENSE);
610 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_DEFENSE);
614 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
616 entity player = M_ARGV(0, entity);
618 if(player.team == assault_attacker_team)
619 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
621 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
624 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
626 entity turret = M_ARGV(0, entity);
628 if(!turret.team || turret.team == MAX_SHOT_DISTANCE)
629 turret.team = 5; // this gets reversed when match starts?
632 MUTATOR_HOOKFUNCTION(as, VehicleSpawn)
634 entity veh = M_ARGV(0, entity);
636 veh.nextthink = time + 0.5;
639 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
641 entity bot = M_ARGV(0, entity);
643 havocbot_ast_reset_role(bot);
647 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
649 entity frag_victim = M_ARGV(0, entity);
651 return (frag_victim.classname == "func_assault_destructible");
654 MUTATOR_HOOKFUNCTION(as, GetTeamCount)
656 // assault always has 2 teams
661 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
663 M_ARGV(0, float) = WinningCondition_Assault();
667 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
669 // no assault warmups
673 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
675 entity ent = M_ARGV(0, entity);
677 switch(ent.classname)
679 case "info_player_team1":
680 case "info_player_team2":
681 case "info_player_team3":
682 case "info_player_team4":
688 void assault_ScoreRules()
690 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
691 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
692 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
693 ScoreRules_basics_end();