forked from Mirrors/openclonk
Objects: Added resource extraction goal
parent
1988ec6e8d
commit
edbf5519c3
|
@ -0,0 +1,5 @@
|
|||
[DefCore]
|
||||
id=Goal_ResourceExtraction
|
||||
Version=5,0,0,0
|
||||
Category=C4D_StaticBack|C4D_Goal
|
||||
Picture=0,0,128,128
|
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
|
@ -0,0 +1,107 @@
|
|||
/*--
|
||||
Resource Extraction
|
||||
Author: Maikel
|
||||
|
||||
Player must extract the resources of the specified type.
|
||||
TODO: Expand to liquids and digable materials.
|
||||
--*/
|
||||
|
||||
|
||||
#include Library_Goal
|
||||
|
||||
local resource_list; // List of materials to be mined.
|
||||
|
||||
protected func Initialize()
|
||||
{
|
||||
resource_list = [];
|
||||
return inherited(...);
|
||||
}
|
||||
|
||||
/*-- Resources --*/
|
||||
|
||||
public func SetResource(string resource)
|
||||
{
|
||||
var pos = GetLength(resource_list);
|
||||
resource_list[pos] = resource;
|
||||
return;
|
||||
}
|
||||
|
||||
/*-- Goal interface --*/
|
||||
|
||||
// The goal is fulfilled if all specified resource have been mined.
|
||||
public func IsFulfilled()
|
||||
{
|
||||
for (var i = 0; i < GetLength(resource_list); i++)
|
||||
{
|
||||
var mat = resource_list[i];
|
||||
var mat_cnt = GetMaterialCount(Material(mat));
|
||||
var blast_ratio = GetMaterialVal("Blast2ObjectRatio", "Material", Material(mat));
|
||||
// Still solid material to be mined.
|
||||
if (mat_cnt == -1 || mat_cnt > 3 * blast_ratio / 2)
|
||||
return false;
|
||||
var res_id = GetMaterialVal("Blast2Object", "Material", Material(mat));
|
||||
// Still objects of material to be collected.
|
||||
if (ObjectCount(Find_ID(res_id)) > 0)
|
||||
return false;
|
||||
}
|
||||
// Goal fulfilled.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Shows or hides a message window with information.
|
||||
public func Activate(int plr)
|
||||
{
|
||||
// If goal message open -> hide it.
|
||||
if (GetEffect("GoalMessage", this))
|
||||
{
|
||||
CustomMessage("", nil, plr, nil, nil, nil, nil, nil, MSG_HCenter);
|
||||
RemoveEffect("GoalMessage", this);
|
||||
return;
|
||||
}
|
||||
// Otherwise open a new message.
|
||||
AddEffect("GoalMessage", this, 100, 0, this);
|
||||
var portrait_def = Format("%i", GetID());
|
||||
var message;
|
||||
if (IsFulfilled())
|
||||
{
|
||||
message = "@$MsgGoalFulfilled$";
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "@$MsgGoalExtraction$";
|
||||
for (var i = 0; i < GetLength(resource_list); i++)
|
||||
{
|
||||
var mat = resource_list[i];
|
||||
var mat_cnt = GetMaterialCount(Material(mat));
|
||||
var res_id = GetMaterialVal("Blast2Object", "Material", Material(mat));
|
||||
var res_cnt = ObjectCount(Find_ID(res_id));
|
||||
var blast_ratio = GetMaterialVal("Blast2ObjectRatio", "Material", Material(mat));
|
||||
var add_msg = Format("$MsgGoalResource$", res_id, (mat_cnt - blast_ratio / 2) / blast_ratio, res_cnt);
|
||||
message = Format("%s%s", message, add_msg);
|
||||
}
|
||||
}
|
||||
CustomMessage(message, nil, plr, 0, 16 + 64, 0xffffff, GUI_MenuDeco, portrait_def, MSG_HCenter);
|
||||
return;
|
||||
}
|
||||
|
||||
protected func FxGoalMessageStart() {}
|
||||
|
||||
public func GetShortDescription(int plr)
|
||||
{
|
||||
// Show resource image with total resource count.
|
||||
var msg = "";
|
||||
for (var i = 0; i < GetLength(resource_list); i++)
|
||||
{
|
||||
var mat = resource_list[i];
|
||||
var mat_cnt = GetMaterialCount(Material(mat));
|
||||
var res_id = GetMaterialVal("Blast2Object", "Material", Material(mat));
|
||||
var res_cnt = ObjectCount(Find_ID(res_id));
|
||||
var blast_ratio = GetMaterialVal("Blast2ObjectRatio", "Material", Material(mat));
|
||||
msg = Format("%s{{%i}}: %d ", msg, res_id, (mat_cnt - blast_ratio / 2) / blast_ratio + res_cnt);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
/*-- Proplist --*/
|
||||
|
||||
local Name = "$Name$";
|
|
@ -0,0 +1,6 @@
|
|||
Name=Resource extraction
|
||||
|
||||
#Goal window
|
||||
MsgGoalFulfilled=Congratulations, all resources have been successfully extracted.
|
||||
MsgGoalExtraction=Successful completion of this goal includes the extraction of the following resources:
|
||||
MsgGoalResource=|{{%i}} %d units of solid material and %d chunks.
|
|
@ -0,0 +1,6 @@
|
|||
Name=Resource extraction
|
||||
|
||||
#Goal window
|
||||
MsgGoalFulfilled=Congratulations, all resources have been successfully extracted.
|
||||
MsgGoalExtraction=Successful completion of this goal includes the extraction of the following resources:
|
||||
MsgGoalResource=|{{%i}} %d units of solid material and %d chunks.
|
|
@ -15,7 +15,7 @@ overlay Mat {
|
|||
// Fills the specified region with some random materials.
|
||||
overlay MatFiller {
|
||||
overlay { mat=Earth; tex=earth; loosebounds=1; };
|
||||
Mat { mat=Granite; tex=gold; a=25; };
|
||||
Mat { mat=Granite; tex=granite; a=25; };
|
||||
Mat { mat=Ore; tex= ore; a=20; };
|
||||
Mat { mat=Tunnel; tex=tunnel; a=20; };
|
||||
Mat { mat=Rock; tex=rock; a=20; };
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
|
||||
protected func Initialize()
|
||||
{
|
||||
// Goal: Resource extraction, set to gold mining.
|
||||
var goal = CreateObject(Goal_ResourceExtraction);
|
||||
goal->SetResource("Gold");
|
||||
goal->SetResource("Ore");
|
||||
DoEnvironment();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue