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, head;
72 centerprint(head, self.message);
74 oldactivator = activator;
77 activator = oldactivator;
83 void assault_setenemytoobjective()
86 for(objective = world; (objective = find(objective, targetname, self.target)); )
88 if(objective.classname == "target_objective")
90 if(self.enemy == world)
91 self.enemy = objective;
93 objerror("more than one objective as target - fix the map!");
98 if(self.enemy == world)
99 objerror("no objective as target - fix the map!");
102 float assault_decreaser_sprite_visible(entity e)
106 decreaser = self.assault_decreaser;
108 if(decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
114 void target_objective_decrease_activate()
118 for(ent = world; (ent = find(ent, target, self.targetname)); )
120 if(ent.assault_sprite != world)
122 WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
123 if(ent.classname == "func_assault_destructible")
127 spr = WaypointSprite_SpawnFixed("<placeholder>", 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE, '1 0.5 0');
128 spr.assault_decreaser = self;
129 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
130 spr.classname = "sprite_waypoint";
131 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
132 if(ent.classname == "func_assault_destructible")
134 WaypointSprite_UpdateSprites(spr, "as-defend", "as-destroy", "as-destroy");
135 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
136 WaypointSprite_UpdateHealth(spr, ent.health);
140 WaypointSprite_UpdateSprites(spr, "as-defend", "as-push", "as-push");
144 void target_objective_decrease_findtarget()
146 assault_setenemytoobjective();
149 void target_assault_roundend_reset()
151 //print("round end reset\n");
152 self.cnt = self.cnt + 1; // up round counter
153 self.winning = 0; // up round
156 void target_assault_roundend_use()
158 self.winning = 1; // round has been won by attackers
161 void assault_roundstart_use()
166 #ifdef TTURRETS_ENABLED
169 //(Re)spawn all turrets
171 ent = find(world, classname, "turret_main");
174 if(ent.team == NUM_TEAM_1)
175 ent.team = NUM_TEAM_2;
177 ent.team = NUM_TEAM_1;
181 // Dubbles as teamchange
182 turret_stdproc_respawn();
184 ent = find(ent, classname, "turret_main");
190 void assault_wall_think()
192 if(self.enemy.health < 0)
195 self.solid = SOLID_NOT;
199 self.model = self.mdl;
200 self.solid = SOLID_BSP;
203 self.nextthink = time + 0.2;
207 // reset objectives, toggle spawnpoints, reset triggers, ...
208 void assault_new_round()
211 self.winning = self.winning + 1;
213 // swap attacker/defender roles
214 if(assault_attacker_team == NUM_TEAM_1)
215 assault_attacker_team = NUM_TEAM_2;
217 assault_attacker_team = NUM_TEAM_1;
220 for(ent = world; (ent = nextent(ent)); )
222 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
224 if(ent.team_saved == NUM_TEAM_1)
225 ent.team_saved = NUM_TEAM_2;
226 else if(ent.team_saved == NUM_TEAM_2)
227 ent.team_saved = NUM_TEAM_1;
231 // reset the level with a countdown
232 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
233 ReadyRestart_force(); // sets game_starttime
237 void spawnfunc_info_player_attacker()
239 if (!g_assault) { remove(self); return; }
241 self.team = NUM_TEAM_1; // red, gets swapped every round
242 spawnfunc_info_player_deathmatch();
245 void spawnfunc_info_player_defender()
247 if (!g_assault) { remove(self); return; }
249 self.team = NUM_TEAM_2; // blue, gets swapped every round
250 spawnfunc_info_player_deathmatch();
253 void spawnfunc_target_objective()
255 if (!g_assault) { remove(self); return; }
257 self.classname = "target_objective";
258 self.use = assault_objective_use;
259 assault_objective_reset();
260 self.reset = assault_objective_reset;
261 self.spawn_evalfunc = target_objective_spawn_evalfunc;
264 void spawnfunc_target_objective_decrease()
266 if (!g_assault) { remove(self); return; }
268 self.classname = "target_objective_decrease";
273 self.use = assault_objective_decrease_use;
274 self.health = ASSAULT_VALUE_INACTIVE;
275 self.max_health = ASSAULT_VALUE_INACTIVE;
278 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
281 // destructible walls that can be used to trigger target_objective_decrease
282 void spawnfunc_func_assault_destructible()
284 if (!g_assault) { remove(self); return; }
287 self.classname = "func_assault_destructible";
289 if(assault_attacker_team == NUM_TEAM_1)
290 self.team = NUM_TEAM_2;
292 self.team = NUM_TEAM_1;
294 spawnfunc_func_breakable();
297 void spawnfunc_func_assault_wall()
299 if (!g_assault) { remove(self); return; }
301 self.classname = "func_assault_wall";
302 self.mdl = self.model;
303 setmodel(self, self.mdl);
304 self.solid = SOLID_BSP;
305 self.think = assault_wall_think;
306 self.nextthink = time;
307 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
310 void spawnfunc_target_assault_roundend()
312 if (!g_assault) { remove(self); return; }
314 self.winning = 0; // round not yet won by attackers
315 self.classname = "target_assault_roundend";
316 self.use = target_assault_roundend_use;
317 self.cnt = 0; // first round
318 self.reset = target_assault_roundend_reset;
321 void spawnfunc_target_assault_roundstart()
323 if (!g_assault) { remove(self); return; }
325 assault_attacker_team = NUM_TEAM_1;
326 self.classname = "target_assault_roundstart";
327 self.use = assault_roundstart_use;
328 self.reset2 = assault_roundstart_use;
329 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
333 void havocbot_goalrating_ast_targets(float ratingscale)
335 entity ad, best, wp, tod;
336 float radius, found, bestvalue;
339 ad = findchain(classname, "func_assault_destructible");
341 for(0; ad; ad = ad.chain)
350 for(tod = world; (tod = find(tod, targetname, ad.target)); )
352 if(tod.classname == "target_objective_decrease")
354 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
356 // dprint(etos(ad),"\n");
365 /// dprint("target not found\n");
368 /// dprint("target #", etos(ad), " found\n");
371 p = 0.5 * (ad.absmin + ad.absmax);
372 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
373 // te_knightspike(p);
374 // te_lightning2(world, '0 0 0', p);
376 // Find and rate waypoints around it
379 bestvalue = 99999999999;
380 for(radius=0; radius<1500 && !found; radius+=500)
382 for(wp=findradius(p, radius); wp; wp=wp.chain)
384 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
385 if(wp.classname=="waypoint")
386 if(checkpvs(wp.origin, ad))
400 /// dprint("waypoints around target were found\n");
401 // te_lightning2(world, '0 0 0', best.origin);
402 // te_knightspike(best.origin);
404 navigation_routerating(best, ratingscale, 4000);
407 self.havocbot_attack_time = 0;
409 if(checkpvs(self.view_ofs,ad))
410 if(checkpvs(self.view_ofs,best))
412 // dprint("increasing attack time for this target\n");
413 self.havocbot_attack_time = time + 2;
419 void havocbot_role_ast_offense()
421 if(self.deadflag != DEAD_NO)
423 self.havocbot_attack_time = 0;
424 havocbot_ast_reset_role(self);
428 // Set the role timeout if necessary
429 if (!self.havocbot_role_timeout)
430 self.havocbot_role_timeout = time + 120;
432 if (time > self.havocbot_role_timeout)
434 havocbot_ast_reset_role(self);
438 if(self.havocbot_attack_time>time)
441 if (self.bot_strategytime < time)
443 navigation_goalrating_start();
444 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
445 havocbot_goalrating_ast_targets(20000);
446 havocbot_goalrating_items(15000, self.origin, 10000);
447 navigation_goalrating_end();
449 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
453 void havocbot_role_ast_defense()
455 if(self.deadflag != DEAD_NO)
457 self.havocbot_attack_time = 0;
458 havocbot_ast_reset_role(self);
462 // Set the role timeout if necessary
463 if (!self.havocbot_role_timeout)
464 self.havocbot_role_timeout = time + 120;
466 if (time > self.havocbot_role_timeout)
468 havocbot_ast_reset_role(self);
472 if(self.havocbot_attack_time>time)
475 if (self.bot_strategytime < time)
477 navigation_goalrating_start();
478 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
479 havocbot_goalrating_ast_targets(20000);
480 havocbot_goalrating_items(15000, self.origin, 10000);
481 navigation_goalrating_end();
483 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
487 void havocbot_role_ast_setrole(entity bot, float role)
491 case HAVOCBOT_AST_ROLE_DEFENSE:
492 bot.havocbot_role = havocbot_role_ast_defense;
493 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
494 bot.havocbot_role_timeout = 0;
496 case HAVOCBOT_AST_ROLE_OFFENSE:
497 bot.havocbot_role = havocbot_role_ast_offense;
498 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
499 bot.havocbot_role_timeout = 0;
504 void havocbot_ast_reset_role(entity bot)
506 if(self.deadflag != DEAD_NO)
509 if(bot.team == assault_attacker_team)
510 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
512 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
516 MUTATOR_HOOKFUNCTION(assault_PlayerSpawn)
518 if(self.team == assault_attacker_team)
519 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
521 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
526 MUTATOR_HOOKFUNCTION(assault_TurretSpawn)
534 MUTATOR_HOOKFUNCTION(assault_VehicleSpawn)
536 self.nextthink = time + 0.5;
541 MUTATOR_HOOKFUNCTION(assault_BotRoles)
543 havocbot_ast_reset_role(self);
548 void assault_ScoreRules()
550 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
551 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
552 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
553 ScoreRules_basics_end();
556 MUTATOR_DEFINITION(gamemode_assault)
558 MUTATOR_HOOK(PlayerSpawn, assault_PlayerSpawn, CBC_ORDER_ANY);
559 MUTATOR_HOOK(TurretSpawn, assault_TurretSpawn, CBC_ORDER_ANY);
560 MUTATOR_HOOK(VehicleSpawn, assault_VehicleSpawn, CBC_ORDER_ANY);
561 MUTATOR_HOOK(HavocBot_ChooseRole, assault_BotRoles, CBC_ORDER_ANY);
565 if(time > 1) // game loads at time 1
566 error("This is a game type and it cannot be added at runtime.");
567 assault_ScoreRules();
570 MUTATOR_ONROLLBACK_OR_REMOVE
572 // we actually cannot roll back assault_Initialize here
573 // BUT: we don't need to! If this gets called, adding always
579 print("This is a game type and it cannot be removed at runtime.");