<?xml version="1.0"?>
<_templates Include="trucks">
	<Constraint>
		<Crane Name="Crane" />
		<AnchorBase Type="Hinge" AxisLocal="(1;0;0)">
			<Motor Type="Position" Force="2000" />
		</AnchorBase>
		<Anchor
			Name="Anchor"
			Type="Prismatic"
			AxisLocal="(0;1;0)"
			MinLimit="0"
			MaxLimit="0.8"
		>
			<Motor Type="Position" Force="8000" />
		</Anchor>
		<Grappler Type="Hinge" AxisLocal="(0;0;1)">
			<Motor
				Type="Position"
				Force="2000"
				Tau="0.04"
			/>
		</Grappler>
	</Constraint>
</_templates>
<TruckAddon>
	<GameData Title="Volvo FM Crane" Description="-">
	
		<InstallSocket Type="volvoCraneSedlo" />		
	</GameData>
	<PhysicsModel Mesh="trucks/volvofm_crane">
		<Body ModelFrame="body" Mass="2500" ImpactType="Truck">
			<Constraint Type="Fixed" />
			<Body ModelFrame="crane" Collisions="Internal" Mass="1000">
				<Constraint
					_template="Crane"
					Type="Hinge"
					AxisLocal="(0;1;0)"
					MinLimit="-180"
					MaxLimit="180"
				>
				<Motor Force="40000" Tau="0.04" Type="Position" />
				</Constraint>

				<Body
					ModelFrame="arm"
					Mass="200"
					Collisions="Internal"
				>
					<Constraint
						_template="Crane"
						Type="Hinge"
						AxisLocal="(1;0;0)"
						MinLimit="0"
						MaxLimit="100"
					>
						<Motor Type="Position" Force="100000" />
					</Constraint>
					<Body
						ModelFrame="arm1"
						Mass="200"
						Collisions="Internal"
					>
						<Constraint
							_template="Crane"
							Type="Hinge"
							AxisLocal="(1;0;0)"
							MinLimit="-300"
							MaxLimit="0"
						>
							<Motor Type="Position" Force="50000" />
						</Constraint>
						<Body
							ModelFrame="arm2"
							Mass="100"
							Collisions="Internal"
						>
							<Constraint
								_template="Crane"
								Type="Prismatic"
								AxisLocal="(0;1;0)"
								MinLimit="0"
								MaxLimit="1"
							>
								<Motor Type="Position" Force="35000" />
							</Constraint>
									<Body
										ModelFrame="attach"
										Mass="20"
										Collisions="Internal" 
									>
										<Constraint
											
											Type="Hinge"
											AxisLocal="(1;0;0)"
											MinLimit="0"
											MaxLimit="180"
										>
											<Motor

												Type="Spring"

												Spring="20"

												Damping="100"

											/>
										</Constraint>
										<Body
											ModelFrame="charmroot"
											Mass="20"
											Collisions="Internal" 
										>
											<Constraint
												
												Type="Hinge"
												AxisLocal="(0;0;1)"
												MinLimit="-45"
												MaxLimit="45"
											>
												<Motor

													Type="Spring"

													Spring="20"

													Damping="100"

												/>
											</Constraint>
              										<Body
												ModelFrame="charm"
												Mass="30"
												Collisions="Internal"
											>
												<Constraint
													Name="CharmBase"
													Type="Hinge"
													AxisLocal="(0;1;0)"
													MinLimit="-180"
													MaxLimit="180"
												>
													<Motor Type="Position" Force="8000" Tau="0.05" />
												</Constraint>
												<Body
													ModelFrame="charmL"
													Mass="30"
													Collisions="Internal"
													Friction="4"

													NoStatCollisions="true"
												>
													<Constraint
														_template="Grappler"
														Name="LeftCharm"
														MinLimit="0"
														MaxLimit="130"
													/>
												</Body>
												<Body
													ModelFrame="charmR"
													Mass="30"
													Collisions="Internal"
													Friction="4"

													NoStatCollisions="true"
												>
													<Constraint
														_template="Grappler"
														Name="RightCharm"
														MinLimit="-130"
														MaxLimit="0"
													/>
												</Body>
											</Body>
										</Body>
									</Body>
						</Body>
					</Body>
				</Body>
			</Body>

				<Body
					ModelFrame="supL"
					Mass="40"
					NoFoliageCollisions="true"
				>
					<Constraint
						_template="Anchor"
						MinLimit="-0.8"
						MaxLimit="0"
					/>
				</Body>
				<Body
					ModelFrame="supR"
					Mass="40"
					NoFoliageCollisions="true"
				>
					<Constraint
						_template="Anchor"
						MinLimit="-0.8"
						MaxLimit="0"
					/>
				</Body>
		</Body>
	</PhysicsModel>

	<PoweredConstraints>
		<Group Id="grap">

			<Constraint Name="RightCharm" Position="-130" InitialFix="true" />

			<Constraint Name="LeftCharm" Position="130" InitialFix="true" />

		</Group>
		<Group Id="push_anchors">
			<Constraint
				Name="Anchor"
				Position="-0.6"
				TerminalFix="true"
			/>
		</Group>
	</PoweredConstraints>
	<ControlledIK>
		<Chain
			ModelFrames="body,crane,arm,arm1,arm2"
			AffectedFrames="crane,arm,arm1,arm2"
			HelperVisFrame="BoneGrappler_cdt"
			Id="crane"
			CenterXZ="(1.017; 0.982; 1.0)"
			EndOffset="(0; 0; 0)"
		/>
	</ControlledIK>
	<ControlledConstraints>
		<Constraint Id="crane_grappler"
			Name="CharmBase"
			LinkedControlledIK="crane"
		/>
	</ControlledConstraints>
</TruckAddon>