Fix parkour checkpoint initialization when loaded form scenario

qteditor
Sven Eberhardt 2016-08-08 14:56:57 -04:00
parent 6811546dae
commit 0c31bc7985
2 changed files with 21 additions and 4 deletions

View File

@ -14,6 +14,11 @@
*Bonus - Player receives a bonus if he cleares this CP.
--*/
// TODO: The checkpoints themselves carry (and duplicate) a lot of logic that is
// handled much easier by the parkour goal. The script could be cleaned up to
// make the checkpoints lightweight and just callback to the parkour goal to do
// any logic with cross-checkpoint interaction (finding the next checkpoint, etc.)
/*-- Checkpoint modes --*/
local cp_mode;
@ -33,17 +38,23 @@ public func SetCPMode(int mode)
{
// PARKOUR_CP_Start always occurs alone.
if (mode & PARKOUR_CP_Start)
{
mode = PARKOUR_CP_Start;
if (cp_con) cp_con->SetIndexedCP(this, 0);
}
// PARKOUR_CP_Finish only in combination with PARKOUR_CP_Team.
if (mode & PARKOUR_CP_Finish)
{
mode = mode & (PARKOUR_CP_Finish | PARKOUR_CP_Team);
if (cp_con) cp_con->SetIndexedCP(this, GetNextCPNumber());
}
// PARKOUR_CP_Ordered must have PARKOUR_CP_Check and a number.
var had_cp_num;
if (mode & PARKOUR_CP_Ordered)
{
mode = mode | PARKOUR_CP_Check;
// Set CP number.
if (!cp_num) SetCPNumber(ObjectCount(Find_ID(GetID()), Find_Func("GetCPNumber")) + 1);
if (!cp_num) SetCPNumber(GetNextCPNumber());
if (cp_con) cp_con->SetIndexedCP(this, cp_num);
}
else
@ -63,6 +74,12 @@ public func SetCPMode(int mode)
return;
}
private func GetNextCPNumber()
{
// TODO: This should really go through the controller...
return ObjectCount(Find_ID(GetID()), Find_Func("GetCPNumber")) + 1;
}
public func RenumberOrderedCheckpoints()
{
// Reassign all CP numbers. Use old numbers where possible

View File

@ -81,9 +81,9 @@ public func SetStartpoint(int x, int y)
var cp = FindObject(Find_ID(ParkourCheckpoint), Find_Func("FindCPMode", PARKOUR_CP_Start));
if (!cp)
cp = CreateObjectAbove(ParkourCheckpoint, x, y, NO_OWNER);
cp->SetCPController(this);
cp->SetPosition(x, y);
cp->SetCPMode(PARKOUR_CP_Start);
cp->SetCPController(this);
return cp;
}
@ -95,12 +95,12 @@ public func SetFinishpoint(int x, int y, bool team)
var cp = FindObject(Find_ID(ParkourCheckpoint), Find_Func("FindCPMode", PARKOUR_CP_Finish));
if (!cp)
cp = CreateObjectAbove(ParkourCheckpoint, x, y, NO_OWNER);
cp->SetCPController(this);
cp->SetPosition(x, y);
var mode = PARKOUR_CP_Finish;
if (team)
mode = mode | PARKOUR_CP_Team;
cp->SetCPMode(mode);
cp->SetCPController(this);
return cp;
}
@ -110,9 +110,9 @@ public func AddCheckpoint(int x, int y, int mode)
x = BoundBy(x, 0, LandscapeWidth());
y = BoundBy(y, 0, LandscapeHeight());
var cp = CreateObjectAbove(ParkourCheckpoint, x, y, NO_OWNER);
cp->SetCPController(this);
cp->SetPosition(x, y);
cp->SetCPMode(mode);
cp->SetCPController(this);
return cp;
}