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 == NUM_TEAM_1)
182 ent.team = NUM_TEAM_2;
184 ent.team = NUM_TEAM_1;
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 assault_new_round()
218 self.winning = self.winning + 1;
220 // swap attacker/defender roles
221 if(assault_attacker_team == NUM_TEAM_1)
222 assault_attacker_team = NUM_TEAM_2;
224 assault_attacker_team = NUM_TEAM_1;
227 for(ent = world; (ent = nextent(ent)); )
229 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
231 if(ent.team_saved == NUM_TEAM_1)
232 ent.team_saved = NUM_TEAM_2;
233 else if(ent.team_saved == NUM_TEAM_2)
234 ent.team_saved = NUM_TEAM_1;
238 // reset the level with a countdown
239 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
240 ReadyRestart_force(); // sets game_starttime
244 void spawnfunc_info_player_attacker()
246 if (!g_assault) { remove(self); return; }
248 self.team = NUM_TEAM_1; // red, gets swapped every round
249 spawnfunc_info_player_deathmatch();
252 void spawnfunc_info_player_defender()
254 if (!g_assault) { remove(self); return; }
256 self.team = NUM_TEAM_2; // blue, gets swapped every round
257 spawnfunc_info_player_deathmatch();
260 void spawnfunc_target_objective()
262 if (!g_assault) { remove(self); return; }
264 self.classname = "target_objective";
265 self.use = assault_objective_use;
266 assault_objective_reset();
267 self.reset = assault_objective_reset;
268 self.spawn_evalfunc = target_objective_spawn_evalfunc;
271 void spawnfunc_target_objective_decrease()
273 if (!g_assault) { remove(self); return; }
275 self.classname = "target_objective_decrease";
280 self.use = assault_objective_decrease_use;
281 self.health = ASSAULT_VALUE_INACTIVE;
282 self.max_health = ASSAULT_VALUE_INACTIVE;
285 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
288 // destructible walls that can be used to trigger target_objective_decrease
289 void spawnfunc_func_assault_destructible()
291 if (!g_assault) { remove(self); return; }
294 self.classname = "func_assault_destructible";
296 if(assault_attacker_team == NUM_TEAM_1)
297 self.team = NUM_TEAM_2;
299 self.team = NUM_TEAM_1;
301 spawnfunc_func_breakable();
304 void spawnfunc_func_assault_wall()
306 if (!g_assault) { remove(self); return; }
308 self.classname = "func_assault_wall";
309 self.mdl = self.model;
310 setmodel(self, self.mdl);
311 self.solid = SOLID_BSP;
312 self.think = assault_wall_think;
313 self.nextthink = time;
314 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
317 void spawnfunc_target_assault_roundend()
319 if (!g_assault) { remove(self); return; }
321 self.winning = 0; // round not yet won by attackers
322 self.classname = "target_assault_roundend";
323 self.use = target_assault_roundend_use;
324 self.cnt = 0; // first round
325 self.reset = target_assault_roundend_reset;
328 void spawnfunc_target_assault_roundstart()
330 if (!g_assault) { remove(self); return; }
332 assault_attacker_team = NUM_TEAM_1;
333 self.classname = "target_assault_roundstart";
334 self.use = assault_roundstart_use;
335 self.reset2 = assault_roundstart_use;
336 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
340 void havocbot_goalrating_ast_targets(float ratingscale)
342 entity ad, best, wp, tod;
343 float radius, found, bestvalue;
346 ad = findchain(classname, "func_assault_destructible");
348 for (; ad; ad = ad.chain)
357 for(tod = world; (tod = find(tod, targetname, ad.target)); )
359 if(tod.classname == "target_objective_decrease")
361 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
363 // dprint(etos(ad),"\n");
372 /// dprint("target not found\n");
375 /// dprint("target #", etos(ad), " found\n");
378 p = 0.5 * (ad.absmin + ad.absmax);
379 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
380 // te_knightspike(p);
381 // te_lightning2(world, '0 0 0', p);
383 // Find and rate waypoints around it
386 bestvalue = 99999999999;
387 for(radius=0; radius<1500 && !found; radius+=500)
389 for(wp=findradius(p, radius); wp; wp=wp.chain)
391 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
392 if(wp.classname=="waypoint")
393 if(checkpvs(wp.origin, ad))
407 /// dprint("waypoints around target were found\n");
408 // te_lightning2(world, '0 0 0', best.origin);
409 // te_knightspike(best.origin);
411 navigation_routerating(best, ratingscale, 4000);
414 self.havocbot_attack_time = 0;
416 if(checkpvs(self.view_ofs,ad))
417 if(checkpvs(self.view_ofs,best))
419 // dprint("increasing attack time for this target\n");
420 self.havocbot_attack_time = time + 2;
426 void havocbot_role_ast_offense()
428 if(self.deadflag != DEAD_NO)
430 self.havocbot_attack_time = 0;
431 havocbot_ast_reset_role(self);
435 // Set the role timeout if necessary
436 if (!self.havocbot_role_timeout)
437 self.havocbot_role_timeout = time + 120;
439 if (time > self.havocbot_role_timeout)
441 havocbot_ast_reset_role(self);
445 if(self.havocbot_attack_time>time)
448 if (self.bot_strategytime < time)
450 navigation_goalrating_start();
451 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
452 havocbot_goalrating_ast_targets(20000);
453 havocbot_goalrating_items(15000, self.origin, 10000);
454 navigation_goalrating_end();
456 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
460 void havocbot_role_ast_defense()
462 if(self.deadflag != DEAD_NO)
464 self.havocbot_attack_time = 0;
465 havocbot_ast_reset_role(self);
469 // Set the role timeout if necessary
470 if (!self.havocbot_role_timeout)
471 self.havocbot_role_timeout = time + 120;
473 if (time > self.havocbot_role_timeout)
475 havocbot_ast_reset_role(self);
479 if(self.havocbot_attack_time>time)
482 if (self.bot_strategytime < time)
484 navigation_goalrating_start();
485 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
486 havocbot_goalrating_ast_targets(20000);
487 havocbot_goalrating_items(15000, self.origin, 10000);
488 navigation_goalrating_end();
490 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
494 void havocbot_role_ast_setrole(entity bot, float role)
498 case HAVOCBOT_AST_ROLE_DEFENSE:
499 bot.havocbot_role = havocbot_role_ast_defense;
500 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
501 bot.havocbot_role_timeout = 0;
503 case HAVOCBOT_AST_ROLE_OFFENSE:
504 bot.havocbot_role = havocbot_role_ast_offense;
505 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
506 bot.havocbot_role_timeout = 0;
511 void havocbot_ast_reset_role(entity bot)
513 if(self.deadflag != DEAD_NO)
516 if(bot.team == assault_attacker_team)
517 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
519 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
523 MUTATOR_HOOKFUNCTION(assault_PlayerSpawn)
525 if(self.team == assault_attacker_team)
526 centerprint(self, "You are attacking!");
528 centerprint(self, "You are defending!");
533 MUTATOR_HOOKFUNCTION(assault_TurretSpawn)
541 MUTATOR_HOOKFUNCTION(assault_VehicleSpawn)
543 self.nextthink = time + 0.5;
548 MUTATOR_HOOKFUNCTION(assault_BotRoles)
550 havocbot_ast_reset_role(self);
555 void assault_ScoreRules()
557 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, TRUE);
558 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
559 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
560 ScoreRules_basics_end();
563 MUTATOR_DEFINITION(gamemode_assault)
565 MUTATOR_HOOK(PlayerSpawn, assault_PlayerSpawn, CBC_ORDER_ANY);
566 MUTATOR_HOOK(TurretSpawn, assault_TurretSpawn, CBC_ORDER_ANY);
567 MUTATOR_HOOK(VehicleSpawn, assault_VehicleSpawn, CBC_ORDER_ANY);
568 MUTATOR_HOOK(HavocBot_ChooseRule, assault_BotRoles, CBC_ORDER_ANY);
572 if(time > 1) // game loads at time 1
573 error("This is a game type and it cannot be added at runtime.");
574 assault_ScoreRules();
577 MUTATOR_ONROLLBACK_OR_REMOVE
579 // we actually cannot roll back assault_Initialize here
580 // BUT: we don't need to! If this gets called, adding always
586 print("This is a game type and it cannot be removed at runtime.");