3 // TODO: split into sv_assault
6 #define AS_ROUND_DELAY 5
8 IntrusiveList g_assault_destructibles;
9 IntrusiveList g_assault_objectivedecreasers;
10 IntrusiveList g_assault_objectives;
11 STATIC_INIT(g_assault)
13 g_assault_destructibles = IL_NEW();
14 g_assault_objectivedecreasers = IL_NEW();
15 g_assault_objectives = IL_NEW();
19 void assault_objective_use(entity this, entity actor, entity trigger)
22 SetResourceAmountExplicit(this, RESOURCE_HEALTH, 100);
23 //print("^2Activated objective ", this.targetname, "=", etos(this), "\n");
24 //print("Activator is ", actor.classname, "\n");
26 IL_EACH(g_assault_objectivedecreasers, it.target == this.targetname,
28 target_objective_decrease_activate(it);
32 vector target_objective_spawn_evalfunc(entity this, entity player, entity spot, vector current)
34 if(GetResourceAmount(this, RESOURCE_HEALTH) < 0 || GetResourceAmount(this, RESOURCE_HEALTH) >= ASSAULT_VALUE_INACTIVE)
39 // reset this objective. Used when spawning an objective
40 // and when a new round starts
41 void assault_objective_reset(entity this)
43 SetResourceAmountExplicit(this, RESOURCE_HEALTH, ASSAULT_VALUE_INACTIVE);
46 // decrease the health of targeted objectives
47 void assault_objective_decrease_use(entity this, entity actor, entity trigger)
49 if(actor.team != assault_attacker_team)
51 // wrong team triggered decrease
55 if(trigger.assault_sprite)
57 WaypointSprite_Disown(trigger.assault_sprite, waypointsprite_deadlifetime);
58 if(trigger.classname == "func_assault_destructible")
59 trigger.sprite = NULL; // TODO: just unsetting it?!
62 return; // already activated! cannot activate again!
64 if(GetResourceAmount(this.enemy, RESOURCE_HEALTH) < ASSAULT_VALUE_INACTIVE)
66 if(GetResourceAmount(this.enemy, RESOURCE_HEALTH) - this.dmg > 0.5)
68 GameRules_scoring_add_team(actor, SCORE, this.dmg);
69 TakeResource(this.enemy, RESOURCE_HEALTH, this.dmg);
73 GameRules_scoring_add_team(actor, SCORE, GetResourceAmount(this.enemy, RESOURCE_HEALTH));
74 GameRules_scoring_add_team(actor, ASSAULT_OBJECTIVES, 1);
75 SetResourceAmountExplicit(this.enemy, RESOURCE_HEALTH, -1);
77 if(this.enemy.message)
78 FOREACH_CLIENT(IS_PLAYER(it), { centerprint(it, this.enemy.message); });
80 SUB_UseTargets(this.enemy, this, trigger);
85 void assault_setenemytoobjective(entity this)
87 IL_EACH(g_assault_objectives, it.targetname == this.target,
89 if(this.enemy == NULL)
92 objerror(this, "more than one objective as target - fix the map!");
96 if(this.enemy == NULL)
97 objerror(this, "no objective as target - fix the map!");
100 bool assault_decreaser_sprite_visible(entity this, entity player, entity view)
102 if(GetResourceAmount(this.assault_decreaser.enemy, RESOURCE_HEALTH) >= ASSAULT_VALUE_INACTIVE)
108 void target_objective_decrease_activate(entity this)
112 FOREACH_ENTITY_STRING(target, this.targetname,
114 if(it.assault_sprite != NULL)
116 WaypointSprite_Disown(it.assault_sprite, waypointsprite_deadlifetime);
117 if(it.classname == "func_assault_destructible")
118 it.sprite = NULL; // TODO: just unsetting it?!
121 spr = WaypointSprite_SpawnFixed(WP_AssaultDefend, 0.5 * (it.absmin + it.absmax), it, assault_sprite, RADARICON_OBJECTIVE);
122 spr.assault_decreaser = this;
123 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
124 spr.classname = "sprite_waypoint";
125 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
126 if(it.classname == "func_assault_destructible")
128 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
129 WaypointSprite_UpdateMaxHealth(spr, it.max_health);
130 WaypointSprite_UpdateHealth(spr, GetResourceAmount(it, RESOURCE_HEALTH));
134 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
138 void target_objective_decrease_findtarget(entity this)
140 assault_setenemytoobjective(this);
143 void target_assault_roundend_reset(entity this)
145 //print("round end reset\n");
146 ++this.cnt; // up round counter
147 this.winning = false; // up round
150 void target_assault_roundend_use(entity this, entity actor, entity trigger)
152 this.winning = 1; // round has been won by attackers
155 void assault_roundstart_use(entity this, entity actor, entity trigger)
157 SUB_UseTargets(this, this, trigger);
159 //(Re)spawn all turrets
160 IL_EACH(g_turrets, true,
163 if(it.team == NUM_TEAM_1)
164 it.team = NUM_TEAM_2;
166 it.team = NUM_TEAM_1;
168 // Doubles as teamchange
172 void assault_roundstart_use_this(entity this)
174 assault_roundstart_use(this, NULL, NULL);
177 void assault_wall_think(entity this)
179 if(GetResourceAmount(this.enemy, RESOURCE_HEALTH) < 0)
182 this.solid = SOLID_NOT;
186 this.model = this.mdl;
187 this.solid = SOLID_BSP;
190 this.nextthink = time + 0.2;
194 // reset objectives, toggle spawnpoints, reset triggers, ...
195 void assault_new_round(entity this)
197 //bprint("ASSAULT: new round\n");
200 this.winning = this.winning + 1;
202 // swap attacker/defender roles
203 if(assault_attacker_team == NUM_TEAM_1)
204 assault_attacker_team = NUM_TEAM_2;
206 assault_attacker_team = NUM_TEAM_1;
208 IL_EACH(g_saved_team, !IS_CLIENT(it),
210 if(it.team_saved == NUM_TEAM_1)
211 it.team_saved = NUM_TEAM_2;
212 else if(it.team_saved == NUM_TEAM_2)
213 it.team_saved = NUM_TEAM_1;
216 // reset the level with a countdown
217 cvar_set("timelimit", ftos(ceil(time - AS_ROUND_DELAY - game_starttime) / 60));
218 ReadyRestart_force(); // sets game_starttime
223 void as_round_think()
225 game_stopped = false;
226 assault_new_round(as_round.ent_winning);
231 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
232 // they win. Otherwise the defending team wins once the timelimit passes.
233 int WinningCondition_Assault()
238 WinningConditionHelper(NULL); // set worldstatus
240 int status = WINNING_NO;
241 // as the timelimit has not yet passed just assume the defending team will win
242 if(assault_attacker_team == NUM_TEAM_1)
244 SetWinners(team, NUM_TEAM_2);
248 SetWinners(team, NUM_TEAM_1);
252 ent = find(NULL, classname, "target_assault_roundend");
255 if(ent.winning) // round end has been triggered by attacking team
257 bprint("Assault: round completed.\n");
258 SetWinners(team, assault_attacker_team);
260 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
262 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
264 status = WINNING_YES;
268 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ASSAULT_OBJ_DESTROYED, ceil(time - game_starttime));
269 as_round = new(as_round);
270 as_round.think = as_round_think;
271 as_round.ent_winning = ent;
272 as_round.nextthink = time + AS_ROUND_DELAY;
275 // make sure timelimit isn't hit while the game is blocked
276 if(autocvar_timelimit > 0)
277 if(time + AS_ROUND_DELAY >= game_starttime + autocvar_timelimit * 60)
278 cvar_set("timelimit", ftos(autocvar_timelimit + AS_ROUND_DELAY / 60));
287 spawnfunc(info_player_attacker)
289 if (!g_assault) { delete(this); return; }
291 this.team = NUM_TEAM_1; // red, gets swapped every round
292 spawnfunc_info_player_deathmatch(this);
295 spawnfunc(info_player_defender)
297 if (!g_assault) { delete(this); return; }
299 this.team = NUM_TEAM_2; // blue, gets swapped every round
300 spawnfunc_info_player_deathmatch(this);
303 spawnfunc(target_objective)
305 if (!g_assault) { delete(this); return; }
307 this.classname = "target_objective";
308 IL_PUSH(g_assault_objectives, this);
309 this.use = assault_objective_use;
310 this.reset = assault_objective_reset;
312 this.spawn_evalfunc = target_objective_spawn_evalfunc;
315 spawnfunc(target_objective_decrease)
317 if (!g_assault) { delete(this); return; }
319 this.classname = "target_objective_decrease";
320 IL_PUSH(g_assault_objectivedecreasers, this);
325 this.use = assault_objective_decrease_use;
326 SetResourceAmountExplicit(this, RESOURCE_HEALTH, ASSAULT_VALUE_INACTIVE);
327 this.max_health = ASSAULT_VALUE_INACTIVE;
330 InitializeEntity(this, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
333 // destructible walls that can be used to trigger target_objective_decrease
334 bool destructible_heal(entity targ, entity inflictor, float amount, float limit)
336 float true_limit = ((limit != RESOURCE_LIMIT_NONE) ? limit : targ.max_health);
337 if(GetResourceAmount(targ, RESOURCE_HEALTH) <= 0 || GetResourceAmount(targ, RESOURCE_HEALTH) >= true_limit)
340 GiveResourceWithLimit(targ, RESOURCE_HEALTH, amount, true_limit);
343 WaypointSprite_UpdateHealth(targ.sprite, GetResourceAmount(targ, RESOURCE_HEALTH));
345 func_breakable_colormod(targ);
349 spawnfunc(func_breakable);
350 spawnfunc(func_assault_destructible)
352 if (!g_assault) { delete(this); return; }
355 this.classname = "func_assault_destructible";
356 this.event_heal = destructible_heal;
357 IL_PUSH(g_assault_destructibles, this);
359 if(assault_attacker_team == NUM_TEAM_1)
360 this.team = NUM_TEAM_2;
362 this.team = NUM_TEAM_1;
364 spawnfunc_func_breakable(this);
367 spawnfunc(func_assault_wall)
369 if (!g_assault) { delete(this); return; }
371 this.classname = "func_assault_wall";
372 this.mdl = this.model;
373 _setmodel(this, this.mdl);
374 this.solid = SOLID_BSP;
375 setthink(this, assault_wall_think);
376 this.nextthink = time;
377 InitializeEntity(this, assault_setenemytoobjective, INITPRIO_FINDTARGET);
380 spawnfunc(target_assault_roundend)
382 if (!g_assault) { delete(this); return; }
384 this.winning = 0; // round not yet won by attackers
385 this.classname = "target_assault_roundend";
386 this.use = target_assault_roundend_use;
387 this.cnt = 0; // first round
388 this.reset = target_assault_roundend_reset;
391 spawnfunc(target_assault_roundstart)
393 if (!g_assault) { delete(this); return; }
395 assault_attacker_team = NUM_TEAM_1;
396 this.classname = "target_assault_roundstart";
397 this.use = assault_roundstart_use;
398 this.reset2 = assault_roundstart_use_this;
399 InitializeEntity(this, assault_roundstart_use_this, INITPRIO_FINDTARGET);
403 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
405 IL_EACH(g_assault_destructibles, it.bot_attack,
412 IL_EACH(g_assault_objectivedecreasers, it.targetname == destr.target,
414 if(GetResourceAmount(it.enemy, RESOURCE_HEALTH) > 0 && GetResourceAmount(it.enemy, RESOURCE_HEALTH) < ASSAULT_VALUE_INACTIVE)
424 vector p = 0.5 * (it.absmin + it.absmax);
426 // Find and rate waypoints around it
429 float bestvalue = FLOAT_MAX;
431 for (float radius = 500; radius <= 1500 && !found; radius += 500)
433 FOREACH_ENTITY_RADIUS(p, radius, it.classname == "waypoint" && !(it.wpflags & WAYPOINTFLAG_GENERATED),
435 if(checkpvs(it.origin, des))
438 if(it.cnt < bestvalue)
449 /// dprint("waypoints around target were found\n");
450 // te_lightning2(NULL, '0 0 0', best.origin);
451 // te_knightspike(best.origin);
453 navigation_routerating(this, best, ratingscale, 4000);
456 this.havocbot_attack_time = 0;
458 if(checkpvs(this.origin + this.view_ofs, it))
459 if(checkpvs(this.origin + this.view_ofs, best))
461 // dprint("increasing attack time for this target\n");
462 this.havocbot_attack_time = time + 2;
468 void havocbot_role_ast_offense(entity this)
472 this.havocbot_attack_time = 0;
473 havocbot_ast_reset_role(this);
477 // Set the role timeout if necessary
478 if (!this.havocbot_role_timeout)
479 this.havocbot_role_timeout = time + 120;
481 if (time > this.havocbot_role_timeout)
483 havocbot_ast_reset_role(this);
487 if(this.havocbot_attack_time>time)
490 if (navigation_goalrating_timeout(this))
492 navigation_goalrating_start(this);
493 havocbot_goalrating_enemyplayers(this, 10000, this.origin, 650);
494 havocbot_goalrating_ast_targets(this, 20000);
495 havocbot_goalrating_items(this, 15000, this.origin, 10000);
496 navigation_goalrating_end(this);
498 navigation_goalrating_timeout_set(this);
502 void havocbot_role_ast_defense(entity this)
506 this.havocbot_attack_time = 0;
507 havocbot_ast_reset_role(this);
511 // Set the role timeout if necessary
512 if (!this.havocbot_role_timeout)
513 this.havocbot_role_timeout = time + 120;
515 if (time > this.havocbot_role_timeout)
517 havocbot_ast_reset_role(this);
521 if(this.havocbot_attack_time>time)
524 if (navigation_goalrating_timeout(this))
526 navigation_goalrating_start(this);
527 havocbot_goalrating_enemyplayers(this, 10000, this.origin, 3000);
528 havocbot_goalrating_ast_targets(this, 20000);
529 havocbot_goalrating_items(this, 15000, this.origin, 10000);
530 navigation_goalrating_end(this);
532 navigation_goalrating_timeout_set(this);
536 void havocbot_role_ast_setrole(entity this, float role)
540 case HAVOCBOT_AST_ROLE_DEFENSE:
541 this.havocbot_role = havocbot_role_ast_defense;
542 this.havocbot_role_timeout = 0;
544 case HAVOCBOT_AST_ROLE_OFFENSE:
545 this.havocbot_role = havocbot_role_ast_offense;
546 this.havocbot_role_timeout = 0;
551 void havocbot_ast_reset_role(entity this)
556 if(this.team == assault_attacker_team)
557 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_OFFENSE);
559 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_DEFENSE);
563 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
565 entity player = M_ARGV(0, entity);
567 if(player.team == assault_attacker_team)
568 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
570 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
573 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
575 entity turret = M_ARGV(0, entity);
577 if(!turret.team || turret.team == FLOAT_MAX)
578 turret.team = 5; // this gets reversed when match starts?
581 MUTATOR_HOOKFUNCTION(as, VehicleInit)
583 entity veh = M_ARGV(0, entity);
585 veh.nextthink = time + 0.5;
588 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
590 entity bot = M_ARGV(0, entity);
592 havocbot_ast_reset_role(bot);
596 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
598 entity frag_victim = M_ARGV(0, entity);
600 return (frag_victim.classname == "func_assault_destructible");
603 MUTATOR_HOOKFUNCTION(as, CheckAllowedTeams)
605 // assault always has 2 teams
610 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
612 M_ARGV(0, float) = WinningCondition_Assault();
616 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
620 sv_ready_restart_after_countdown = 0;
623 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
625 entity ent = M_ARGV(0, entity);
627 switch(ent.classname)
629 case "info_player_team1":
630 case "info_player_team2":
631 case "info_player_team3":
632 case "info_player_team4":
637 MUTATOR_HOOKFUNCTION(as, ReadyRestart_Deny)
639 // readyrestart not supported (yet)