1 #include "gamemode_assault.qh"
8 void assault_objective_use()
12 //print("^2Activated objective ", self.targetname, "=", etos(self), "\n");
13 //print("Activator is ", activator.classname, "\n");
15 for (entity e = world; (e = find(e, target, this.targetname)); )
17 if (e.classname == "target_objective_decrease")
19 WITH(entity, self, e, target_objective_decrease_activate());
26 vector target_objective_spawn_evalfunc(entity player, entity spot, vector current)
28 if(self.health < 0 || self.health >= ASSAULT_VALUE_INACTIVE)
33 // reset this objective. Used when spawning an objective
34 // and when a new round starts
35 void assault_objective_reset()
37 self.health = ASSAULT_VALUE_INACTIVE;
40 // decrease the health of targeted objectives
41 void assault_objective_decrease_use()
43 if(activator.team != assault_attacker_team)
45 // wrong team triggered decrease
49 if(other.assault_sprite)
51 WaypointSprite_Disown(other.assault_sprite, waypointsprite_deadlifetime);
52 if(other.classname == "func_assault_destructible")
56 return; // already activated! cannot activate again!
58 if(self.enemy.health < ASSAULT_VALUE_INACTIVE)
60 if(self.enemy.health - self.dmg > 0.5)
62 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.dmg);
63 self.enemy.health = self.enemy.health - self.dmg;
67 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.enemy.health);
68 PlayerTeamScore_Add(activator, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
69 self.enemy.health = -1;
71 entity oldactivator, head;
76 centerprint(head, self.message);
78 oldactivator = activator;
81 activator = oldactivator;
87 void assault_setenemytoobjective()
90 for(objective = world; (objective = find(objective, targetname, self.target)); )
92 if(objective.classname == "target_objective")
94 if(self.enemy == world)
95 self.enemy = objective;
97 objerror("more than one objective as target - fix the map!");
102 if(self.enemy == world)
103 objerror("no objective as target - fix the map!");
106 float assault_decreaser_sprite_visible(entity e)
110 decreaser = self.assault_decreaser;
112 if(decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
118 void target_objective_decrease_activate()
122 for(ent = world; (ent = find(ent, target, self.targetname)); )
124 if(ent.assault_sprite != world)
126 WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
127 if(ent.classname == "func_assault_destructible")
131 spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE);
132 spr.assault_decreaser = self;
133 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
134 spr.classname = "sprite_waypoint";
135 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
136 if(ent.classname == "func_assault_destructible")
138 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
139 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
140 WaypointSprite_UpdateHealth(spr, ent.health);
144 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
148 void target_objective_decrease_findtarget()
150 assault_setenemytoobjective();
153 void target_assault_roundend_reset()
155 //print("round end reset\n");
156 self.cnt = self.cnt + 1; // up round counter
157 self.winning = 0; // up round
160 void target_assault_roundend_use()
162 self.winning = 1; // round has been won by attackers
165 void assault_roundstart_use()
170 //(Re)spawn all turrets
171 for(entity ent = NULL; (ent = find(ent, classname, "turret_main")); ) {
173 if(ent.team == NUM_TEAM_1)
174 ent.team = NUM_TEAM_2;
176 ent.team = NUM_TEAM_1;
178 // Dubbles as teamchange
179 WITH(entity, self, ent, turret_respawn());
183 void assault_wall_think()
185 if(self.enemy.health < 0)
188 self.solid = SOLID_NOT;
192 self.model = self.mdl;
193 self.solid = SOLID_BSP;
196 self.nextthink = time + 0.2;
200 // reset objectives, toggle spawnpoints, reset triggers, ...
201 void vehicles_clearreturn(entity veh);
202 void vehicles_spawn();
203 void assault_new_round()
205 //bprint("ASSAULT: new round\n");
207 // Eject players from vehicles
213 WITH(entity, self, e, vehicles_exit(VHEF_RELEASE));
217 for (entity e_ = findchainflags(vehicle_flags, VHF_ISVEHICLE); e_; e_ = e_.chain)
220 vehicles_clearreturn(self);
227 self.winning = self.winning + 1;
229 // swap attacker/defender roles
230 if(assault_attacker_team == NUM_TEAM_1)
231 assault_attacker_team = NUM_TEAM_2;
233 assault_attacker_team = NUM_TEAM_1;
236 for(ent = world; (ent = nextent(ent)); )
238 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
240 if(ent.team_saved == NUM_TEAM_1)
241 ent.team_saved = NUM_TEAM_2;
242 else if(ent.team_saved == NUM_TEAM_2)
243 ent.team_saved = NUM_TEAM_1;
247 // reset the level with a countdown
248 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
249 ReadyRestart_force(); // sets game_starttime
253 spawnfunc(info_player_attacker)
255 if (!g_assault) { remove(self); return; }
257 self.team = NUM_TEAM_1; // red, gets swapped every round
258 spawnfunc_info_player_deathmatch(this);
261 spawnfunc(info_player_defender)
263 if (!g_assault) { remove(self); return; }
265 self.team = NUM_TEAM_2; // blue, gets swapped every round
266 spawnfunc_info_player_deathmatch(this);
269 spawnfunc(target_objective)
271 if (!g_assault) { remove(self); return; }
273 self.classname = "target_objective";
274 self.use = assault_objective_use;
275 assault_objective_reset();
276 self.reset = assault_objective_reset;
277 self.spawn_evalfunc = target_objective_spawn_evalfunc;
280 spawnfunc(target_objective_decrease)
282 if (!g_assault) { remove(self); return; }
284 self.classname = "target_objective_decrease";
289 self.use = assault_objective_decrease_use;
290 self.health = ASSAULT_VALUE_INACTIVE;
291 self.max_health = ASSAULT_VALUE_INACTIVE;
294 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
297 // destructible walls that can be used to trigger target_objective_decrease
298 spawnfunc(func_breakable);
299 spawnfunc(func_assault_destructible)
301 if (!g_assault) { remove(self); return; }
304 self.classname = "func_assault_destructible";
306 if(assault_attacker_team == NUM_TEAM_1)
307 self.team = NUM_TEAM_2;
309 self.team = NUM_TEAM_1;
311 spawnfunc_func_breakable(this);
314 spawnfunc(func_assault_wall)
316 if (!g_assault) { remove(self); return; }
318 self.classname = "func_assault_wall";
319 self.mdl = self.model;
320 _setmodel(self, self.mdl);
321 self.solid = SOLID_BSP;
322 self.think = assault_wall_think;
323 self.nextthink = time;
324 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
327 spawnfunc(target_assault_roundend)
329 if (!g_assault) { remove(self); return; }
331 self.winning = 0; // round not yet won by attackers
332 self.classname = "target_assault_roundend";
333 self.use = target_assault_roundend_use;
334 self.cnt = 0; // first round
335 self.reset = target_assault_roundend_reset;
338 spawnfunc(target_assault_roundstart)
340 if (!g_assault) { remove(self); return; }
342 assault_attacker_team = NUM_TEAM_1;
343 self.classname = "target_assault_roundstart";
344 self.use = assault_roundstart_use;
345 self.reset2 = assault_roundstart_use;
346 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
350 void havocbot_goalrating_ast_targets(float ratingscale)
352 entity ad, best, wp, tod;
353 float radius, found, bestvalue;
356 ad = findchain(classname, "func_assault_destructible");
358 for (; ad; ad = ad.chain)
367 for(tod = world; (tod = find(tod, targetname, ad.target)); )
369 if(tod.classname == "target_objective_decrease")
371 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
373 // dprint(etos(ad),"\n");
382 /// dprint("target not found\n");
385 /// dprint("target #", etos(ad), " found\n");
388 p = 0.5 * (ad.absmin + ad.absmax);
389 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
390 // te_knightspike(p);
391 // te_lightning2(world, '0 0 0', p);
393 // Find and rate waypoints around it
396 bestvalue = 99999999999;
397 for(radius=0; radius<1500 && !found; radius+=500)
399 for(wp=findradius(p, radius); wp; wp=wp.chain)
401 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
402 if(wp.classname=="waypoint")
403 if(checkpvs(wp.origin, ad))
417 /// dprint("waypoints around target were found\n");
418 // te_lightning2(world, '0 0 0', best.origin);
419 // te_knightspike(best.origin);
421 navigation_routerating(best, ratingscale, 4000);
424 self.havocbot_attack_time = 0;
426 if(checkpvs(self.view_ofs,ad))
427 if(checkpvs(self.view_ofs,best))
429 // dprint("increasing attack time for this target\n");
430 self.havocbot_attack_time = time + 2;
436 void havocbot_role_ast_offense()
438 if(self.deadflag != DEAD_NO)
440 self.havocbot_attack_time = 0;
441 havocbot_ast_reset_role(self);
445 // Set the role timeout if necessary
446 if (!self.havocbot_role_timeout)
447 self.havocbot_role_timeout = time + 120;
449 if (time > self.havocbot_role_timeout)
451 havocbot_ast_reset_role(self);
455 if(self.havocbot_attack_time>time)
458 if (self.bot_strategytime < time)
460 navigation_goalrating_start();
461 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
462 havocbot_goalrating_ast_targets(20000);
463 havocbot_goalrating_items(15000, self.origin, 10000);
464 navigation_goalrating_end();
466 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
470 void havocbot_role_ast_defense()
472 if(self.deadflag != DEAD_NO)
474 self.havocbot_attack_time = 0;
475 havocbot_ast_reset_role(self);
479 // Set the role timeout if necessary
480 if (!self.havocbot_role_timeout)
481 self.havocbot_role_timeout = time + 120;
483 if (time > self.havocbot_role_timeout)
485 havocbot_ast_reset_role(self);
489 if(self.havocbot_attack_time>time)
492 if (self.bot_strategytime < time)
494 navigation_goalrating_start();
495 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
496 havocbot_goalrating_ast_targets(20000);
497 havocbot_goalrating_items(15000, self.origin, 10000);
498 navigation_goalrating_end();
500 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
504 void havocbot_role_ast_setrole(entity bot, float role)
508 case HAVOCBOT_AST_ROLE_DEFENSE:
509 bot.havocbot_role = havocbot_role_ast_defense;
510 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
511 bot.havocbot_role_timeout = 0;
513 case HAVOCBOT_AST_ROLE_OFFENSE:
514 bot.havocbot_role = havocbot_role_ast_offense;
515 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
516 bot.havocbot_role_timeout = 0;
521 void havocbot_ast_reset_role(entity bot)
523 if(self.deadflag != DEAD_NO)
526 if(bot.team == assault_attacker_team)
527 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
529 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
533 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
535 if(self.team == assault_attacker_team)
536 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
538 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
543 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
545 if(!self.team || self.team == MAX_SHOT_DISTANCE)
546 self.team = 5; // this gets reversed when match starts?
551 MUTATOR_HOOKFUNCTION(as, VehicleSpawn)
553 self.nextthink = time + 0.5;
558 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
560 havocbot_ast_reset_role(self);
564 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
566 return (frag_victim.classname == "func_assault_destructible");
569 MUTATOR_HOOKFUNCTION(as, GetTeamCount)
571 // assault always has 2 teams
576 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
578 ret_float = WinningCondition_Assault();
582 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
584 // no assault warmups
590 void assault_ScoreRules()
592 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
593 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
594 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
595 ScoreRules_basics_end();
598 REGISTER_MUTATOR(as, g_assault)
601 have_team_spawns = -1; // request team spawns
605 if(time > 1) // game loads at time 1
606 error("This is a game type and it cannot be added at runtime.");
607 assault_ScoreRules();
610 MUTATOR_ONROLLBACK_OR_REMOVE
612 // we actually cannot roll back assault_Initialize here
613 // BUT: we don't need to! If this gets called, adding always
619 LOG_INFO("This is a game type and it cannot be removed at runtime.");