Implemented SetBase* for BaseMaterial library

heavy-resources
Maikel de Vries 2014-04-17 18:01:18 +02:00
parent 9b96ab2305
commit 47fa8ef4a1
8 changed files with 201 additions and 13 deletions

View File

@ -30,17 +30,19 @@
<desc>Changes availability of buyable objects at the home base.</desc>
<examples>
<example>
<code>DoBaseMaterial(0, Firestone, 1);</code>
<code><funclink>DoBaseMaterial</funclink>(0, Firestone, 1);</code>
<text>The player can now buy one flint more.</text>
</example>
</examples>
<related>
<funclink>GetBaseMaterial</funclink>
<funclink>SetBaseMaterial</funclink>
<funclink>GetBaseProduction</funclink>
<funclink>DoBaseProduction</funclink>
<funclink>SetBaseProduction</funclink>
<funclink>Buy</funclink>
<funclink>Sell</funclink>
</related>
</func>
<author>Sven2</author><date>2001-11</date>
<author>Maikel</author><date>2014-04</date>
</funcs>

View File

@ -36,11 +36,13 @@
</examples>
<related>
<funclink>GetBaseProduction</funclink>
<funclink>SetBaseProduction</funclink>
<funclink>DoBaseMaterial</funclink>
<funclink>GetBaseMaterial</funclink>
<funclink>SetBaseMaterial</funclink>
<funclink>Buy</funclink>
<funclink>Sell</funclink>
</related>
</func>
<author>Clonk-Karl</author><date>2008-03</date>
<author>Maikel</author><date>2014-04</date>
</funcs>

View File

@ -47,8 +47,10 @@
</examples>
<related>
<funclink>DoBaseMaterial</funclink>
<funclink>SetBaseMaterial</funclink>
<funclink>GetBaseProduction</funclink>
<funclink>DoBaseProduction</funclink>
<funclink>SetBaseProduction</funclink>
<funclink>C4D_All</funclink>
<funclink>C4D_Goal</funclink>
<funclink>C4D_Living</funclink>
@ -59,5 +61,5 @@
<funclink>C4D_Vehicle</funclink>
</related>
</func>
<author>Günther</author><date>2002-02</date>
<author>Maikel</author><date>2014-04</date>
</funcs>

View File

@ -45,7 +45,9 @@
<related>
<funclink>GetBaseMaterial</funclink>
<funclink>DoBaseMaterial</funclink>
<funclink>SetBaseMaterial</funclink>
<funclink>DoBaseProduction</funclink>
<funclink>SetBaseProduction</funclink>
<funclink>C4D_All</funclink>
<funclink>C4D_Goal</funclink>
<funclink>C4D_Living</funclink>
@ -56,5 +58,5 @@
<funclink>C4D_Vehicle</funclink>
</related>
</func>
<author>Clonk-Karl</author><date>2008-03</date>
<author>Maikel</author><date>2014-04</date>
</funcs>

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>SetBaseMaterial</title>
<category>Player</category>
<version>5.1 OC</version>
<syntax>
<rtype>bool</rtype>
<params>
<param>
<type>int</type>
<name>player</name>
<desc>Number of the player whose home base material you want to set.</desc>
</param>
<param>
<type>id</type>
<name>definition</name>
<desc>id of the buyable object type you want to adjust.</desc>
</param>
<param>
<type>int</type>
<name>cnt</name>
<desc>Set the available amount (positive).</desc>
</param>
</params>
</syntax>
<desc>Sets the availability of buyable objects at the home base.</desc>
<examples>
<example>
<code><funclink>SetBaseMaterial</funclink>(0, Firestone, 10);</code>
<text>The first player can now buy ten flints.</text>
</example>
</examples>
<related>
<funclink>GetBaseMaterial</funclink>
<funclink>DoBaseMaterial</funclink>
<funclink>GetBaseProduction</funclink>
<funclink>SetBaseProduction</funclink>
<funclink>DoBaseProduction</funclink>
<funclink>Buy</funclink>
<funclink>Sell</funclink>
</related>
</func>
<author>Maikel</author><date>2014-04</date>
</funcs>

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
<func>
<title>SetBaseProduction</title>
<category>Player</category>
<version>5.1 OC</version>
<syntax>
<rtype>bool</rtype>
<params>
<param>
<type>int</type>
<name>player</name>
<desc>Number of the player whose home base resupply list you want to set.</desc>
</param>
<param>
<type>id</type>
<name>type</name>
<desc>id of the object type you want to adjust.</desc>
</param>
<param>
<type>int</type>
<name>cnt</name>
<desc>Set the resupply value (positive).</desc>
</param>
</params>
</syntax>
<desc>Sets resupply speed of buyable objects at the home base.</desc>
<examples>
<example>
<code><funclink>SetBaseProduction</funclink>(0, Firestone, 0);</code>
<text>No more flintstones are resupplied for the first player.</text>
</example>
</examples>
<related>
<funclink>GetBaseProduction</funclink>
<funclink>DoBaseProduction</funclink>
<funclink>DoBaseMaterial</funclink>
<funclink>SetBaseMaterial</funclink>
<funclink>GetBaseMaterial</funclink>
<funclink>Buy</funclink>
<funclink>Sell</funclink>
</related>
</func>
<author>Maikel</author><date>2014-04</date>
</funcs>

View File

@ -3,8 +3,10 @@
Library to control the players base material and production. The initial values are read
from the Scenario.txt entries and per script one can modify these by:
* GetBaseMaterial(int plr, id def, int index, int category)
* SetBaseMaterial(int plr, id def, int cnt)
* DoBaseMaterial(int plr, id def, int change)
* GetBaseProduction(int plr, id def, int index, int category)
* SetBaseProduction(int plr, id def, int cnt)
* DoBaseProduction(int plr, id def, int change)
Performs also two callbacks to a base of the player:
* OnBaseMaterialChange(id def, int change);
@ -24,8 +26,8 @@ local production_unit = 0;
static const BASEMATERIAL_MaxBaseMaterial = 25;
// Maximum number of production.
static const BASEMATERIAL_MaxBaseProduction = 10;
// Produce every X frames.
static const BASEMATERIAL_ProductionRate = 10;
// Produce every X frames (currently set to a minute).
static const BASEMATERIAL_ProductionRate = 2160;
/*-- Global interface --*/
@ -39,6 +41,15 @@ global func GetBaseMaterial(int plr, id def, int index, int category)
return base->GetBaseMat(def, index, category);
}
global func SetBaseMaterial(int plr, id def, int cnt)
{
var base = FindObject(Find_ID(BaseMaterial), Find_Owner(plr));
if (!base)
base = CreateObject(BaseMaterial, AbsX(10), AbsY(10), plr);
if (base)
return base->SetBaseMat(def, cnt);
}
global func DoBaseMaterial(int plr, id def, int change)
{
var base = FindObject(Find_ID(BaseMaterial), Find_Owner(plr));
@ -57,6 +68,15 @@ global func GetBaseProduction(int plr, id def, int index, int category)
return base->GetBaseProd(def, index, category);
}
global func SetBaseProduction(int plr, id def, int cnt)
{
var base = FindObject(Find_ID(BaseMaterial), Find_Owner(plr));
if (!base)
base = CreateObject(BaseMaterial, AbsX(10), AbsY(10), plr);
if (base)
return base->SetBaseProd(def, cnt);
}
global func DoBaseProduction(int plr, id def, int change)
{
var base = FindObject(Find_ID(BaseMaterial), Find_Owner(plr));
@ -154,6 +174,36 @@ public func GetBaseMat(id def, int index, int category)
return;
}
public func SetBaseMat(id def, int cnt)
{
if (cnt == nil)
return;
cnt = Max(0, cnt);
var change = 0;
// Scan through current list of id's and set material if available.
var found = false;
for (var index = 0; index < GetLength(base_material); ++index)
{
if (base_material[index][0] == def)
{
change = cnt - base_material[index][1];
base_material[index][1] = cnt;
found = true;
}
}
// If material is not available add it to the existing list.
if (!found)
{
change = cnt;
PushBack(base_material, [def, cnt]);
}
// Callback to the bases of the player.
var i = 0, base;
while (base = FindBase(GetOwner(), i++))
base->~OnBaseMaterialChange(def, change);
return;
}
public func DoBaseMat(id def, int change)
{
if (change == 0)
@ -162,9 +212,10 @@ public func DoBaseMat(id def, int change)
var found = false;
for (var index = 0; index < GetLength(base_material); ++index)
{
var combo = base_material[index];
if (combo[0] == def)
if (base_material[index][0] == def)
{
// Change must at least be minus the original value.
change = Max(change, -base_material[index][1]);
base_material[index][1] += change;
found = true;
}
@ -172,6 +223,7 @@ public func DoBaseMat(id def, int change)
// If material is not available add it to the existing list.
if (!found)
{
// Change must at least be zero.
change = Max(change, 0);
PushBack(base_material, [def, Max(change, 0)]);
}
@ -208,6 +260,36 @@ public func GetBaseProd(id def, int index, int category)
return;
}
public func SetBaseProd(id def, int cnt)
{
if (cnt == nil)
return;
cnt = Max(0, cnt);
var change = 0;
// Scan through current list of id's and set production if available.
var found = false;
for (var index = 0; index < GetLength(base_production); ++index)
{
if (base_production[index][0] == def)
{
change = cnt - base_production[index][1];
base_production[index][1] = cnt;
found = true;
}
}
// If material is not available add it to the existing list.
if (!found)
{
change = cnt;
PushBack(base_production, [def, cnt]);
}
// Callback to the bases of the player.
var i = 0, base;
while (base = FindBase(GetOwner(), i++))
base->~OnBaseProductionChange(def, change);
return;
}
public func DoBaseProd(id def, int change)
{
if (change == 0)
@ -216,9 +298,10 @@ public func DoBaseProd(id def, int change)
var found = false;
for (var index = 0; index < GetLength(base_production); ++index)
{
var combo = base_production[index];
if (combo[0] == def)
if (base_production[index][0] == def)
{
// Change must at least be minus the original value.
change = Max(change, -base_production[index][1]);
base_production[index][1] += change;
found = true;
}
@ -226,6 +309,7 @@ public func DoBaseProd(id def, int change)
// If production is not available add it to the existing list.
if (!found)
{
// Change must at least be zero.
change = Max(change, 0);
PushBack(base_production, [def, Max(change, 0)]);
}

View File

@ -68,8 +68,8 @@ protected func InitializePlayer(int plr)
var nr_clonks = Max(9 - 2 * SCENOPT_Difficulty, 1);
if (SCENOPT_Difficulty == 1)
nr_clonks += 3;
DoBaseMaterial(plr, Clonk, nr_clonks);
DoBaseProduction(plr, Clonk, nr_clonks);
SetBaseMaterial(plr, Clonk, nr_clonks);
SetBaseProduction(plr, Clonk, nr_clonks);
// Claim ownership of structures, last player who joins owns all the main island flags.
for (var structure in FindObjects(Find_Or(Find_Category(C4D_Structure), Find_Func("IsFlagpole"))))