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("<placeholder>", 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE, '1 0.5 0');
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, "as-defend", "as-destroy", "as-destroy");
142 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
143 WaypointSprite_UpdateHealth(spr, ent.health);
147 WaypointSprite_UpdateSprites(spr, "as-defend", "as-push", "as-push");
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()
173 #ifdef TTURRETS_ENABLED
176 //(Re)spawn all turrets
178 ent = find(world, classname, "turret_main");
181 if(ent.team == NUM_TEAM_1)
182 ent.team = NUM_TEAM_2;
184 ent.team = NUM_TEAM_1;
188 // Dubbles as teamchange
189 turret_stdproc_respawn();
191 ent = find(ent, classname, "turret_main");
197 void assault_wall_think()
199 if(self.enemy.health < 0)
202 self.solid = SOLID_NOT;
206 self.model = self.mdl;
207 self.solid = SOLID_BSP;
210 self.nextthink = time + 0.2;
214 // reset objectives, toggle spawnpoints, reset triggers, ...
215 void vehicles_clearreturn(entity veh);
216 void vehicles_spawn();
217 void assault_new_round()
220 //bprint("ASSAULT: new round\n");
223 // Eject players from vehicles
224 FOR_EACH_PLAYER(self)
227 vehicles_exit(VHEF_RELEASE);
230 self = findchainflags(vehicle_flags, VHF_ISVEHICLE);
233 vehicles_clearreturn(self);
241 self.winning = self.winning + 1;
243 // swap attacker/defender roles
244 if(assault_attacker_team == NUM_TEAM_1)
245 assault_attacker_team = NUM_TEAM_2;
247 assault_attacker_team = NUM_TEAM_1;
250 for(ent = world; (ent = nextent(ent)); )
252 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
254 if(ent.team_saved == NUM_TEAM_1)
255 ent.team_saved = NUM_TEAM_2;
256 else if(ent.team_saved == NUM_TEAM_2)
257 ent.team_saved = NUM_TEAM_1;
261 // reset the level with a countdown
262 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
263 ReadyRestart_force(); // sets game_starttime
267 void spawnfunc_info_player_attacker()
269 if (!g_assault) { remove(self); return; }
271 self.team = NUM_TEAM_1; // red, gets swapped every round
272 spawnfunc_info_player_deathmatch();
275 void spawnfunc_info_player_defender()
277 if (!g_assault) { remove(self); return; }
279 self.team = NUM_TEAM_2; // blue, gets swapped every round
280 spawnfunc_info_player_deathmatch();
283 void spawnfunc_target_objective()
285 if (!g_assault) { remove(self); return; }
287 self.classname = "target_objective";
288 self.use = assault_objective_use;
289 assault_objective_reset();
290 self.reset = assault_objective_reset;
291 self.spawn_evalfunc = target_objective_spawn_evalfunc;
294 void spawnfunc_target_objective_decrease()
296 if (!g_assault) { remove(self); return; }
298 self.classname = "target_objective_decrease";
303 self.use = assault_objective_decrease_use;
304 self.health = ASSAULT_VALUE_INACTIVE;
305 self.max_health = ASSAULT_VALUE_INACTIVE;
308 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
311 // destructible walls that can be used to trigger target_objective_decrease
312 void spawnfunc_func_assault_destructible()
314 if (!g_assault) { remove(self); return; }
317 self.classname = "func_assault_destructible";
319 if(assault_attacker_team == NUM_TEAM_1)
320 self.team = NUM_TEAM_2;
322 self.team = NUM_TEAM_1;
324 spawnfunc_func_breakable();
327 void spawnfunc_func_assault_wall()
329 if (!g_assault) { remove(self); return; }
331 self.classname = "func_assault_wall";
332 self.mdl = self.model;
333 setmodel(self, self.mdl);
334 self.solid = SOLID_BSP;
335 self.think = assault_wall_think;
336 self.nextthink = time;
337 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
340 void spawnfunc_target_assault_roundend()
342 if (!g_assault) { remove(self); return; }
344 self.winning = 0; // round not yet won by attackers
345 self.classname = "target_assault_roundend";
346 self.use = target_assault_roundend_use;
347 self.cnt = 0; // first round
348 self.reset = target_assault_roundend_reset;
351 void spawnfunc_target_assault_roundstart()
353 if (!g_assault) { remove(self); return; }
355 assault_attacker_team = NUM_TEAM_1;
356 self.classname = "target_assault_roundstart";
357 self.use = assault_roundstart_use;
358 self.reset2 = assault_roundstart_use;
359 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
363 void havocbot_goalrating_ast_targets(float ratingscale)
365 entity ad, best, wp, tod;
366 float radius, found, bestvalue;
369 ad = findchain(classname, "func_assault_destructible");
371 for (; ad; ad = ad.chain)
380 for(tod = world; (tod = find(tod, targetname, ad.target)); )
382 if(tod.classname == "target_objective_decrease")
384 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
386 // dprint(etos(ad),"\n");
395 /// dprint("target not found\n");
398 /// dprint("target #", etos(ad), " found\n");
401 p = 0.5 * (ad.absmin + ad.absmax);
402 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
403 // te_knightspike(p);
404 // te_lightning2(world, '0 0 0', p);
406 // Find and rate waypoints around it
409 bestvalue = 99999999999;
410 for(radius=0; radius<1500 && !found; radius+=500)
412 for(wp=findradius(p, radius); wp; wp=wp.chain)
414 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
415 if(wp.classname=="waypoint")
416 if(checkpvs(wp.origin, ad))
430 /// dprint("waypoints around target were found\n");
431 // te_lightning2(world, '0 0 0', best.origin);
432 // te_knightspike(best.origin);
434 navigation_routerating(best, ratingscale, 4000);
437 self.havocbot_attack_time = 0;
439 if(checkpvs(self.view_ofs,ad))
440 if(checkpvs(self.view_ofs,best))
442 // dprint("increasing attack time for this target\n");
443 self.havocbot_attack_time = time + 2;
449 void havocbot_role_ast_offense()
451 if(self.deadflag != DEAD_NO)
453 self.havocbot_attack_time = 0;
454 havocbot_ast_reset_role(self);
458 // Set the role timeout if necessary
459 if (!self.havocbot_role_timeout)
460 self.havocbot_role_timeout = time + 120;
462 if (time > self.havocbot_role_timeout)
464 havocbot_ast_reset_role(self);
468 if(self.havocbot_attack_time>time)
471 if (self.bot_strategytime < time)
473 navigation_goalrating_start();
474 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
475 havocbot_goalrating_ast_targets(20000);
476 havocbot_goalrating_items(15000, self.origin, 10000);
477 navigation_goalrating_end();
479 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
483 void havocbot_role_ast_defense()
485 if(self.deadflag != DEAD_NO)
487 self.havocbot_attack_time = 0;
488 havocbot_ast_reset_role(self);
492 // Set the role timeout if necessary
493 if (!self.havocbot_role_timeout)
494 self.havocbot_role_timeout = time + 120;
496 if (time > self.havocbot_role_timeout)
498 havocbot_ast_reset_role(self);
502 if(self.havocbot_attack_time>time)
505 if (self.bot_strategytime < time)
507 navigation_goalrating_start();
508 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
509 havocbot_goalrating_ast_targets(20000);
510 havocbot_goalrating_items(15000, self.origin, 10000);
511 navigation_goalrating_end();
513 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
517 void havocbot_role_ast_setrole(entity bot, float role)
521 case HAVOCBOT_AST_ROLE_DEFENSE:
522 bot.havocbot_role = havocbot_role_ast_defense;
523 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
524 bot.havocbot_role_timeout = 0;
526 case HAVOCBOT_AST_ROLE_OFFENSE:
527 bot.havocbot_role = havocbot_role_ast_offense;
528 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
529 bot.havocbot_role_timeout = 0;
534 void havocbot_ast_reset_role(entity bot)
536 if(self.deadflag != DEAD_NO)
539 if(bot.team == assault_attacker_team)
540 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
542 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
546 MUTATOR_HOOKFUNCTION(assault_PlayerSpawn)
548 if(self.team == assault_attacker_team)
549 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
551 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
556 MUTATOR_HOOKFUNCTION(assault_TurretSpawn)
564 MUTATOR_HOOKFUNCTION(assault_VehicleSpawn)
566 self.nextthink = time + 0.5;
571 MUTATOR_HOOKFUNCTION(assault_BotRoles)
573 havocbot_ast_reset_role(self);
578 void assault_ScoreRules()
580 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
581 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
582 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
583 ScoreRules_basics_end();
586 MUTATOR_DEFINITION(gamemode_assault)
588 MUTATOR_HOOK(PlayerSpawn, assault_PlayerSpawn, CBC_ORDER_ANY);
589 MUTATOR_HOOK(TurretSpawn, assault_TurretSpawn, CBC_ORDER_ANY);
590 MUTATOR_HOOK(VehicleSpawn, assault_VehicleSpawn, CBC_ORDER_ANY);
591 MUTATOR_HOOK(HavocBot_ChooseRole, assault_BotRoles, CBC_ORDER_ANY);
595 if(time > 1) // game loads at time 1
596 error("This is a game type and it cannot be added at runtime.");
597 assault_ScoreRules();
600 MUTATOR_ONROLLBACK_OR_REMOVE
602 // we actually cannot roll back assault_Initialize here
603 // BUT: we don't need to! If this gets called, adding always
609 print("This is a game type and it cannot be removed at runtime.");