1 #include "gamemode_assault.qh"
9 void assault_objective_use()
13 //print("^2Activated objective ", self.targetname, "=", etos(self), "\n");
14 //print("Activator is ", activator.classname, "\n");
19 for(self = world; (self = find(self, target, oldself.targetname)); )
21 if(self.classname == "target_objective_decrease")
22 target_objective_decrease_activate();
28 vector target_objective_spawn_evalfunc(entity player, entity spot, vector current)
30 if(self.health < 0 || self.health >= ASSAULT_VALUE_INACTIVE)
35 // reset this objective. Used when spawning an objective
36 // and when a new round starts
37 void assault_objective_reset()
39 self.health = ASSAULT_VALUE_INACTIVE;
42 // decrease the health of targeted objectives
43 void assault_objective_decrease_use()
45 if(activator.team != assault_attacker_team)
47 // wrong team triggered decrease
51 if(other.assault_sprite)
53 WaypointSprite_Disown(other.assault_sprite, waypointsprite_deadlifetime);
54 if(other.classname == "func_assault_destructible")
58 return; // already activated! cannot activate again!
60 if(self.enemy.health < ASSAULT_VALUE_INACTIVE)
62 if(self.enemy.health - self.dmg > 0.5)
64 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.dmg);
65 self.enemy.health = self.enemy.health - self.dmg;
69 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.enemy.health);
70 PlayerTeamScore_Add(activator, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
71 self.enemy.health = -1;
73 entity oldself, oldactivator, head;
79 centerprint(head, self.message);
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(WP_Assault, 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE);
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, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
142 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
143 WaypointSprite_UpdateHealth(spr, ent.health);
147 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
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()
175 //(Re)spawn all turrets
177 ent = find(world, classname, "turret_main");
180 if(ent.team == NUM_TEAM_1)
181 ent.team = NUM_TEAM_2;
183 ent.team = NUM_TEAM_1;
187 // Dubbles as teamchange
190 ent = find(ent, classname, "turret_main");
195 void assault_wall_think()
197 if(self.enemy.health < 0)
200 self.solid = SOLID_NOT;
204 self.model = self.mdl;
205 self.solid = SOLID_BSP;
208 self.nextthink = time + 0.2;
212 // reset objectives, toggle spawnpoints, reset triggers, ...
213 void vehicles_clearreturn(entity veh);
214 void vehicles_spawn();
215 void assault_new_round()
218 //bprint("ASSAULT: new round\n");
221 // Eject players from vehicles
222 FOR_EACH_PLAYER(self)
225 vehicles_exit(VHEF_RELEASE);
228 self = findchainflags(vehicle_flags, VHF_ISVEHICLE);
231 vehicles_clearreturn(self);
239 self.winning = self.winning + 1;
241 // swap attacker/defender roles
242 if(assault_attacker_team == NUM_TEAM_1)
243 assault_attacker_team = NUM_TEAM_2;
245 assault_attacker_team = NUM_TEAM_1;
248 for(ent = world; (ent = nextent(ent)); )
250 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
252 if(ent.team_saved == NUM_TEAM_1)
253 ent.team_saved = NUM_TEAM_2;
254 else if(ent.team_saved == NUM_TEAM_2)
255 ent.team_saved = NUM_TEAM_1;
259 // reset the level with a countdown
260 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
261 ReadyRestart_force(); // sets game_starttime
265 void spawnfunc_info_player_attacker()
267 if (!g_assault) { remove(self); return; }
269 self.team = NUM_TEAM_1; // red, gets swapped every round
270 spawnfunc_info_player_deathmatch();
273 void spawnfunc_info_player_defender()
275 if (!g_assault) { remove(self); return; }
277 self.team = NUM_TEAM_2; // blue, gets swapped every round
278 spawnfunc_info_player_deathmatch();
281 void spawnfunc_target_objective()
283 if (!g_assault) { remove(self); return; }
285 self.classname = "target_objective";
286 self.use = assault_objective_use;
287 assault_objective_reset();
288 self.reset = assault_objective_reset;
289 self.spawn_evalfunc = target_objective_spawn_evalfunc;
292 void spawnfunc_target_objective_decrease()
294 if (!g_assault) { remove(self); return; }
296 self.classname = "target_objective_decrease";
301 self.use = assault_objective_decrease_use;
302 self.health = ASSAULT_VALUE_INACTIVE;
303 self.max_health = ASSAULT_VALUE_INACTIVE;
306 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
309 // destructible walls that can be used to trigger target_objective_decrease
310 void spawnfunc_func_assault_destructible()
312 if (!g_assault) { remove(self); return; }
315 self.classname = "func_assault_destructible";
317 if(assault_attacker_team == NUM_TEAM_1)
318 self.team = NUM_TEAM_2;
320 self.team = NUM_TEAM_1;
322 spawnfunc_func_breakable();
325 void spawnfunc_func_assault_wall()
327 if (!g_assault) { remove(self); return; }
329 self.classname = "func_assault_wall";
330 self.mdl = self.model;
331 setmodel(self, self.mdl);
332 self.solid = SOLID_BSP;
333 self.think = assault_wall_think;
334 self.nextthink = time;
335 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
338 void spawnfunc_target_assault_roundend()
340 if (!g_assault) { remove(self); return; }
342 self.winning = 0; // round not yet won by attackers
343 self.classname = "target_assault_roundend";
344 self.use = target_assault_roundend_use;
345 self.cnt = 0; // first round
346 self.reset = target_assault_roundend_reset;
349 void spawnfunc_target_assault_roundstart()
351 if (!g_assault) { remove(self); return; }
353 assault_attacker_team = NUM_TEAM_1;
354 self.classname = "target_assault_roundstart";
355 self.use = assault_roundstart_use;
356 self.reset2 = assault_roundstart_use;
357 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
361 void havocbot_goalrating_ast_targets(float ratingscale)
363 entity ad, best, wp, tod;
364 float radius, found, bestvalue;
367 ad = findchain(classname, "func_assault_destructible");
369 for (; ad; ad = ad.chain)
378 for(tod = world; (tod = find(tod, targetname, ad.target)); )
380 if(tod.classname == "target_objective_decrease")
382 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
384 // dprint(etos(ad),"\n");
393 /// dprint("target not found\n");
396 /// dprint("target #", etos(ad), " found\n");
399 p = 0.5 * (ad.absmin + ad.absmax);
400 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
401 // te_knightspike(p);
402 // te_lightning2(world, '0 0 0', p);
404 // Find and rate waypoints around it
407 bestvalue = 99999999999;
408 for(radius=0; radius<1500 && !found; radius+=500)
410 for(wp=findradius(p, radius); wp; wp=wp.chain)
412 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
413 if(wp.classname=="waypoint")
414 if(checkpvs(wp.origin, ad))
428 /// dprint("waypoints around target were found\n");
429 // te_lightning2(world, '0 0 0', best.origin);
430 // te_knightspike(best.origin);
432 navigation_routerating(best, ratingscale, 4000);
435 self.havocbot_attack_time = 0;
437 if(checkpvs(self.view_ofs,ad))
438 if(checkpvs(self.view_ofs,best))
440 // dprint("increasing attack time for this target\n");
441 self.havocbot_attack_time = time + 2;
447 void havocbot_role_ast_offense()
449 if(self.deadflag != DEAD_NO)
451 self.havocbot_attack_time = 0;
452 havocbot_ast_reset_role(self);
456 // Set the role timeout if necessary
457 if (!self.havocbot_role_timeout)
458 self.havocbot_role_timeout = time + 120;
460 if (time > self.havocbot_role_timeout)
462 havocbot_ast_reset_role(self);
466 if(self.havocbot_attack_time>time)
469 if (self.bot_strategytime < time)
471 navigation_goalrating_start();
472 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
473 havocbot_goalrating_ast_targets(20000);
474 havocbot_goalrating_items(15000, self.origin, 10000);
475 navigation_goalrating_end();
477 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
481 void havocbot_role_ast_defense()
483 if(self.deadflag != DEAD_NO)
485 self.havocbot_attack_time = 0;
486 havocbot_ast_reset_role(self);
490 // Set the role timeout if necessary
491 if (!self.havocbot_role_timeout)
492 self.havocbot_role_timeout = time + 120;
494 if (time > self.havocbot_role_timeout)
496 havocbot_ast_reset_role(self);
500 if(self.havocbot_attack_time>time)
503 if (self.bot_strategytime < time)
505 navigation_goalrating_start();
506 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
507 havocbot_goalrating_ast_targets(20000);
508 havocbot_goalrating_items(15000, self.origin, 10000);
509 navigation_goalrating_end();
511 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
515 void havocbot_role_ast_setrole(entity bot, float role)
519 case HAVOCBOT_AST_ROLE_DEFENSE:
520 bot.havocbot_role = havocbot_role_ast_defense;
521 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
522 bot.havocbot_role_timeout = 0;
524 case HAVOCBOT_AST_ROLE_OFFENSE:
525 bot.havocbot_role = havocbot_role_ast_offense;
526 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
527 bot.havocbot_role_timeout = 0;
532 void havocbot_ast_reset_role(entity bot)
534 if(self.deadflag != DEAD_NO)
537 if(bot.team == assault_attacker_team)
538 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
540 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
544 MUTATOR_HOOKFUNCTION(assault_PlayerSpawn)
546 if(self.team == assault_attacker_team)
547 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
549 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
554 MUTATOR_HOOKFUNCTION(assault_TurretSpawn)
562 MUTATOR_HOOKFUNCTION(assault_VehicleSpawn)
564 self.nextthink = time + 0.5;
569 MUTATOR_HOOKFUNCTION(assault_BotRoles)
571 havocbot_ast_reset_role(self);
575 MUTATOR_HOOKFUNCTION(assault_PlayHitsound)
577 return (frag_victim.classname == "func_assault_destructible");
581 void assault_ScoreRules()
583 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
584 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
585 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
586 ScoreRules_basics_end();
589 MUTATOR_DEFINITION(gamemode_assault)
591 MUTATOR_HOOK(PlayerSpawn, assault_PlayerSpawn, CBC_ORDER_ANY);
592 MUTATOR_HOOK(TurretSpawn, assault_TurretSpawn, CBC_ORDER_ANY);
593 MUTATOR_HOOK(VehicleSpawn, assault_VehicleSpawn, CBC_ORDER_ANY);
594 MUTATOR_HOOK(HavocBot_ChooseRole, assault_BotRoles, CBC_ORDER_ANY);
595 MUTATOR_HOOK(PlayHitsound, assault_PlayHitsound, CBC_ORDER_ANY);
599 if(time > 1) // game loads at time 1
600 error("This is a game type and it cannot be added at runtime.");
601 assault_ScoreRules();
604 MUTATOR_ONROLLBACK_OR_REMOVE
606 // we actually cannot roll back assault_Initialize here
607 // BUT: we don't need to! If this gets called, adding always
613 print("This is a game type and it cannot be removed at runtime.");