Clonk script's cleanup

Sourced context menu and auto production out
Renamed Helpers.c4d as Libraries.c4d
stable-5.2
Felix Wagner 2009-10-11 15:14:23 +02:00
parent a346811dff
commit 2e5ffec460
70 changed files with 349 additions and 236 deletions

View File

@ -2,11 +2,10 @@
#strict 2
// Zauberei - ben<65>tigt, wenn der Clonk Zielzauber z.B. aus dem Zauberturm zaubert
// Auch ben<65>tigt f<>r den K<>nig
local pAimer; // Aktive Zielsteuerung; wird abgrbrochen, wenn der Zauberer gest<73>rt wird (Nur Fantasypack)
local pAimedSpell; // Zauber, der gezielt wird (Nur Fantasypack)
local pAimedSpellOrigin; // Objekt, das einen Zielzauber initiiert hat. An dieses werden SpellFailed/SpellSucceeded-Nachrichten weitergeleitet
// Context menu
#include L_CM;
// Auto production
#include L_AP;
local pInventory;
@ -24,7 +23,7 @@ protected func Initialize()
SetPhysical ("Magic", 0, 1);
SetAction("Walk");
SetDir(Random(2));
// Broadcast f<EFBFBD>r Spielregeln
// Broadcast für Spielregeln
GameCallEx("OnClonkCreation", this);
return 1;
}
@ -48,31 +47,6 @@ protected func Recruitment(int iPlr) {
GameCallEx("OnClonkRecruitment", this, iPlr);
}
/* Kontext */
public func HasConstructMenu() { return HasKnowledge() && GetPhysical("CanConstruct"); }
public func HasKnowledge() { return GetPlrKnowledge(GetOwner(),nil,0,C4D_Structure); }
public func HasBase() { return FindBase(GetOwner()) && Contained()->GetBase() != GetOwner(); }
public func ReleaseAllowed() { return ObjectCount(Find_ID(REAC)); }
public func AtConstructionSite() { return !Contained() && FindConstructionSite() && ObjectCount(CNMT); }
public func AtEnergySite() { return !Contained() && FindEnergySite(); }
public func AtTreeToChop() { return !Contained() && FindTree() && GetPhysical("CanChop"); }
public func FindConstructionSite()
{
return FindObject(Find_AtRect(-1,-16,2,32), Find_OCF(OCF_Construct), Find_Layer(GetObjectLayer()));
}
public func FindEnergySite()
{
return FindObject(Find_AtPoint(), Find_OCF(OCF_PowerConsumer), Find_NoContainer(), Find_Layer(GetObjectLayer()), Find_Func("NeedsEnergy"));
}
public func FindTree()
{
return FindObject(Find_AtPoint(), Find_OCF(OCF_Chop), Find_Layer(GetObjectLayer()));
}
/* Steuerung */
protected func ControlLeft()
@ -268,30 +242,6 @@ protected func ControlUpdate(object self, int comdir, bool dig, bool throw)
return 0;
}
protected func ControlCommand(szCommand, pTarget, iTx, iTy, pTarget2, Data)
{
// Kommando MoveTo an Pferd weiterleiten
if (szCommand == "MoveTo")
if (IsRiding())
return GetActionTarget()->~ControlCommand(szCommand, pTarget, iTx, iTy);
// Anderes Kommando beim Reiten: absteigen (Ausnahme: Context)
if (IsRiding() && szCommand != "Context")
{
GetActionTarget()->SetComDir(COMD_Stop);
GetActionTarget()->~ControlDownDouble(this);
}
// RejectConstruction Callback beim Bauen durch Drag'n'Drop aus einem Gebaeude-Menu
if(szCommand == "Construct")
{
if(Data->~RejectConstruction(iTx - GetX(), iTy - GetY(), this) )
{
return 1;
}
}
// Kein <20>berladenes Kommando
return 0;
}
/* Verwandlung */
private func RedefinePhysical(szPhys, idTo)
@ -586,65 +536,8 @@ protected func CheckStuck()
/* Status */
public func IsRiding()
{
// Reitet der Clonk?
return (WildcardMatch(GetAction(), "Ride*"));
}
public func IsClonk() { return 1; }
/* Kontext */
public func ContextRelease(pCaller)
{
[$CtxRelease$|Image=CXRL|Condition=ReleaseAllowed]
FindObject(REAC)->Activate(GetOwner());
return 1;
}
public func ContextEnergy(pCaller)
{
[$TxtEnergysupply$|Image=CXEC|Condition=AtEnergySite]
var pSite;
if (pSite = FindEnergySite())
SetCommand("Energy", pSite);
return 1;
}
public func ContextConstructionSite(pCaller)
{
[$CtxConstructionMaterial$|Image=CXCM|Condition=AtConstructionSite]
var pSite;
if (pSite = FindConstructionSite())
PlayerMessage(GetOwner(), pSite->GetNeededMatStr(), pSite);
return 1;
}
public func ContextChop(pCaller)
{
[$CtxChop$|Image=CXCP|Condition=AtTreeToChop]
var pTree;
if (pTree = FindTree())
SetCommand("Chop", pTree);
return 1;
}
public func ContextConstruction(pCaller)
{
[$CtxConstructionDesc$|Image=CXCN|Condition=HasConstructMenu]
SetCommand("Construct");
ExecuteCommand();
return 1;
}
public func ContextHome(pCaller)
{
[$CtxHomeDesc$|Image=CXHM|Condition=HasBase]
SetCommand("Home");
return 1;
}
/* Hilfsfunktion */
public func ContainedCall(string strFunction, object pTarget)
@ -654,104 +547,6 @@ public func ContainedCall(string strFunction, object pTarget)
AddCommand(this, "Enter", pTarget);
}
/* Steuerung */
protected func ControlSpecial2()
{
[$CtrlMenuDesc$|Image=CXTX]
// In einem Geb<65>ude oder Fahrzeug: das Kontextmen<65> des Geb<65>udes <20>ffnen
if (Contained())
if ((Contained()->GetCategory() & C4D_Structure) || (Contained()->GetCategory() & C4D_Vehicle))
{
SetCommand("Context",nil,0,0,Contained());
return ExecuteCommand();
}
// Fasst ein Objekt an: Kontextmen<65> des angefassten Objekts <20>ffnen
if (GetAction() == "Push")
{
SetCommand("Context",nil,0,0,GetActionTarget());
return ExecuteCommand();
}
// Tr<54>gt ein Objekt: Kontextmen<65> des ersten getragenen Objekts <20>ffnen
if (Contents(0))
{
SetCommand("Context",nil,0,0,Contents(0));
return ExecuteCommand();
}
// Ansonsten das Kontextmen<65> des Clonks <20>ffnen
SetCommand("Context",nil,0,0,this);
return ExecuteCommand();
}
/* Callback beim Auswahl aus dem Construct-Kontextmenu */
public func ControlCommandConstruction(target, x, y, target2, def)
{
// Keine Konstruktion erlaubt?
if(def->~RejectConstruction(x - GetX(), y - GetY(), this) )
// Construct-Kommando beenden
return FinishCommand(false, 0) ;
}
/* Automatische Produktion */
public func ControlCommandAcquire(target, x, y, target2, def)
{
// Falls das Teil rumliegt nur aufsammeln
var obj = GetAvailableObject (def, target2);
if (obj) {
AddEffect("IntNotAvailable", obj, 1, 5, this);
AddCommand ("Get", obj, 0, 0, 0, 40);
return 1;
}
// Geb<65>ude suchen worin man's herstellen kann
if (obj = GetProducerOf (def)) {
AddCommand ("Call", this, 0, 0, 0, 0, "AutoProduction", 0, 1);
obj -> ~HowToProduce (this, def);
return 1;
}
AddCommand ("Buy", 0, 0, 0, 0, 100, def, 0, C4CMD_Sub);
return 1;
}
public func AutoProduction() { return 1; }
public func AutoProductionFailed()
{
var def = GetCommand (5, 1);
if (!FindContents(def)) {
var obj = GetAvailableObject (def, GetCommand (4, 1));
if (obj) {
AddEffect("IntNotAvailable", obj, 1, 5, this);
AddCommand ("Get", obj,0,0,0,40);
return 1;
}
AddCommand ("Buy", 0, 0, 0, 0, 100, GetCommand(5, 1), 0, C4CMD_Sub);
}
return 1;
}
public func FxIntNotAvailableStart(target, number)
{
EffectVar(0, target, number) = this;
}
public func FxIntNotAvailableTimer(target, number)
{
var clonk = EffectVar(0, target, number);
// Check wether the clonk still wants to get the object
for (var i = 0; GetCommand(clonk,0,i); ++i) {
if (GetCommand(clonk, 0, i) == "Get" && GetCommand(clonk, 1, i) == target)
return;
}
return FX_Execute_Kill;
}
public func GetProducerOf(def)
{
return FindObject(Find_InRect(-500,-250,1000,500), Find_Func("IsProducerOf", this, def), Sort_Distance());
}
/* Trinken */
public func Drink(object pDrink)
@ -910,32 +705,6 @@ private func GetNonSpecialCount()
return iCnt;
}
/* Reiten */
public func ContextDescend(pCaller)
{
[$TxtDescend$|Image=DSCN|Condition=IsRiding]
DescendVehicle();
}
public func DescendVehicle()
{
var pOldVehicle = GetActionTarget();
SetAction("Walk");
// Feststecken nach Absteigen? Dann besser direkt beim Gef<65>hrt absteigen.
if (Stuck()) if (pOldVehicle)
{
var x=GetX(), y=GetY();
SetPosition(pOldVehicle->GetX(), pOldVehicle->GetY());
if (Stuck())
{
// Das Gef<65>hrt steckt auch? Dann hilft es alles nichts. Zur<75>ck zum Ursprungsort.
SetPosition(x,y);
}
}
}
/* Effektsteuerung */
private func Control2Effect(string szControl)

View File

@ -0,0 +1,7 @@
[DefCore]
id=L_AP
Version=4,10,0,0
Name=Lib Auto Production
Category=C4D_StaticBack
Width=1
Height=1

View File

@ -0,0 +1 @@
Damit ein Clonk Arbeitsschritte kombinieren kann.

View File

@ -0,0 +1 @@
To enable the clonk to combine work steps.

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

View File

@ -0,0 +1,2 @@
DE:Autoproduktion
US:Auto production

View File

@ -0,0 +1,60 @@
/*--- Auto production ---*/
#strict 2
public func ControlCommandAcquire(target, x, y, target2, def)
{
// If the object is lying around just pick it up
var obj = GetAvailableObject (def, target2);
if (obj) {
AddEffect("IntNotAvailable", obj, 1, 5, this);
AddCommand (this, "Get", obj, 0, 0, 0, 40);
return 1;
}
// Search for a building to produce the object
if (obj = GetProducerOf (def)) {
AddCommand (this (), "Call", this, 0, 0, 0, 0, "AutoProduction", 0, 1);
obj -> HowToProduce (this, def);
return 1;
}
AddCommand (this, "Buy", 0, 0, 0, 0, 100, def, 0, C4CMD_Sub);
return 1;
}
public func AutoProduction() { return 1; }
public func AutoProductionFailed()
{
var def = GetCommand (this (), 5, 1);
if (!FindContents(def)) {
var obj = GetAvailableObject (def, GetCommand (this (), 4, 1));
if (obj) {
AddEffect("IntNotAvailable", obj, 1, 5, this);
AddCommand (this, "Get", obj,0,0,0,40);
return 1;
}
AddCommand (this, "Buy", 0, 0, 0, 0, 100, GetCommand(this, 5, 1), 0, C4CMD_Sub);
}
return 1;
}
public func FxIntNotAvailableStart(target, number)
{
EffectVar(0, target, number) = this;
}
public func FxIntNotAvailableTimer(target, number)
{
var clonk = EffectVar(0, target, number);
// Check wether the clonk still wants to get the object
for (var i = 0; GetCommand(clonk,0,i); ++i) {
if (GetCommand(clonk, 0, i) == "Get" && GetCommand(clonk, 1, i) == target)
return;
}
return FX_Execute_Kill;
}
public func GetProducerOf(def)
{
return FindObject2(Find_InRect(-500,-250,1000,500), Find_Func("IsProducerOf", this, def), Sort_Distance());
}

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -0,0 +1,7 @@
[DefCore]
id=L_CM
Version=4,10,0,0
Name=Lib Context Menu
Category=C4D_StaticBack
Width=1
Height=1

View File

@ -0,0 +1 @@
Enthält die wesentlichen Kontextmenüeinträge.

View File

@ -0,0 +1 @@
The basic context menu entries.

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

View File

@ -0,0 +1,8 @@
[DefCore]
id=CXCP
Version=4,9,8,1
Name=Symbol
Category=C4D_StaticBack
Width=1
Height=1
Picture=0,0,64,64

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -0,0 +1,8 @@
[DefCore]
id=CXCN
Version=4,9,8
Name=Symbol
Category=C4D_StaticBack
Width=1
Height=1
Picture=0,0,64,64

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@ -0,0 +1,8 @@
[DefCore]
id=CXCM
Version=4,9,8
Name=Symbol
Category=C4D_StaticBack
Width=1
Height=1
Picture=0,0,16,16

Binary file not shown.

After

Width:  |  Height:  |  Size: 853 B

View File

@ -0,0 +1,8 @@
[DefCore]
id=CXTX
Version=4,9,8
Name=Symbol
Category=C4D_StaticBack
Width=1
Height=1
Picture=0,0,64,64

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -0,0 +1,8 @@
[DefCore]
id=DSCN
Version=4,9,8
Name=Descend
Category=C4D_StaticBack
Width=1
Height=1
Picture=0,0,64,64

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -0,0 +1,2 @@
DE:Absteigen
US:Descend

View File

@ -0,0 +1,8 @@
[DefCore]
id=CXHM
Version=4,9,8
Name=Symbol
Category=C4D_StaticBack
Width=1
Height=1
Picture=0,0,64,64

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -0,0 +1,8 @@
[DefCore]
id=CXIN
Version=4,9,8
Name=Symbol
Category=C4D_StaticBack
Width=1
Height=1
Picture=0,0,32,32

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,8 @@
[DefCore]
id=CXIV
Version=4,9,8
Name=InventorySymbol
Category=C4D_StaticBack
Width=1
Height=1
Picture=0,0,64,64

View File

@ -0,0 +1 @@
Select active item.

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

View File

@ -0,0 +1,2 @@
DE:Inventar
US:Inventory

View File

@ -0,0 +1,8 @@
[DefCore]
id=CXRL
Version=4,9,8
Name=Symbol
Category=C4D_StaticBack
Width=1
Height=1
Picture=0,0,64,64

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

@ -0,0 +1,2 @@
DE:Kontextmenü
US:Context menu

View File

@ -0,0 +1,168 @@
/*--- Context menu ---*/
#strict 2
/* Control */
protected func ControlSpecial2()
{
[$CtrlMenuDesc$|Image=CXTX]
// Inside a building or vehicle: open context menu of the container
if (Contained())
if ((Contained()->GetCategory() & C4D_Structure) || (Contained()->GetCategory() & C4D_Vehicle))
{
SetCommand(this,"Context",0,0,0,Contained());
return ExecuteCommand();
}
// Is pushing an object: open context menu of the pushed object
if (GetAction() == "Push")
{
SetCommand(this,"Context",0,0,0,GetActionTarget());
return ExecuteCommand();
}
// Carries an object: open context menu of the first carried object
if (Contents(0))
{
SetCommand(this,"Context",0,0,0,Contents(0));
return ExecuteCommand();
}
// Open context menu of the clonk then
SetCommand(this,"Context",0,0,0,this);
return ExecuteCommand();
}
/* Context menu entries */
/*public func ContextRelease(pCaller)
{
[$CtxRelease$|Image=CXRL|Condition=ReleaseAllowed]
FindObject(REAC)->Activate(GetOwner());
return 1;
}*/
public func ContextEnergy(pCaller)
{
[$TxtEnergysupply$|Image=CXEC|Condition=AtEnergySite]
var pSite;
if (pSite = FindEnergySite())
SetCommand(this, "Energy", pSite);
return 1;
}
public func ContextConstructionSite(pCaller)
{
[$CtxConstructionMaterial$|Image=CXCM|Condition=AtConstructionSite]
var pSite;
if (pSite = FindConstructionSite())
PlayerMessage(GetOwner(), pSite->GetNeededMatStr(), pSite);
return 1;
}
public func ContextChop(pCaller)
{
[$CtxChop$|Image=CXCP|Condition=AtTreeToChop]
var pTree;
if (pTree = FindTree())
SetCommand(this, "Chop", pTree);
return 1;
}
public func ContextConstruction(pCaller)
{
[$CtxConstructionDesc$|Image=CXCN|Condition=HasConstructMenu]
SetCommand(this, "Construct");
ExecuteCommand();
return 1;
}
public func ContextHome(pCaller)
{
[$CtxHomeDesc$|Image=CXHM|Condition=HasBase]
SetCommand(this, "Home");
return 1;
}
public func ContextDescend(pCaller)
{
[$TxtDescend$|Image=DSCN|Condition=IsRiding]
DescendVehicle();
}
/* Conditions */
public func IsRiding() { return (WildcardMatch(GetAction(), "Ride*")); }
public func HasConstructMenu() { return HasKnowledge() && GetPhysical("CanConstruct"); }
public func HasKnowledge() { return GetPlrKnowledge(GetOwner(),nil,0,C4D_Structure); }
public func HasBase() { return FindBase(GetOwner()) && GetBase(Contained()) != GetOwner(); }
public func ReleaseAllowed() { return ObjectCount(REAC); }
public func AtConstructionSite() { return !Contained() && FindConstructionSite() && ObjectCount(CNMT); }
public func AtEnergySite() { return !Contained() && FindEnergySite(); }
public func AtTreeToChop() { return !Contained() && FindTree() && GetPhysical("CanChop"); }
public func FindConstructionSite()
{
return FindObject2(Find_AtRect(-1,-16,2,32), Find_OCF(OCF_Construct), Find_Layer(GetObjectLayer()));
}
public func FindEnergySite()
{
return FindObject2(Find_AtPoint(), Find_OCF(OCF_PowerConsumer), Find_NoContainer(), Find_Layer(GetObjectLayer()), Find_Func("NeedsEnergy"));
}
public func FindTree()
{
return FindObject2(Find_AtPoint(), Find_OCF(OCF_Chop), Find_Layer(GetObjectLayer()));
}
/* Misc */
protected func ControlCommand(szCommand, pTarget, iTx, iTy, pTarget2, Data)
{
// Forward MoveTo command to the horse
if (szCommand == "MoveTo")
if (IsRiding())
return GetActionTarget()->~ControlCommand(szCommand, pTarget, iTx, iTy);
// Other command when riding: descend (exception: Context)
if (IsRiding() && szCommand != "Context")
{
SetComDir(COMD_Stop,GetActionTarget());
GetActionTarget()->~ControlDownDouble(this);
}
// RejectConstruction Callback when constructing via Drag'n'Drop from a building menu
if(szCommand == "Construct")
{
if(Data->~RejectConstruction(iTx - GetX(), iTy - GetY(), this) )
{
return 1;
}
}
// Call base implementation
return _inherited(...);
}
// Callback when selecting the "Construct" menu entry
public func ControlCommandConstruction(target, x, y, target2, def)
{
// Construction prohibited?
if(def->~RejectConstruction(x - GetX(), y - GetY(), this) )
// Finish construction command
return FinishCommand(this, false, 0) ;
}
// Called when selecting the "Descend" menu entry
public func DescendVehicle()
{
var pOldVehicle = GetActionTarget();
SetAction("Walk");
// Stuck after descending? Descend at the vehicle's position
if (Stuck()) if (pOldVehicle)
{
var x=GetX(), y=GetY();
SetPosition(GetX(pOldVehicle), GetY(pOldVehicle));
if (Stuck())
{
// Vehicle is stuck as well? Back to the roots.
SetPosition(x,y);
}
}
}

View File

@ -0,0 +1,8 @@
CtxConstructionDesc=Bauauftrag
CtxConstructionMaterial=Baumaterial
CtxHomeDesc=Zurück zur Basis
CtxRelease=Entlassen
CtxChop=Fällen
CtrlMenuDesc=Menü
TxtDescend=Abspringen
TxtEnergysupply=Energieversorgung

View File

@ -0,0 +1,8 @@
CtxConstructionDesc=Construction
CtxConstructionMaterial=Construction material
CtxHomeDesc=Back to base
CtxRelease=Release
CtxChop=Chop
CtrlMenuDesc=Menu
TxtDescend=Jump off
TxtEnergysupply=Energy supply

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 141 B

After

Width:  |  Height:  |  Size: 141 B