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 float hlth = GetResourceAmount(this, RESOURCE_HEALTH);
35 if (hlth < 0 || hlth >= ASSAULT_VALUE_INACTIVE)
40 // reset this objective. Used when spawning an objective
41 // and when a new round starts
42 void assault_objective_reset(entity this)
44 SetResourceAmountExplicit(this, RESOURCE_HEALTH, ASSAULT_VALUE_INACTIVE);
47 // decrease the health of targeted objectives
48 void assault_objective_decrease_use(entity this, entity actor, entity trigger)
50 if(actor.team != assault_attacker_team)
52 // wrong team triggered decrease
56 if(trigger.assault_sprite)
58 WaypointSprite_Disown(trigger.assault_sprite, waypointsprite_deadlifetime);
59 if(trigger.classname == "func_assault_destructible")
60 trigger.sprite = NULL; // TODO: just unsetting it?!
63 return; // already activated! cannot activate again!
65 float hlth = GetResourceAmount(this.enemy, RESOURCE_HEALTH);
66 if (hlth < ASSAULT_VALUE_INACTIVE)
68 if (hlth - this.dmg > 0.5)
70 GameRules_scoring_add_team(actor, SCORE, this.dmg);
71 TakeResource(this.enemy, RESOURCE_HEALTH, this.dmg);
75 GameRules_scoring_add_team(actor, SCORE, hlth);
76 GameRules_scoring_add_team(actor, ASSAULT_OBJECTIVES, 1);
77 SetResourceAmountExplicit(this.enemy, RESOURCE_HEALTH, -1);
79 if(this.enemy.message)
80 FOREACH_CLIENT(IS_PLAYER(it), { centerprint(it, this.enemy.message); });
82 SUB_UseTargets(this.enemy, this, trigger);
87 void assault_setenemytoobjective(entity this)
89 IL_EACH(g_assault_objectives, it.targetname == this.target,
91 if(this.enemy == NULL)
94 objerror(this, "more than one objective as target - fix the map!");
98 if(this.enemy == NULL)
99 objerror(this, "no objective as target - fix the map!");
102 bool assault_decreaser_sprite_visible(entity this, entity player, entity view)
104 if(GetResourceAmount(this.assault_decreaser.enemy, RESOURCE_HEALTH) >= ASSAULT_VALUE_INACTIVE)
110 void target_objective_decrease_activate(entity this)
114 FOREACH_ENTITY_STRING(target, this.targetname,
116 if(it.assault_sprite != NULL)
118 WaypointSprite_Disown(it.assault_sprite, waypointsprite_deadlifetime);
119 if(it.classname == "func_assault_destructible")
120 it.sprite = NULL; // TODO: just unsetting it?!
123 spr = WaypointSprite_SpawnFixed(WP_AssaultDefend, 0.5 * (it.absmin + it.absmax), it, assault_sprite, RADARICON_OBJECTIVE);
124 spr.assault_decreaser = this;
125 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
126 spr.classname = "sprite_waypoint";
127 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
128 if(it.classname == "func_assault_destructible")
130 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultDestroy, WP_AssaultDestroy);
131 WaypointSprite_UpdateMaxHealth(spr, it.max_health);
132 WaypointSprite_UpdateHealth(spr, GetResourceAmount(it, RESOURCE_HEALTH));
136 WaypointSprite_UpdateSprites(spr, WP_AssaultDefend, WP_AssaultPush, WP_AssaultPush);
140 void target_objective_decrease_findtarget(entity this)
142 assault_setenemytoobjective(this);
145 void target_assault_roundend_reset(entity this)
147 //print("round end reset\n");
148 ++this.cnt; // up round counter
149 this.winning = false; // up round
152 void target_assault_roundend_use(entity this, entity actor, entity trigger)
154 this.winning = 1; // round has been won by attackers
157 void assault_roundstart_use(entity this, entity actor, entity trigger)
159 SUB_UseTargets(this, this, trigger);
161 //(Re)spawn all turrets
162 IL_EACH(g_turrets, true,
165 if(it.team == NUM_TEAM_1)
166 it.team = NUM_TEAM_2;
168 it.team = NUM_TEAM_1;
170 // Doubles as teamchange
174 void assault_roundstart_use_this(entity this)
176 assault_roundstart_use(this, NULL, NULL);
179 void assault_wall_think(entity this)
181 if(GetResourceAmount(this.enemy, RESOURCE_HEALTH) < 0)
184 this.solid = SOLID_NOT;
188 this.model = this.mdl;
189 this.solid = SOLID_BSP;
192 this.nextthink = time + 0.2;
196 // reset objectives, toggle spawnpoints, reset triggers, ...
197 void assault_new_round(entity this)
199 //bprint("ASSAULT: new round\n");
202 this.winning = this.winning + 1;
204 // swap attacker/defender roles
205 if(assault_attacker_team == NUM_TEAM_1)
206 assault_attacker_team = NUM_TEAM_2;
208 assault_attacker_team = NUM_TEAM_1;
210 IL_EACH(g_saved_team, !IS_CLIENT(it),
212 if(it.team_saved == NUM_TEAM_1)
213 it.team_saved = NUM_TEAM_2;
214 else if(it.team_saved == NUM_TEAM_2)
215 it.team_saved = NUM_TEAM_1;
218 // reset the level with a countdown
219 cvar_set("timelimit", ftos(ceil(time - AS_ROUND_DELAY - game_starttime) / 60));
220 ReadyRestart_force(); // sets game_starttime
225 void as_round_think()
227 game_stopped = false;
228 assault_new_round(as_round.ent_winning);
233 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
234 // they win. Otherwise the defending team wins once the timelimit passes.
235 int WinningCondition_Assault()
240 WinningConditionHelper(NULL); // set worldstatus
242 int status = WINNING_NO;
243 // as the timelimit has not yet passed just assume the defending team will win
244 if(assault_attacker_team == NUM_TEAM_1)
246 SetWinners(team, NUM_TEAM_2);
250 SetWinners(team, NUM_TEAM_1);
254 ent = find(NULL, classname, "target_assault_roundend");
257 if(ent.winning) // round end has been triggered by attacking team
259 bprint("Assault: round completed.\n");
260 SetWinners(team, assault_attacker_team);
262 TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 666 - TeamScore_AddToTeam(assault_attacker_team, ST_ASSAULT_OBJECTIVES, 0));
264 if(ent.cnt == 1 || autocvar_g_campaign) // this was the second round
266 status = WINNING_YES;
270 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ASSAULT_OBJ_DESTROYED, ceil(time - game_starttime));
271 as_round = new(as_round);
272 as_round.think = as_round_think;
273 as_round.ent_winning = ent;
274 as_round.nextthink = time + AS_ROUND_DELAY;
277 // make sure timelimit isn't hit while the game is blocked
278 if(autocvar_timelimit > 0)
279 if(time + AS_ROUND_DELAY >= game_starttime + autocvar_timelimit * 60)
280 cvar_set("timelimit", ftos(autocvar_timelimit + AS_ROUND_DELAY / 60));
289 spawnfunc(info_player_attacker)
291 if (!g_assault) { delete(this); return; }
293 this.team = NUM_TEAM_1; // red, gets swapped every round
294 spawnfunc_info_player_deathmatch(this);
297 spawnfunc(info_player_defender)
299 if (!g_assault) { delete(this); return; }
301 this.team = NUM_TEAM_2; // blue, gets swapped every round
302 spawnfunc_info_player_deathmatch(this);
305 spawnfunc(target_objective)
307 if (!g_assault) { delete(this); return; }
309 this.classname = "target_objective";
310 IL_PUSH(g_assault_objectives, this);
311 this.use = assault_objective_use;
312 this.reset = assault_objective_reset;
314 this.spawn_evalfunc = target_objective_spawn_evalfunc;
317 spawnfunc(target_objective_decrease)
319 if (!g_assault) { delete(this); return; }
321 this.classname = "target_objective_decrease";
322 IL_PUSH(g_assault_objectivedecreasers, this);
327 this.use = assault_objective_decrease_use;
328 SetResourceAmountExplicit(this, RESOURCE_HEALTH, ASSAULT_VALUE_INACTIVE);
329 this.max_health = ASSAULT_VALUE_INACTIVE;
332 InitializeEntity(this, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
335 // destructible walls that can be used to trigger target_objective_decrease
336 bool destructible_heal(entity targ, entity inflictor, float amount, float limit)
338 float true_limit = ((limit != RESOURCE_LIMIT_NONE) ? limit : targ.max_health);
339 float hlth = GetResourceAmount(targ, RESOURCE_HEALTH);
340 if (hlth <= 0 || hlth >= true_limit)
343 GiveResourceWithLimit(targ, RESOURCE_HEALTH, amount, true_limit);
346 WaypointSprite_UpdateHealth(targ.sprite, GetResourceAmount(targ, RESOURCE_HEALTH));
348 func_breakable_colormod(targ);
352 spawnfunc(func_breakable);
353 spawnfunc(func_assault_destructible)
355 if (!g_assault) { delete(this); return; }
358 this.classname = "func_assault_destructible";
359 this.event_heal = destructible_heal;
360 IL_PUSH(g_assault_destructibles, this);
362 if(assault_attacker_team == NUM_TEAM_1)
363 this.team = NUM_TEAM_2;
365 this.team = NUM_TEAM_1;
367 spawnfunc_func_breakable(this);
370 spawnfunc(func_assault_wall)
372 if (!g_assault) { delete(this); return; }
374 this.classname = "func_assault_wall";
375 this.mdl = this.model;
376 _setmodel(this, this.mdl);
377 this.solid = SOLID_BSP;
378 setthink(this, assault_wall_think);
379 this.nextthink = time;
380 InitializeEntity(this, assault_setenemytoobjective, INITPRIO_FINDTARGET);
383 spawnfunc(target_assault_roundend)
385 if (!g_assault) { delete(this); return; }
387 this.winning = 0; // round not yet won by attackers
388 this.classname = "target_assault_roundend";
389 this.use = target_assault_roundend_use;
390 this.cnt = 0; // first round
391 this.reset = target_assault_roundend_reset;
394 spawnfunc(target_assault_roundstart)
396 if (!g_assault) { delete(this); return; }
398 assault_attacker_team = NUM_TEAM_1;
399 this.classname = "target_assault_roundstart";
400 this.use = assault_roundstart_use;
401 this.reset2 = assault_roundstart_use_this;
402 InitializeEntity(this, assault_roundstart_use_this, INITPRIO_FINDTARGET);
406 void havocbot_goalrating_ast_targets(entity this, float ratingscale)
408 IL_EACH(g_assault_destructibles, it.bot_attack,
415 IL_EACH(g_assault_objectivedecreasers, it.targetname == destr.target,
417 float hlth = GetResourceAmount(it.enemy, RESOURCE_HEALTH);
418 if (hlth > 0 && hlth < ASSAULT_VALUE_INACTIVE)
428 vector p = 0.5 * (it.absmin + it.absmax);
430 // Find and rate waypoints around it
433 float bestvalue = 99999999999;
435 for(float radius = 0; radius < 1500 && !found; radius += 500)
437 FOREACH_ENTITY_RADIUS(p, radius, it.classname == "waypoint" && !(it.wpflags & WAYPOINTFLAG_GENERATED),
439 if(checkpvs(it.origin, des))
442 if(it.cnt < bestvalue)
453 /// dprint("waypoints around target were found\n");
454 // te_lightning2(NULL, '0 0 0', best.origin);
455 // te_knightspike(best.origin);
457 navigation_routerating(this, best, ratingscale, 4000);
460 this.havocbot_attack_time = 0;
462 if(checkpvs(this.origin + this.view_ofs, it))
463 if(checkpvs(this.origin + this.view_ofs, best))
465 // dprint("increasing attack time for this target\n");
466 this.havocbot_attack_time = time + 2;
472 void havocbot_role_ast_offense(entity this)
476 this.havocbot_attack_time = 0;
477 havocbot_ast_reset_role(this);
481 // Set the role timeout if necessary
482 if (!this.havocbot_role_timeout)
483 this.havocbot_role_timeout = time + 120;
485 if (time > this.havocbot_role_timeout)
487 havocbot_ast_reset_role(this);
491 if(this.havocbot_attack_time>time)
494 if (navigation_goalrating_timeout(this))
496 navigation_goalrating_start(this);
497 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
498 havocbot_goalrating_ast_targets(this, 20000);
499 havocbot_goalrating_items(this, 15000, this.origin, 10000);
500 navigation_goalrating_end(this);
502 navigation_goalrating_timeout_set(this);
506 void havocbot_role_ast_defense(entity this)
510 this.havocbot_attack_time = 0;
511 havocbot_ast_reset_role(this);
515 // Set the role timeout if necessary
516 if (!this.havocbot_role_timeout)
517 this.havocbot_role_timeout = time + 120;
519 if (time > this.havocbot_role_timeout)
521 havocbot_ast_reset_role(this);
525 if(this.havocbot_attack_time>time)
528 if (navigation_goalrating_timeout(this))
530 navigation_goalrating_start(this);
531 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 3000);
532 havocbot_goalrating_ast_targets(this, 20000);
533 havocbot_goalrating_items(this, 15000, this.origin, 10000);
534 navigation_goalrating_end(this);
536 navigation_goalrating_timeout_set(this);
540 void havocbot_role_ast_setrole(entity this, float role)
544 case HAVOCBOT_AST_ROLE_DEFENSE:
545 this.havocbot_role = havocbot_role_ast_defense;
546 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
547 this.havocbot_role_timeout = 0;
549 case HAVOCBOT_AST_ROLE_OFFENSE:
550 this.havocbot_role = havocbot_role_ast_offense;
551 this.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
552 this.havocbot_role_timeout = 0;
557 void havocbot_ast_reset_role(entity this)
562 if(this.team == assault_attacker_team)
563 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_OFFENSE);
565 havocbot_role_ast_setrole(this, HAVOCBOT_AST_ROLE_DEFENSE);
569 MUTATOR_HOOKFUNCTION(as, PlayerSpawn)
571 entity player = M_ARGV(0, entity);
573 if(player.team == assault_attacker_team)
574 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_ATTACKING);
576 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ASSAULT_DEFENDING);
579 MUTATOR_HOOKFUNCTION(as, TurretSpawn)
581 entity turret = M_ARGV(0, entity);
583 if(!turret.team || turret.team == FLOAT_MAX)
584 turret.team = 5; // this gets reversed when match starts?
587 MUTATOR_HOOKFUNCTION(as, VehicleInit)
589 entity veh = M_ARGV(0, entity);
591 veh.nextthink = time + 0.5;
594 MUTATOR_HOOKFUNCTION(as, HavocBot_ChooseRole)
596 entity bot = M_ARGV(0, entity);
598 havocbot_ast_reset_role(bot);
602 MUTATOR_HOOKFUNCTION(as, PlayHitsound)
604 entity frag_victim = M_ARGV(0, entity);
606 return (frag_victim.classname == "func_assault_destructible");
609 MUTATOR_HOOKFUNCTION(as, TeamBalance_CheckAllowedTeams)
611 // assault always has 2 teams
612 M_ARGV(0, float) = BIT(0) | BIT(1);
616 MUTATOR_HOOKFUNCTION(as, CheckRules_World)
618 M_ARGV(0, float) = WinningCondition_Assault();
622 MUTATOR_HOOKFUNCTION(as, ReadLevelCvars)
626 sv_ready_restart_after_countdown = 0;
629 MUTATOR_HOOKFUNCTION(as, OnEntityPreSpawn)
631 entity ent = M_ARGV(0, entity);
633 switch(ent.classname)
635 case "info_player_team1":
636 case "info_player_team2":
637 case "info_player_team3":
638 case "info_player_team4":
643 MUTATOR_HOOKFUNCTION(as, ReadyRestart_Deny)
645 // readyrestart not supported (yet)