Skip to content

Commit

Permalink
Removed bridge action (#96)
Browse files Browse the repository at this point in the history
Removed the bridge procedure.
  • Loading branch information
gitMarky committed Apr 13, 2019
1 parent 2b0085f commit 006b67f
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 150 deletions.
7 changes: 1 addition & 6 deletions docs/sdk/definition/procedures.xml
Expand Up @@ -68,12 +68,6 @@
<col>Behaviour according to <emlink href="definition/actmap.html">activity</emlink>.</col>
<col>CNAT_Bottom</col>
</row>
<row id="BRIDGE">
<col>DFA_BRIDGE</col>
<col>Bridge building</col>
<col>According to <emlink href="script/fn/SetComDir.html">ComDir</emlink>. Bridge material is a material number in <emlink href="script/fn/SetActionData.html">Data</emlink>.</col>
<col>CNAT_Bottom</col>
</row>
<row id="PUSH">
<col>DFA_PUSH</col>
<col>Pushing</col>
Expand Down Expand Up @@ -114,4 +108,5 @@
</text>
<text>Procedures are hardcoded in the engine and are from older times in which is was not yet possible to implement the same functionality in script. Most procedures represent highly complex behaviour which is useful only for clonks.</text>
<author>Sven2</author><date>2002-04</date>
<author>Marky</author><date>2019-04</date>
</doc>
4 changes: 3 additions & 1 deletion docs/sdk/script/fn/SetBridgeActionData.xml
Expand Up @@ -7,7 +7,7 @@
<title>SetBridgeActionData</title>
<category>Objects</category>
<subcat>Activity</subcat>
<version>1.0 OC</version>
<version>1.0 OC<extversion>9.0 OC</extversion></version>
<syntax>
<rtype>bool</rtype>
<params>
Expand All @@ -34,6 +34,7 @@
</params>
</syntax>
<desc>Sets additional parameters for a currently executed BRIDGE procedure of the calling object.</desc>
<remark>Removed in 9.0 OC. You can draw bridges on an object via <emlink href="script/Effects.html">effects</emlink> and <funclink>DrawMaterialQuad</funclink>.</remark>
<related>
<funclink>SetAction</funclink>
<funclink>SetActionData</funclink>
Expand All @@ -45,4 +46,5 @@
</related>
</func>
<author>Clonkonaut</author><date>2008-05</date>
<author>Marky</author><date>2019-04</date>
</funcs>
1 change: 0 additions & 1 deletion planet/System.ocg/Action.c
Expand Up @@ -14,7 +14,6 @@ static const DFA_HANGLE = "HANGLE";
static const DFA_DIG = "DIG";
static const DFA_SWIM = "SWIM";
static const DFA_THROW = "THROW";
static const DFA_BRIDGE = "BRIDGE";
static const DFA_PUSH = "PUSH";
static const DFA_LIFT = "LIFT";
static const DFA_FLOAT = "FLOAT";
Expand Down
10 changes: 10 additions & 0 deletions planet/System.ocg/Legacy.c
Expand Up @@ -27,9 +27,19 @@ global func SetNextMission(string filename, string title, string description)
return SetNextScenario(filename, title, description);
}

global func SetBridgeActionData()
{
LogLegacyWarningRemoved("SetBridgeActionData");
}

/* -- Internal helpers -- */

global func LogLegacyWarning(string function_name, string replacement_name, string version)
{
Log("WARNING: Do not use the legacy function \"%s\" anymore; use \"%s\" instead (complete removal is planned for \"%s\").", function_name, replacement_name, version);
}

global func LogLegacyWarningRemoved(string function_name)
{
Log("WARNING: Do not use the legacy function \"%s\" anymore; it was removed and has no effect.", function_name);
}
4 changes: 2 additions & 2 deletions src/object/C4Command.cpp
Expand Up @@ -316,8 +316,8 @@ void C4Command::MoveTo()
if (cObj->Action.Target)
{ cx=cObj->Action.Target->GetX(); cy=cObj->Action.Target->GetY(); }
break;
// dig, bridge: stop
case DFA_DIG: case DFA_BRIDGE:
// dig: stop
case DFA_DIG:
ObjectComStop(cObj);
break;
}
Expand Down
4 changes: 0 additions & 4 deletions src/object/C4Object.h
Expand Up @@ -91,10 +91,6 @@ class C4Action
public:
void Default();
void CompileFunc(StdCompiler *pComp);

// BRIDGE procedure: data mask
void SetBridgeData(int32_t iBridgeTime, bool fMoveClonk, bool fWall, int32_t iBridgeMaterial);
void GetBridgeData(int32_t &riBridgeTime, bool &rfMoveClonk, bool &rfWall, int32_t &riBridgeMaterial);
};

class C4Object: public C4PropListNumbered
Expand Down
111 changes: 0 additions & 111 deletions src/object/C4ObjectAction.cpp
Expand Up @@ -31,82 +31,6 @@
#include "platform/C4SoundSystem.h"


bool DoBridge(C4Object *clk)
{
int32_t iBridgeTime; bool fMoveClonk, fWall; int32_t iBridgeMaterial;
clk->Action.GetBridgeData(iBridgeTime, fMoveClonk, fWall, iBridgeMaterial);
if (!iBridgeTime) iBridgeTime = 100; // default bridge time
if (clk->Action.Time>=iBridgeTime) { ObjectActionStand(clk); return false; }
// get bridge advancement
int32_t dtp;
if (fWall) switch (clk->Action.ComDir)
{
case COMD_Left: case COMD_Right: dtp = 4; fMoveClonk = false; break; // vertical wall: default 25 pixels
case COMD_UpLeft: case COMD_UpRight: dtp = 5; fMoveClonk = false; break; // diagonal roof over Clonk: default 20 pixels up and 20 pixels side (28 pixels - optimized to close tunnels completely)
case COMD_Up: dtp = 5; break; // horizontal roof over Clonk
default: return true; // bridge procedure just for show
}
else switch (clk->Action.ComDir)
{
case COMD_Left: case COMD_Right: dtp = 5; break; // horizontal bridges: default 20 pixels
case COMD_Up: dtp = 4; break; // vertical bridges: default 25 pixels (same as
case COMD_UpLeft: case COMD_UpRight: dtp = 6; break; // diagonal bridges: default 16 pixels up and 16 pixels side (23 pixels)
default: return true; // bridge procedure just for show
}
if (clk->Action.Time % dtp) return true; // no advancement in this frame
// get target pos for Clonk and bridge
int32_t cx=clk->GetX(), cy=clk->GetY(), cw=clk->Shape.Wdt, ch=clk->Shape.Hgt;
int32_t tx=cx,ty=cy+ch/2;
int32_t dt;
if (fMoveClonk) dt = 0; else dt = clk->Action.Time / dtp;
if (fWall) switch (clk->Action.ComDir)
{
case COMD_Left: tx-=cw/2; ty+=-dt; break;
case COMD_Right: tx+=cw/2; ty+=-dt; break;
case COMD_Up:
{
int32_t x0;
if (fMoveClonk) x0=-3; else x0=(iBridgeTime/dtp)/-2;
tx+=(x0+dt)*((clk->Action.Dir==DIR_Right)*2-1); cx+=((clk->Action.Dir==DIR_Right)*2-1); ty-=ch+3; break;
}
case COMD_UpLeft: tx-=-4+dt; ty+=-ch-7+dt; break;
case COMD_UpRight: tx+=-4+dt; ty+=-ch-7+dt; break;
}
else switch (clk->Action.ComDir)
{
case COMD_Left: tx+=-3-dt; --cx; break;
case COMD_Right: tx+=+2+dt; ++cx; break;
case COMD_Up: tx+=(-cw/2+(cw-1)*(clk->Action.Dir==DIR_Right))*(!fMoveClonk); ty+=-dt-fMoveClonk; --cy; break;
case COMD_UpLeft: tx+=-5-dt+fMoveClonk*3; ty+=2-dt-fMoveClonk*3; --cx; --cy; break;
case COMD_UpRight: tx+=+5+dt-fMoveClonk*2; ty+=2-dt-fMoveClonk*3; ++cx; --cy; break;
}
// check if Clonk movement is posible
if (fMoveClonk)
{
int32_t cx2=cx, cy2=cy;
if (/*!clk->Shape.Attach(cx2, cy2, (clk->Action.t_attach & CNAT_Flags) | CNAT_Bottom) ||*/ clk->Shape.CheckContact(cx2, cy2-1))
{
// Clonk would collide here: Change to nonmoving Clonk mode and redo bridging
iBridgeTime -= clk->Action.Time;
clk->Action.Time = 0;
if (fWall && clk->Action.ComDir==COMD_Up)
{
// special for roof above Clonk: The nonmoving roof is started at bridgelength before the Clonk
// so, when interrupted, an action time halfway through the action must be set
clk->Action.Time = iBridgeTime;
iBridgeTime += iBridgeTime;
}
clk->Action.SetBridgeData(iBridgeTime, false, fWall, iBridgeMaterial);
return DoBridge(clk);
}
}
// draw bridge into landscape
::Landscape.DrawMaterialRect(iBridgeMaterial,tx-2,ty,4,3);
// Move Clonk
if (fMoveClonk) clk->MovePosition(cx-clk->GetX(), cy-clk->GetY());
return true;
}

void GrabLost(C4Object *cObj, C4Object *prev_target)
{
// Grab lost script call on target (quite hacky stuff...)
Expand Down Expand Up @@ -176,27 +100,6 @@ void Towards(C4Real &val, C4Real target, C4Real step)
if (val<target) val+=step; else val-=step;
}

void C4Action::SetBridgeData(int32_t iBridgeTime, bool fMoveClonk, bool fWall, int32_t iBridgeMaterial)
{
// validity
iBridgeMaterial = std::min(iBridgeMaterial, ::MaterialMap.Num-1);
if (iBridgeMaterial < 0) iBridgeMaterial = 0xff;
iBridgeTime = Clamp<int32_t>(iBridgeTime, 0, 0xffff);
// mask in this->Data
Data = (uint32_t(iBridgeTime) << 16) + (uint32_t(fMoveClonk) << 8) + (uint32_t(fWall) << 9) + iBridgeMaterial;
}

void C4Action::GetBridgeData(int32_t &riBridgeTime, bool &rfMoveClonk, bool &rfWall, int32_t &riBridgeMaterial)
{
// mask from this->Data
uint32_t uiData = Data;
riBridgeTime = (uint32_t(uiData) >> 16);
rfMoveClonk = !!(uiData & 0x100);
rfWall = !!(uiData & 0x200);
riBridgeMaterial = (uiData & 0xff);
if (riBridgeMaterial == 0xff) riBridgeMaterial = -1;
}

void C4Object::UpdateFace(bool bUpdateShape, bool fTemp)
{

Expand Down Expand Up @@ -779,7 +682,6 @@ void C4Object::ExecAction()
case DFA_WALK:
case DFA_KNEEL:
case DFA_THROW:
case DFA_BRIDGE:
case DFA_PUSH:
case DFA_PULL:
case DFA_DIG:
Expand Down Expand Up @@ -1027,19 +929,6 @@ void C4Object::ExecAction()
Mobile=true;
break;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
case DFA_BRIDGE:
{
if (!DoBridge(this)) return;
switch (Action.ComDir)
{
case COMD_Left: case COMD_UpLeft: SetDir(DIR_Left); break;
case COMD_Right: case COMD_UpRight: SetDir(DIR_Right); break;
}
ydir=0; xdir=0;
Mobile=true;
}
break;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
case DFA_PUSH:
// No target
if (!Action.Target) { StopActionDelayCommand(this); return; }
Expand Down
23 changes: 0 additions & 23 deletions src/object/C4ObjectScript.cpp
Expand Up @@ -481,35 +481,13 @@ static bool FnSetAction(C4Object *Obj, C4String *szAction,
C4Object::SAC_StartCall | C4Object::SAC_AbortCall, !!fDirect);
}

static bool FnSetBridgeActionData(C4Object *Obj, long iBridgeLength, bool fMoveClonk, bool fWall, long iBridgeMaterial)
{
if (!Obj->Status)
{
return false;
}
C4PropList* pActionDef = Obj->GetAction();
// Action must be BRIDGE
if (!pActionDef || pActionDef->GetPropertyP(P_Procedure) != DFA_BRIDGE)
{
return false;
}
// Set data
Obj->Action.SetBridgeData(iBridgeLength, fMoveClonk, fWall, iBridgeMaterial);
return true;
}

static bool FnSetActionData(C4Object *Obj, long iData)
{
if (!Obj->Status)
{
return false;
}
C4PropList* pActionDef = Obj->GetAction();
// Bridge: Convert from old style
if (pActionDef && (pActionDef->GetPropertyP(P_Procedure) == DFA_BRIDGE))
{
return FnSetBridgeActionData(Obj, 0, false, false, iData);
}
// Attach: check for valid vertex indices
if (pActionDef && (pActionDef->GetPropertyP(P_Procedure) == DFA_ATTACH))
{
Expand Down Expand Up @@ -3344,7 +3322,6 @@ void InitObjectFunctionMap(C4AulScriptEngine *pEngine)
F(SetAction);
F(SetActionData);

F(SetBridgeActionData);
F(GetAction);
F(GetActTime);
F(GetOwner);
Expand Down
1 change: 0 additions & 1 deletion src/script/C4StringTable.cpp
Expand Up @@ -322,7 +322,6 @@ C4StringTable::C4StringTable()
P[DFA_DIG] = "DIG";
P[DFA_SWIM] = "SWIM";
P[DFA_THROW] = "THROW";
P[DFA_BRIDGE] = "BRIDGE";
P[DFA_PUSH] = "PUSH";
P[DFA_LIFT] = "LIFT";
P[DFA_FLOAT] = "FLOAT";
Expand Down
1 change: 0 additions & 1 deletion src/script/C4StringTable.h
Expand Up @@ -549,7 +549,6 @@ enum C4PropertyName
DFA_DIG,
DFA_SWIM,
DFA_THROW,
DFA_BRIDGE,
DFA_PUSH,
DFA_LIFT,
DFA_FLOAT,
Expand Down

0 comments on commit 006b67f

Please sign in to comment.