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() havocbot_role;
49 .void() havocbot_previous_role;
51 void() havocbot_role_ast_defense;
52 void() havocbot_role_ast_offense;
53 .entity havocbot_ast_target;
55 void(entity bot) havocbot_ast_reset_role;
57 void(float ratingscale, vector org, float sradius) havocbot_goalrating_items;
58 void(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();
72 void assault_objective_use()
76 //print("^2Activated objective ", self.targetname, "=", etos(self), "\n");
77 //print("Activator is ", activator.classname, "\n");
79 for (entity e = world; (e = find(e, target, this.targetname)); )
81 if (e.classname == "target_objective_decrease")
83 WITH(entity, self, e, target_objective_decrease_activate());
90 vector target_objective_spawn_evalfunc(entity player, entity spot, vector current)
92 if(self.health < 0 || self.health >= ASSAULT_VALUE_INACTIVE)
97 // reset this objective. Used when spawning an objective
98 // and when a new round starts
99 void assault_objective_reset(entity this)
101 this.health = ASSAULT_VALUE_INACTIVE;
104 // decrease the health of targeted objectives
105 void assault_objective_decrease_use()
107 if(activator.team != assault_attacker_team)
109 // wrong team triggered decrease
113 if(other.assault_sprite)
115 WaypointSprite_Disown(other.assault_sprite, waypointsprite_deadlifetime);
116 if(other.classname == "func_assault_destructible")
117 other.sprite = world;
120 return; // already activated! cannot activate again!
122 if(self.enemy.health < ASSAULT_VALUE_INACTIVE)
124 if(self.enemy.health - self.dmg > 0.5)
126 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.dmg);
127 self.enemy.health = self.enemy.health - self.dmg;
131 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.enemy.health);
132 PlayerTeamScore_Add(activator, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
133 self.enemy.health = -1;
139 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(centerprint(it, self.message)));
141 oldactivator = activator;
144 activator = oldactivator;
150 void assault_setenemytoobjective()
153 for(objective = world; (objective = find(objective, targetname, self.target)); )
155 if(objective.classname == "target_objective")
157 if(self.enemy == world)
158 self.enemy = objective;
160 objerror("more than one objective as target - fix the map!");
165 if(self.enemy == world)
166 objerror("no objective as target - fix the map!");
169 float assault_decreaser_sprite_visible(entity e)
173 decreaser = self.assault_decreaser;
175 if(decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
181 void target_objective_decrease_activate()
185 for(ent = world; (ent = find(ent, target, self.targetname)); )
187 if(ent.assault_sprite != world)
189 WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
190 if(ent.classname == "func_assault_destructible")
194 spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE);
195 spr.assault_decreaser = self;
196 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
197 spr.classname = "sprite_waypoint";
198 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
199 if(ent.classname == "func_assault_destructible")
201 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
202 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
203 WaypointSprite_UpdateHealth(spr, ent.health);
207 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
211 void target_objective_decrease_findtarget()
213 assault_setenemytoobjective();
216 void target_assault_roundend_reset(entity this)
218 //print("round end reset\n");
219 ++this.cnt; // up round counter
220 this.winning = false; // up round
223 void target_assault_roundend_use()
225 self.winning = 1; // round has been won by attackers
228 void assault_roundstart_use()
233 //(Re)spawn all turrets
234 FOREACH_ENTITY_CLASS("turret_main", true, LAMBDA(
236 if(it.team == NUM_TEAM_1)
237 it.team = NUM_TEAM_2;
239 it.team = NUM_TEAM_1;
241 // Dubbles as teamchange
242 WITH(entity, self, it, turret_respawn());
246 void assault_wall_think()
248 if(self.enemy.health < 0)
251 self.solid = SOLID_NOT;
255 self.model = self.mdl;
256 self.solid = SOLID_BSP;
259 self.nextthink = time + 0.2;
263 // reset objectives, toggle spawnpoints, reset triggers, ...
264 void vehicles_clearreturn(entity veh);
265 void vehicles_spawn();
266 void assault_new_round()
268 //bprint("ASSAULT: new round\n");
270 // Eject players from vehicles
271 FOREACH_CLIENT(IS_PLAYER(it) && it.vehicle, LAMBDA(WITH(entity, self, it, vehicles_exit(VHEF_RELEASE))));
273 FOREACH_ENTITY_FLAGS(vehicle_flags, VHF_ISVEHICLE, LAMBDA(
275 vehicles_clearreturn(self);
282 self.winning = self.winning + 1;
284 // swap attacker/defender roles
285 if(assault_attacker_team == NUM_TEAM_1)
286 assault_attacker_team = NUM_TEAM_2;
288 assault_attacker_team = NUM_TEAM_1;
290 FOREACH_ENTITY(IS_NOT_A_CLIENT(it), LAMBDA(
291 if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
292 else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
295 // reset the level with a countdown
296 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
297 ReadyRestart_force(); // sets game_starttime
300 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
301 // they win. Otherwise the defending team wins once the timelimit passes.
302 int WinningCondition_Assault()
305 WinningConditionHelper(); // set worldstatus
307 int status = WINNING_NO;
308 // as the timelimit has not yet passed just assume the defending team will win
309 if(assault_attacker_team == NUM_TEAM_1)
311 SetWinners(team, NUM_TEAM_2);
315 SetWinners(team, NUM_TEAM_1);
319 ent = find(world, classname, "target_assault_roundend");
322 if(ent.winning) // round end has been triggered by attacking team
324 bprint("ASSAULT: round completed...\n");
325 SetWinners(team, assault_attacker_team);
327 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
329 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
331 status = WINNING_YES;
335 WITH(entity, self, ent, assault_new_round());
344 spawnfunc(info_player_attacker)
346 if (!g_assault) { remove(self); return; }
348 self.team = NUM_TEAM_1; // red, gets swapped every round
349 spawnfunc_info_player_deathmatch(this);
352 spawnfunc(info_player_defender)
354 if (!g_assault) { remove(self); return; }
356 self.team = NUM_TEAM_2; // blue, gets swapped every round
357 spawnfunc_info_player_deathmatch(this);
360 spawnfunc(target_objective)
362 if (!g_assault) { remove(this); return; }
364 this.classname = "target_objective";
365 this.use = assault_objective_use;
366 this.reset = assault_objective_reset;
368 this.spawn_evalfunc = target_objective_spawn_evalfunc;
371 spawnfunc(target_objective_decrease)
373 if (!g_assault) { remove(self); return; }
375 self.classname = "target_objective_decrease";
380 self.use = assault_objective_decrease_use;
381 self.health = ASSAULT_VALUE_INACTIVE;
382 self.max_health = ASSAULT_VALUE_INACTIVE;
385 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
388 // destructible walls that can be used to trigger target_objective_decrease
389 spawnfunc(func_breakable);
390 spawnfunc(func_assault_destructible)
392 if (!g_assault) { remove(self); return; }
395 self.classname = "func_assault_destructible";
397 if(assault_attacker_team == NUM_TEAM_1)
398 self.team = NUM_TEAM_2;
400 self.team = NUM_TEAM_1;
402 spawnfunc_func_breakable(this);
405 spawnfunc(func_assault_wall)
407 if (!g_assault) { remove(self); return; }
409 self.classname = "func_assault_wall";
410 self.mdl = self.model;
411 _setmodel(self, self.mdl);
412 self.solid = SOLID_BSP;
413 self.think = assault_wall_think;
414 self.nextthink = time;
415 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
418 spawnfunc(target_assault_roundend)
420 if (!g_assault) { remove(self); return; }
422 self.winning = 0; // round not yet won by attackers
423 self.classname = "target_assault_roundend";
424 self.use = target_assault_roundend_use;
425 self.cnt = 0; // first round
426 self.reset = target_assault_roundend_reset;
429 spawnfunc(target_assault_roundstart)
431 if (!g_assault) { remove(self); return; }
433 assault_attacker_team = NUM_TEAM_1;
434 self.classname = "target_assault_roundstart";
435 self.use = assault_roundstart_use;
436 self.reset2 = assault_roundstart_use;
437 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
441 void havocbot_goalrating_ast_targets(float ratingscale)
443 entity ad, best, wp, tod;
444 float radius, found, bestvalue;
447 ad = findchain(classname, "func_assault_destructible");
449 for (; ad; ad = ad.chain)
458 for(tod = world; (tod = find(tod, targetname, ad.target)); )
460 if(tod.classname == "target_objective_decrease")
462 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
464 // dprint(etos(ad),"\n");
473 /// dprint("target not found\n");
476 /// dprint("target #", etos(ad), " found\n");
479 p = 0.5 * (ad.absmin + ad.absmax);
480 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
481 // te_knightspike(p);
482 // te_lightning2(world, '0 0 0', p);
484 // Find and rate waypoints around it
487 bestvalue = 99999999999;
488 for(radius=0; radius<1500 && !found; radius+=500)
490 for(wp=findradius(p, radius); wp; wp=wp.chain)
492 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
493 if(wp.classname=="waypoint")
494 if(checkpvs(wp.origin, ad))
508 /// dprint("waypoints around target were found\n");
509 // te_lightning2(world, '0 0 0', best.origin);
510 // te_knightspike(best.origin);
512 navigation_routerating(best, ratingscale, 4000);
515 self.havocbot_attack_time = 0;
517 if(checkpvs(self.view_ofs,ad))
518 if(checkpvs(self.view_ofs,best))
520 // dprint("increasing attack time for this target\n");
521 self.havocbot_attack_time = time + 2;
527 void havocbot_role_ast_offense()
531 self.havocbot_attack_time = 0;
532 havocbot_ast_reset_role(self);
536 // Set the role timeout if necessary
537 if (!self.havocbot_role_timeout)
538 self.havocbot_role_timeout = time + 120;
540 if (time > self.havocbot_role_timeout)
542 havocbot_ast_reset_role(self);
546 if(self.havocbot_attack_time>time)
549 if (self.bot_strategytime < time)
551 navigation_goalrating_start();
552 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
553 havocbot_goalrating_ast_targets(20000);
554 havocbot_goalrating_items(15000, self.origin, 10000);
555 navigation_goalrating_end();
557 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
561 void havocbot_role_ast_defense()
565 self.havocbot_attack_time = 0;
566 havocbot_ast_reset_role(self);
570 // Set the role timeout if necessary
571 if (!self.havocbot_role_timeout)
572 self.havocbot_role_timeout = time + 120;
574 if (time > self.havocbot_role_timeout)
576 havocbot_ast_reset_role(self);
580 if(self.havocbot_attack_time>time)
583 if (self.bot_strategytime < time)
585 navigation_goalrating_start();
586 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
587 havocbot_goalrating_ast_targets(20000);
588 havocbot_goalrating_items(15000, self.origin, 10000);
589 navigation_goalrating_end();
591 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
595 void havocbot_role_ast_setrole(entity bot, float role)
599 case HAVOCBOT_AST_ROLE_DEFENSE:
600 bot.havocbot_role = havocbot_role_ast_defense;
601 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
602 bot.havocbot_role_timeout = 0;
604 case HAVOCBOT_AST_ROLE_OFFENSE:
605 bot.havocbot_role = havocbot_role_ast_offense;
606 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
607 bot.havocbot_role_timeout = 0;
612 void havocbot_ast_reset_role(entity bot)
617 if(bot.team == assault_attacker_team)
618 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
620 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
624 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
626 if(self.team == assault_attacker_team)
627 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
629 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
634 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
636 if(!self.team || self.team == MAX_SHOT_DISTANCE)
637 self.team = 5; // this gets reversed when match starts?
642 MUTATOR_HOOKFUNCTION(as, VehicleSpawn)
644 self.nextthink = time + 0.5;
649 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
651 havocbot_ast_reset_role(self);
655 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
657 return (frag_victim.classname == "func_assault_destructible");
660 MUTATOR_HOOKFUNCTION(as, GetTeamCount)
662 // assault always has 2 teams
667 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
669 ret_float = WinningCondition_Assault();
673 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
675 // no assault warmups
680 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
683 switch(self.classname)
685 case "info_player_team1":
686 case "info_player_team2":
687 case "info_player_team3":
688 case "info_player_team4":
696 void assault_ScoreRules()
698 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
699 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
700 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
701 ScoreRules_basics_end();