1 #include "../../common/triggers/subs.qh"
4 void assault_objective_use()
8 //print("^2Activated objective ", self.targetname, "=", etos(self), "\n");
9 //print("Activator is ", activator.classname, "\n");
14 for(self = world; (self = find(self, target, oldself.targetname)); )
16 if(self.classname == "target_objective_decrease")
17 target_objective_decrease_activate();
23 vector target_objective_spawn_evalfunc(entity player, entity spot, vector current)
25 if(self.health < 0 || self.health >= ASSAULT_VALUE_INACTIVE)
30 // reset this objective. Used when spawning an objective
31 // and when a new round starts
32 void assault_objective_reset()
34 self.health = ASSAULT_VALUE_INACTIVE;
37 // decrease the health of targeted objectives
38 void assault_objective_decrease_use()
40 if(activator.team != assault_attacker_team)
42 // wrong team triggered decrease
46 if(other.assault_sprite)
48 WaypointSprite_Disown(other.assault_sprite, waypointsprite_deadlifetime);
49 if(other.classname == "func_assault_destructible")
53 return; // already activated! cannot activate again!
55 if(self.enemy.health < ASSAULT_VALUE_INACTIVE)
57 if(self.enemy.health - self.dmg > 0.5)
59 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.dmg);
60 self.enemy.health = self.enemy.health - self.dmg;
64 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.enemy.health);
65 PlayerTeamScore_Add(activator, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
66 self.enemy.health = -1;
68 entity oldself, oldactivator, head;
74 centerprint(head, self.message);
76 oldactivator = activator;
79 activator = oldactivator;
85 void assault_setenemytoobjective()
88 for(objective = world; (objective = find(objective, targetname, self.target)); )
90 if(objective.classname == "target_objective")
92 if(self.enemy == world)
93 self.enemy = objective;
95 objerror("more than one objective as target - fix the map!");
100 if(self.enemy == world)
101 objerror("no objective as target - fix the map!");
104 float assault_decreaser_sprite_visible(entity e)
108 decreaser = self.assault_decreaser;
110 if(decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
116 void target_objective_decrease_activate()
120 for(ent = world; (ent = find(ent, target, self.targetname)); )
122 if(ent.assault_sprite != world)
124 WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
125 if(ent.classname == "func_assault_destructible")
129 spr = WaypointSprite_SpawnFixed("<placeholder>", 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE, '1 0.5 0');
130 spr.assault_decreaser = self;
131 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
132 spr.classname = "sprite_waypoint";
133 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
134 if(ent.classname == "func_assault_destructible")
136 WaypointSprite_UpdateSprites(spr, "as-defend", "as-destroy", "as-destroy");
137 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
138 WaypointSprite_UpdateHealth(spr, ent.health);
142 WaypointSprite_UpdateSprites(spr, "as-defend", "as-push", "as-push");
146 void target_objective_decrease_findtarget()
148 assault_setenemytoobjective();
151 void target_assault_roundend_reset()
153 //print("round end reset\n");
154 self.cnt = self.cnt + 1; // up round counter
155 self.winning = 0; // up round
158 void target_assault_roundend_use()
160 self.winning = 1; // round has been won by attackers
163 void assault_roundstart_use()
168 #ifdef TTURRETS_ENABLED
171 //(Re)spawn all turrets
173 ent = find(world, classname, "turret_main");
176 if(ent.team == NUM_TEAM_1)
177 ent.team = NUM_TEAM_2;
179 ent.team = NUM_TEAM_1;
183 // Dubbles as teamchange
184 turret_stdproc_respawn();
186 ent = find(ent, classname, "turret_main");
192 void assault_wall_think()
194 if(self.enemy.health < 0)
197 self.solid = SOLID_NOT;
201 self.model = self.mdl;
202 self.solid = SOLID_BSP;
205 self.nextthink = time + 0.2;
209 // reset objectives, toggle spawnpoints, reset triggers, ...
210 void assault_new_round()
213 self.winning = self.winning + 1;
215 // swap attacker/defender roles
216 if(assault_attacker_team == NUM_TEAM_1)
217 assault_attacker_team = NUM_TEAM_2;
219 assault_attacker_team = NUM_TEAM_1;
222 for(ent = world; (ent = nextent(ent)); )
224 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
226 if(ent.team_saved == NUM_TEAM_1)
227 ent.team_saved = NUM_TEAM_2;
228 else if(ent.team_saved == NUM_TEAM_2)
229 ent.team_saved = NUM_TEAM_1;
233 // reset the level with a countdown
234 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
235 ReadyRestart_force(); // sets game_starttime
239 void spawnfunc_info_player_attacker()
241 if (!g_assault) { remove(self); return; }
243 self.team = NUM_TEAM_1; // red, gets swapped every round
244 spawnfunc_info_player_deathmatch();
247 void spawnfunc_info_player_defender()
249 if (!g_assault) { remove(self); return; }
251 self.team = NUM_TEAM_2; // blue, gets swapped every round
252 spawnfunc_info_player_deathmatch();
255 void spawnfunc_target_objective()
257 if (!g_assault) { remove(self); return; }
259 self.classname = "target_objective";
260 self.use = assault_objective_use;
261 assault_objective_reset();
262 self.reset = assault_objective_reset;
263 self.spawn_evalfunc = target_objective_spawn_evalfunc;
266 void spawnfunc_target_objective_decrease()
268 if (!g_assault) { remove(self); return; }
270 self.classname = "target_objective_decrease";
275 self.use = assault_objective_decrease_use;
276 self.health = ASSAULT_VALUE_INACTIVE;
277 self.max_health = ASSAULT_VALUE_INACTIVE;
280 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
283 // destructible walls that can be used to trigger target_objective_decrease
284 void spawnfunc_func_assault_destructible()
286 if (!g_assault) { remove(self); return; }
289 self.classname = "func_assault_destructible";
291 if(assault_attacker_team == NUM_TEAM_1)
292 self.team = NUM_TEAM_2;
294 self.team = NUM_TEAM_1;
296 spawnfunc_func_breakable();
299 void spawnfunc_func_assault_wall()
301 if (!g_assault) { remove(self); return; }
303 self.classname = "func_assault_wall";
304 self.mdl = self.model;
305 setmodel(self, self.mdl);
306 self.solid = SOLID_BSP;
307 self.think = assault_wall_think;
308 self.nextthink = time;
309 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
312 void spawnfunc_target_assault_roundend()
314 if (!g_assault) { remove(self); return; }
316 self.winning = 0; // round not yet won by attackers
317 self.classname = "target_assault_roundend";
318 self.use = target_assault_roundend_use;
319 self.cnt = 0; // first round
320 self.reset = target_assault_roundend_reset;
323 void spawnfunc_target_assault_roundstart()
325 if (!g_assault) { remove(self); return; }
327 assault_attacker_team = NUM_TEAM_1;
328 self.classname = "target_assault_roundstart";
329 self.use = assault_roundstart_use;
330 self.reset2 = assault_roundstart_use;
331 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
335 void havocbot_goalrating_ast_targets(float ratingscale)
337 entity ad, best, wp, tod;
338 float radius, found, bestvalue;
341 ad = findchain(classname, "func_assault_destructible");
343 for (; ad; ad = ad.chain)
352 for(tod = world; (tod = find(tod, targetname, ad.target)); )
354 if(tod.classname == "target_objective_decrease")
356 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
358 // dprint(etos(ad),"\n");
367 /// dprint("target not found\n");
370 /// dprint("target #", etos(ad), " found\n");
373 p = 0.5 * (ad.absmin + ad.absmax);
374 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
375 // te_knightspike(p);
376 // te_lightning2(world, '0 0 0', p);
378 // Find and rate waypoints around it
381 bestvalue = 99999999999;
382 for(radius=0; radius<1500 && !found; radius+=500)
384 for(wp=findradius(p, radius); wp; wp=wp.chain)
386 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
387 if(wp.classname=="waypoint")
388 if(checkpvs(wp.origin, ad))
402 /// dprint("waypoints around target were found\n");
403 // te_lightning2(world, '0 0 0', best.origin);
404 // te_knightspike(best.origin);
406 navigation_routerating(best, ratingscale, 4000);
409 self.havocbot_attack_time = 0;
411 if(checkpvs(self.view_ofs,ad))
412 if(checkpvs(self.view_ofs,best))
414 // dprint("increasing attack time for this target\n");
415 self.havocbot_attack_time = time + 2;
421 void havocbot_role_ast_offense()
423 if(self.deadflag != DEAD_NO)
425 self.havocbot_attack_time = 0;
426 havocbot_ast_reset_role(self);
430 // Set the role timeout if necessary
431 if (!self.havocbot_role_timeout)
432 self.havocbot_role_timeout = time + 120;
434 if (time > self.havocbot_role_timeout)
436 havocbot_ast_reset_role(self);
440 if(self.havocbot_attack_time>time)
443 if (self.bot_strategytime < time)
445 navigation_goalrating_start();
446 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
447 havocbot_goalrating_ast_targets(20000);
448 havocbot_goalrating_items(15000, self.origin, 10000);
449 navigation_goalrating_end();
451 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
455 void havocbot_role_ast_defense()
457 if(self.deadflag != DEAD_NO)
459 self.havocbot_attack_time = 0;
460 havocbot_ast_reset_role(self);
464 // Set the role timeout if necessary
465 if (!self.havocbot_role_timeout)
466 self.havocbot_role_timeout = time + 120;
468 if (time > self.havocbot_role_timeout)
470 havocbot_ast_reset_role(self);
474 if(self.havocbot_attack_time>time)
477 if (self.bot_strategytime < time)
479 navigation_goalrating_start();
480 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
481 havocbot_goalrating_ast_targets(20000);
482 havocbot_goalrating_items(15000, self.origin, 10000);
483 navigation_goalrating_end();
485 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
489 void havocbot_role_ast_setrole(entity bot, float role)
493 case HAVOCBOT_AST_ROLE_DEFENSE:
494 bot.havocbot_role = havocbot_role_ast_defense;
495 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
496 bot.havocbot_role_timeout = 0;
498 case HAVOCBOT_AST_ROLE_OFFENSE:
499 bot.havocbot_role = havocbot_role_ast_offense;
500 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
501 bot.havocbot_role_timeout = 0;
506 void havocbot_ast_reset_role(entity bot)
508 if(self.deadflag != DEAD_NO)
511 if(bot.team == assault_attacker_team)
512 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
514 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
518 MUTATOR_HOOKFUNCTION(assault_PlayerSpawn)
520 if(self.team == assault_attacker_team)
521 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
523 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
528 MUTATOR_HOOKFUNCTION(assault_TurretSpawn)
536 MUTATOR_HOOKFUNCTION(assault_VehicleSpawn)
538 self.nextthink = time + 0.5;
543 MUTATOR_HOOKFUNCTION(assault_BotRoles)
545 havocbot_ast_reset_role(self);
550 void assault_ScoreRules()
552 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
553 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
554 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
555 ScoreRules_basics_end();
558 MUTATOR_DEFINITION(gamemode_assault)
560 MUTATOR_HOOK(PlayerSpawn, assault_PlayerSpawn, CBC_ORDER_ANY);
561 MUTATOR_HOOK(TurretSpawn, assault_TurretSpawn, CBC_ORDER_ANY);
562 MUTATOR_HOOK(VehicleSpawn, assault_VehicleSpawn, CBC_ORDER_ANY);
563 MUTATOR_HOOK(HavocBot_ChooseRole, assault_BotRoles, CBC_ORDER_ANY);
567 if(time > 1) // game loads at time 1
568 error("This is a game type and it cannot be added at runtime.");
569 assault_ScoreRules();
572 MUTATOR_ONROLLBACK_OR_REMOVE
574 // we actually cannot roll back assault_Initialize here
575 // BUT: we don't need to! If this gets called, adding always
581 print("This is a game type and it cannot be removed at runtime.");