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");
16 for (entity e = world; (e = find(e, target, this.targetname)); )
18 if (e.classname == "target_objective_decrease")
20 WITH(entity, self, e, target_objective_decrease_activate());
27 vector target_objective_spawn_evalfunc(entity player, entity spot, vector current)
29 if(self.health < 0 || self.health >= ASSAULT_VALUE_INACTIVE)
34 // reset this objective. Used when spawning an objective
35 // and when a new round starts
36 void assault_objective_reset()
38 self.health = ASSAULT_VALUE_INACTIVE;
41 // decrease the health of targeted objectives
42 void assault_objective_decrease_use()
44 if(activator.team != assault_attacker_team)
46 // wrong team triggered decrease
50 if(other.assault_sprite)
52 WaypointSprite_Disown(other.assault_sprite, waypointsprite_deadlifetime);
53 if(other.classname == "func_assault_destructible")
57 return; // already activated! cannot activate again!
59 if(self.enemy.health < ASSAULT_VALUE_INACTIVE)
61 if(self.enemy.health - self.dmg > 0.5)
63 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.dmg);
64 self.enemy.health = self.enemy.health - self.dmg;
68 PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.enemy.health);
69 PlayerTeamScore_Add(activator, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
70 self.enemy.health = -1;
72 entity oldactivator, head;
77 centerprint(head, self.message);
79 oldactivator = activator;
82 activator = oldactivator;
88 void assault_setenemytoobjective()
91 for(objective = world; (objective = find(objective, targetname, self.target)); )
93 if(objective.classname == "target_objective")
95 if(self.enemy == world)
96 self.enemy = objective;
98 objerror("more than one objective as target - fix the map!");
103 if(self.enemy == world)
104 objerror("no objective as target - fix the map!");
107 float assault_decreaser_sprite_visible(entity e)
111 decreaser = self.assault_decreaser;
113 if(decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
119 void target_objective_decrease_activate()
123 for(ent = world; (ent = find(ent, target, self.targetname)); )
125 if(ent.assault_sprite != world)
127 WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
128 if(ent.classname == "func_assault_destructible")
132 spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE);
133 spr.assault_decreaser = self;
134 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
135 spr.classname = "sprite_waypoint";
136 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
137 if(ent.classname == "func_assault_destructible")
139 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
140 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
141 WaypointSprite_UpdateHealth(spr, ent.health);
145 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
149 void target_objective_decrease_findtarget()
151 assault_setenemytoobjective();
154 void target_assault_roundend_reset()
156 //print("round end reset\n");
157 self.cnt = self.cnt + 1; // up round counter
158 self.winning = 0; // up round
161 void target_assault_roundend_use()
163 self.winning = 1; // round has been won by attackers
166 void assault_roundstart_use()
171 //(Re)spawn all turrets
172 for(entity ent = NULL; (ent = find(ent, classname, "turret_main")); ) {
174 if(ent.team == NUM_TEAM_1)
175 ent.team = NUM_TEAM_2;
177 ent.team = NUM_TEAM_1;
179 // Dubbles as teamchange
180 WITH(entity, self, ent, turret_respawn());
184 void assault_wall_think()
186 if(self.enemy.health < 0)
189 self.solid = SOLID_NOT;
193 self.model = self.mdl;
194 self.solid = SOLID_BSP;
197 self.nextthink = time + 0.2;
201 // reset objectives, toggle spawnpoints, reset triggers, ...
202 void vehicles_clearreturn(entity veh);
203 void vehicles_spawn();
204 void assault_new_round()
206 //bprint("ASSAULT: new round\n");
208 // Eject players from vehicles
214 WITH(entity, self, e, vehicles_exit(VHEF_RELEASE));
218 for (entity e_ = findchainflags(vehicle_flags, VHF_ISVEHICLE); e_; e_ = e_.chain)
221 vehicles_clearreturn(self);
228 self.winning = self.winning + 1;
230 // swap attacker/defender roles
231 if(assault_attacker_team == NUM_TEAM_1)
232 assault_attacker_team = NUM_TEAM_2;
234 assault_attacker_team = NUM_TEAM_1;
237 for(ent = world; (ent = nextent(ent)); )
239 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
241 if(ent.team_saved == NUM_TEAM_1)
242 ent.team_saved = NUM_TEAM_2;
243 else if(ent.team_saved == NUM_TEAM_2)
244 ent.team_saved = NUM_TEAM_1;
248 // reset the level with a countdown
249 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
250 ReadyRestart_force(); // sets game_starttime
254 void spawnfunc_info_player_attacker()
256 if (!g_assault) { remove(self); return; }
258 self.team = NUM_TEAM_1; // red, gets swapped every round
259 spawnfunc_info_player_deathmatch();
262 void spawnfunc_info_player_defender()
264 if (!g_assault) { remove(self); return; }
266 self.team = NUM_TEAM_2; // blue, gets swapped every round
267 spawnfunc_info_player_deathmatch();
270 void spawnfunc_target_objective()
272 if (!g_assault) { remove(self); return; }
274 self.classname = "target_objective";
275 self.use = assault_objective_use;
276 assault_objective_reset();
277 self.reset = assault_objective_reset;
278 self.spawn_evalfunc = target_objective_spawn_evalfunc;
281 void spawnfunc_target_objective_decrease()
283 if (!g_assault) { remove(self); return; }
285 self.classname = "target_objective_decrease";
290 self.use = assault_objective_decrease_use;
291 self.health = ASSAULT_VALUE_INACTIVE;
292 self.max_health = ASSAULT_VALUE_INACTIVE;
295 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
298 // destructible walls that can be used to trigger target_objective_decrease
299 void spawnfunc_func_assault_destructible()
301 if (!g_assault) { remove(self); return; }
304 self.classname = "func_assault_destructible";
306 if(assault_attacker_team == NUM_TEAM_1)
307 self.team = NUM_TEAM_2;
309 self.team = NUM_TEAM_1;
311 spawnfunc_func_breakable();
314 void spawnfunc_func_assault_wall()
316 if (!g_assault) { remove(self); return; }
318 self.classname = "func_assault_wall";
319 self.mdl = self.model;
320 _setmodel(self, self.mdl);
321 self.solid = SOLID_BSP;
322 self.think = assault_wall_think;
323 self.nextthink = time;
324 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
327 void spawnfunc_target_assault_roundend()
329 if (!g_assault) { remove(self); return; }
331 self.winning = 0; // round not yet won by attackers
332 self.classname = "target_assault_roundend";
333 self.use = target_assault_roundend_use;
334 self.cnt = 0; // first round
335 self.reset = target_assault_roundend_reset;
338 void spawnfunc_target_assault_roundstart()
340 if (!g_assault) { remove(self); return; }
342 assault_attacker_team = NUM_TEAM_1;
343 self.classname = "target_assault_roundstart";
344 self.use = assault_roundstart_use;
345 self.reset2 = assault_roundstart_use;
346 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
350 void havocbot_goalrating_ast_targets(float ratingscale)
352 entity ad, best, wp, tod;
353 float radius, found, bestvalue;
356 ad = findchain(classname, "func_assault_destructible");
358 for (; ad; ad = ad.chain)
367 for(tod = world; (tod = find(tod, targetname, ad.target)); )
369 if(tod.classname == "target_objective_decrease")
371 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
373 // dprint(etos(ad),"\n");
382 /// dprint("target not found\n");
385 /// dprint("target #", etos(ad), " found\n");
388 p = 0.5 * (ad.absmin + ad.absmax);
389 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
390 // te_knightspike(p);
391 // te_lightning2(world, '0 0 0', p);
393 // Find and rate waypoints around it
396 bestvalue = 99999999999;
397 for(radius=0; radius<1500 && !found; radius+=500)
399 for(wp=findradius(p, radius); wp; wp=wp.chain)
401 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
402 if(wp.classname=="waypoint")
403 if(checkpvs(wp.origin, ad))
417 /// dprint("waypoints around target were found\n");
418 // te_lightning2(world, '0 0 0', best.origin);
419 // te_knightspike(best.origin);
421 navigation_routerating(best, ratingscale, 4000);
424 self.havocbot_attack_time = 0;
426 if(checkpvs(self.view_ofs,ad))
427 if(checkpvs(self.view_ofs,best))
429 // dprint("increasing attack time for this target\n");
430 self.havocbot_attack_time = time + 2;
436 void havocbot_role_ast_offense()
438 if(self.deadflag != DEAD_NO)
440 self.havocbot_attack_time = 0;
441 havocbot_ast_reset_role(self);
445 // Set the role timeout if necessary
446 if (!self.havocbot_role_timeout)
447 self.havocbot_role_timeout = time + 120;
449 if (time > self.havocbot_role_timeout)
451 havocbot_ast_reset_role(self);
455 if(self.havocbot_attack_time>time)
458 if (self.bot_strategytime < time)
460 navigation_goalrating_start();
461 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
462 havocbot_goalrating_ast_targets(20000);
463 havocbot_goalrating_items(15000, self.origin, 10000);
464 navigation_goalrating_end();
466 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
470 void havocbot_role_ast_defense()
472 if(self.deadflag != DEAD_NO)
474 self.havocbot_attack_time = 0;
475 havocbot_ast_reset_role(self);
479 // Set the role timeout if necessary
480 if (!self.havocbot_role_timeout)
481 self.havocbot_role_timeout = time + 120;
483 if (time > self.havocbot_role_timeout)
485 havocbot_ast_reset_role(self);
489 if(self.havocbot_attack_time>time)
492 if (self.bot_strategytime < time)
494 navigation_goalrating_start();
495 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
496 havocbot_goalrating_ast_targets(20000);
497 havocbot_goalrating_items(15000, self.origin, 10000);
498 navigation_goalrating_end();
500 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
504 void havocbot_role_ast_setrole(entity bot, float role)
508 case HAVOCBOT_AST_ROLE_DEFENSE:
509 bot.havocbot_role = havocbot_role_ast_defense;
510 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
511 bot.havocbot_role_timeout = 0;
513 case HAVOCBOT_AST_ROLE_OFFENSE:
514 bot.havocbot_role = havocbot_role_ast_offense;
515 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
516 bot.havocbot_role_timeout = 0;
521 void havocbot_ast_reset_role(entity bot)
523 if(self.deadflag != DEAD_NO)
526 if(bot.team == assault_attacker_team)
527 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
529 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
533 MUTATOR_HOOKFUNCTION(assault_PlayerSpawn)
535 if(self.team == assault_attacker_team)
536 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
538 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
543 MUTATOR_HOOKFUNCTION(assault_TurretSpawn)
545 if(!self.team || self.team == MAX_SHOT_DISTANCE)
546 self.team = 5; // this gets reversed when match starts?
551 MUTATOR_HOOKFUNCTION(assault_VehicleSpawn)
553 self.nextthink = time + 0.5;
558 MUTATOR_HOOKFUNCTION(assault_BotRoles)
560 havocbot_ast_reset_role(self);
564 MUTATOR_HOOKFUNCTION(assault_PlayHitsound)
566 return (frag_victim.classname == "func_assault_destructible");
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_ChooseRole, assault_BotRoles, CBC_ORDER_ANY);
584 MUTATOR_HOOK(PlayHitsound, assault_PlayHitsound, 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 LOG_INFO("This is a game type and it cannot be removed at runtime.");