2 void assault_objective_use()
6 //print("^2Activated objective ", self.targetname, "=", etos(self), "\n");
7 //print("Activator is ", activator.classname, "\n");
12 for(self = world; (self = find(self, target, oldself.targetname)); )
14 if(self.classname == "target_objective_decrease")
15 target_objective_decrease_activate();
21 vector target_objective_spawn_evalfunc(entity player, entity spot, vector current)
23 if(self.health < 0 || self.health >= ASSAULT_VALUE_INACTIVE)
28 // reset this objective. Used when spawning an objective
29 // and when a new round starts
30 void assault_objective_reset()
32 self.health = ASSAULT_VALUE_INACTIVE;
35 // decrease the health of targeted objectives
36 void assault_objective_decrease_use()
38 if(activator.team != assault_attacker_team)
40 // wrong team triggered decrease
44 if(other.assault_sprite)
46 WaypointSprite_Disown(other.assault_sprite, waypointsprite_deadlifetime);
47 if(other.classname == "func_assault_destructible")
51 return; // already activated! cannot activate again!
53 if(self.enemy.health < ASSAULT_VALUE_INACTIVE)
55 if(self.enemy.health - self.dmg > 0.5)
57 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.dmg);
58 self.enemy.health = self.enemy.health - self.dmg;
62 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.enemy.health);
63 PlayerTeamScore_Add(activator, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
64 self.enemy.health = -1;
66 entity oldself, oldactivator;
74 FOR_EACH_PLAYER(player)
76 s = strcat(self.message, "\n");
77 centerprint(player, s);
81 oldactivator = activator;
84 activator = oldactivator;
90 void assault_setenemytoobjective()
93 for(objective = world; (objective = find(objective, targetname, self.target)); )
95 if(objective.classname == "target_objective")
97 if(self.enemy == world)
98 self.enemy = objective;
100 objerror("more than one objective as target - fix the map!");
105 if(self.enemy == world)
106 objerror("no objective as target - fix the map!");
109 float assault_decreaser_sprite_visible(entity e)
113 decreaser = self.assault_decreaser;
115 if(decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
121 void target_objective_decrease_activate()
125 for(ent = world; (ent = find(ent, target, self.targetname)); )
127 if(ent.assault_sprite != world)
129 WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
130 if(ent.classname == "func_assault_destructible")
134 spr = WaypointSprite_SpawnFixed("<placeholder>", 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE, '1 0.5 0');
135 spr.assault_decreaser = self;
136 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
137 spr.classname = "sprite_waypoint";
138 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
139 if(ent.classname == "func_assault_destructible")
141 WaypointSprite_UpdateSprites(spr, "as-defend", "as-destroy", "as-destroy");
142 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
143 WaypointSprite_UpdateHealth(spr, ent.health);
147 WaypointSprite_UpdateSprites(spr, "as-defend", "as-push", "as-push");
151 void target_objective_decrease_findtarget()
153 assault_setenemytoobjective();
156 void target_assault_roundend_reset()
158 //print("round end reset\n");
159 self.cnt = self.cnt + 1; // up round counter
160 self.winning = 0; // up round
163 void target_assault_roundend_use()
165 self.winning = 1; // round has been won by attackers
168 void assault_roundstart_use()
173 #ifdef TTURRETS_ENABLED
176 //(Re)spawn all turrets
178 ent = find(world, classname, "turret_main");
181 if(ent.team == COLOR_TEAM1)
182 ent.team = COLOR_TEAM2;
184 ent.team = COLOR_TEAM1;
188 // Dubbles as teamchange
189 turret_stdproc_respawn();
191 ent = find(ent, classname, "turret_main");
197 void assault_wall_think()
199 if(self.enemy.health < 0)
202 self.solid = SOLID_NOT;
206 self.model = self.mdl;
207 self.solid = SOLID_BSP;
210 self.nextthink = time + 0.2;
214 // reset objectives, toggle spawnpoints, reset triggers, ...
215 void vehicles_clearrturn();
216 void vehicles_spawn();
217 void assault_new_round()
220 //bprint("ASSAULT: new round\n");
223 // Eject players from vehicles
224 FOR_EACH_PLAYER(self)
227 vehicles_exit(VHEF_RELESE);
230 self = findchainflags(vehicle_flags, VHF_ISVEHICLE);
233 vehicles_clearrturn();
241 self.winning = self.winning + 1;
243 // swap attacker/defender roles
244 if(assault_attacker_team == COLOR_TEAM1) {
245 assault_attacker_team = COLOR_TEAM2;
247 assault_attacker_team = COLOR_TEAM1;
252 for(ent = world; (ent = nextent(ent)); )
254 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
256 if(ent.team_saved == COLOR_TEAM1)
257 ent.team_saved = COLOR_TEAM2;
258 else if(ent.team_saved == COLOR_TEAM2)
259 ent.team_saved = COLOR_TEAM1;
263 // reset the level with a countdown
264 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
265 ReadyRestart_force(); // sets game_starttime
269 void spawnfunc_info_player_attacker()
276 self.team = COLOR_TEAM1; // red, gets swapped every round
277 spawnfunc_info_player_deathmatch();
280 void spawnfunc_info_player_defender()
287 self.team = COLOR_TEAM2; // blue, gets swapped every round
288 spawnfunc_info_player_deathmatch();
291 void spawnfunc_target_objective()
298 self.classname = "target_objective";
299 self.use = assault_objective_use;
300 assault_objective_reset();
301 self.reset = assault_objective_reset;
302 self.spawn_evalfunc = target_objective_spawn_evalfunc;
305 void spawnfunc_target_objective_decrease()
313 self.classname = "target_objective_decrease";
318 self.use = assault_objective_decrease_use;
319 self.health = ASSAULT_VALUE_INACTIVE;
320 self.max_health = ASSAULT_VALUE_INACTIVE;
323 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
326 // destructible walls that can be used to trigger target_objective_decrease
327 void spawnfunc_func_assault_destructible()
335 self.classname = "func_assault_destructible";
337 if(assault_attacker_team == COLOR_TEAM1)
338 self.team = COLOR_TEAM2;
340 self.team = COLOR_TEAM1;
342 spawnfunc_func_breakable();
345 void spawnfunc_func_assault_wall()
352 self.classname = "func_assault_wall";
353 self.mdl = self.model;
354 setmodel(self, self.mdl);
355 self.solid = SOLID_BSP;
356 self.think = assault_wall_think;
357 self.nextthink = time;
358 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
361 void spawnfunc_target_assault_roundend()
368 self.winning = 0; // round not yet won by attackers
369 self.classname = "target_assault_roundend";
370 self.use = target_assault_roundend_use;
371 self.cnt = 0; // first round
372 self.reset = target_assault_roundend_reset;
375 void spawnfunc_target_assault_roundstart()
382 assault_attacker_team = COLOR_TEAM1;
383 self.classname = "target_assault_roundstart";
384 self.use = assault_roundstart_use;
385 self.reset2 = assault_roundstart_use;
386 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
390 void havocbot_goalrating_ast_targets(float ratingscale)
392 entity ad, best, wp, tod;
393 float radius, found, bestvalue;
396 ad = findchain(classname, "func_assault_destructible");
398 for (; ad; ad = ad.chain)
403 if not(ad.bot_attack)
407 for(tod = world; (tod = find(tod, targetname, ad.target)); )
409 if(tod.classname == "target_objective_decrease")
411 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
413 // dprint(etos(ad),"\n");
422 /// dprint("target not found\n");
425 /// dprint("target #", etos(ad), " found\n");
428 p = 0.5 * (ad.absmin + ad.absmax);
429 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
430 // te_knightspike(p);
431 // te_lightning2(world, '0 0 0', p);
433 // Find and rate waypoints around it
436 bestvalue = 99999999999;
437 for(radius=0; radius<1500 && !found; radius+=500)
439 for(wp=findradius(p, radius); wp; wp=wp.chain)
441 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
442 if(wp.classname=="waypoint")
443 if(checkpvs(wp.origin, ad))
457 /// dprint("waypoints around target were found\n");
458 // te_lightning2(world, '0 0 0', best.origin);
459 // te_knightspike(best.origin);
461 navigation_routerating(best, ratingscale, 4000);
464 self.havocbot_attack_time = 0;
466 if(checkpvs(self.view_ofs,ad))
467 if(checkpvs(self.view_ofs,best))
469 // dprint("increasing attack time for this target\n");
470 self.havocbot_attack_time = time + 2;
476 void havocbot_role_ast_offense()
478 if(self.deadflag != DEAD_NO)
480 self.havocbot_attack_time = 0;
481 havocbot_ast_reset_role(self);
485 // Set the role timeout if necessary
486 if (!self.havocbot_role_timeout)
487 self.havocbot_role_timeout = time + 120;
489 if (time > self.havocbot_role_timeout)
491 havocbot_ast_reset_role(self);
495 if(self.havocbot_attack_time>time)
498 if (self.bot_strategytime < time)
500 navigation_goalrating_start();
501 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
502 havocbot_goalrating_ast_targets(20000);
503 havocbot_goalrating_items(15000, self.origin, 10000);
504 navigation_goalrating_end();
506 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
510 void havocbot_role_ast_defense()
512 if(self.deadflag != DEAD_NO)
514 self.havocbot_attack_time = 0;
515 havocbot_ast_reset_role(self);
519 // Set the role timeout if necessary
520 if (!self.havocbot_role_timeout)
521 self.havocbot_role_timeout = time + 120;
523 if (time > self.havocbot_role_timeout)
525 havocbot_ast_reset_role(self);
529 if(self.havocbot_attack_time>time)
532 if (self.bot_strategytime < time)
534 navigation_goalrating_start();
535 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
536 havocbot_goalrating_ast_targets(20000);
537 havocbot_goalrating_items(15000, self.origin, 10000);
538 navigation_goalrating_end();
540 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
544 void havocbot_role_ast_setrole(entity bot, float role)
548 case HAVOCBOT_AST_ROLE_DEFENSE:
549 bot.havocbot_role = havocbot_role_ast_defense;
550 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
551 bot.havocbot_role_timeout = 0;
553 case HAVOCBOT_AST_ROLE_OFFENSE:
554 bot.havocbot_role = havocbot_role_ast_offense;
555 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
556 bot.havocbot_role_timeout = 0;
561 void havocbot_ast_reset_role(entity bot)
563 if(self.deadflag != DEAD_NO)
566 if(bot.team == assault_attacker_team)
567 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
569 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
572 void havocbot_chooserole_ast()
574 havocbot_ast_reset_role(self);
578 MUTATOR_HOOKFUNCTION(assault_PlayerSpawn)
580 if(self.team == assault_attacker_team)
581 centerprint(self, "You are attacking!");
583 centerprint(self, "You are defending!");
588 MUTATOR_HOOKFUNCTION(assault_TurretSpawn)
596 MUTATOR_HOOKFUNCTION(assault_VehicleSpawn)
598 self.nextthink = time + 0.5;
603 MUTATOR_HOOKFUNCTION(assault_BotRoles)
605 havocbot_chooserole_ast();
610 void assault_ScoreRules()
612 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, TRUE);
613 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
614 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
615 ScoreRules_basics_end();
618 MUTATOR_DEFINITION(gamemode_assault)
620 MUTATOR_HOOK(PlayerSpawn, assault_PlayerSpawn, CBC_ORDER_ANY);
621 MUTATOR_HOOK(TurretSpawn, assault_TurretSpawn, CBC_ORDER_ANY);
622 MUTATOR_HOOK(VehicleSpawn, assault_VehicleSpawn, CBC_ORDER_ANY);
623 MUTATOR_HOOK(HavocBot_ChooseRule, assault_BotRoles, CBC_ORDER_ANY);
627 if(time > 1) // game loads at time 1
628 error("This is a game type and it cannot be added at runtime.");
629 assault_ScoreRules();
632 MUTATOR_ONROLLBACK_OR_REMOVE
634 // we actually cannot roll back assault_Initialize here
635 // BUT: we don't need to! If this gets called, adding always
641 print("This is a game type and it cannot be removed at runtime.");