From 1fc4dad5ab9796a97550b873b12e22a5f6cd2ea8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=BCnther=20Brammer?= <gbrammer@gmx.de>
Date: Wed, 8 Feb 2012 23:53:43 +0100
Subject: [PATCH] Use Action.Attach even when Action.Procedure is not nil

But default to the previously used value when Attach is nil. Use 0 to
override the default.
---
 src/game/object/C4Object.cpp |   58 +++++++++++++++++++----------------------
 1 files changed, 27 insertions(+), 31 deletions(-)

diff --git a/src/game/object/C4Object.cpp b/src/game/object/C4Object.cpp
index 2f9856f..853d18b 100644
--- a/src/game/object/C4Object.cpp
+++ b/src/game/object/C4Object.cpp
@@ -3449,7 +3449,6 @@ bool ReduceLineSegments(C4Shape &rShape, bool fAlternate)
 
 void C4Object::ExecAction()
 {
-	Action.t_attach=CNAT_None;
 	C4Real iTXDir;
 	C4Real lftspeed,tydir;
 	int32_t iTargetX;
@@ -3490,11 +3489,32 @@ void C4Object::ExecAction()
 		if (pActionDef->GetPropertyStr(P_InLiquidAction))
 			{ SetActionByName(pActionDef->GetPropertyStr(P_InLiquidAction)); return; }
 
-	// assign extra action attachment (CNAT_MultiAttach)
-	// regular attachment values cannot be set for backwards compatibility reasons
-	// this parameter had always been ignored for actions using an internal procedure,
-	// but is for some obscure reasons set in the KneelDown-actions of the golems
-	Action.t_attach |= (pActionDef->GetPropertyInt(P_Attach) & CNAT_MultiAttach);
+	C4Value Attach;
+	if (pActionDef->GetProperty(P_Attach, &Attach))
+	{
+		Action.t_attach = Attach.getInt();
+	}
+	else switch (pActionDef->GetPropertyP(P_Procedure))
+	{
+	case DFA_SCALE:
+		if (Action.Dir == DIR_Left)  Action.t_attach = CNAT_Left;
+		if (Action.Dir == DIR_Right) Action.t_attach = CNAT_Right;
+		break;
+	case DFA_HANGLE:
+		Action.t_attach = CNAT_Top;
+		break;
+	case DFA_WALK:
+	case DFA_KNEEL:
+	case DFA_THROW:
+	case DFA_BRIDGE:
+	case DFA_PUSH:
+	case DFA_PULL:
+	case DFA_DIG:
+		Action.t_attach = CNAT_Bottom;
+		break;
+	default:
+		Action.t_attach = CNAT_None;
+	}
 
 	// if an object is in controllable state, so it can be assumed that if it dies later because of NO_OWNER's cause,
 	// it has been its own fault and not the fault of the last one who threw a flint on it
@@ -3551,7 +3571,6 @@ void C4Object::ExecAction()
 			iPhaseAdvance=+fixtoi(xdir*10);
 		}
 
-		Action.t_attach|=CNAT_Bottom;
 		Mobile=1;
 		// object is rotateable? adjust to ground, if in horizontal movement or not attached to the center vertex
 		if (Def->Rotateable && Shape.AttachMat != MNone && (!!xdir || Def->Shape.VtxX[Shape.iAttachVtx]))
@@ -3562,7 +3581,6 @@ void C4Object::ExecAction()
 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 	case DFA_KNEEL:
 		ydir=0;
-		Action.t_attach|=CNAT_Bottom;
 		Mobile=1;
 		break;
 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -3589,8 +3607,6 @@ void C4Object::ExecAction()
 		if (ydir<0) iPhaseAdvance=-fixtoi(ydir*14);
 		if (ydir>0) iPhaseAdvance=+fixtoi(ydir*14);
 		xdir=0;
-		if (Action.Dir==DIR_Left)  Action.t_attach|=CNAT_Left;
-		if (Action.Dir==DIR_Right) Action.t_attach|=CNAT_Right;
 		Mobile=1;
 		break;
 	}
@@ -3619,7 +3635,6 @@ void C4Object::ExecAction()
 		if (xdir<0) { iPhaseAdvance=-fixtoi(xdir*10); SetDir(DIR_Left); }
 		if (xdir>0) { iPhaseAdvance=+fixtoi(xdir*10); SetDir(DIR_Right); }
 		ydir=0;
-		Action.t_attach|=CNAT_Top;
 		Mobile=1;
 		break;
 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -3652,14 +3667,6 @@ void C4Object::ExecAction()
 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 	case DFA_DIG:
 	{
-		if (pActionDef->GetPropertyInt(P_Attach))
-		{
-			Action.t_attach |= pActionDef->GetPropertyInt(P_Attach);
-		}
-		else
-		{
-			Action.t_attach |= CNAT_Bottom;
-		}
 		smpx=GetX(); smpy=GetY();
 		bool fAttachOK = false;
 		if (Action.t_attach & CNAT_Bottom && Shape.Attach(smpx,smpy,CNAT_Bottom)) fAttachOK = true;
@@ -3719,14 +3726,11 @@ void C4Object::ExecAction()
 		if (xdir<0) SetDir(DIR_Left);
 		if (xdir>0) SetDir(DIR_Right);
 		iPhaseAdvance=fixtoi(limit*10);
-		Action.t_attach=CNAT_None;
 		Mobile=1;
 
 		break;
 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 	case DFA_THROW:
-		//ydir=0; xdir=0;
-		Action.t_attach|=CNAT_Bottom;
 		Mobile=1;
 		break;
 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -3739,7 +3743,6 @@ void C4Object::ExecAction()
 		case COMD_Right: case COMD_UpRight: SetDir(DIR_Right); break;
 		}
 		ydir=0; xdir=0;
-		Action.t_attach|=CNAT_Bottom;
 		Mobile=1;
 	}
 	break;
@@ -3794,9 +3797,6 @@ void C4Object::ExecAction()
 		if (xdir>0) { iPhaseAdvance=+fixtoi(xdir*10); SetDir(DIR_Right); }
 		// No YDir
 		ydir=0;
-		// Attachment
-		Action.t_attach|=CNAT_Bottom;
-		// Mobile
 		Mobile=1;
 		break;
 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -3871,9 +3871,6 @@ void C4Object::ExecAction()
 		if (xdir>0) { iPhaseAdvance=+fixtoi(xdir*10); SetDir(DIR_Right); }
 		// No YDir
 		ydir=0;
-		// Attachment
-		Action.t_attach|=CNAT_Bottom;
-		// Mobile
 		Mobile=1;
 
 		break;
@@ -4055,9 +4052,8 @@ void C4Object::ExecAction()
 		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 	default:
 		// Attach
-		if (pActionDef->GetPropertyInt(P_Attach))
+		if (Action.t_attach)
 		{
-			Action.t_attach |= pActionDef->GetPropertyInt(P_Attach);
 			xdir = ydir = 0;
 			Mobile = 1;
 		}
-- 
1.7.8.3

