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()
175 //(Re)spawn all turrets
177 ent = find(world, classname, "turret_main");
180 if(ent.team == NUM_TEAM_1)
181 ent.team = NUM_TEAM_2;
183 ent.team = NUM_TEAM_1;
187 // Dubbles as teamchange
190 ent = find(ent, classname, "turret_main");
195 void assault_wall_think()
197 if(self.enemy.health < 0)
200 self.solid = SOLID_NOT;
204 self.model = self.mdl;
205 self.solid = SOLID_BSP;
208 self.nextthink = time + 0.2;
212 // reset objectives, toggle spawnpoints, reset triggers, ...
213 void assault_new_round()
216 self.winning = self.winning + 1;
218 // swap attacker/defender roles
219 if(assault_attacker_team == NUM_TEAM_1)
220 assault_attacker_team = NUM_TEAM_2;
222 assault_attacker_team = NUM_TEAM_1;
225 for(ent = world; (ent = nextent(ent)); )
227 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
229 if(ent.team_saved == NUM_TEAM_1)
230 ent.team_saved = NUM_TEAM_2;
231 else if(ent.team_saved == NUM_TEAM_2)
232 ent.team_saved = NUM_TEAM_1;
236 // reset the level with a countdown
237 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
238 ReadyRestart_force(); // sets game_starttime
242 void spawnfunc_info_player_attacker()
244 if (!g_assault) { remove(self); return; }
246 self.team = NUM_TEAM_1; // red, gets swapped every round
247 spawnfunc_info_player_deathmatch();
250 void spawnfunc_info_player_defender()
252 if (!g_assault) { remove(self); return; }
254 self.team = NUM_TEAM_2; // blue, gets swapped every round
255 spawnfunc_info_player_deathmatch();
258 void spawnfunc_target_objective()
260 if (!g_assault) { remove(self); return; }
262 self.classname = "target_objective";
263 self.use = assault_objective_use;
264 assault_objective_reset();
265 self.reset = assault_objective_reset;
266 self.spawn_evalfunc = target_objective_spawn_evalfunc;
269 void spawnfunc_target_objective_decrease()
271 if (!g_assault) { remove(self); return; }
273 self.classname = "target_objective_decrease";
278 self.use = assault_objective_decrease_use;
279 self.health = ASSAULT_VALUE_INACTIVE;
280 self.max_health = ASSAULT_VALUE_INACTIVE;
283 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
286 // destructible walls that can be used to trigger target_objective_decrease
287 void spawnfunc_func_assault_destructible()
289 if (!g_assault) { remove(self); return; }
292 self.classname = "func_assault_destructible";
294 if(assault_attacker_team == NUM_TEAM_1)
295 self.team = NUM_TEAM_2;
297 self.team = NUM_TEAM_1;
299 spawnfunc_func_breakable();
302 void spawnfunc_func_assault_wall()
304 if (!g_assault) { remove(self); return; }
306 self.classname = "func_assault_wall";
307 self.mdl = self.model;
308 setmodel(self, self.mdl);
309 self.solid = SOLID_BSP;
310 self.think = assault_wall_think;
311 self.nextthink = time;
312 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
315 void spawnfunc_target_assault_roundend()
317 if (!g_assault) { remove(self); return; }
319 self.winning = 0; // round not yet won by attackers
320 self.classname = "target_assault_roundend";
321 self.use = target_assault_roundend_use;
322 self.cnt = 0; // first round
323 self.reset = target_assault_roundend_reset;
326 void spawnfunc_target_assault_roundstart()
328 if (!g_assault) { remove(self); return; }
330 assault_attacker_team = NUM_TEAM_1;
331 self.classname = "target_assault_roundstart";
332 self.use = assault_roundstart_use;
333 self.reset2 = assault_roundstart_use;
334 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
338 void havocbot_goalrating_ast_targets(float ratingscale)
340 entity ad, best, wp, tod;
341 float radius, found, bestvalue;
344 ad = findchain(classname, "func_assault_destructible");
346 for (; ad; ad = ad.chain)
355 for(tod = world; (tod = find(tod, targetname, ad.target)); )
357 if(tod.classname == "target_objective_decrease")
359 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
361 // dprint(etos(ad),"\n");
370 /// dprint("target not found\n");
373 /// dprint("target #", etos(ad), " found\n");
376 p = 0.5 * (ad.absmin + ad.absmax);
377 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
378 // te_knightspike(p);
379 // te_lightning2(world, '0 0 0', p);
381 // Find and rate waypoints around it
384 bestvalue = 99999999999;
385 for(radius=0; radius<1500 && !found; radius+=500)
387 for(wp=findradius(p, radius); wp; wp=wp.chain)
389 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
390 if(wp.classname=="waypoint")
391 if(checkpvs(wp.origin, ad))
405 /// dprint("waypoints around target were found\n");
406 // te_lightning2(world, '0 0 0', best.origin);
407 // te_knightspike(best.origin);
409 navigation_routerating(best, ratingscale, 4000);
412 self.havocbot_attack_time = 0;
414 if(checkpvs(self.view_ofs,ad))
415 if(checkpvs(self.view_ofs,best))
417 // dprint("increasing attack time for this target\n");
418 self.havocbot_attack_time = time + 2;
424 void havocbot_role_ast_offense()
426 if(self.deadflag != DEAD_NO)
428 self.havocbot_attack_time = 0;
429 havocbot_ast_reset_role(self);
433 // Set the role timeout if necessary
434 if (!self.havocbot_role_timeout)
435 self.havocbot_role_timeout = time + 120;
437 if (time > self.havocbot_role_timeout)
439 havocbot_ast_reset_role(self);
443 if(self.havocbot_attack_time>time)
446 if (self.bot_strategytime < time)
448 navigation_goalrating_start();
449 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
450 havocbot_goalrating_ast_targets(20000);
451 havocbot_goalrating_items(15000, self.origin, 10000);
452 navigation_goalrating_end();
454 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
458 void havocbot_role_ast_defense()
460 if(self.deadflag != DEAD_NO)
462 self.havocbot_attack_time = 0;
463 havocbot_ast_reset_role(self);
467 // Set the role timeout if necessary
468 if (!self.havocbot_role_timeout)
469 self.havocbot_role_timeout = time + 120;
471 if (time > self.havocbot_role_timeout)
473 havocbot_ast_reset_role(self);
477 if(self.havocbot_attack_time>time)
480 if (self.bot_strategytime < time)
482 navigation_goalrating_start();
483 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
484 havocbot_goalrating_ast_targets(20000);
485 havocbot_goalrating_items(15000, self.origin, 10000);
486 navigation_goalrating_end();
488 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
492 void havocbot_role_ast_setrole(entity bot, float role)
496 case HAVOCBOT_AST_ROLE_DEFENSE:
497 bot.havocbot_role = havocbot_role_ast_defense;
498 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
499 bot.havocbot_role_timeout = 0;
501 case HAVOCBOT_AST_ROLE_OFFENSE:
502 bot.havocbot_role = havocbot_role_ast_offense;
503 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
504 bot.havocbot_role_timeout = 0;
509 void havocbot_ast_reset_role(entity bot)
511 if(self.deadflag != DEAD_NO)
514 if(bot.team == assault_attacker_team)
515 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
517 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
521 MUTATOR_HOOKFUNCTION(assault_PlayerSpawn)
523 if(self.team == assault_attacker_team)
524 centerprint(self, "You are attacking!");
526 centerprint(self, "You are defending!");
531 MUTATOR_HOOKFUNCTION(assault_TurretSpawn)
539 MUTATOR_HOOKFUNCTION(assault_VehicleSpawn)
541 self.nextthink = time + 0.5;
546 MUTATOR_HOOKFUNCTION(assault_BotRoles)
548 havocbot_ast_reset_role(self);
553 void assault_ScoreRules()
555 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, TRUE);
556 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
557 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
558 ScoreRules_basics_end();
561 MUTATOR_DEFINITION(gamemode_assault)
563 MUTATOR_HOOK(PlayerSpawn, assault_PlayerSpawn, CBC_ORDER_ANY);
564 MUTATOR_HOOK(TurretSpawn, assault_TurretSpawn, CBC_ORDER_ANY);
565 MUTATOR_HOOK(VehicleSpawn, assault_VehicleSpawn, CBC_ORDER_ANY);
566 MUTATOR_HOOK(HavocBot_ChooseRule, assault_BotRoles, CBC_ORDER_ANY);
570 if(time > 1) // game loads at time 1
571 error("This is a game type and it cannot be added at runtime.");
572 assault_ScoreRules();
575 MUTATOR_ONROLLBACK_OR_REMOVE
577 // we actually cannot roll back assault_Initialize here
578 // BUT: we don't need to! If this gets called, adding always
584 print("This is a game type and it cannot be removed at runtime.");