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;
71 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_TRIGGER, self.message);
73 oldactivator = activator;
76 activator = oldactivator;
82 void assault_setenemytoobjective()
85 for(objective = world; (objective = find(objective, targetname, self.target)); )
87 if(objective.classname == "target_objective")
89 if(self.enemy == world)
90 self.enemy = objective;
92 objerror("more than one objective as target - fix the map!");
97 if(self.enemy == world)
98 objerror("no objective as target - fix the map!");
101 float assault_decreaser_sprite_visible(entity e)
105 decreaser = self.assault_decreaser;
107 if(decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
113 void target_objective_decrease_activate()
117 for(ent = world; (ent = find(ent, target, self.targetname)); )
119 if(ent.assault_sprite != world)
121 WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
122 if(ent.classname == "func_assault_destructible")
126 spr = WaypointSprite_SpawnFixed("<placeholder>", 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE, '1 0.5 0');
127 spr.assault_decreaser = self;
128 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
129 spr.classname = "sprite_waypoint";
130 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
131 if(ent.classname == "func_assault_destructible")
133 WaypointSprite_UpdateSprites(spr, "as-defend", "as-destroy", "as-destroy");
134 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
135 WaypointSprite_UpdateHealth(spr, ent.health);
139 WaypointSprite_UpdateSprites(spr, "as-defend", "as-push", "as-push");
143 void target_objective_decrease_findtarget()
145 assault_setenemytoobjective();
148 void target_assault_roundend_reset()
150 //print("round end reset\n");
151 self.cnt = self.cnt + 1; // up round counter
152 self.winning = 0; // up round
155 void target_assault_roundend_use()
157 self.winning = 1; // round has been won by attackers
160 void assault_roundstart_use()
165 #ifdef TTURRETS_ENABLED
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
181 turret_stdproc_respawn();
183 ent = find(ent, classname, "turret_main");
189 void assault_wall_think()
191 if(self.enemy.health < 0)
194 self.solid = SOLID_NOT;
198 self.model = self.mdl;
199 self.solid = SOLID_BSP;
202 self.nextthink = time + 0.2;
206 // reset objectives, toggle spawnpoints, reset triggers, ...
207 void vehicles_clearrturn();
208 void vehicles_spawn();
209 void assault_new_round()
212 //bprint("ASSAULT: new round\n");
215 // Eject players from vehicles
216 FOR_EACH_PLAYER(self)
219 vehicles_exit(VHEF_RELESE);
222 self = findchainflags(vehicle_flags, VHF_ISVEHICLE);
225 vehicles_clearrturn();
233 self.winning = self.winning + 1;
235 // swap attacker/defender roles
236 if(assault_attacker_team == NUM_TEAM_1)
237 assault_attacker_team = NUM_TEAM_2;
239 assault_attacker_team = NUM_TEAM_1;
242 for(ent = world; (ent = nextent(ent)); )
244 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
246 if(ent.team_saved == NUM_TEAM_1)
247 ent.team_saved = NUM_TEAM_2;
248 else if(ent.team_saved == NUM_TEAM_2)
249 ent.team_saved = NUM_TEAM_1;
253 // reset the level with a countdown
254 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
255 ReadyRestart_force(); // sets game_starttime
259 void spawnfunc_info_player_attacker()
261 if not(g_assault) { remove(self); return; }
263 self.team = NUM_TEAM_1; // red, gets swapped every round
264 spawnfunc_info_player_deathmatch();
267 void spawnfunc_info_player_defender()
269 if not(g_assault) { remove(self); return; }
271 self.team = NUM_TEAM_2; // blue, gets swapped every round
272 spawnfunc_info_player_deathmatch();
275 void spawnfunc_target_objective()
277 if not(g_assault) { remove(self); return; }
279 self.classname = "target_objective";
280 self.use = assault_objective_use;
281 assault_objective_reset();
282 self.reset = assault_objective_reset;
283 self.spawn_evalfunc = target_objective_spawn_evalfunc;
286 void spawnfunc_target_objective_decrease()
288 if not(g_assault) { remove(self); return; }
290 self.classname = "target_objective_decrease";
295 self.use = assault_objective_decrease_use;
296 self.health = ASSAULT_VALUE_INACTIVE;
297 self.max_health = ASSAULT_VALUE_INACTIVE;
300 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
303 // destructible walls that can be used to trigger target_objective_decrease
304 void spawnfunc_func_assault_destructible()
306 if not(g_assault) { remove(self); return; }
309 self.classname = "func_assault_destructible";
311 if(assault_attacker_team == NUM_TEAM_1)
312 self.team = NUM_TEAM_2;
314 self.team = NUM_TEAM_1;
316 spawnfunc_func_breakable();
319 void spawnfunc_func_assault_wall()
321 if not(g_assault) { remove(self); return; }
323 self.classname = "func_assault_wall";
324 self.mdl = self.model;
325 setmodel(self, self.mdl);
326 self.solid = SOLID_BSP;
327 self.think = assault_wall_think;
328 self.nextthink = time;
329 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
332 void spawnfunc_target_assault_roundend()
334 if not(g_assault) { remove(self); return; }
336 self.winning = 0; // round not yet won by attackers
337 self.classname = "target_assault_roundend";
338 self.use = target_assault_roundend_use;
339 self.cnt = 0; // first round
340 self.reset = target_assault_roundend_reset;
343 void spawnfunc_target_assault_roundstart()
345 if not(g_assault) { remove(self); return; }
347 assault_attacker_team = NUM_TEAM_1;
348 self.classname = "target_assault_roundstart";
349 self.use = assault_roundstart_use;
350 self.reset2 = assault_roundstart_use;
351 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
355 void havocbot_goalrating_ast_targets(float ratingscale)
357 entity ad, best, wp, tod;
358 float radius, found, bestvalue;
361 ad = findchain(classname, "func_assault_destructible");
363 for (; ad; ad = ad.chain)
368 if not(ad.bot_attack)
372 for(tod = world; (tod = find(tod, targetname, ad.target)); )
374 if(tod.classname == "target_objective_decrease")
376 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
378 // dprint(etos(ad),"\n");
387 /// dprint("target not found\n");
390 /// dprint("target #", etos(ad), " found\n");
393 p = 0.5 * (ad.absmin + ad.absmax);
394 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
395 // te_knightspike(p);
396 // te_lightning2(world, '0 0 0', p);
398 // Find and rate waypoints around it
401 bestvalue = 99999999999;
402 for(radius=0; radius<1500 && !found; radius+=500)
404 for(wp=findradius(p, radius); wp; wp=wp.chain)
406 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
407 if(wp.classname=="waypoint")
408 if(checkpvs(wp.origin, ad))
422 /// dprint("waypoints around target were found\n");
423 // te_lightning2(world, '0 0 0', best.origin);
424 // te_knightspike(best.origin);
426 navigation_routerating(best, ratingscale, 4000);
429 self.havocbot_attack_time = 0;
431 if(checkpvs(self.view_ofs,ad))
432 if(checkpvs(self.view_ofs,best))
434 // dprint("increasing attack time for this target\n");
435 self.havocbot_attack_time = time + 2;
441 void havocbot_role_ast_offense()
443 if(self.deadflag != DEAD_NO)
445 self.havocbot_attack_time = 0;
446 havocbot_ast_reset_role(self);
450 // Set the role timeout if necessary
451 if (!self.havocbot_role_timeout)
452 self.havocbot_role_timeout = time + 120;
454 if (time > self.havocbot_role_timeout)
456 havocbot_ast_reset_role(self);
460 if(self.havocbot_attack_time>time)
463 if (self.bot_strategytime < time)
465 navigation_goalrating_start();
466 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
467 havocbot_goalrating_ast_targets(20000);
468 havocbot_goalrating_items(15000, self.origin, 10000);
469 navigation_goalrating_end();
471 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
475 void havocbot_role_ast_defense()
477 if(self.deadflag != DEAD_NO)
479 self.havocbot_attack_time = 0;
480 havocbot_ast_reset_role(self);
484 // Set the role timeout if necessary
485 if (!self.havocbot_role_timeout)
486 self.havocbot_role_timeout = time + 120;
488 if (time > self.havocbot_role_timeout)
490 havocbot_ast_reset_role(self);
494 if(self.havocbot_attack_time>time)
497 if (self.bot_strategytime < time)
499 navigation_goalrating_start();
500 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
501 havocbot_goalrating_ast_targets(20000);
502 havocbot_goalrating_items(15000, self.origin, 10000);
503 navigation_goalrating_end();
505 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
509 void havocbot_role_ast_setrole(entity bot, float role)
513 case HAVOCBOT_AST_ROLE_DEFENSE:
514 bot.havocbot_role = havocbot_role_ast_defense;
515 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
516 bot.havocbot_role_timeout = 0;
518 case HAVOCBOT_AST_ROLE_OFFENSE:
519 bot.havocbot_role = havocbot_role_ast_offense;
520 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
521 bot.havocbot_role_timeout = 0;
526 void havocbot_ast_reset_role(entity bot)
528 if(self.deadflag != DEAD_NO)
531 if(bot.team == assault_attacker_team)
532 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
534 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
538 MUTATOR_HOOKFUNCTION(assault_PlayerSpawn)
540 if(self.team == assault_attacker_team)
541 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
543 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
548 MUTATOR_HOOKFUNCTION(assault_TurretSpawn)
556 MUTATOR_HOOKFUNCTION(assault_VehicleSpawn)
558 self.nextthink = time + 0.5;
563 MUTATOR_HOOKFUNCTION(assault_BotRoles)
565 havocbot_ast_reset_role(self);
570 void assault_ScoreRules()
572 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, TRUE);
573 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
574 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
575 ScoreRules_basics_end();
578 MUTATOR_DEFINITION(gamemode_assault)
580 MUTATOR_HOOK(PlayerSpawn, assault_PlayerSpawn, CBC_ORDER_ANY);
581 MUTATOR_HOOK(TurretSpawn, assault_TurretSpawn, CBC_ORDER_ANY);
582 MUTATOR_HOOK(VehicleSpawn, assault_VehicleSpawn, CBC_ORDER_ANY);
583 MUTATOR_HOOK(HavocBot_ChooseRule, assault_BotRoles, CBC_ORDER_ANY);
587 if(time > 1) // game loads at time 1
588 error("This is a game type and it cannot be added at runtime.");
589 assault_ScoreRules();
592 MUTATOR_ONROLLBACK_OR_REMOVE
594 // we actually cannot roll back assault_Initialize here
595 // BUT: we don't need to! If this gets called, adding always
601 print("This is a game type and it cannot be removed at runtime.");