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 vehicles_clearreturn(entity veh);
209 void vehicles_spawn();
210 void assault_new_round()
213 //bprint("ASSAULT: new round\n");
216 // Eject players from vehicles
217 FOR_EACH_PLAYER(self)
220 vehicles_exit(VHEF_RELEASE);
223 self = findchainflags(vehicle_flags, VHF_ISVEHICLE);
226 vehicles_clearreturn(self);
234 self.winning = self.winning + 1;
236 // swap attacker/defender roles
237 if(assault_attacker_team == NUM_TEAM_1)
238 assault_attacker_team = NUM_TEAM_2;
240 assault_attacker_team = NUM_TEAM_1;
243 for(ent = world; (ent = nextent(ent)); )
245 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
247 if(ent.team_saved == NUM_TEAM_1)
248 ent.team_saved = NUM_TEAM_2;
249 else if(ent.team_saved == NUM_TEAM_2)
250 ent.team_saved = NUM_TEAM_1;
254 // reset the level with a countdown
255 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
256 ReadyRestart_force(); // sets game_starttime
260 void spawnfunc_info_player_attacker()
262 if (!g_assault) { remove(self); return; }
264 self.team = NUM_TEAM_1; // red, gets swapped every round
265 spawnfunc_info_player_deathmatch();
268 void spawnfunc_info_player_defender()
270 if (!g_assault) { remove(self); return; }
272 self.team = NUM_TEAM_2; // blue, gets swapped every round
273 spawnfunc_info_player_deathmatch();
276 void spawnfunc_target_objective()
278 if (!g_assault) { remove(self); return; }
280 self.classname = "target_objective";
281 self.use = assault_objective_use;
282 assault_objective_reset();
283 self.reset = assault_objective_reset;
284 self.spawn_evalfunc = target_objective_spawn_evalfunc;
287 void spawnfunc_target_objective_decrease()
289 if (!g_assault) { remove(self); return; }
291 self.classname = "target_objective_decrease";
296 self.use = assault_objective_decrease_use;
297 self.health = ASSAULT_VALUE_INACTIVE;
298 self.max_health = ASSAULT_VALUE_INACTIVE;
301 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
304 // destructible walls that can be used to trigger target_objective_decrease
305 void spawnfunc_func_assault_destructible()
307 if (!g_assault) { remove(self); return; }
310 self.classname = "func_assault_destructible";
312 if(assault_attacker_team == NUM_TEAM_1)
313 self.team = NUM_TEAM_2;
315 self.team = NUM_TEAM_1;
317 spawnfunc_func_breakable();
320 void spawnfunc_func_assault_wall()
322 if (!g_assault) { remove(self); return; }
324 self.classname = "func_assault_wall";
325 self.mdl = self.model;
326 setmodel(self, self.mdl);
327 self.solid = SOLID_BSP;
328 self.think = assault_wall_think;
329 self.nextthink = time;
330 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
333 void spawnfunc_target_assault_roundend()
335 if (!g_assault) { remove(self); return; }
337 self.winning = 0; // round not yet won by attackers
338 self.classname = "target_assault_roundend";
339 self.use = target_assault_roundend_use;
340 self.cnt = 0; // first round
341 self.reset = target_assault_roundend_reset;
344 void spawnfunc_target_assault_roundstart()
346 if (!g_assault) { remove(self); return; }
348 assault_attacker_team = NUM_TEAM_1;
349 self.classname = "target_assault_roundstart";
350 self.use = assault_roundstart_use;
351 self.reset2 = assault_roundstart_use;
352 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
356 void havocbot_goalrating_ast_targets(float ratingscale)
358 entity ad, best, wp, tod;
359 float radius, found, bestvalue;
362 ad = findchain(classname, "func_assault_destructible");
364 for (; ad; ad = ad.chain)
373 for(tod = world; (tod = find(tod, targetname, ad.target)); )
375 if(tod.classname == "target_objective_decrease")
377 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
379 // dprint(etos(ad),"\n");
388 /// dprint("target not found\n");
391 /// dprint("target #", etos(ad), " found\n");
394 p = 0.5 * (ad.absmin + ad.absmax);
395 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
396 // te_knightspike(p);
397 // te_lightning2(world, '0 0 0', p);
399 // Find and rate waypoints around it
402 bestvalue = 99999999999;
403 for(radius=0; radius<1500 && !found; radius+=500)
405 for(wp=findradius(p, radius); wp; wp=wp.chain)
407 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
408 if(wp.classname=="waypoint")
409 if(checkpvs(wp.origin, ad))
423 /// dprint("waypoints around target were found\n");
424 // te_lightning2(world, '0 0 0', best.origin);
425 // te_knightspike(best.origin);
427 navigation_routerating(best, ratingscale, 4000);
430 self.havocbot_attack_time = 0;
432 if(checkpvs(self.view_ofs,ad))
433 if(checkpvs(self.view_ofs,best))
435 // dprint("increasing attack time for this target\n");
436 self.havocbot_attack_time = time + 2;
442 void havocbot_role_ast_offense()
444 if(self.deadflag != DEAD_NO)
446 self.havocbot_attack_time = 0;
447 havocbot_ast_reset_role(self);
451 // Set the role timeout if necessary
452 if (!self.havocbot_role_timeout)
453 self.havocbot_role_timeout = time + 120;
455 if (time > self.havocbot_role_timeout)
457 havocbot_ast_reset_role(self);
461 if(self.havocbot_attack_time>time)
464 if (self.bot_strategytime < time)
466 navigation_goalrating_start();
467 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
468 havocbot_goalrating_ast_targets(20000);
469 havocbot_goalrating_items(15000, self.origin, 10000);
470 navigation_goalrating_end();
472 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
476 void havocbot_role_ast_defense()
478 if(self.deadflag != DEAD_NO)
480 self.havocbot_attack_time = 0;
481 havocbot_ast_reset_role(self);
485 // Set the role timeout if necessary
486 if (!self.havocbot_role_timeout)
487 self.havocbot_role_timeout = time + 120;
489 if (time > self.havocbot_role_timeout)
491 havocbot_ast_reset_role(self);
495 if(self.havocbot_attack_time>time)
498 if (self.bot_strategytime < time)
500 navigation_goalrating_start();
501 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
502 havocbot_goalrating_ast_targets(20000);
503 havocbot_goalrating_items(15000, self.origin, 10000);
504 navigation_goalrating_end();
506 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
510 void havocbot_role_ast_setrole(entity bot, float role)
514 case HAVOCBOT_AST_ROLE_DEFENSE:
515 bot.havocbot_role = havocbot_role_ast_defense;
516 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
517 bot.havocbot_role_timeout = 0;
519 case HAVOCBOT_AST_ROLE_OFFENSE:
520 bot.havocbot_role = havocbot_role_ast_offense;
521 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
522 bot.havocbot_role_timeout = 0;
527 void havocbot_ast_reset_role(entity bot)
529 if(self.deadflag != DEAD_NO)
532 if(bot.team == assault_attacker_team)
533 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
535 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
539 MUTATOR_HOOKFUNCTION(assault_PlayerSpawn)
541 if(self.team == assault_attacker_team)
542 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
544 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
549 MUTATOR_HOOKFUNCTION(assault_TurretSpawn)
557 MUTATOR_HOOKFUNCTION(assault_VehicleSpawn)
559 self.nextthink = time + 0.5;
564 MUTATOR_HOOKFUNCTION(assault_BotRoles)
566 havocbot_ast_reset_role(self);
571 void assault_ScoreRules()
573 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, TRUE);
574 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
575 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
576 ScoreRules_basics_end();
579 MUTATOR_DEFINITION(gamemode_assault)
581 MUTATOR_HOOK(PlayerSpawn, assault_PlayerSpawn, CBC_ORDER_ANY);
582 MUTATOR_HOOK(TurretSpawn, assault_TurretSpawn, CBC_ORDER_ANY);
583 MUTATOR_HOOK(VehicleSpawn, assault_VehicleSpawn, CBC_ORDER_ANY);
584 MUTATOR_HOOK(HavocBot_ChooseRole, assault_BotRoles, CBC_ORDER_ANY);
588 if(time > 1) // game loads at time 1
589 error("This is a game type and it cannot be added at runtime.");
590 assault_ScoreRules();
593 MUTATOR_ONROLLBACK_OR_REMOVE
595 // we actually cannot roll back assault_Initialize here
596 // BUT: we don't need to! If this gets called, adding always
602 print("This is a game type and it cannot be removed at runtime.");