1 #ifndef GAMEMODE_ASSAULT_H
2 #define GAMEMODE_ASSAULT_H
4 void assault_ScoreRules();
6 REGISTER_MUTATOR(as, false)
9 have_team_spawns = -1; // request team spawns
13 if (time > 1) // game loads at time 1
14 error("This is a game type and it cannot be added at runtime.");
18 MUTATOR_ONROLLBACK_OR_REMOVE
20 // we actually cannot roll back assault_Initialize here
21 // BUT: we don't need to! If this gets called, adding always
27 LOG_INFO("This is a game type and it cannot be removed at runtime.");
35 .entity assault_decreaser;
36 .entity assault_sprite;
39 const int HAVOCBOT_AST_ROLE_NONE = 0;
40 const int HAVOCBOT_AST_ROLE_DEFENSE = 2;
41 const int HAVOCBOT_AST_ROLE_OFFENSE = 4;
43 .int havocbot_role_flags;
44 .float havocbot_attack_time;
46 .void() havocbot_role;
47 .void() havocbot_previous_role;
49 void() havocbot_role_ast_defense;
50 void() havocbot_role_ast_offense;
51 .entity havocbot_ast_target;
53 void(entity bot) havocbot_ast_reset_role;
55 void(float ratingscale, vector org, float sradius) havocbot_goalrating_items;
56 void(float ratingscale, vector org, float sradius) havocbot_goalrating_enemyplayers;
59 const float ST_ASSAULT_OBJECTIVES = 1;
60 const float SP_ASSAULT_OBJECTIVES = 4;
62 // predefined spawnfuncs
63 void target_objective_decrease_activate();
70 void assault_objective_use()
74 //print("^2Activated objective ", self.targetname, "=", etos(self), "\n");
75 //print("Activator is ", activator.classname, "\n");
77 for (entity e = world; (e = find(e, target, this.targetname)); )
79 if (e.classname == "target_objective_decrease")
81 WITH(entity, self, e, target_objective_decrease_activate());
88 vector target_objective_spawn_evalfunc(entity player, entity spot, vector current)
90 if(self.health < 0 || self.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()
105 if(activator.team != assault_attacker_team)
107 // wrong team triggered decrease
111 if(other.assault_sprite)
113 WaypointSprite_Disown(other.assault_sprite, waypointsprite_deadlifetime);
114 if(other.classname == "func_assault_destructible")
115 other.sprite = world;
118 return; // already activated! cannot activate again!
120 if(self.enemy.health < ASSAULT_VALUE_INACTIVE)
122 if(self.enemy.health - self.dmg > 0.5)
124 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.dmg);
125 self.enemy.health = self.enemy.health - self.dmg;
129 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.enemy.health);
130 PlayerTeamScore_Add(activator, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
131 self.enemy.health = -1;
137 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(centerprint(it, self.message)));
139 oldactivator = activator;
142 activator = oldactivator;
148 void assault_setenemytoobjective()
151 for(objective = world; (objective = find(objective, targetname, self.target)); )
153 if(objective.classname == "target_objective")
155 if(self.enemy == world)
156 self.enemy = objective;
158 objerror("more than one objective as target - fix the map!");
163 if(self.enemy == world)
164 objerror("no objective as target - fix the map!");
167 float assault_decreaser_sprite_visible(entity e)
171 decreaser = self.assault_decreaser;
173 if(decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
179 void target_objective_decrease_activate()
183 for(ent = world; (ent = find(ent, target, self.targetname)); )
185 if(ent.assault_sprite != world)
187 WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
188 if(ent.classname == "func_assault_destructible")
192 spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE);
193 spr.assault_decreaser = self;
194 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
195 spr.classname = "sprite_waypoint";
196 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
197 if(ent.classname == "func_assault_destructible")
199 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
200 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
201 WaypointSprite_UpdateHealth(spr, ent.health);
205 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
209 void target_objective_decrease_findtarget()
211 assault_setenemytoobjective();
214 void target_assault_roundend_reset(entity this)
216 //print("round end reset\n");
217 ++this.cnt; // up round counter
218 this.winning = false; // up round
221 void target_assault_roundend_use()
223 self.winning = 1; // round has been won by attackers
226 void assault_roundstart_use()
231 //(Re)spawn all turrets
232 for(entity ent = NULL; (ent = find(ent, classname, "turret_main")); ) {
234 if(ent.team == NUM_TEAM_1)
235 ent.team = NUM_TEAM_2;
237 ent.team = NUM_TEAM_1;
239 // Dubbles as teamchange
240 WITH(entity, self, ent, turret_respawn());
244 void assault_wall_think()
246 if(self.enemy.health < 0)
249 self.solid = SOLID_NOT;
253 self.model = self.mdl;
254 self.solid = SOLID_BSP;
257 self.nextthink = time + 0.2;
261 // reset objectives, toggle spawnpoints, reset triggers, ...
262 void vehicles_clearreturn(entity veh);
263 void vehicles_spawn();
264 void assault_new_round()
266 //bprint("ASSAULT: new round\n");
268 // Eject players from vehicles
269 FOREACH_CLIENT(IS_PLAYER(it) && it.vehicle, LAMBDA(WITH(entity, self, it, vehicles_exit(VHEF_RELEASE))));
271 FOREACH_ENTITY_FLAGS(vehicle_flags, VHF_ISVEHICLE, LAMBDA(
273 vehicles_clearreturn(self);
280 self.winning = self.winning + 1;
282 // swap attacker/defender roles
283 if(assault_attacker_team == NUM_TEAM_1)
284 assault_attacker_team = NUM_TEAM_2;
286 assault_attacker_team = NUM_TEAM_1;
288 FOREACH_ENTITY(IS_NOT_A_CLIENT(it), LAMBDA(
289 if (it.team_saved == NUM_TEAM_1) it.team_saved = NUM_TEAM_2;
290 else if (it.team_saved == NUM_TEAM_2) it.team_saved = NUM_TEAM_1;
293 // reset the level with a countdown
294 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
295 ReadyRestart_force(); // sets game_starttime
299 spawnfunc(info_player_attacker)
301 if (!g_assault) { remove(self); return; }
303 self.team = NUM_TEAM_1; // red, gets swapped every round
304 spawnfunc_info_player_deathmatch(this);
307 spawnfunc(info_player_defender)
309 if (!g_assault) { remove(self); return; }
311 self.team = NUM_TEAM_2; // blue, gets swapped every round
312 spawnfunc_info_player_deathmatch(this);
315 spawnfunc(target_objective)
317 if (!g_assault) { remove(this); return; }
319 this.classname = "target_objective";
320 this.use = assault_objective_use;
321 this.reset = assault_objective_reset;
323 this.spawn_evalfunc = target_objective_spawn_evalfunc;
326 spawnfunc(target_objective_decrease)
328 if (!g_assault) { remove(self); return; }
330 self.classname = "target_objective_decrease";
335 self.use = assault_objective_decrease_use;
336 self.health = ASSAULT_VALUE_INACTIVE;
337 self.max_health = ASSAULT_VALUE_INACTIVE;
340 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
343 // destructible walls that can be used to trigger target_objective_decrease
344 spawnfunc(func_breakable);
345 spawnfunc(func_assault_destructible)
347 if (!g_assault) { remove(self); return; }
350 self.classname = "func_assault_destructible";
352 if(assault_attacker_team == NUM_TEAM_1)
353 self.team = NUM_TEAM_2;
355 self.team = NUM_TEAM_1;
357 spawnfunc_func_breakable(this);
360 spawnfunc(func_assault_wall)
362 if (!g_assault) { remove(self); return; }
364 self.classname = "func_assault_wall";
365 self.mdl = self.model;
366 _setmodel(self, self.mdl);
367 self.solid = SOLID_BSP;
368 self.think = assault_wall_think;
369 self.nextthink = time;
370 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
373 spawnfunc(target_assault_roundend)
375 if (!g_assault) { remove(self); return; }
377 self.winning = 0; // round not yet won by attackers
378 self.classname = "target_assault_roundend";
379 self.use = target_assault_roundend_use;
380 self.cnt = 0; // first round
381 self.reset = target_assault_roundend_reset;
384 spawnfunc(target_assault_roundstart)
386 if (!g_assault) { remove(self); return; }
388 assault_attacker_team = NUM_TEAM_1;
389 self.classname = "target_assault_roundstart";
390 self.use = assault_roundstart_use;
391 self.reset2 = assault_roundstart_use;
392 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
396 void havocbot_goalrating_ast_targets(float ratingscale)
398 entity ad, best, wp, tod;
399 float radius, found, bestvalue;
402 ad = findchain(classname, "func_assault_destructible");
404 for (; ad; ad = ad.chain)
413 for(tod = world; (tod = find(tod, targetname, ad.target)); )
415 if(tod.classname == "target_objective_decrease")
417 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
419 // dprint(etos(ad),"\n");
428 /// dprint("target not found\n");
431 /// dprint("target #", etos(ad), " found\n");
434 p = 0.5 * (ad.absmin + ad.absmax);
435 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
436 // te_knightspike(p);
437 // te_lightning2(world, '0 0 0', p);
439 // Find and rate waypoints around it
442 bestvalue = 99999999999;
443 for(radius=0; radius<1500 && !found; radius+=500)
445 for(wp=findradius(p, radius); wp; wp=wp.chain)
447 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
448 if(wp.classname=="waypoint")
449 if(checkpvs(wp.origin, ad))
463 /// dprint("waypoints around target were found\n");
464 // te_lightning2(world, '0 0 0', best.origin);
465 // te_knightspike(best.origin);
467 navigation_routerating(best, ratingscale, 4000);
470 self.havocbot_attack_time = 0;
472 if(checkpvs(self.view_ofs,ad))
473 if(checkpvs(self.view_ofs,best))
475 // dprint("increasing attack time for this target\n");
476 self.havocbot_attack_time = time + 2;
482 void havocbot_role_ast_offense()
484 if(self.deadflag != DEAD_NO)
486 self.havocbot_attack_time = 0;
487 havocbot_ast_reset_role(self);
491 // Set the role timeout if necessary
492 if (!self.havocbot_role_timeout)
493 self.havocbot_role_timeout = time + 120;
495 if (time > self.havocbot_role_timeout)
497 havocbot_ast_reset_role(self);
501 if(self.havocbot_attack_time>time)
504 if (self.bot_strategytime < time)
506 navigation_goalrating_start();
507 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
508 havocbot_goalrating_ast_targets(20000);
509 havocbot_goalrating_items(15000, self.origin, 10000);
510 navigation_goalrating_end();
512 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
516 void havocbot_role_ast_defense()
518 if(self.deadflag != DEAD_NO)
520 self.havocbot_attack_time = 0;
521 havocbot_ast_reset_role(self);
525 // Set the role timeout if necessary
526 if (!self.havocbot_role_timeout)
527 self.havocbot_role_timeout = time + 120;
529 if (time > self.havocbot_role_timeout)
531 havocbot_ast_reset_role(self);
535 if(self.havocbot_attack_time>time)
538 if (self.bot_strategytime < time)
540 navigation_goalrating_start();
541 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
542 havocbot_goalrating_ast_targets(20000);
543 havocbot_goalrating_items(15000, self.origin, 10000);
544 navigation_goalrating_end();
546 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
550 void havocbot_role_ast_setrole(entity bot, float role)
554 case HAVOCBOT_AST_ROLE_DEFENSE:
555 bot.havocbot_role = havocbot_role_ast_defense;
556 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
557 bot.havocbot_role_timeout = 0;
559 case HAVOCBOT_AST_ROLE_OFFENSE:
560 bot.havocbot_role = havocbot_role_ast_offense;
561 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
562 bot.havocbot_role_timeout = 0;
567 void havocbot_ast_reset_role(entity bot)
569 if(self.deadflag != DEAD_NO)
572 if(bot.team == assault_attacker_team)
573 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
575 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
579 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
581 if(self.team == assault_attacker_team)
582 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
584 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
589 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
591 if(!self.team || self.team == MAX_SHOT_DISTANCE)
592 self.team = 5; // this gets reversed when match starts?
597 MUTATOR_HOOKFUNCTION(as, VehicleSpawn)
599 self.nextthink = time + 0.5;
604 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
606 havocbot_ast_reset_role(self);
610 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
612 return (frag_victim.classname == "func_assault_destructible");
615 MUTATOR_HOOKFUNCTION(as, GetTeamCount)
617 // assault always has 2 teams
622 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
624 ret_float = WinningCondition_Assault();
628 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
630 // no assault warmups
635 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
637 switch(self.classname)
639 case "info_player_team1":
640 case "info_player_team2":
641 case "info_player_team3":
642 case "info_player_team4":
650 void assault_ScoreRules()
652 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
653 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
654 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
655 ScoreRules_basics_end();