fix relaunching in CTFs

alut-include-path
Maikel de Vries 2017-04-30 18:42:44 +02:00
parent 0fead04978
commit 18057587d6
3 changed files with 36 additions and 28 deletions

View File

@ -14,22 +14,19 @@ protected func Initialize()
// Goal: Capture the flag, with bases in both hideouts.
var goal = CreateObject(Goal_CaptureTheFlag, 0, 0, NO_OWNER);
goal->SetFlagBase(1, 120, 502);
goal->SetFlagBase(2, LandscapeWidth() - 120, 502);
goal->SetFlagBase(1, 120, 506);
goal->SetFlagBase(2, LandscapeWidth() - 120, 506);
// Rules
GetRelaunchRule()
->SetDefaultRelaunchCount(nil)
->AllowPlayerRestart();
var relaunch_rule = GetRelaunchRule();
relaunch_rule->AllowPlayerRestart();
relaunch_rule->SetRespawnDelay(8);
relaunch_rule->SetLastWeaponUse(false);
CreateObject(Rule_ObjectFade)->DoFadeTime(5 * 36);
CreateObject(Rule_KillLogs);
CreateObject(Rule_Gravestones);
GetRelaunchRule()->SetDefaultRelaunchCount(nil);
GetRelaunchRule()->SetRespawnDelay(8);
GetRelaunchRule()->SetLastWeaponUse(false);
var lwidth = LandscapeWidth();
// Doors and spinwheels.
var gate, wheel;
gate = CreateObjectAbove(StoneDoor, 364, 448, NO_OWNER);

View File

@ -18,8 +18,12 @@ func ScoreboardTeamID(int team)
protected func Initialize()
{
score_list = [];
GetRelaunchRule()->SetRespawnDelay(0);
GetRelaunchRule()->SetDefaultRelaunches(nil);
var relaunch_rule = GetRelaunchRule();
relaunch_rule->SetRespawnDelay(0);
relaunch_rule->SetDefaultRelaunches(nil);
relaunch_rule->AllowPlayerRestart();
relaunch_rule.FindRelaunchPos = GetID().FindRelaunchPos;
// init scoreboard
Scoreboard->Init(
@ -43,9 +47,9 @@ private func GetScoreGoal()
public func SetFlagBase(int team, int x, int y)
{
var base = CreateObject(Goal_FlagBase, x, y, NO_OWNER);
var base = CreateObjectAbove(Goal_FlagBase, x, y, NO_OWNER);
base->SetTeam(team);
var flag = CreateObject(Goal_Flag, x, y, NO_OWNER);
var flag = CreateObjectAbove(Goal_Flag, x, y, NO_OWNER);
flag->SetAction("AttachBase", base);
flag->SetTeam(team);
return;
@ -77,23 +81,24 @@ private func EliminateOthers(int win_team)
protected func InitializePlayer(int plr, int x, int y, object base, int team)
{
// Join new clonk.
GetRelaunchRule()->DoRelaunch(plr, nil, RelaunchPosition(team), true);
GetRelaunchRule()->DoRelaunch(plr, nil, FindRelaunchPos(plr), true);
// make scoreboard entry for team
Scoreboard->NewEntry(ScoreboardTeamID(team), GetTaggedTeamName(team));
return _inherited(plr, x, y, base, team, ...);
}
public func RelaunchPosition(int iTeam)
public func FindRelaunchPos(int plr)
{
var base = FindObject(Find_ID(Goal_FlagBase), Find_Func("FindTeam", iTeam));
if (base) return [base->GetX(), base->GetY() - 10];
var team = GetPlayerTeam(plr);
var base = FindObject(Find_ID(Goal_FlagBase), Find_Func("FindTeam", team));
if (base)
return [base->GetX(), base->GetY() - 10];
return nil;
}
protected func RemovePlayer(int plr)
{
return _inherited(plr, ...);
}

View File

@ -205,9 +205,9 @@ public func OnClonkDeath(object clonk, int killer)
return DoRelaunch(plr, clonk, nil);
}
private func RespawnAtBase(object clonk)
private func RespawnAtBase(int plr, object clonk)
{
var base = GetRelaunchBase(clonk);
var base = GetRelaunchBase(plr, clonk);
if (base)
return [base->GetX(), base->GetY() + base->GetDefHeight() / 2];
}
@ -235,14 +235,20 @@ private func TransferInventory(object from, object to)
return to->GrabContents(from);
}
private func GetRelaunchBase(object clonk)
private func GetRelaunchBase(int plr, object clonk)
{
var plr = clonk->GetOwner();
plr = plr ?? clonk->GetOwner();
// Neutral flagpoles are preferred respawn points, because they are used as the only respawn points in missions.
var base = clonk->FindObject(Find_ID(Flagpole), Find_Func("IsNeutral"), clonk->Sort_Distance());
var base = FindObject(Find_ID(Flagpole), Find_Func("IsNeutral"), Sort_Random());
if (clonk)
clonk->FindObject(Find_ID(Flagpole), Find_Func("IsNeutral"), clonk->Sort_Distance());
// If there are no neutral flagpoles, find closest base owned by the player (or team) and try to buy a clonk.
if (!base)
base = clonk->FindObject(Find_Func("IsBaseBuilding"), Find_Allied(plr), clonk->Sort_Distance());
{
base = FindObject(Find_Func("IsBaseBuilding"), Find_Allied(plr), Sort_Random());
if (clonk)
base = clonk->FindObject(Find_Func("IsBaseBuilding"), Find_Allied(plr), clonk->Sort_Distance());
}
return base;
}
@ -254,9 +260,9 @@ public func DoRelaunch(int plr, object clonk, array position, bool no_creation)
return;
if (respawn_at_base)
position = RespawnAtBase(clonk);
position = position ?? GameCallEx("RelaunchPosition", plr, GetPlayerTeam(plr));
position = position ?? FindRelaunchPos(plr);
position = RespawnAtBase(plr, clonk);
position = position ?? GameCall("RelaunchPosition", plr, GetPlayerTeam(plr));
position = position ?? this->FindRelaunchPos(plr);
var spawn;
// Position array either has the form [x, y] or [[x, y], [x, y], ...].