2014-04-18 19:16:31 +00:00
|
|
|
/**
|
|
|
|
Treasure Hunt
|
2014-09-21 19:49:03 +00:00
|
|
|
Find the treasure and swap it for a barrel of oil
|
2014-04-18 19:16:31 +00:00
|
|
|
|
|
|
|
@authors Sven2
|
|
|
|
*/
|
|
|
|
|
|
|
|
static g_is_initialized; // set after first player join
|
|
|
|
static g_max_player_num; // max number of players that were ever joined
|
2014-09-21 19:49:03 +00:00
|
|
|
static g_plr_inventory; // array indexed by players: Array containing inventory of Clonk just before it died
|
|
|
|
|
2014-09-22 17:52:34 +00:00
|
|
|
static npc_pyrit, npc_dagobert, npc_tarzan, g_golden_shovel, g_flagpole;
|
2014-09-21 19:49:03 +00:00
|
|
|
static g_got_gem_task, g_got_oil, g_goal, g_treasure_collected;
|
2014-04-18 19:16:31 +00:00
|
|
|
|
2014-09-11 23:01:12 +00:00
|
|
|
func Initialize()
|
|
|
|
{
|
|
|
|
SetNextMission("Mission.ocf/DarkCastle.ocs");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-04-18 19:16:31 +00:00
|
|
|
func DoInit(int first_player)
|
|
|
|
{
|
|
|
|
ClearFreeRect(530,1135, 50,2);
|
2014-09-21 19:49:03 +00:00
|
|
|
// Start Intro.
|
2014-09-22 17:52:34 +00:00
|
|
|
StartSequence("Intro", 0, g_flagpole);
|
2014-04-18 19:16:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
func InitializePlayer(int plr)
|
|
|
|
{
|
|
|
|
// Players only
|
|
|
|
if (GetPlayerType(plr)!=C4PT_User) return;
|
|
|
|
// Scenario init
|
|
|
|
if (!g_is_initialized) g_is_initialized = DoInit(plr);
|
|
|
|
// Harsh zoom range
|
|
|
|
for (var flag in [PLRZOOM_LimitMax, PLRZOOM_Direct])
|
|
|
|
SetPlayerZoomByViewRange(plr,400,250,flag);
|
|
|
|
SetPlayerViewLock(plr, true);
|
|
|
|
// Create per-player-counted tools
|
|
|
|
if (g_max_player_num < GetPlayerCount(C4PT_User))
|
|
|
|
{
|
|
|
|
++g_max_player_num;
|
|
|
|
for (var obj in FindObjects(Find_ID(Chest)))
|
|
|
|
if (obj.tool_spawn)
|
|
|
|
obj->CreateContents(obj.tool_spawn);
|
|
|
|
}
|
|
|
|
// Initial join
|
|
|
|
JoinPlayer(plr);
|
|
|
|
GetCrew(plr)->CreateContents(Shovel);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
func JoinPlayer(int plr)
|
|
|
|
{
|
|
|
|
// Place in village
|
|
|
|
var crew;
|
|
|
|
for(var index = 0; crew = GetCrew(plr, index); ++index)
|
|
|
|
{
|
|
|
|
var x = 190 + Random(20);
|
|
|
|
var y = 1175;
|
|
|
|
crew->SetPosition(x , y);
|
|
|
|
crew->SetDir(DIR_Right);
|
|
|
|
crew->DoEnergy(1000);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Enemy encounter messages */
|
|
|
|
|
|
|
|
func EncounterCastle(object enemy, object player)
|
|
|
|
{
|
2014-09-21 19:49:03 +00:00
|
|
|
Dialogue->MessageBoxAll("$MsgEncounterCastle$", enemy, true);
|
2014-04-18 19:16:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
func EncounterFinal(object enemy, object player)
|
|
|
|
{
|
2014-09-21 19:49:03 +00:00
|
|
|
Dialogue->MessageBoxAll("$MsgEncounterFinal$", enemy, true);
|
2014-04-18 19:16:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
func OnTreasureCollected(object treasure)
|
|
|
|
{
|
2014-09-21 19:49:03 +00:00
|
|
|
g_treasure_collected = true;
|
|
|
|
Dialogue->MessageBoxAll("$MsgTreasureCollected$", treasure->Contained(), true);
|
|
|
|
// Dagobert has something new to say now
|
|
|
|
if (npc_dagobert)
|
|
|
|
{
|
|
|
|
var dlg = Dialogue->FindByTarget(npc_dagobert);
|
|
|
|
if (dlg) dlg->AddAttention();
|
|
|
|
}
|
2014-04-18 19:16:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-21 19:49:03 +00:00
|
|
|
func OnPlaneLoaded(object plane, object oil)
|
|
|
|
{
|
|
|
|
if (!plane || !oil) return false; // disappeared in that one frame?
|
|
|
|
oil->Enter(plane);
|
|
|
|
g_goal->OnOilDelivered();
|
|
|
|
return StartSequence("Outro", 0, plane);
|
|
|
|
}
|
|
|
|
|
2014-04-21 00:01:36 +00:00
|
|
|
static g_num_goldbars;
|
2014-04-21 16:43:37 +00:00
|
|
|
static const MAX_GOLD_BARS = 20;
|
2014-04-18 19:16:31 +00:00
|
|
|
|
2014-09-21 19:49:03 +00:00
|
|
|
func OnGoldBarCollected(object collector)
|
2014-04-18 19:16:31 +00:00
|
|
|
{
|
|
|
|
++g_num_goldbars;
|
2014-04-20 17:37:36 +00:00
|
|
|
UpdateLeagueScores();
|
2014-09-21 19:49:03 +00:00
|
|
|
Dialogue->MessageBoxAll(Format("$MsgGoldBarCollected$", g_num_goldbars, MAX_GOLD_BARS), collector, true);
|
2014-04-18 19:16:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-04-20 17:37:36 +00:00
|
|
|
|
2014-09-21 19:49:03 +00:00
|
|
|
public func OnGoalsFulfilled()
|
2014-04-20 17:37:36 +00:00
|
|
|
{
|
2014-09-11 23:01:12 +00:00
|
|
|
GainMissionAccess("S2Treasure");
|
2014-09-21 19:49:03 +00:00
|
|
|
UpdateLeagueScores();
|
|
|
|
// Return true to force goal rule to not call GameOver() yet, as it will be done by outro sequence
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
func OnGameOver()
|
|
|
|
{
|
|
|
|
// In case gems are collected after game end.
|
2014-04-20 17:37:36 +00:00
|
|
|
UpdateLeagueScores();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
func UpdateLeagueScores()
|
|
|
|
{
|
|
|
|
// +50 for finishing and +5 for every gold bar
|
2014-09-21 19:49:03 +00:00
|
|
|
var goal_finished = (g_goal && g_goal->IsFulfilled());
|
2014-04-21 00:01:36 +00:00
|
|
|
return SetLeagueProgressScore(g_num_goldbars, g_num_goldbars * 5 + goal_finished * 50);
|
2014-04-20 17:37:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func OnInvincibleDamage(object damaged_target)
|
|
|
|
{
|
|
|
|
// Closest Clonk remarks that the door is invincible
|
|
|
|
if (damaged_target && damaged_target->GetID() == StoneDoor)
|
|
|
|
{
|
|
|
|
var observer = damaged_target->FindObject(Find_ID(Clonk), Find_OCF(OCF_Alive), damaged_target->Sort_Distance());
|
|
|
|
if (observer)
|
|
|
|
{
|
2014-09-21 19:49:03 +00:00
|
|
|
Dialogue->MessageBoxAll("$MsgStoneDoorNoDamage$", observer, true);
|
2014-04-20 17:37:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-11 23:01:12 +00:00
|
|
|
|