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()
168 //(Re)spawn all turrets
170 ent = find(world, classname, "turret_main");
173 if(ent.team == NUM_TEAM_1)
174 ent.team = NUM_TEAM_2;
176 ent.team = NUM_TEAM_1;
180 // Dubbles as teamchange
183 ent = find(ent, classname, "turret_main");
188 void assault_wall_think()
190 if(self.enemy.health < 0)
193 self.solid = SOLID_NOT;
197 self.model = self.mdl;
198 self.solid = SOLID_BSP;
201 self.nextthink = time + 0.2;
205 // reset objectives, toggle spawnpoints, reset triggers, ...
206 void assault_new_round()
209 self.winning = self.winning + 1;
211 // swap attacker/defender roles
212 if(assault_attacker_team == NUM_TEAM_1)
213 assault_attacker_team = NUM_TEAM_2;
215 assault_attacker_team = NUM_TEAM_1;
218 for(ent = world; (ent = nextent(ent)); )
220 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
222 if(ent.team_saved == NUM_TEAM_1)
223 ent.team_saved = NUM_TEAM_2;
224 else if(ent.team_saved == NUM_TEAM_2)
225 ent.team_saved = NUM_TEAM_1;
229 // reset the level with a countdown
230 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
231 ReadyRestart_force(); // sets game_starttime
235 void spawnfunc_info_player_attacker()
237 if (!g_assault) { remove(self); return; }
239 self.team = NUM_TEAM_1; // red, gets swapped every round
240 spawnfunc_info_player_deathmatch();
243 void spawnfunc_info_player_defender()
245 if (!g_assault) { remove(self); return; }
247 self.team = NUM_TEAM_2; // blue, gets swapped every round
248 spawnfunc_info_player_deathmatch();
251 void spawnfunc_target_objective()
253 if (!g_assault) { remove(self); return; }
255 self.classname = "target_objective";
256 self.use = assault_objective_use;
257 assault_objective_reset();
258 self.reset = assault_objective_reset;
259 self.spawn_evalfunc = target_objective_spawn_evalfunc;
262 void spawnfunc_target_objective_decrease()
264 if (!g_assault) { remove(self); return; }
266 self.classname = "target_objective_decrease";
271 self.use = assault_objective_decrease_use;
272 self.health = ASSAULT_VALUE_INACTIVE;
273 self.max_health = ASSAULT_VALUE_INACTIVE;
276 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
279 // destructible walls that can be used to trigger target_objective_decrease
280 void spawnfunc_func_assault_destructible()
282 if (!g_assault) { remove(self); return; }
285 self.classname = "func_assault_destructible";
287 if(assault_attacker_team == NUM_TEAM_1)
288 self.team = NUM_TEAM_2;
290 self.team = NUM_TEAM_1;
292 spawnfunc_func_breakable();
295 void spawnfunc_func_assault_wall()
297 if (!g_assault) { remove(self); return; }
299 self.classname = "func_assault_wall";
300 self.mdl = self.model;
301 setmodel(self, self.mdl);
302 self.solid = SOLID_BSP;
303 self.think = assault_wall_think;
304 self.nextthink = time;
305 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
308 void spawnfunc_target_assault_roundend()
310 if (!g_assault) { remove(self); return; }
312 self.winning = 0; // round not yet won by attackers
313 self.classname = "target_assault_roundend";
314 self.use = target_assault_roundend_use;
315 self.cnt = 0; // first round
316 self.reset = target_assault_roundend_reset;
319 void spawnfunc_target_assault_roundstart()
321 if (!g_assault) { remove(self); return; }
323 assault_attacker_team = NUM_TEAM_1;
324 self.classname = "target_assault_roundstart";
325 self.use = assault_roundstart_use;
326 self.reset2 = assault_roundstart_use;
327 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
331 void havocbot_goalrating_ast_targets(float ratingscale)
333 entity ad, best, wp, tod;
334 float radius, found, bestvalue;
337 ad = findchain(classname, "func_assault_destructible");
339 for (; ad; ad = ad.chain)
348 for(tod = world; (tod = find(tod, targetname, ad.target)); )
350 if(tod.classname == "target_objective_decrease")
352 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
354 // dprint(etos(ad),"\n");
363 /// dprint("target not found\n");
366 /// dprint("target #", etos(ad), " found\n");
369 p = 0.5 * (ad.absmin + ad.absmax);
370 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
371 // te_knightspike(p);
372 // te_lightning2(world, '0 0 0', p);
374 // Find and rate waypoints around it
377 bestvalue = 99999999999;
378 for(radius=0; radius<1500 && !found; radius+=500)
380 for(wp=findradius(p, radius); wp; wp=wp.chain)
382 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
383 if(wp.classname=="waypoint")
384 if(checkpvs(wp.origin, ad))
398 /// dprint("waypoints around target were found\n");
399 // te_lightning2(world, '0 0 0', best.origin);
400 // te_knightspike(best.origin);
402 navigation_routerating(best, ratingscale, 4000);
405 self.havocbot_attack_time = 0;
407 if(checkpvs(self.view_ofs,ad))
408 if(checkpvs(self.view_ofs,best))
410 // dprint("increasing attack time for this target\n");
411 self.havocbot_attack_time = time + 2;
417 void havocbot_role_ast_offense()
419 if(self.deadflag != DEAD_NO)
421 self.havocbot_attack_time = 0;
422 havocbot_ast_reset_role(self);
426 // Set the role timeout if necessary
427 if (!self.havocbot_role_timeout)
428 self.havocbot_role_timeout = time + 120;
430 if (time > self.havocbot_role_timeout)
432 havocbot_ast_reset_role(self);
436 if(self.havocbot_attack_time>time)
439 if (self.bot_strategytime < time)
441 navigation_goalrating_start();
442 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
443 havocbot_goalrating_ast_targets(20000);
444 havocbot_goalrating_items(15000, self.origin, 10000);
445 navigation_goalrating_end();
447 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
451 void havocbot_role_ast_defense()
453 if(self.deadflag != DEAD_NO)
455 self.havocbot_attack_time = 0;
456 havocbot_ast_reset_role(self);
460 // Set the role timeout if necessary
461 if (!self.havocbot_role_timeout)
462 self.havocbot_role_timeout = time + 120;
464 if (time > self.havocbot_role_timeout)
466 havocbot_ast_reset_role(self);
470 if(self.havocbot_attack_time>time)
473 if (self.bot_strategytime < time)
475 navigation_goalrating_start();
476 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
477 havocbot_goalrating_ast_targets(20000);
478 havocbot_goalrating_items(15000, self.origin, 10000);
479 navigation_goalrating_end();
481 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
485 void havocbot_role_ast_setrole(entity bot, float role)
489 case HAVOCBOT_AST_ROLE_DEFENSE:
490 bot.havocbot_role = havocbot_role_ast_defense;
491 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
492 bot.havocbot_role_timeout = 0;
494 case HAVOCBOT_AST_ROLE_OFFENSE:
495 bot.havocbot_role = havocbot_role_ast_offense;
496 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
497 bot.havocbot_role_timeout = 0;
502 void havocbot_ast_reset_role(entity bot)
504 if(self.deadflag != DEAD_NO)
507 if(bot.team == assault_attacker_team)
508 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
510 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
514 MUTATOR_HOOKFUNCTION(assault_PlayerSpawn)
516 if(self.team == assault_attacker_team)
517 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
519 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
524 MUTATOR_HOOKFUNCTION(assault_TurretSpawn)
532 MUTATOR_HOOKFUNCTION(assault_VehicleSpawn)
534 self.nextthink = time + 0.5;
539 MUTATOR_HOOKFUNCTION(assault_BotRoles)
541 havocbot_ast_reset_role(self);
546 void assault_ScoreRules()
548 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
549 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
550 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
551 ScoreRules_basics_end();
554 MUTATOR_DEFINITION(gamemode_assault)
556 MUTATOR_HOOK(PlayerSpawn, assault_PlayerSpawn, CBC_ORDER_ANY);
557 MUTATOR_HOOK(TurretSpawn, assault_TurretSpawn, CBC_ORDER_ANY);
558 MUTATOR_HOOK(VehicleSpawn, assault_VehicleSpawn, CBC_ORDER_ANY);
559 MUTATOR_HOOK(HavocBot_ChooseRole, assault_BotRoles, CBC_ORDER_ANY);
563 if(time > 1) // game loads at time 1
564 error("This is a game type and it cannot be added at runtime.");
565 assault_ScoreRules();
568 MUTATOR_ONROLLBACK_OR_REMOVE
570 // we actually cannot roll back assault_Initialize here
571 // BUT: we don't need to! If this gets called, adding always
577 print("This is a game type and it cannot be removed at runtime.");