parkour: clear checkpoint for team members by default

objectmenu
Maikel de Vries 2016-01-25 22:18:25 +01:00
parent 2dc291f8f6
commit 08dfaeed9e
2 changed files with 73 additions and 42 deletions

View File

@ -53,6 +53,7 @@ public func GetCPMode() { return cp_mode; }
public func FindCPMode(int mode) { return cp_mode & mode; }
/*-- Checkpoint controller --*/
local cp_con;
@ -64,6 +65,7 @@ public func SetCPController(object con)
public func GetCPController() { return cp_con; }
/*-- Checkpoint number --*/
local cp_num;
@ -75,6 +77,7 @@ public func SetCPNumber(int num)
public func GetCPNumber() { return cp_num; }
/*-- Checkpoint size --*/
local cp_size;
@ -86,6 +89,7 @@ public func SetCPSize(int size)
public func GetCPSize() { return cp_size; }
/*-- Initialize --*/
local cleared_by_plr; // Array to keep track of players which were already here.
@ -107,6 +111,7 @@ protected func Initialize()
return;
}
/*-- Checkpoint status --*/
// Returns whether this checkpoint has been cleared by player.
@ -190,6 +195,7 @@ public func IsActiveForTeam(int team)
return false;
}
/*-- Checkpoint activity --*/
protected func FxIntCheckpointTimer(object target, effect, int fxtime)
@ -225,9 +231,7 @@ protected func CheckForClonks()
if (cp_mode & PARKOUR_CP_Check)
{
var team_clear = !ClearedByTeam(team);
cleared_by_plr[plrid] = true;
Sound("UI::Cleared", false, 100, plr);
cp_con->AddPlayerClearedCP(plr, this); // Notify parkour goal.
ClearCPForPlr(plr);
if (ClearedByTeam(team) && team_clear)
cp_con->AddTeamClearedCP(team, this); // Notify parkour goal.
}
@ -255,6 +259,34 @@ protected func CheckForClonks()
return;
}
// Clear this checkpoint for the player, and possibly its team members.
private func ClearCPForPlr(int plr)
{
if (!(cp_mode & PARKOUR_CP_Check))
return;
var plrid = GetPlayerID(plr);
cleared_by_plr[plrid] = true;
Sound("UI::Cleared", false, 100, plr);
cp_con->AddPlayerClearedCP(plr, this); // Notify parkour goal.
// Also clear for team members if the checkpoint is not PARKOUR_CP_Team.
var team = GetPlayerTeam(plr);
if (team && !(cp_mode & PARKOUR_CP_Team))
{
for (var test_plr in GetPlayers())
{
if (test_plr != plr && GetPlayerTeam(test_plr) == team)
{
var test_plr_id = GetPlayerID(test_plr);
cleared_by_plr[test_plr_id] = true;
Sound("UI::Cleared", false, 100, test_plr);
cp_con->AddPlayerClearedCP(test_plr, this); // Notify parkour goal.
}
}
}
return;
}
/*-- Checkpoint appearance --*/
// Mode graphics.
@ -329,6 +361,7 @@ protected func GetColorByAngle(int angle)
return RGBa(255, 255, 255, 192);
}
/*-- Misc --*/
// Clears all materials behind a checkpoint.

View File

@ -1,6 +1,5 @@
/*--
/**
Parkour
Authors: Maikel
The goal is to be the first to reach the finish, the team or player to do so wins the round.
Checkpoints can be added to make the path more interesting and more complex.
@ -9,10 +8,9 @@
* Check: On/Off - The clonk must pass through these checkpoints before being able to finish.
* Ordered: On/Off - The checkpoints mussed be passed in the order specified.
* The start and finish are also checkpoints.
TODO:
* Update CP Graphics -> looks satisfactory atm but cpu intensive.
--*/
@author Maikel
*/
#include Library_Goal
@ -27,6 +25,7 @@ local time_store; // String for best time storage in player file.
local no_respawn_handling; // Set to true if this goal should not handle respawn.
local transfer_contents; // Set to true if contents should be transferred on respawn.
/*-- General --*/
protected func Initialize()
@ -50,6 +49,7 @@ protected func Initialize()
return _inherited(...);
}
/*-- Checkpoint creation --*/
public func SetStartpoint(int x, int y)
@ -116,10 +116,9 @@ public func AddCheckpoint(int x, int y, int mode)
public func DisableRespawnHandling()
{
// Call this to disable respawn handling by goal
// This might be useful if
// a) you don't want any respawns or
// b) the scenario already provides an alternate respawn handling
// Call this to disable respawn handling by goal. This might be useful if
// a) you don't want any respawns, or
// b) the scenario already provides an alternate respawn handling.
no_respawn_handling = true;
return true;
}
@ -130,19 +129,6 @@ public func TransferContentsOnRelaunch(bool on)
return;
}
/*-- Scenario saving --*/
public func SaveScenarioObject(props)
{
if (!inherited(props, ...)) return false;
// force dependency on restartr rule
var restart_rule = FindObject(Find_ID(Rule_Restart));
if (restart_rule) restart_rule->MakeScenarioSaveName();
if (no_respawn_handling) props->AddCall("Goal", this, "DisableRespawnHandling");
if (transfer_contents) props->AddCall("Goal", this, "TransferContentsOnRelaunch", true);
return true;
}
/*-- Checkpoint interaction --*/
@ -195,6 +181,7 @@ public func AddTeamClearedCP(int team, object cp)
return;
}
/*-- Goal interface --*/
// Eliminates all players apart from the winner and his team.
@ -443,24 +430,11 @@ protected func JoinPlayer(int plr)
return;
}
// You always respawn at the last completed checkpoint you passed by.
// More complicated behavior should be set by the scenario.
private func FindRespawnCP(int plr)
{
var best_cp = respawn_list[plr];
var team = GetPlayerTeam(plr);
if (!team)
return best_cp;
// Loop over team members to find a better checkpoint.
for (var i = 0; i < GetPlayerCount(); i++)
{
var test_plr = GetPlayerByIndex(i);
if (GetPlayerTeam(test_plr) == team)
{
var test_cp = respawn_list[test_plr];
if (test_cp->GetCPNumber() && test_cp->GetCPNumber() > best_cp->GetCPNumber())
best_cp = test_cp;
}
}
return best_cp;
return respawn_list[plr];
}
private func FindRespawnPos(int plr)
@ -476,6 +450,25 @@ protected func RemovePlayer(int plr)
return;
}
/*-- Scenario saving --*/
public func SaveScenarioObject(props)
{
if (!inherited(props, ...))
return false;
// Force dependency on restart rule.
var restart_rule = FindObject(Find_ID(Rule_Restart));
if (restart_rule)
restart_rule->MakeScenarioSaveName();
if (no_respawn_handling)
props->AddCall("Goal", this, "DisableRespawnHandling");
if (transfer_contents)
props->AddCall("Goal", this, "TransferContentsOnRelaunch", true);
return true;
}
/*-- Scoreboard --*/
static const SBRD_Checkpoints = 0;
@ -513,6 +506,7 @@ private func UpdateScoreboard(int plr)
return;
}
/*-- Direction indication --*/
// Effect for direction indication for the clonk.
@ -579,6 +573,7 @@ protected func FxIntDirNextCPStop(object target, effect)
return;
}
/*-- Time tracker --*/
// Store the best time in the player file, same for teammembers.
@ -625,6 +620,7 @@ private func TimeToString(int time)
return Format("%d.%.1d", (time / 36) % 60, (10 * time / 36) % 10);
}
/*-- Evaluation data --*/
private func SetEvalData(int winner)
@ -662,5 +658,7 @@ private func AddEvalData(int plr)
return;
}
/*-- Proplist --*/
local Name = "$Name$";