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 SELFCALL(e, 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 oldactivator, head;
78 centerprint(head, self.message);
80 oldactivator = activator;
83 activator = oldactivator;
89 void assault_setenemytoobjective()
92 for(objective = world; (objective = find(objective, targetname, self.target)); )
94 if(objective.classname == "target_objective")
96 if(self.enemy == world)
97 self.enemy = objective;
99 objerror("more than one objective as target - fix the map!");
104 if(self.enemy == world)
105 objerror("no objective as target - fix the map!");
108 float assault_decreaser_sprite_visible(entity e)
112 decreaser = self.assault_decreaser;
114 if(decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
120 void target_objective_decrease_activate()
124 for(ent = world; (ent = find(ent, target, self.targetname)); )
126 if(ent.assault_sprite != world)
128 WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
129 if(ent.classname == "func_assault_destructible")
133 spr = WaypointSprite_SpawnFixed(WP_Assault, 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE);
134 spr.assault_decreaser = self;
135 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
136 spr.classname = "sprite_waypoint";
137 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
138 if(ent.classname == "func_assault_destructible")
140 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
141 WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
142 WaypointSprite_UpdateHealth(spr, ent.health);
146 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
150 void target_objective_decrease_findtarget()
152 assault_setenemytoobjective();
155 void target_assault_roundend_reset()
157 //print("round end reset\n");
158 self.cnt = self.cnt + 1; // up round counter
159 self.winning = 0; // up round
162 void target_assault_roundend_use()
164 self.winning = 1; // round has been won by attackers
167 void assault_roundstart_use()
172 //(Re)spawn all turrets
173 for(entity ent = NULL; (ent = find(ent, classname, "turret_main")); ) {
175 if(ent.team == NUM_TEAM_1)
176 ent.team = NUM_TEAM_2;
178 ent.team = NUM_TEAM_1;
180 // Dubbles as teamchange
181 SELFCALL(ent, turret_respawn());
186 void assault_wall_think()
188 if(self.enemy.health < 0)
191 self.solid = SOLID_NOT;
195 self.model = self.mdl;
196 self.solid = SOLID_BSP;
199 self.nextthink = time + 0.2;
203 // reset objectives, toggle spawnpoints, reset triggers, ...
204 void vehicles_clearreturn(entity veh);
205 void vehicles_spawn();
206 void assault_new_round()
208 //bprint("ASSAULT: new round\n");
210 // Eject players from vehicles
216 SELFCALL(e, vehicles_exit(VHEF_RELEASE));
221 for (entity e_ = findchainflags(vehicle_flags, VHF_ISVEHICLE); e_; e_ = e_.chain)
224 vehicles_clearreturn(self);
231 self.winning = self.winning + 1;
233 // swap attacker/defender roles
234 if(assault_attacker_team == NUM_TEAM_1)
235 assault_attacker_team = NUM_TEAM_2;
237 assault_attacker_team = NUM_TEAM_1;
240 for(ent = world; (ent = nextent(ent)); )
242 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
244 if(ent.team_saved == NUM_TEAM_1)
245 ent.team_saved = NUM_TEAM_2;
246 else if(ent.team_saved == NUM_TEAM_2)
247 ent.team_saved = NUM_TEAM_1;
251 // reset the level with a countdown
252 cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
253 ReadyRestart_force(); // sets game_starttime
257 void spawnfunc_info_player_attacker()
259 if (!g_assault) { remove(self); return; }
261 self.team = NUM_TEAM_1; // red, gets swapped every round
262 spawnfunc_info_player_deathmatch();
265 void spawnfunc_info_player_defender()
267 if (!g_assault) { remove(self); return; }
269 self.team = NUM_TEAM_2; // blue, gets swapped every round
270 spawnfunc_info_player_deathmatch();
273 void spawnfunc_target_objective()
275 if (!g_assault) { remove(self); return; }
277 self.classname = "target_objective";
278 self.use = assault_objective_use;
279 assault_objective_reset();
280 self.reset = assault_objective_reset;
281 self.spawn_evalfunc = target_objective_spawn_evalfunc;
284 void spawnfunc_target_objective_decrease()
286 if (!g_assault) { remove(self); return; }
288 self.classname = "target_objective_decrease";
293 self.use = assault_objective_decrease_use;
294 self.health = ASSAULT_VALUE_INACTIVE;
295 self.max_health = ASSAULT_VALUE_INACTIVE;
298 InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
301 // destructible walls that can be used to trigger target_objective_decrease
302 void spawnfunc_func_assault_destructible()
304 if (!g_assault) { remove(self); return; }
307 self.classname = "func_assault_destructible";
309 if(assault_attacker_team == NUM_TEAM_1)
310 self.team = NUM_TEAM_2;
312 self.team = NUM_TEAM_1;
314 spawnfunc_func_breakable();
317 void spawnfunc_func_assault_wall()
319 if (!g_assault) { remove(self); return; }
321 self.classname = "func_assault_wall";
322 self.mdl = self.model;
323 setmodel(self, self.mdl);
324 self.solid = SOLID_BSP;
325 self.think = assault_wall_think;
326 self.nextthink = time;
327 InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
330 void spawnfunc_target_assault_roundend()
332 if (!g_assault) { remove(self); return; }
334 self.winning = 0; // round not yet won by attackers
335 self.classname = "target_assault_roundend";
336 self.use = target_assault_roundend_use;
337 self.cnt = 0; // first round
338 self.reset = target_assault_roundend_reset;
341 void spawnfunc_target_assault_roundstart()
343 if (!g_assault) { remove(self); return; }
345 assault_attacker_team = NUM_TEAM_1;
346 self.classname = "target_assault_roundstart";
347 self.use = assault_roundstart_use;
348 self.reset2 = assault_roundstart_use;
349 InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
353 void havocbot_goalrating_ast_targets(float ratingscale)
355 entity ad, best, wp, tod;
356 float radius, found, bestvalue;
359 ad = findchain(classname, "func_assault_destructible");
361 for (; ad; ad = ad.chain)
370 for(tod = world; (tod = find(tod, targetname, ad.target)); )
372 if(tod.classname == "target_objective_decrease")
374 if(tod.enemy.health > 0 && tod.enemy.health < ASSAULT_VALUE_INACTIVE)
376 // dprint(etos(ad),"\n");
385 /// dprint("target not found\n");
388 /// dprint("target #", etos(ad), " found\n");
391 p = 0.5 * (ad.absmin + ad.absmax);
392 // dprint(vtos(ad.origin), " ", vtos(ad.absmin), " ", vtos(ad.absmax),"\n");
393 // te_knightspike(p);
394 // te_lightning2(world, '0 0 0', p);
396 // Find and rate waypoints around it
399 bestvalue = 99999999999;
400 for(radius=0; radius<1500 && !found; radius+=500)
402 for(wp=findradius(p, radius); wp; wp=wp.chain)
404 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
405 if(wp.classname=="waypoint")
406 if(checkpvs(wp.origin, ad))
420 /// dprint("waypoints around target were found\n");
421 // te_lightning2(world, '0 0 0', best.origin);
422 // te_knightspike(best.origin);
424 navigation_routerating(best, ratingscale, 4000);
427 self.havocbot_attack_time = 0;
429 if(checkpvs(self.view_ofs,ad))
430 if(checkpvs(self.view_ofs,best))
432 // dprint("increasing attack time for this target\n");
433 self.havocbot_attack_time = time + 2;
439 void havocbot_role_ast_offense()
441 if(self.deadflag != DEAD_NO)
443 self.havocbot_attack_time = 0;
444 havocbot_ast_reset_role(self);
448 // Set the role timeout if necessary
449 if (!self.havocbot_role_timeout)
450 self.havocbot_role_timeout = time + 120;
452 if (time > self.havocbot_role_timeout)
454 havocbot_ast_reset_role(self);
458 if(self.havocbot_attack_time>time)
461 if (self.bot_strategytime < time)
463 navigation_goalrating_start();
464 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
465 havocbot_goalrating_ast_targets(20000);
466 havocbot_goalrating_items(15000, self.origin, 10000);
467 navigation_goalrating_end();
469 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
473 void havocbot_role_ast_defense()
475 if(self.deadflag != DEAD_NO)
477 self.havocbot_attack_time = 0;
478 havocbot_ast_reset_role(self);
482 // Set the role timeout if necessary
483 if (!self.havocbot_role_timeout)
484 self.havocbot_role_timeout = time + 120;
486 if (time > self.havocbot_role_timeout)
488 havocbot_ast_reset_role(self);
492 if(self.havocbot_attack_time>time)
495 if (self.bot_strategytime < time)
497 navigation_goalrating_start();
498 havocbot_goalrating_enemyplayers(20000, self.origin, 3000);
499 havocbot_goalrating_ast_targets(20000);
500 havocbot_goalrating_items(15000, self.origin, 10000);
501 navigation_goalrating_end();
503 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
507 void havocbot_role_ast_setrole(entity bot, float role)
511 case HAVOCBOT_AST_ROLE_DEFENSE:
512 bot.havocbot_role = havocbot_role_ast_defense;
513 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
514 bot.havocbot_role_timeout = 0;
516 case HAVOCBOT_AST_ROLE_OFFENSE:
517 bot.havocbot_role = havocbot_role_ast_offense;
518 bot.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
519 bot.havocbot_role_timeout = 0;
524 void havocbot_ast_reset_role(entity bot)
526 if(self.deadflag != DEAD_NO)
529 if(bot.team == assault_attacker_team)
530 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_OFFENSE);
532 havocbot_role_ast_setrole(bot, HAVOCBOT_AST_ROLE_DEFENSE);
536 MUTATOR_HOOKFUNCTION(assault_PlayerSpawn)
538 if(self.team == assault_attacker_team)
539 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
541 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
546 MUTATOR_HOOKFUNCTION(assault_TurretSpawn)
548 if(!self.team || self.team == MAX_SHOT_DISTANCE)
549 self.team = 5; // this gets reversed when match starts?
554 MUTATOR_HOOKFUNCTION(assault_VehicleSpawn)
556 self.nextthink = time + 0.5;
561 MUTATOR_HOOKFUNCTION(assault_BotRoles)
563 havocbot_ast_reset_role(self);
567 MUTATOR_HOOKFUNCTION(assault_PlayHitsound)
569 return (frag_victim.classname == "func_assault_destructible");
573 void assault_ScoreRules()
575 ScoreRules_basics(2, SFL_SORT_PRIO_SECONDARY, SFL_SORT_PRIO_SECONDARY, true);
576 ScoreInfo_SetLabel_TeamScore( ST_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
577 ScoreInfo_SetLabel_PlayerScore(SP_ASSAULT_OBJECTIVES, "objectives", SFL_SORT_PRIO_PRIMARY);
578 ScoreRules_basics_end();
581 MUTATOR_DEFINITION(gamemode_assault)
583 MUTATOR_HOOK(PlayerSpawn, assault_PlayerSpawn, CBC_ORDER_ANY);
584 MUTATOR_HOOK(TurretSpawn, assault_TurretSpawn, CBC_ORDER_ANY);
585 MUTATOR_HOOK(VehicleSpawn, assault_VehicleSpawn, CBC_ORDER_ANY);
586 MUTATOR_HOOK(HavocBot_ChooseRole, assault_BotRoles, CBC_ORDER_ANY);
587 MUTATOR_HOOK(PlayHitsound, assault_PlayHitsound, CBC_ORDER_ANY);
591 if(time > 1) // game loads at time 1
592 error("This is a game type and it cannot be added at runtime.");
593 assault_ScoreRules();
596 MUTATOR_ONROLLBACK_OR_REMOVE
598 // we actually cannot roll back assault_Initialize here
599 // BUT: we don't need to! If this gets called, adding always
605 LOG_INFO("This is a game type and it cannot be removed at runtime.");