# HG changeset patch
# User Icewing 
# Date 1255025082 -7200
# Node ID 02437d695c046112d477eae6d7d568852fb80b94
# Parent  f84a36dfc11c30a42b00e4a079be4d8452d9f59b
Moved line pick up to clonk

diff -r f84a36dfc11c -r 02437d695c04 planet/Objects.c4d/Clonk.c4d/Script.c
--- a/planet/Objects.c4d/Clonk.c4d/Script.c	Mon Oct 05 21:17:50 2009 +0200
+++ b/planet/Objects.c4d/Clonk.c4d/Script.c	Thu Oct 08 20:04:42 2009 +0200
@@ -645,6 +645,13 @@ public func ContextHome(pCaller)
   return 1;
 }
 
+public func ContextLinePickup(pCaller)
+{
+  [$CtxLinePickupDesc$|Image=LNKT|Condition=AtLineToPickup]
+  LinePickup();
+  return 1;
+}
+
 /* Hilfsfunktion */
 
 public func ContainedCall(string strFunction, object pTarget)
@@ -1058,6 +1065,57 @@ private func SetMagicAction(id idForSpel
 private func SetMagicAction(id idForSpell) {}
 private func SetCastAction() {}
 private func EndMagicAction() {}
+
+/* Line pickup */
+
+protected func AtLineToPickup()
+{
+  var struct = FindObject(Find_AtPoint(), Find_OCF(OCF_LineConstruct));
+  if (!struct) return false;
+  var line = FindObject(Find_Action("Connect"),Find_ActionTarget(struct));
+  if (!line) return false;
+  return true;
+}
+
+private func LinePickup()
+{
+  // Check physical
+  if (!GetPhysical("CanConstruct")) return false;
+  var linekit, tstruct, cline;
+  tstruct=FindObject(Find_AtPoint(), Find_OCF(OCF_LineConstruct));
+  if (!tstruct) return false;
+  
+  SetXDir(0);
+  SetYDir(0);
+  SetComDir(COMD_Stop);
+
+  // Check line pickup
+  if (!(cline=FindObject(Find_Action("Connect"),Find_ActionTarget(tstruct)))) return false;
+  // Check line connected to linekit at other end
+  if ( (cline->GetActionTarget(0) && (cline->GetActionTarget(0)->~IsLineKit()))
+    || (cline->GetActionTarget(1) && (cline->GetActionTarget(1)->~IsLineKit())) )
+  {
+    Sound("Error",false,this, 100);
+    Message("$TxtNoDoubleKit$", this, cline->GetName());
+    return false;
+  }
+  var kitID = cline->~LineKitID() || LNKT; //downwards compatible
+  // Create new linekit
+  if (!(linekit=CreateObject(kitID, 0, 0, cline->GetOwner()))) return false;
+  // Collect linekit
+  if (!Collect(linekit))
+  {
+    // Collect failed: abort operation
+    linekit->RemoveObject(); return false;
+  }
+  // Attach line to collected linekit
+  Sound("Connect",false, this, 100);
+  if (cline->GetActionTarget(0)==tstruct) cline->SetActionTargets(linekit, cline->GetActionTarget(1));
+  if (cline->GetActionTarget(1)==tstruct) cline->SetActionTargets(linekit, cline->GetActionTarget(0));
+  // Message
+  Message("$TxtDisconnect$", this, cline->GetName(),tstruct->GetName());
+  return true;
+}
 
 func Definition(def) {
   SetProperty("ActMap", {
diff -r f84a36dfc11c -r 02437d695c04 planet/Objects.c4d/Clonk.c4d/StringTblDE.txt
--- a/planet/Objects.c4d/Clonk.c4d/StringTblDE.txt	Mon Oct 05 21:17:50 2009 +0200
+++ b/planet/Objects.c4d/Clonk.c4d/StringTblDE.txt	Thu Oct 08 20:04:42 2009 +0200
@@ -3,6 +3,9 @@ CtxHomeDesc=Zurück zur Basis
 CtxHomeDesc=Zurück zur Basis
 CtxRelease=Entlassen
 CtxChop=Fällen
+CtxLinePickupDesc=Leitung aufnehmen
 CtrlMenuDesc=Menü
 TxtDescend=Abspringen
 TxtEnergysupply=Energieversorgung
+TxtNoDoubleKit=%s wird bereits|am anderen Ende verlegt.
+TxtDisconnect=%s von|%s getrennt.
diff -r f84a36dfc11c -r 02437d695c04 planet/Objects.c4d/Clonk.c4d/StringTblUS.txt
--- a/planet/Objects.c4d/Clonk.c4d/StringTblUS.txt	Mon Oct 05 21:17:50 2009 +0200
+++ b/planet/Objects.c4d/Clonk.c4d/StringTblUS.txt	Thu Oct 08 20:04:42 2009 +0200
@@ -3,6 +3,9 @@ CtxHomeDesc=Back to base
 CtxHomeDesc=Back to base
 CtxRelease=Release
 CtxChop=Chop
+CtxLinePickupDesc=Line pickup
 CtrlMenuDesc=Menu
 TxtDescend=Jump off
 TxtEnergysupply=Energy supply
+TxtNoDoubleKit=%s is not fixed at the other end.
+TxtDisconnect=%s disconnected|from %s.
diff -r f84a36dfc11c -r 02437d695c04 planet/Objects.c4d/Items.c4d/WireRoll.c4d/PowerLine.c4d/Script.c
--- a/planet/Objects.c4d/Items.c4d/WireRoll.c4d/PowerLine.c4d/Script.c	Mon Oct 05 21:17:50 2009 +0200
+++ b/planet/Objects.c4d/Items.c4d/WireRoll.c4d/PowerLine.c4d/Script.c	Thu Oct 08 20:04:42 2009 +0200
@@ -20,6 +20,11 @@ public func IsConnectedTo(object pObject
 public func IsConnectedTo(object pObject)
 {
 	return GetActionTarget(0) == pObject || GetActionTarget(1) == pObject;
+}
+
+public func LineKitID()
+{
+	return LNKT;
 }
 
 // Returns the object which is connected to pObject through this power line.
@@ -57,4 +62,4 @@ NextAction = "Connect",
 NextAction = "Connect",
 },  }, def);
   SetProperty("Name", "$Name$", def);
-}
\ No newline at end of file
+}
diff -r f84a36dfc11c -r 02437d695c04 planet/Objects.c4d/Items.c4d/WireRoll.c4d/Script.c
--- a/planet/Objects.c4d/Items.c4d/WireRoll.c4d/Script.c	Mon Oct 05 21:17:50 2009 +0200
+++ b/planet/Objects.c4d/Items.c4d/WireRoll.c4d/Script.c	Thu Oct 08 20:04:42 2009 +0200
@@ -8,6 +8,8 @@ protected func Hit()
 }
 
 public func IsToolProduct() { return 1; }
+
+public func IsLineKit() { return true; }
 
 /*-- Line connection --*/
 
diff -r f84a36dfc11c -r 02437d695c04 src/game/object/C4ObjectCom.cpp
--- a/src/game/object/C4ObjectCom.cpp	Mon Oct 05 21:17:50 2009 +0200
+++ b/src/game/object/C4ObjectCom.cpp	Thu Oct 08 20:04:42 2009 +0200
@@ -395,160 +395,6 @@ C4Object *CreateLine(C4ID idType, int32_
 	return pLine;
 	}
 
-bool ObjectComLineConstruction(C4Object *cObj)
-	{
-	C4Object *linekit,*tstruct,*cline;
-	DWORD ocf;
-
-  ObjectActionStand(cObj);
-
-  // Check physical
-  if (!cObj->GetPhysical()->CanConstruct)
-		{
-		GameMsgObject(FormatString(LoadResStr("IDS_OBJ_NOLINECONSTRUCT"),cObj->GetName()).getData(),cObj); return false;
-		}
-
-	// - - - - - - - - - - - - - - - - - - Line pickup - - - - - - - - - - - - - - - - -
-
-	// Check for linekit
-	if (!(linekit=cObj->Contents.Find(C4ID_Linekit)))
-		{
-		// Check for collection limit
-		if (cObj->Def->CollectionLimit && (cObj->Contents.ObjectCount()>=cObj->Def->CollectionLimit) ) return false;
-    // Check line pickup
-		ocf=OCF_LineConstruct;
-		tstruct=::Objects.AtObject(cObj->GetX(),cObj->GetY(),ocf,cObj);
-		if (!tstruct || !(ocf & OCF_LineConstruct)) return false;
-		if (!(cline=Game.FindObject(C4ID_None,0,0,0,0,OCF_All,"Connect",tstruct))) return false;
-		// Check line connected to linekit at other end
-		if ( (cline->Action.Target && (cline->Action.Target->Def->id==C4ID_Linekit))
-			|| (cline->Action.Target2 && (cline->Action.Target2->Def->id==C4ID_Linekit)) )
-				{
-				StartSoundEffect("Error",false,100,cObj);
-				GameMsgObject(FormatString(LoadResStr("IDS_OBJ_NODOUBLEKIT"),cline->GetName()).getData(),cObj);	return false;
-				}
-		// Create new linekit
-    if (!(linekit=Game.CreateObject(C4ID_Linekit,cObj,cline->Owner))) return false;
-		// Enter linekit into clonk
-		bool fRejectCollect;
-		if (!linekit->Enter(cObj, true, true, &fRejectCollect))
-			{
-			// Enter failed: abort operation
-			linekit->AssignRemoval(); return false;
-			}
-		// Attach line to collected linekit
-		StartSoundEffect("Connect",false,100,cObj);
-		if (cline->Action.Target==tstruct) cline->Action.Target=linekit;
-		if (cline->Action.Target2==tstruct) cline->Action.Target2=linekit;
-		// Message
-		GameMsgObject(FormatString(LoadResStr("IDS_OBJ_DISCONNECT"),cline->GetName(),tstruct->GetName()).getData(),tstruct);
-		return true;
-		}
-
-	// - - - - - - - - - -  - - - - - Active construction - - - - - - - - - - - - - - - - -
-
-	// Active line construction
-	if (cline=Game.FindObject(C4ID_None,0,0,0,0,OCF_All,"Connect",linekit))
-		{
-
-		// Check for structure connection
-		ocf=OCF_LineConstruct;
-		tstruct=::Objects.AtObject(cObj->GetX(),cObj->GetY(),ocf,cObj);
-		// No structure
-		if (!tstruct || !(ocf & OCF_LineConstruct))
-			{
-			// No connect
-			StartSoundEffect("Error",false,100,cObj);
-			GameMsgObject(FormatString(LoadResStr("IDS_OBJ_NOCONNECT")).getData(),cObj);	return false;
-			}
-
-		// Check short circuit -> removal
-		if ((cline->Action.Target==tstruct)
-		 || (cline->Action.Target2==tstruct))
-			{
-			StartSoundEffect("Connect",false,100,cObj);
-			GameMsgObject(FormatString(LoadResStr("IDS_OBJ_LINEREMOVAL"),cline->GetName()).getData(),tstruct);
-			cline->AssignRemoval();
-			return true;
-			}
-
-		// Check for correct connection type
-		bool connect_okay=false;
-		switch (cline->Def->Line)
-			{
-			case C4D_Line_Power:
-				if (tstruct->Def->LineConnect & C4D_Power_Input) connect_okay=true;
-				if (tstruct->Def->LineConnect & C4D_Power_Output) connect_okay=true;
-				break;
-			case C4D_Line_Source:
-				if (tstruct->Def->LineConnect & C4D_Liquid_Output) connect_okay=true;	break;
-			case C4D_Line_Drain:
-				if (tstruct->Def->LineConnect & C4D_Liquid_Input) connect_okay=true;	break;
-			default: return false; // Undefined line type
-			}
-	  if (!connect_okay)
-			{
-			StartSoundEffect("Error",false,100,cObj);
-			GameMsgObject(FormatString(LoadResStr("IDS_OBJ_NOCONNECTTYPE"),cline->GetName(),tstruct->GetName()).getData(),tstruct);
-			return false;
-			}
-
-		// Connect line to structure
-		StartSoundEffect("Connect",false,100,cObj);
-		if (cline->Action.Target==linekit) cline->Action.Target=tstruct;
-		if (cline->Action.Target2==linekit) cline->Action.Target2=tstruct;
-		linekit->Exit();
-		linekit->AssignRemoval();
-
-		GameMsgObject(FormatString(LoadResStr("IDS_OBJ_CONNECT"),cline->GetName(),tstruct->GetName()).getData(),tstruct);
-
-		return true;
-		}
-
-	// - - - - - - - - - - - - - - - - New line - - - - - - - - - - - - - - - - - - - - -
-
-	// Check for new structure connection
-	ocf=OCF_LineConstruct;
-	tstruct=::Objects.AtObject(cObj->GetX(),cObj->GetY(),ocf,cObj);
-	if (!tstruct || !(ocf & OCF_LineConstruct))
-		{
-		StartSoundEffect("Error",false,100,cObj);
-		GameMsgObject(FormatString(LoadResStr("IDS_OBJ_NONEWLINE")).getData(),cObj);	return false;
-		}
-
-	// Determine new line type
-	C4ID linetype=C4ID_None;
-	// Check source pipe
-	if (linetype==C4ID_None)
-		if (tstruct->Def->LineConnect & C4D_Liquid_Pump)
-			if (!Game.FindObject(C4ID_SourcePipe,0,0,0,0,OCF_All,"Connect",tstruct))
-				linetype = C4ID_SourcePipe;
-	// Check drain pipe
-	if (linetype==C4ID_None)
-		if (tstruct->Def->LineConnect & C4D_Liquid_Output)
-			if (!Game.FindObject(C4ID_DrainPipe,0,0,0,0,OCF_All,"Connect",tstruct))
-				linetype = C4ID_DrainPipe;
-	// Check power
-	if (linetype==C4ID_None)
-		if (tstruct->Def->LineConnect & C4D_Power_Output)
-			linetype = C4ID_PowerLine;
-	// No good
-	if (linetype==C4ID_None)
-		{
-		StartSoundEffect("Error",false,100,cObj);
-		GameMsgObject(FormatString(LoadResStr("IDS_OBJ_NONEWLINE")).getData(),cObj);	return false;
-		}
-
-	// Create new line
-	C4Object *newline=CreateLine(linetype,cObj->Owner,
-															 tstruct,linekit);
-	if (!newline) return false;
-	StartSoundEffect("Connect",false,100,cObj);
-	GameMsgObject(FormatString(LoadResStr("IDS_OBJ_NEWLINE"),newline->GetName()).getData(),tstruct);
-
-	return true;
-	}
-
 void ObjectComDigDouble(C4Object *cObj) // "Activation" by DFA_WALK, DFA_DIG, DFA_SWIM
   {
 	C4Object *pTarget;
@@ -560,13 +406,6 @@ void ObjectComDigDouble(C4Object *cObj) 
 		if (!! cObj->Contents.GetObject()->Call(PSF_Activate,&C4AulParSet(C4VObj(cObj))))
 			return;
 
-	// Linekit: Line construction (move to linekit script...)
-  if (cObj->Contents.GetObject() && (cObj->Contents.GetObject()->id==C4ID_Linekit))
-    {
-		ObjectComLineConstruction(cObj);
-		return;
-    }
-
 	// Chop
   ocf=OCF_Chop;
   if (phys->CanChop)
@@ -577,15 +416,6 @@ void ObjectComDigDouble(C4Object *cObj) 
 				  PlayerObjectCommand(cObj->Owner,C4CMD_Chop,pTarget);
 					return;
 					}
-
-	// Line construction pick up
-  ocf=OCF_LineConstruct;
-  if (phys->CanConstruct)
-	  if (!cObj->Contents.GetObject())
-	    if ((pTarget=::Objects.AtObject(cObj->GetX(),cObj->GetY(),ocf,cObj)))
-		    if (ocf & OCF_LineConstruct)
-			    if (ObjectComLineConstruction(cObj))
-						return;
 
   // Own activation call
   if (!! cObj->Call(PSF_Activate, &C4AulParSet(C4VObj(cObj)))) return;
