Make parkour checkpoint and respawn management more robust to runtime editor development

qteditor
Sven Eberhardt 2016-08-07 01:02:23 -04:00
parent 596d2a5e68
commit 7a9ff289f5
2 changed files with 41 additions and 26 deletions

View File

@ -44,6 +44,7 @@ public func SetCPMode(int mode)
mode = mode | PARKOUR_CP_Check;
// Set CP number.
if (!cp_num) SetCPNumber(ObjectCount(Find_ID(GetID()), Find_Func("GetCPNumber")) + 1);
if (cp_con) cp_con->SetIndexedCP(this, cp_num);
}
else
{
@ -54,6 +55,11 @@ public func SetCPMode(int mode)
if (had_cp_num) RenumberOrderedCheckpoints();
DoGraphics();
UpdateEditorHelp();
if (cp_con)
{
if (mode & PARKOUR_CP_Start) cp_con->SetIndexedCP(this, 0);
if (mode & PARKOUR_CP_Finish) cp_con->SetIndexedCP(this, ObjectCount(Find_ID(GetID()), Find_Func("GetCPNumber")) + 1);
}
return;
}
@ -62,26 +68,36 @@ public func RenumberOrderedCheckpoints()
// Reassign all CP numbers. Use old numbers where possible
var cps = FindObjects(Find_ID(ParkourCheckpoint), Find_Func("FindCPMode", PARKOUR_CP_Ordered)), i;
SortArrayByProperty(cps, "cp_num");
// If there is no start or finish checkpoint, create new ones
// If there is no start or finish checkpoint, assign them from the numbered pool
var cp_start = FindObject(Find_ID(ParkourCheckpoint), Find_Func("FindCPMode", PARKOUR_CP_Start));
var cp_finish = FindObject(Find_ID(ParkourCheckpoint), Find_Func("FindCPMode", PARKOUR_CP_Finish));
if (!cp_start && GetLength(cps))
{
cps[0]->SetCPNumber(0);
cps[0]->SetCPMode(PARKOUR_CP_Start | cps[0]->GetCPMode());
cp_start = cps[0];
cps = cps[1:];
}
if (!cp_finish && GetLength(cps))
{
cps[-1]->SetCPNumber(0);
cps[-1]->SetCPMode(PARKOUR_CP_Finish | cps[-1]->GetCPMode());
cp_finish = cps[-1];
cps = cps[:-1];
}
// Re-label start and finish
if (cp_start)
{
cp_start->SetCPNumber(0);
cp_start->SetCPMode(PARKOUR_CP_Start | cp_start->GetCPMode());
}
if (cp_finish)
{
cp_finish->SetCPNumber(0);
cp_finish->SetCPMode(PARKOUR_CP_Finish | cp_finish->GetCPMode());
}
// Re-label remaining CPs
for (var cp in cps)
{
cp->SetCPNumber(++i);
cp->DoGraphics();
if (cp->GetCPController()) cp->GetCPController()->SetIndexedCP(cp, i);
}
return true;
}
@ -545,7 +561,7 @@ public func EditorInitialize()
new_mode = PARKOUR_CP_Finish;
// Change old finish point to numbered checkpoint
var cp = FindObject(Find_ID(GetID()), Find_Func("FindCPMode", PARKOUR_CP_Finish));
if (cp) cp->SetCPMode(PARKOUR_CP_Check | PARKOUR_CP_Ordered);
if (cp) cp->SetCPMode(PARKOUR_CP_Check | PARKOUR_CP_Ordered | PARKOUR_CP_Respawn);
SetCPMode(new_mode);
UpdateEditorHelp();
return this;

View File

@ -84,7 +84,6 @@ public func SetStartpoint(int x, int y)
cp->SetPosition(x, y);
cp->SetCPMode(PARKOUR_CP_Start);
cp->SetCPController(this);
cp_list[0] = cp;
return cp;
}
@ -102,9 +101,6 @@ public func SetFinishpoint(int x, int y, bool team)
mode = mode | PARKOUR_CP_Team;
cp->SetCPMode(mode);
cp->SetCPController(this);
cp_count++;
cp_list[cp_count] = cp;
UpdateScoreboardTitle();
return cp;
}
@ -117,21 +113,6 @@ public func AddCheckpoint(int x, int y, int mode)
cp->SetPosition(x, y);
cp->SetCPMode(mode);
cp->SetCPController(this);
// Only increase cp count and update list if mode is check.
if (!(cp->GetCPMode() & PARKOUR_CP_Check))
return cp;
// Move finish one place further in checkpoint list.
if (cp_list[cp_count] && cp_list[cp_count]->GetCPMode() & PARKOUR_CP_Finish)
{
cp_list[cp_count + 1] = cp_list[cp_count];
cp_list[cp_count] = cp;
}
else
{
cp_list[cp_count + 1] = cp;
}
cp_count++;
UpdateScoreboardTitle();
return cp;
}
@ -150,6 +131,20 @@ public func TransferContentsOnRelaunch(bool on)
return;
}
public func SetIndexedCP(object cp, int index)
{
// Called directly from checkpoints after index assignment, resorting, etc.
// Update internal list
cp_list[index] = cp;
if (cp->GetCPMode() & PARKOUR_CP_Finish)
{
cp_count = index;
SetLength(cp_list, cp_count+1);
}
UpdateScoreboardTitle();
return true;
}
/*-- Checkpoint interaction --*/
@ -475,17 +470,21 @@ protected func JoinPlayer(int plr)
// More complicated behavior should be set by the scenario.
private func FindRespawnCP(int plr)
{
return respawn_list[plr];
var respawn_cp = respawn_list[plr];
if (!respawn_cp) respawn_cp = respawn_list[plr] = cp_list[0];
return respawn_cp;
}
private func FindRespawnPos(int plr)
{
var cp = FindRespawnCP(plr);
if (!cp) cp = this; // Have to start somewhere
return [cp->GetX(), cp->GetY()];
}
protected func RemovePlayer(int plr)
{
respawn_list[plr] = nil;
if (!finished)
AddEvalData(plr);
return;