[TeamTalk 144]: [681] usarsim: 1) Update from USARSim.
tk@edam.speech.cs.cmu.edu
tk at edam.speech.cs.cmu.edu
Wed Aug 1 13:43:45 EDT 2007
An HTML attachment was scrubbed...
URL: http://mailman.srv.cs.cmu.edu/pipermail/teamtalk-developers/attachments/20070801/7c314880/attachment-0001.html
-------------- next part --------------
Modified: usarsim/System/Makefile
===================================================================
--- usarsim/System/Makefile 2007-08-01 17:41:33 UTC (rev 680)
+++ usarsim/System/Makefile 2007-08-01 17:43:45 UTC (rev 681)
@@ -1,46 +1,75 @@
INSTALL_DIR=../../ut2004-linux
-PACKAGES=USARBotAPI.u USARBot.u USARMisPkg.u USARModels.u USARVictims.u \
- TreasureHunt.u
+INSTALL_SYS=$(INSTALL_DIR)/System
-INSTALL_MAPS=$(INSTALL_DIR)/Maps/DM-RoboticsLab_250.ut2
+PACKAGES=../System/USARBotAPI.u \
+ ../System/USARBot.u \
+ ../System/USARMisPkg.u \
+ ../System/USARModels.u \
+ ../System/USARVictims.u \
+ ../System/TreasureHunt.u
-INSTALL_PACKAGES=$(INSTALL_DIR)/System/USARBotAPI.u \
- $(INSTALL_DIR)/System/USARBot.u \
- $(INSTALL_DIR)/System/USARMisPkg.u \
- $(INSTALL_DIR)/System/USARModels.u \
- $(INSTALL_DIR)/System/USARVictims.u \
- $(INSTALL_DIR)/System/TreasureHunt.u
+INSTALL_PACKAGES=$(INSTALL_SYS)/../System/USARBotAPI.u \
+ $(INSTALL_SYS)/../System/USARBot.u \
+ $(INSTALL_SYS)/../System/USARMisPkg.u \
+ $(INSTALL_SYS)/../System/USARModels.u \
+ $(INSTALL_SYS)/../System/USARVictims.u \
+ $(INSTALL_SYS)/../System/TreasureHunt.u
-INSTALL_INIS=$(INSTALL_DIR)/System/USARSim.ini
+MAPS=../Maps/DM-RoboticsLab_250.ut2
-INSTALL_BATCH=$(INSTALL_DIR)/System/usar_sx.sh
+INSTALL_MAPS=$(INSTALL_SYS)/../Maps/DM-RoboticsLab_250.ut2
-all: $(PACKAGES) ucc
+INIS=../System/USARSim.ini ../System/TreasureHunt.ini
-install: $(INSTALL_MAPS) $(INSTALL_PACKAGES) $(INSTALL_INIS) $(INSTALL_BATCH)
+INSTALL_INIS=$(INSTALL_SYS)/../System/USARSim.ini \
+ $(INSTALL_SYS)/../System/TreasureHunt.ini
+BATCH=../System/usar_sx.sh
+
+INSTALL_BATCH=$(INSTALL_SYS)/../System/usar_sx.sh
+
+TEXTURES=../Textures/TreasureHuntTex.utx
+
+INSTALL_TEXTURES=$(INSTALL_SYS)/../Textures/TreasureHuntTex.utx
+
+STATICMESHES=../StaticMeshes/TreasureHuntMesh.usx
+
+INSTALL_STATICMESHES=$(INSTALL_SYS)/../StaticMeshes/TreasureHuntMesh.usx
+
+all: build install package
+
+build: $(PACKAGES) ucc
+
+install: $(INSTALL_MAPS) $(INSTALL_PACKAGES) $(INSTALL_INIS) $(INSTALL_BATCH) \
+ $(INSTALL_TEXTURES) $(INSTALL_STATICMESHES)
+
+package:
+ cd $(INSTALL_SYS); zip -u TreasureHunt.zip $(PACKAGES) $(MAPS) $(TEXTURES) $(STATICMESHES)
+
$(INSTALL_DIR)/%:../%
cp -f $< $@
ucc:
wine UCC.exe make -ini=USARSim.ini
-USARBotAPI.u:../USARBotAPI/Classes/*.uc
+../System/USARBotAPI.u:../USARBotAPI/Classes/*.uc
rm -f $@
-USARBot.u:../USARBot/Classes/*.uc
+../System/USARBot.u:../USARBot/Classes/*.uc
rm -f $@
-USARMisPkg.u:../USARMisPkg/Classes/*.uc
+../System/USARMisPkg.u:../USARMisPkg/Classes/*.uc
rm -f $@
-USARModels.u:../USARModels/Classes/*.uc
+../System/USARModels.u:../USARModels/Classes/*.uc
rm -f $@
-USARVictims.u:../USARVictims/Classes/*.uc
+../System/USARVictims.u:../USARVictims/Classes/*.uc
rm -f $@
-TreasureHunt.u:../TreasureHunt/Classes/*.uc
+../System/TreasureHunt.u:../TreasureHunt/Classes/*.uc
rm -f $@
+clean:
+ rm -f $(PACKAGES) TreasureHunt.zip
\ No newline at end of file
Modified: usarsim/USARBot/Classes/AerialVehicle.uc
===================================================================
--- usarsim/USARBot/Classes/AerialVehicle.uc 2007-08-01 17:41:33 UTC (rev 680)
+++ usarsim/USARBot/Classes/AerialVehicle.uc 2007-08-01 17:43:45 UTC (rev 681)
@@ -67,6 +67,10 @@
local string confName;
local string confSteeringType;
local string confMass;
+ local string confMaxAltitudeVelocity;
+ local string confMaxLinearVelocity;
+ local string confMaxLateralVelocity;
+ local string confMaxRotationalVelocity;
confType = "AerialVehicle";
Divide(string(self.class), ".", tmpStr, confName);
@@ -74,6 +78,13 @@
if(ClassIsChildOf(self.Class,class'RotaryWingRobot')) confSteeringType = "RotaryWing";
confMass = converter.FloatString(Weight);
+
+ confMaxAltitudeVelocity = converter.FloatString(maxAltitudeVelocity);
+ confMaxLinearVelocity = converter.FloatString(maxLinearVelocity);
+ confMaxLateralVelocity = converter.FloatString(maxLateralVelocity);
+ confMaxRotationalVelocity = converter.FloatString(maxRotationalVelocity);
- return "CONF {Type " $ confType $ "} {Name " $ confName $ "} {SteeringType " $ confSteeringType $ "} {Mass " $ confMass $ "}";
+ return "CONF {Type " $ confType $ "} {Name " $ confName $ "} {SteeringType " $ confSteeringType $ "} {Mass " $ confMass $ "} " $
+ "{MaxAltitudeVelocity " $ confMaxAltitudeVelocity $ "} {MaxLinearVelocity " $ confMaxLinearVelocity $ "} " $
+ "{MaxLateralVelocity " $ confMaxLateralVelocity $ "} {MaxRotationalVelocity " $ confMaxRotationalVelocity $ "}";
}
\ No newline at end of file
Modified: usarsim/USARBot/Classes/GroundVehicle.uc
===================================================================
--- usarsim/USARBot/Classes/GroundVehicle.uc 2007-08-01 17:41:33 UTC (rev 680)
+++ usarsim/USARBot/Classes/GroundVehicle.uc 2007-08-01 17:43:45 UTC (rev 681)
@@ -14,6 +14,17 @@
};
var array<WheelData> Wheels; //Array to store the wheel data of all the wheels
+// Flipper Properties (to set inside the defaultproperties section of the robot)
+var float frontFlipperLength;
+var float frontFlipperWidth;
+var float rearFlipperLength;
+var float rearFlipperWidth;
+var float minFlipperFrontAngle;
+var float maxFlipperFrontAngle;
+var float minFlipperRearAngle;
+var float maxFlipperRearAngle;
+
+
function ProcessCarInput()
{
Super.ProcessCarInput();
@@ -29,7 +40,7 @@
function timer()
{
- local string outstring, FrontSteerAngle, RearSteerAngle;
+ local string outstring, FrontSteerAngle, RearSteerAngle, FRFlipper, FLFlipper, RRFlipper, RLFlipper;
local float time;
local int i;
@@ -62,10 +73,31 @@
break;
}
}
+
+ // Get information about the flippers, if applicable
+ for(i=0; i<JointParts.Length; i++)
+ {
+ // Get the current front-right flipper angle
+ if(string(JointParts[i].PartName) == "FRFlipper")
+ FRFlipper = " {FRFlipper " $ Converter.Str_AngleFromUU(-KDHinge(Joints[i]).KCurrentAngle) $ "}";
+ // Get the current front-left flipper angle
+ else if(string(JointParts[i].PartName) == "FLFlipper")
+ FLFlipper = " {FLFlipper " $ Converter.Str_AngleFromUU(-KDHinge(Joints[i]).KCurrentAngle) $ "}";
+
+ // Get the current rear-right flipper angle
+ if(string(JointParts[i].PartName) == "RRFlipper")
+ RRFlipper = " {RRFlipper " $ Converter.Str_AngleFromUU(-KDHinge(Joints[i]).KCurrentAngle) $ "}";
+
+ // Get the current rear-left flipper angle
+ if(string(JointParts[i].PartName) == "RLFlipper")
+ RLFlipper = " {RLFlipper " $ Converter.Str_AngleFromUU(-KDHinge(Joints[i]).KCurrentAngle) $ "}";
+ }
+
outstring = "STA {Type GroundVehicle} {Time "$time$"}"$
" {FrontSteer "$FrontSteerAngle$"}"$
" {RearSteer "$RearSteerAngle$"}"$
+ FRFlipper $ FLFlipper $ RRFlipper $ RLFlipper $
" {LightToggle "$bHeadlightOn$"}"$
" {LightIntensity "$HeadlightItensity$"}"$
" {Battery "$(batteryLife-myLife)$"}"$
@@ -89,6 +121,8 @@
local string geoWheelRadius;
local string geoWheelSeparation;
local string geoWheelBase;
+ local string geoFrontFlippers;
+ local string geoRearFlippers;
geoType = "GroundVehicle";
Divide(string(self.class), ".", tmpStr, geoName);
@@ -117,8 +151,26 @@
geoWheelBase = converter.FloatString(currentMax1);
+ // Here, we go through the list of joint parts and find if we have flippers
+ for(i=0; i<JointParts.Length; i++)
+ {
+ if(string(JointParts[i].PartName) == "FRFlipper")
+ {
+ geoFrontFlippers = " {Flipper Front} {Offset " $ converter.LengthFromUU((JointParts[i].ParentPos-JointParts[i].SelfPos).X) $ "," $
+ converter.LengthFromUU((JointParts[i].ParentPos-JointParts[i].SelfPos).Y) $ "," $
+ converter.LengthFromUU(-(JointParts[i].ParentPos-JointParts[i].SelfPos).Z) $ "} " $
+ "{Length " $ converter.FloatString(frontFlipperLength) $ "} {Width " $ converter.FloatString(frontFlipperWidth) $ "}";
+ }
+ else if(string(JointParts[i].PartName) == "RRFlipper")
+ geoRearFlippers = " {Flipper Rear} {Offset " $ converter.LengthFromUU((JointParts[i].ParentPos-JointParts[i].SelfPos).X) $ "," $
+ converter.LengthFromUU((JointParts[i].ParentPos-JointParts[i].SelfPos).Y) $ "," $
+ converter.LengthFromUU(-(JointParts[i].ParentPos-JointParts[i].SelfPos).Z) $ "} " $
+ "{Length " $ converter.FloatString(rearFlipperLength) $ "} {Width " $ converter.FloatString(rearFlipperWidth) $ "}";
+ }
+
return "GEO {Type " $ geoType $ "} {Name " $ geoName $ "} {Dimensions " $ geoDimensions $ "} {COG " $ geoCOG $ "} " $
- "{WheelRadius " $ geoWheelRadius $ "} " $ "{WheelSeparation " $ geoWheelSeparation $ "} {WheelBase " $ geoWheelBase $ "}";
+ "{WheelRadius " $ geoWheelRadius $ "} " $ "{WheelSeparation " $ geoWheelSeparation $ "} {WheelBase " $ geoWheelBase $ "}" $
+ geoFrontFlippers $ geoRearFlippers;
}
function string getRobotConf()
@@ -136,6 +188,8 @@
local string confSteeringType;
local string confMaxFrontSteer;
local string confMaxRearSteer;
+ local string confFrontFlippers;
+ local string confRearFlippers;
confType = "GroundVehicle";
Divide(string(self.class), ".", tmpStr, confName);
@@ -168,7 +222,19 @@
confMaxFrontSteer = converter.FloatString(currentMax1);
confMaxRearSteer = converter.FloatString(currentMax2);
+ // Here, we go through the list of joint parts and find if we have flippers
+ for(i=0; i<JointParts.Length; i++)
+ {
+ if(string(JointParts[i].PartName) == "FRFlipper")
+ {
+ confFrontFlippers = " {Flipper Front} {MinAngle " $ converter.FloatString(minFlipperFrontAngle) $ "} {MaxAngle " $ converter.FloatString(maxFlipperFrontAngle) $ "}";
+ }
+ else if(string(JointParts[i].PartName) == "RRFlipper")
+ {
+ confRearFlippers = " {Flipper Rear} {MinAngle " $ converter.FloatString(minFlipperRearAngle) $ "} {MaxAngle " $ converter.FloatString(maxFlipperRearAngle) $ "}";
+ }
+ }
return "CONF {Type " $ confType $ "} {Name " $ confName $ "} {SteeringType " $ confSteeringType $ "} {Mass " $ confMass $ "} {MaxSpeed " $ confMaxSpeed $ "} " $
- "{MaxTorque " $ confMaxTorque $ "} {MaxFrontSteer " $ confMaxFrontSteer $ "} {MaxRearSteer " $ confMaxRearSteer $ "}";
+ "{MaxTorque " $ confMaxTorque $ "} {MaxFrontSteer " $ confMaxFrontSteer $ "} {MaxRearSteer " $ confMaxRearSteer $ "}" $ confFrontFlippers $ confRearFlippers;
}
\ No newline at end of file
Modified: usarsim/USARBot/Classes/KRobot.uc
===================================================================
--- usarsim/USARBot/Classes/KRobot.uc 2007-08-01 17:41:33 UTC (rev 680)
+++ usarsim/USARBot/Classes/KRobot.uc 2007-08-01 17:43:45 UTC (rev 681)
@@ -1,2911 +1,2707 @@
-class KRobot extends KVehicle config(USARBot) abstract;
-
-////////////////////////////////////////////////
-// PHYSICAL ROBOT
-////////////////////////////////////////////////
-
-// Part Definiens
-struct JointPart {
- // Part
- var() name PartName;
- var() class<KActor> PartClass;
- var() vector DrawScale3D;
-
- // Joint
- var() class<KConstraint> JointClass;
- var() bool bSteeringLocked;
- var() bool bSuspensionLocked;
- var() float BrakeTorque;
- var() name Parent;
- var() vector ParentPos;
- //var() rotator ParentRot;
- var() vector ParentAxis;
- var() vector ParentAxis2;
- var() vector SelfPos;
- var() vector SelfAxis;
- var() vector SelfAxis2;
-};
-var config array<JointPart> JointParts;
-
-// Mission Package Data Structure
-struct MisPkg
-{
- var() name PkgName;
- var() vector Location;
- var() class<MisPkgInfo> PkgClass;
-};
-var config array<MisPkg> MisPkgs;
-
-// Joint Control
-struct JointControl {
- var byte state; // Control state:
- // 0: no commands;
- // 1: new command;
- // 2: finished;
- var float steer; // Steer angle
- var byte order; // Specify the followed value.
- var float value; // Control value:
- // order = 0 , value=absolute angle;
- // order = 1 , value=absolute speed;
- // order = 2 , value=absolute torque;
- // order = 10 , value=relative angle;
- // order = 11 , value=relative speed;
- // order = 12 , value=relative torque;
-
- var byte lastCommandId; // There are new commands if lastCommandId != RS_JointsCommandId
-
- //Variables used only by order = 0 control:
- var float angle; // the desired spining angle. used for order=0 control.
- var int startAng; // the start angle. used for compare spined angle.
-};
-var array<JointControl> JointsControl;
-
-struct RobotSkin
-{
- var string Name;
- var texture Skin;
- var string Comment;
-};
-var config array<RobotSkin> RobotSkins;
-
-//=======================
-// Networking RobotState
-//=======================
-//
-// Replication variables used to update Robot State on clients
-
-var KRBVec RS_ChassisPosition;
-var Quat RS_ChassisQuaternion;
-var KRBVec RS_ChassisLinVel;
-var KRBVec RS_ChassisAngVel;
-
-// dynamic array canot be replicated. So we must use static array here.
-// Here, to make the client and server have the same state, we directly
-// replicate the RigidBodyState. In the KCar class, it replicates the
-// RigidBodyState related to the chassis. I don't know why they use relative
-// state. I had tried to use relative state. But it involves vector and
-// quaternion calculation. We need to calculate the relative pos and relative
-// quat. For relative pos, it's just subtract part's (wheel's) pos from chassis
-// pos. For relative quat, we need to use the third axis, that's
-// Joints[i].KPriAxis1 Cross Joints[i].KSecAxis1), to calculate the relative
-// quat. However, I cannot figure out the correct calculating method for general
-// case, such as connect the y axis of the part to the x axis of the chassis
-// through a joint. ANYWAY, the simplest, most stable and straightforward method
-// is replicating all the (absolute) RigidBodyState. If the server is correct,
-// then the client should also be correct. The only weakness of this method is we
-// need to replicate more data.
-
-var KRBVec RS_PartsPos[32];
-var Quat RS_PartsQuat[32];
-var vector RS_PartsLinVel[32];
-var vector RS_PartsAngVel[32];
-
-var float RS_JointsSteer[32];
-var byte RS_JointsOrder[32];
-var float RS_JointsValue[32];
-var byte RS_JointsCommandId[32];
-
-// It denotes new replicated robot state. VehicleStateReceived will
-// load on client side these new params and set bNewRobotState to true.
-// Should be a boolean but it's a byte that increments at each replication,
-// otherwise replication mechanism would not work becasue bool var would be
-// always true on server (read the code for further details).
-// (using struct wuold be a possible solution to replication, but it's not necessary)
-var byte RS_RobotUpdateId;
-
-//Used to change the robot skin
-var string RS_skinName;
-var byte RS_skinUpdateId;
-
-// -- End Replication variables
-
-// if CacheRobotUpdateId on client is different from RS_RobotUpdateId received from server
-// then ther's a new robot state to be loaded. At this point CacheRobotUpdateId is set
-// equal to RS_RobotUpdateId and bNewRobotState is set to true.
-var byte CacheRobotUpdateId;
-
-var byte CacheSkinUpdateId;
-
-// New RB params were loaded from replication and we must notify
-// Karma to update RB state on client side
-var bool bNewRobotState;
-
-var bool bNewCommand; //only used on server in ProcessCarInput()
-var float NextNetUpdateTime; // Next time we should force an update of vehicles state.
-var float MaxNetUpdateInterval;
-
-// Parts that build a robot (every part has a part a parent and a joint)
-var array<KActor> Parts;
-var array<Actor> Parents;
-var array<KConstraint> Joints;
-
-//========================
-// KCarWheelJoint settings
-//========================
-
-// Steering
-var float SteerPropGap;
-var float SteerTorque;
-var float SteerSpeed;
-
-// KCarWheelSuspension setting
-var float SuspStiffness;
-var float SuspDamping;
-var float SuspHighLimit;
-var float SuspLowLimit;
-var float SuspRef;
-
-// The Max torque for all the joints
-var config float MaxTorque;
-var config float SafeForce;
-var config float ProtectTime;
-
-// KDHinge Joint settings
-var config float HingePropGap;
-
-// KCarWheelJoint defalut working torque
-var config float MotorTorque;
-var config float MotorSpeed;
-var float uuMotorSpeed;
-var config float maxSpinSpeed;
-
-//========================
-// KTire settings
-//========================
-
-var float TireRollFriction;
-var float TireLateralFriction;
-var float TireRollSlip;
-var float TireLateralSlip;
-var float TireMinSlip;
-var float TireSlipRate;
-var float TireSoftness;
-var float TireAdhesion;
-var float TireRestitution;
-//========================
-
-// Robot parameters
-var config float Payload;
-var config float Weight;
-var KRigidBodyState ChassisState;
-var KRigidBodyState TeleportLocation; //!< Used to move the robot with MoveRobot() function.
-var config float ChassisMass;
-var config InterpCurve TorqueCurve; // Engine RPM in, Torque out.
-var float HitSoundThreshold;
-var float WheelRadius;
-var vector Dimensions;
-
-// Flip
-var config float FlipTorque;
-var config float FlipTime;
-var float FlipTimeLeft;
-
-//===============================
-// Items mounted on the robot
-//===============================
-
-// Item mount structure
-struct sItem {
- var class<Actor> ItemClass;
- var name Parent;
- var string ItemName;
- var vector Position;
- var vector Direction;
- var rotator uuDirection;
-};
-
-// Sensors
-var config array<sItem> Sensors;
-var config float msgTimer; // Timer used for sending out sensor data
-var array<Sensor> SensorList;
-var array<byte> ProcessedSensors;
-// Effecters
-var config array<sItem> Effecters;
-var array<Effecter> EffecterList;
-
-// Battery
-var config int batteryLife;
-var int startTime;
-var int myLife;
-
-// Headlight
-var config sItem HeadLight;
-var USARHeadlight myHeadLight;
-var bool bHeadlightOn;
-var byte HeadlightItensity;
-
-// Camera
-var config array<sItem> Cameras;
-var array<RobotCamera> CamList;
-var RobotCamera myCamera;
-var float PanSpeed, TiltSpeed;
-
-// DrawHud Variables (to determine how many screens, which camera, etc...)
-var int viewportMode; // 0 is single view, 1 is dualviewhorizontal, 2 is dualviewvertical, and 3 is quad view
-var int CamsToView[4]; // Store the camera indexes of the camera view to be displayed on the viewport
-var bool bDrawHud;
-
-//=========================
-// Others
-//=========================
-
-// Variables used for programming
-var string RobotName;
-var config bool bDebug;
-var int CurrentPart;
-var config bool bDisplayTeamBeacon;
-var float lastTime, previousTime;
-var vector lastLocation, previousLocation;
-var bool bRobotBuilt;
-var name fpsLogger;
-var config string ConverterClass;
-var USARConverter converter;
-var USARUtils utils;
-var config bool bMountByUU;
-var config float logging_period;
-var config bool bBarCode;
-var float old_time;
-var FileLog PosLog;
-var FileLog CollLog;
-var KSimParams oldKSP, newKSP;
-var name tmpName; // Used to convert string to name
-
-//var bool bstats; //used for bump/touch events.
-//var int bump_touch_cnt;
-
-// MultiView Addon
-var int ViewNum; //Viewport number (assigned by Register()) used by DrawHUD to render the scene
-var MultiView ViewManager; //the actual ViewManager actor (a bot)
-
-//#############################################################################
-// KROBOT CODE
-//#############################################################################
-
-replication
-{
- // We replicate the robot state.
-
- reliable if(Role == ROLE_Authority)
- RS_ChassisPosition, RS_ChassisQuaternion, RS_ChassisLinVel, RS_ChassisAngVel,
- RS_PartsPos, RS_PartsQuat, RS_PartsLinVel, RS_PartsAngVel,RS_RobotUpdateId;
-
- reliable if(Role == ROLE_Authority)
- RS_JointsSteer, RS_JointsOrder, RS_JointsValue, RS_JointsCommandId;
-
- reliable if(Role == ROLE_Authority)
- FlipTimeLeft, bHeadlightOn, RobotName;
-
- reliable if(Role == ROLE_Authority)
- RS_skinName, RS_skinUpdateId, ViewManager, ViewNum;
-}
-
-simulated event PreBeginPlay()
-{
- local class<USARConverter> cClass;
-
- Super.PreBeginPlay();
- utils = New class'USARUtils';
- bNoTeamBeacon=!bDisplayTeamBeacon;
- cClass = class<USARConverter>(DynamicLoadObject(ConverterClass, class'Class'));
- converter = new cClass;
- ConvertParam(converter);
- if (MotorTorque>MaxTorque)
- MotorTorque = MaxTorque;
-
- //Adjust Karma params
- KGetSimParams(oldKSP);
- newKSP = oldKSP;
-
- newKSP.Epsilon = 0.03;
- newKSP.GammaPerSec = 0.5;
-// newKSP.ContactSoftness = 0.001;
- newKSP.MaxPenetration = 1;
- newKSP.PenetrationScale = 5;
-
- KSetSimParams(newKSP);
-}
-
-simulated function ConvertParam(USARConverter converter)
-{
- local int i;
-
- if (converter==None) {
- uuMotorSpeed = MotorSpeed;
- } else {
- uuMotorSpeed = converter.SpinSpeedToUU(MotorSpeed);
- }
- if (!bMountByUU && converter!=None) {
- for (i=0;i<JointParts.length;i++) {
- JointParts[i].ParentPos = converter.LengthVectorToUU(JointParts[i].ParentPos);
- JointParts[i].SelfPos = converter.LengthVectorToUU(JointParts[i].SelfPos);
- }
- if (HeadLight.ItemName!="") {
- HeadLight.Position = converter.LengthVectorToUU(HeadLight.Position);
- HeadLight.uuDirection = converter.RotatorToUU(HeadLight.Direction);
- }
- for (i=0;i<Cameras.length;i++) {
- Cameras[i].Position = converter.LengthVectorToUU(Cameras[i].Position);
- Cameras[i].uuDirection = converter.RotatorToUU(Cameras[i].Direction);
- }
- for (i=0;i<Sensors.length;i++) {
- Sensors[i].Position = converter.LengthVectorToUU(Sensors[i].Position);
- Sensors[i].uuDirection = converter.RotatorToUU(Sensors[i].Direction);
- }
- for (i=0;i<Effecters.length;i++) {
- Effecters[i].Position = converter.LengthVectorToUU(Effecters[i].Position);
- Effecters[i].uuDirection = converter.RotatorToUU(Effecters[i].Direction);
- }
- } else {
- if (HeadLight.ItemName!="") {
- HeadLight.uuDirection.Roll = int(HeadLight.Direction.X);
- HeadLight.uuDirection.Pitch = int(HeadLight.Direction.Y);
- HeadLight.uuDirection.Yaw = int(HeadLight.Direction.Z);
- }
- for (i=0;i<Cameras.length;i++) {
- Cameras[i].uuDirection.Roll = int(Cameras[i].Direction.X);
- Cameras[i].uuDirection.Pitch = int(Cameras[i].Direction.Y);
- Cameras[i].uuDirection.Yaw = int(Cameras[i].Direction.Z);
- }
- for (i=0;i<Sensors.length;i++) {
- Sensors[i].uuDirection.Roll = int(Sensors[i].Direction.X);
- Sensors[i].uuDirection.Pitch = int(Sensors[i].Direction.Y);
- Sensors[i].uuDirection.Yaw = int(Sensors[i].Direction.Z);
- }
- for (i=0;i<Effecters.length;i++) {
- Effecters[i].uuDirection.Roll = int(Effecters[i].Direction.X);
- Effecters[i].uuDirection.Pitch = int(Effecters[i].Direction.Y);
- Effecters[i].uuDirection.Yaw = int(Effecters[i].Direction.Z);
- }
- }
-}
-
-// Register to the game
-function Register()
-{
- local USARDeathMatch UsarGame;
- local int Index;
-
- UsarGame = USARDeathMatch(Level.Game);
- Index = UsarGame.Vehicles.length;
- UsarGame.Vehicles.Insert(Index,1);
- UsarGame.Vehicles[Index]=self;
-
- //bstats = UsarGame.bstats;
-
- old_time = startTime;
-
- if(myCamera != none)
- {
- foreach AllActors(class'MultiView', ViewManager) break;
- }
- if(ViewManager != None)
- ViewNum = ViewManager.RegisterView();
- else
- ViewNum = -1;
-}
-
-// Unregister from the game
-function Unregister()
-{
- local USARDeathMatch UsarGame;
- local int i;
-
- UsarGame = USARDeathMatch(Level.Game);
- for (i=0;i<UsarGame.Vehicles.length;i++) {
- if (UsarGame.Vehicles[i]==self) {
- UsarGame.Vehicles.Remove(i,1);
- break;
- }
- }
- if(ViewManager != None)
- {
- ViewManager.DeleteView(ViewNum);
- }
-}
-
-// When new information is received, see if its new. If so, pass bits off the the wheels.
-// Each part will then update its rigid body position via the KUpdateState event.
-// JTODO: This is where clever unpacking would happen.
-simulated event VehicleStateReceived()
-{
- local KTire Tire;
- local KDPart Part;
- local int i;
- local bool UpdateParts;
-
- /*
- KGetRigidBodyState(ChassisState);
- log("State<<"@ChassisState.Position.X at ChassisState.Position.Y@ChassisState.Position.Z);
- log(" "@ChassisState.Quaternion.X at ChassisState.Quaternion.Y@ChassisState.Quaternion.Z at ChassisState.Quaternion.W);
- log(" "@ChassisState.LinVel.X at ChassisState.LinVel.Y@ChassisState.LinVel.Z);
- log(" "@ChassisState.AngVel.X at ChassisState.AngVel.Y@ChassisState.AngVel.Z@">>");
-
- log("Receive<<"@RS_ChassisPosition.X at RS_ChassisPosition.Y@RS_ChassisPosition.Z);
- log(" "@RS_ChassisQuaternion.X at RS_ChassisQuaternion.Y@RS_ChassisQuaternion.Z);
- log(" "@RS_ChassisLinVel.X at RS_ChassisLinVel.Y@RS_ChassisLinVel.Z);
- log(" "@RS_ChassisAngVel.X at RS_ChassisAngVel.Y@RS_ChassisAngVel.Z@">>");
- */
-
- // Don't do anything if vehicle isn't started up.
- if(!bRobotBuilt) {
- if(Parts.length == 0)
- return;
- for (i=0; i<Parts.length; i++)
- if (Parts[i] == None) return;
- bRobotBuilt = true;
- }
-
- //Serves a skin update request
- if(cacheSkinUpdateId != RS_skinUpdateId)
- {
- SetSkin(RS_skinName);
- cacheSkinUpdateId = RS_skinUpdateId;
- }
-
- ///////////////////////////
- // Update root chassis info
- ///////////////////////////
- if (CacheRobotUpdateId != RS_RobotUpdateId)
- {
- ChassisState.Position = RS_ChassisPosition;
- ChassisState.Quaternion = RS_ChassisQuaternion;
- ChassisState.LinVel = RS_ChassisLinVel;
- ChassisState.AngVel = RS_ChassisAngVel;
- UpdateParts = true;
- CacheRobotUpdateId = RS_RobotUpdateId;
- bNewRobotState = true;
- }
-
- // Figure out new state of parts
- for (i=0;i<Parts.length;i++) {
-
- ///////////////////////////
- // Update Parts
- ///////////////////////////
- if (UpdateParts)
- {
- if (Parts[i].IsA('KTire'))
- {
- Tire = KTire(Parts[i]);
- Tire.KGetRigidBodyState(Tire.ReceiveState);
-
- Tire.ReceiveState.Position = RS_PartsPos[i];
- Tire.ReceiveState.Quaternion = RS_PartsQuat[i];
- Tire.ReceiveState.LinVel = KRBVecFromVector(RS_PartsLinVel[i]);
- Tire.ReceiveState.AngVel = KRBVecFromVector(RS_PartsAngVel[i]);
- Tire.bReceiveStateNew = true;
- }
- else if (Parts[i].IsA('KDPart'))
- {
- Part = KDPart(Parts[i]);
- Part.KGetRigidBodyState(Part.ReceiveState);
-
- Part.ReceiveState.Position = RS_PartsPos[i];
- Part.ReceiveState.Quaternion = RS_PartsQuat[i];
- Part.ReceiveState.LinVel = KRBVecFromVector(RS_PartsLinVel[i]);
- Part.ReceiveState.AngVel = KRBVecFromVector(RS_PartsAngVel[i]);
- Part.bReceiveStateNew = true;
- }
- }
-
- ///////////////////////////
- // Update Commands
- ///////////////////////////
- if (JointsControl[i].lastCommandId!=RS_JointsCommandId[i]) {
- JointsControl[i].steer = RS_JointsSteer[i];
- JointsControl[i].order = RS_JointsOrder[i];
- JointsControl[i].value = RS_JointsValue[i];
- JointsControl[i].state = 1;
- JointsControl[i].lastCommandId = RS_JointsCommandId[i];
- }
- }
-}
-
-// This only update the chassis. The parts update themselves.
-simulated event bool KUpdateState(out KRigidBodyState newState)
-{
- // This should never get called on the server - but just in case!
- if(Role == ROLE_Authority)
- {
- if(!bNewRobotState)
- return false;
- else
- {
- // bNewRobotState will be true on server only if we're trying
- // to teleport the robot from one location to another.
- newState = TeleportLocation;
- bNewRobotState = false;
- return true;
- }
- }
- // Apply received data as new position of car chassis.
- newState = ChassisState;
- bNewRobotState = false;
- return true;
-}
-
-// Pack current state of whole car into the state struct, to be sent to the client.
-// Should only get called on the server.
-function PackState()
-{
- local KRigidBodyState RBState;
- local int i;
- local bool UpdateParts;
-
- if(!KIsAwake() && !bNewCommand)
- return; // Never send updates if physics is at rest
-
- if(Level.TimeSeconds > NextNetUpdateTime)
- {
- ///////////////////////////
- // Pack Chassis state
- ///////////////////////////
- KGetRigidBodyState(RBState);
- RS_ChassisPosition = RBState.Position;
- RS_ChassisQuaternion = RBState.Quaternion;
- RS_ChassisLinVel = RBState.LinVel;
- RS_ChassisAngVel = RBState.AngVel;
- UpdateParts = true;
- RS_RobotUpdateId += 1;
- NextNetUpdateTime = Level.TimeSeconds + MaxNetUpdateInterval;
- }
-
- // Get each part's state.
- for (i=0;i<Parts.length;i++) {
- ///////////////////////////
- // Pack Parts State
- ///////////////////////////
- if(UpdateParts)
- {
- Parts[i].KGetRigidBodyState(RBState);
- RS_PartsPos[i] = RBState.Position;
- RS_PartsQuat[i] = RBState.Quaternion;
- RS_PartsLinVel[i] = KRBVecToVector(RBState.LinVel);
- RS_PartsAngVel[i] = KRBVecToVector(RBState.AngVel);
- }
- ///////////////////////////
- // Pack Commands State
- ///////////////////////////
-
- if (JointsControl[i].state==1)
- {
- RS_JointsCommandId[i]+=1;
- RS_JointsSteer[i] = JointsControl[i].steer;
- RS_JointsOrder[i] = JointsControl[i].order;
- RS_JointsValue[i] = JointsControl[i].value;
- }
- }
-}
-
-function RobotCamera GetCamera(String name)
-{
- local int i;
-
- for (i=0;i<CamList.length;i++)
- if (CamList[i].ItemName==name)
- return CamList[i];
-
- return myCamera;
-}
-
-simulated function Actor FindPart(name PartName)
-{
- local int i;
-
- if (PartName == '' || PartName == 'None') return self;
-
- for (i=0;i<JointParts.length;i++) {
- if (JointParts[i].PartName == PartName) {
- return Parts[i];
- }
- }
- return None;
-}
-
-simulated function int FindLinkParent(MisPkgInfo Package, int ParentLinkNumber)
-{
- local int i;
-
- for(i=0; i<Package.Links.length; i++)
- {
- if(Package.Links[i].LinkNumber == ParentLinkNumber)
- {
- return i;
- }
- }
- return -1;
-}
-
-simulated function MisPkgLinkInfo getMisPkgLinkInfo(int PartNumber, string MisPkgName)
-{
- local int i,j;
- local MisPkgInfo aMisPkg;
-
- if(MisPkgName == "")
- {
- for(i=0; i<MisPkgs.length; i++)
- {
- aMisPkg = New MisPkgs[i].PkgClass;
-
- for(j=0; j<aMisPkg.Links.Length; j++)
- {
- if(aMisPkg.Links[j].LinkNumber == PartNumber)
- {
- return New aMisPkg.Links[j].LinkClass;
- }
- }
- }
- }
- else
- {
- for(i=0; i<MisPkgs.Length; i++)
- {
- if(string(MisPkgs[i].PkgName) == MisPkgName)
- {
- aMisPkg = New MisPkgs[i].PkgClass;
-
- for(j=0; j<aMisPkg.Links.Length; j++)
- {
- if(aMisPkg.Links[j].LinkNumber == PartNumber)
- {
- return New aMisPkg.Links[j].LinkClass;
- }
- }
-
- break;
- }
- }
- }
-
- return None;
-}
-
-simulated function int FindMisPkgLinkIndex(Name LinkName)
-{
- local int i;
-
- for(i=0; i<Joints.Length; i++)
- {
- if(JointParts[i].PartName == LinkName)
- {
- return i;
- }
- }
- return -1;
-}
-
-simulated function name getMisPkgPartName_str(string PkgName, int LinkNumber)
-{
- tmpName = '';
-
- if(LinkNumber >= 0)
- {
- SetPropertyText("tmpName", PkgName $ "_Link" $ string(LinkNumber));
- }
-
- return tmpName;
-}
-
-simulated function name getMisPkgPartName(Name PkgName, int LinkNumber)
-{
- tmpName = '';
-
- if(LinkNumber >= 0)
- {
- SetPropertyText("tmpName", string(PkgName) $ "_Link" $ string(LinkNumber));
- }
-
- return tmpName;
-}
-
-simulated function int getLinkNumber(string strLink)
-{
- return int(Right(strLink, Len(strLink) - (InStr(strLink, "Link") + 4)));
-}
-
-simulated function string getMisPkgName(string strLink)
-{
- return Left(strLink, InStr(strLink, "_Link"));
-}
-
-simulated function PostNetBeginPlay()
-{
- local int i, j;
- local Actor Parent;
- local vector RotX, RotY, RotZ, offset;
-
- local MisPkgInfo aMisPkg;
- local MisPkgLinkInfo selfLink, parentLink;
-
- Super.PostNetBeginPlay();
-
- // Turn the information about the mission packages into joint parts
- for(i=0; i<MisPkgs.length; i++)
- {
- aMisPkg = New MisPkgs[i].PkgClass;
-
- for(j=0; j<aMisPkg.Links.length; j++)
- {
- selfLink = New aMisPkg.Links[j].LinkClass;
- JointParts.Insert(JointParts.length, 1); // Make space in the dynamic array to add a part from the mission package
- JointParts[JointParts.length - 1].PartName = getMisPkgPartName(MisPkgs[i].PkgName, aMisPkg.Links[j].LinkNumber);
- JointParts[JointParts.length - 1].PartClass = selfLink.ModelClass;
- JointParts[JointParts.length - 1].DrawScale3D = aMisPkg.Links[j].DrawScale3D;
- JointParts[JointParts.length - 1].bSteeringLocked = true;
- JointParts[JointParts.length - 1].bSuspensionLocked = true;
- JointParts[JointParts.length - 1].BrakeTorque = 0;
- JointParts[JointParts.length - 1].Parent = getMisPkgPartName(MisPkgs[i].PkgName, aMisPkg.Links[j].ParentLinkNumber);
-
- if(Caps(selfLink.getMountPointJointType(aMisPkg.Links[j].SelfMount)) == "REVOLUTE")
- {
- JointParts[JointParts.length - 1].JointClass = class'USARBot.KDHinge';
-
- if(j == 0)
- {
- JointParts[JointParts.length - 1].ParentPos = converter.LengthVectorToUU(MisPkgs[i].Location);
- }
- else
- {
- parentLink = New aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].LinkClass;
- JointParts[JointParts.length - 1].ParentPos = converter.LengthVectorToUU(parentLink.getMountPointLocation(aMisPkg.Links[j].ParentMount) * aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].DrawScale3D);
- }
-
- JointParts[JointParts.length - 1].ParentAxis = (Vect(0,0,-1) >> converter.RotatorToUU(selfLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))) * Vect(-1,-1,-1);
- JointParts[JointParts.length - 1].SelfAxis = JointParts[JointParts.length - 1].ParentAxis;
- JointParts[JointParts.length - 1].ParentAxis2 = (Vect(0,1,0) >> converter.RotatorToUU(selfLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))) * Vect(-1,-1,-1);
- JointParts[JointParts.length - 1].SelfAxis2 = JointParts[JointParts.length - 1].ParentAxis2;
-
- JointParts[JointParts.length - 1].SelfPos = converter.LengthVectorToUU(selfLink.getMountPointLocation(aMisPkg.Links[j].SelfMount) * aMisPkg.Links[j].DrawScale3D);
- }
- else if(Caps(selfLink.getMountPointJointType(aMisPkg.Links[j].SelfMount)) == "PRISMATIC")
- {
- JointParts[JointParts.length - 1].JointClass = class'USARBot.KSlider';
-
- if(j == 0)
- {
- JointParts[JointParts.length - 1].ParentPos = converter.LengthVectorToUU(MisPkgs[i].Location - (selfLink.getMountPointLocation(aMisPkg.Links[j].SelfMount) * aMisPkg.Links[j].DrawScale3D));
- }
- else
- {
- parentLink = New aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].LinkClass;
- JointParts[JointParts.length - 1].ParentPos = converter.LengthVectorToUU((parentLink.getMountPointLocation(aMisPkg.Links[j].ParentMount) * aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].DrawScale3D) - (selfLink.getMountPointLocation(aMisPkg.Links[j].SelfMount) * aMisPkg.Links[j].DrawScale3D));
- }
-
- JointParts[JointParts.length - 1].ParentAxis = (Vect(0,1,0) >> converter.RotatorToUU(selfLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))) * Vect(-1,-1,-1);
- JointParts[JointParts.length - 1].SelfAxis = JointParts[JointParts.length - 1].ParentAxis;
- JointParts[JointParts.length - 1].ParentAxis2 = (Vect(1,0,0) >> converter.RotatorToUU(selfLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))) * Vect(-1,-1,-1);
- JointParts[JointParts.length - 1].SelfAxis2 = JointParts[JointParts.length - 1].ParentAxis2;
-
- JointParts[JointParts.length - 1].SelfPos = converter.LengthVectorToUU(-selfLink.MaxRange * (Vect(0,0,-1) >> converter.RotatorToUU(selfLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))));
- }
- /*else if(Caps(selfLink.getMountPointJointType(aMisPkg.Links[j].SelfMount)) == "WHEELJOINT")
- {
- JointParts[JointParts.length - 1].JointClass = class'Engine.KCarWheelJoint';
- JointParts[JointParts.length - 1].BrakeTorque = 10;
-
- if(j == 0)
- {
- JointParts[JointParts.length - 1].ParentPos = converter.LengthVectorToUU(MisPkgs[i].Location);
- }
- else
- {
- parentLink = New aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].LinkClass;
- JointParts[JointParts.length - 1].ParentPos = converter.LengthVectorToUU(parentLink.getMountPointLocation(aMisPkg.Links[j].ParentMount) * aMisPkg.Links[FindLinkParent(aMisPkg, aMisPkg.Links[j].ParentLinkNumber)].DrawScale3D);
- }
-
- JointParts[JointParts.length - 1].ParentAxis = (Vect(0,0,-1) >> converter.RotatorToUU(selfLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))) * Vect(-1,-1,-1);
- JointParts[JointParts.length - 1].SelfAxis = JointParts[JointParts.length - 1].ParentAxis;
- JointParts[JointParts.length - 1].ParentAxis2 = (Vect(0,1,0) >> converter.RotatorToUU(selfLink.getMountPointOrientation(aMisPkg.Links[j].SelfMount))) * Vect(-1,-1,-1);
- JointParts[JointParts.length - 1].SelfAxis2 = JointParts[JointParts.length - 1].ParentAxis2;
-
- JointParts[JointParts.length - 1].SelfPos = converter.LengthVectorToUU(selfLink.getMountPointLocation(aMisPkg.Links[j].SelfMount) * aMisPkg.Links[j].DrawScale3D);
- }*/
- }
- }
-
- ////////////////////////////////
- // Create physical robot
- ////////////////////////////////
- for (CurrentPart=0;CurrentPart<JointParts.length;CurrentPart++) {
- // Find parent
- Parent = FindPart(JointParts[CurrentPart].Parent);
- if (Parent==None) continue;
- Parents[CurrentPart] = Parent;
- if (bDebug) log("<"@Parent at Parent.Location@Parent.Rotation@">");
- GetAxes(Parent.Rotation,RotX,RotY,RotZ);
-
- //Spawn Joint (any KConstraint class)
- Joints[CurrentPart] = spawn(JointParts[CurrentPart].JointClass,Parent);
-
- if (Joints[CurrentPart].IsA('KSlider')) {
- KSlider(Joints[CurrentPart]).init1(Parent,JointParts[CurrentPart].ParentPos,JointParts[CurrentPart].ParentAxis,JointParts[CurrentPart].ParentAxis2,
- JointParts[CurrentPart].SelfPos,JointParts[CurrentPart].SelfAxis,JointParts[CurrentPart].SelfAxis2);
- offset = JointParts[CurrentPart].ParentPos - JointParts[CurrentPart].SelfPos;
- Parts[CurrentPart] = spawn(JointParts[CurrentPart].PartClass, KSlider(Joints[CurrentPart]).Part2,, Parent.Location + offset.X*RotX + offset.Y*RotY + offset.Z*RotZ,Parent.Rotation);
- Parts[CurrentPart].SetDrawScale3D(JointParts[CurrentPart].DrawScale3D);
- log("Init"@Joints[CurrentPart]);
- KSlider(Joints[CurrentPart]).init2(JointParts[CurrentPart].ParentPos,JointParts[CurrentPart].ParentAxis,JointParts[CurrentPart].ParentAxis2,
- Parts[CurrentPart],JointParts[CurrentPart].SelfPos,JointParts[CurrentPart].SelfAxis,JointParts[CurrentPart].SelfAxis2);
- } else {
- //Spawn Part
- offset = JointParts[CurrentPart].ParentPos - JointParts[CurrentPart].SelfPos;
- Parts[CurrentPart] = spawn(JointParts[CurrentPart].PartClass, Parent,, Parent.Location + offset.X*RotX + offset.Y*RotY + offset.Z*RotZ,Parent.Rotation);
- Parts[CurrentPart].SetDrawScale3D(JointParts[CurrentPart].DrawScale3D);
-
- //Set primary constraint params
- Joints[CurrentPart].KConstraintActor1 = Parent;
- Joints[CurrentPart].KPos1 = JointParts[CurrentPart].ParentPos/50;
- Joints[CurrentPart].KPriAxis1 = JointParts[CurrentPart].ParentAxis;
- if (VSize(JointParts[CurrentPart].ParentAxis2)>0)
- Joints[CurrentPart].KSecAxis1 = JointParts[CurrentPart].ParentAxis2;
-
- //Set secondary constraint params
- Joints[CurrentPart].KConstraintActor2 = Parts[CurrentPart];
- Joints[CurrentPart].KPos2 = JointParts[CurrentPart].SelfPos/50;
- Joints[CurrentPart].KPriAxis2 = JointParts[CurrentPart].SelfAxis;
- if (VSize(JointParts[CurrentPart].SelfAxis2)>0)
- Joints[CurrentPart].KSecAxis2 = JointParts[CurrentPart].SelfAxis2;
-
- Joints[CurrentPart].SetPhysics(PHYS_Karma);
- }
-
- if (ClassIsChildOf(JointParts[CurrentPart].PartClass,class'KTire') &&
- Joints[CurrentPart].IsA('KCarWheelJoint')) {
- (KTire(Parts[CurrentPart])).WheelJoint = KCarWheelJoint(Joints[CurrentPart]);
- (KTire(Parts[CurrentPart])).WheelJoint.KUpdateConstraintParams();
- if (Joints[CurrentPart].IsA('KSCarWheelJoint')) {
- KSCarWheelJoint(Joints[CurrentPart]).KForceThreshold = SafeForce;
- KSCarWheelJoint(Joints[CurrentPart]).StallTime = ProtectTime;
- }
- } else if (ClassIsChildOf(JointParts[CurrentPart].PartClass,class'USARBot.KDPart'))
- (KDPart(Parts[CurrentPart])).setJoint(Joints[CurrentPart]);
-
- if(Role != ROLE_Authority)
- KarmaParams(Parts[CurrentPart].KParams).bDestroyOnSimError = False;
- }
- if (bDebug) {
- //DumpPackages();
- DumpJoints();
- }
-
- // Initially make sure parameters are sync'ed with Karma
- KVehicleUpdateParams();
-
- // For KImpact event
- KSetImpactThreshold(HitSoundThreshold);
-
- // If this is not 'authority' version - don't destroy it if there is a problem.
- // The network should sort things out.
- if(Role != ROLE_Authority)
- KarmaParams(KParams).bDestroyOnSimError = False;
-
- // init the array size
- JointsControl.length = JointParts.length;
-
- /////////////////////////////////
- // Mount Items
- /////////////////////////////////
-
- // Mount headlight
- if (HeadLight.ItemName!="") {
- Parent = FindPart(HeadLight.Parent);
- if (Parent!=None) {
- GetAxes(Parent.Rotation,RotX,RotY,RotZ);
- myHeadLight = USARHeadlight(spawn(HeadLight.ItemClass,
- Parent,,
- Parent.Location + HeadLight.Position.X * RotX + HeadLight.Position.Y * RotY + HeadLight.Position.Z * RotZ,
- ));
- myHeadlight.SetBase(Parent);
- myHeadlight.SetRelativeRotation(HeadLight.uuDirection);
- }
- }
-
- // Mount cameras
- for (i=0;i<Cameras.length;i++)
- {
- if(i < 4)
- CamsToView[i] = i;
-
- Parent = FindPart(Cameras[i].Parent);
- if (Parent==None) continue;
- GetAxes(Parent.Rotation,RotX,RotY,RotZ);
- CamList[i] = RobotCamera(spawn(Cameras[i].ItemClass, Parent,,
- Parent.Location + Cameras[i].Position.X * RotX + Cameras[i].Position.Y * RotY + Cameras[i].Position.Z * RotZ,
- ));
- CamList[i].init(Cameras[i].ItemName,Parent,Cameras[i].Position,Cameras[i].uuDirection,self,Cameras[i].Parent);
- }
- if (CamList.length>0)
- {
- if(CamList.Length == 1)
- viewportMode = 0;
- else
- viewportMode = 1;
-
- myCamera = CamList[0];
- }
-
- // Mount sensors
- for (i=0;i<Sensors.length;i++) {
- Parent = FindPart(Sensors[i].Parent);
- if (Parent==None) continue;
- GetAxes(Parent.Rotation,RotX,RotY,RotZ);
- SensorList[i] = Sensor(spawn(Sensors[i].ItemClass,
- Parent,,
- Parent.Location + Sensors[i].Position.X * RotX + Sensors[i].Position.Y * RotY + Sensors[i].Position.Z * RotZ,
- ));
- SensorList[i].init(Sensors[i].ItemName,Parent,Sensors[i].Position,Sensors[i].uuDirection,self,Sensors[i].Parent);
- ProcessedSensors[i]=0;
- }
-
- // Mount Effecters
- for (i=0;i<Effecters.length;i++) {
- Parent = FindPart(Effecters[i].Parent);
- if (Parent==None) continue;
- GetAxes(Parent.Rotation,RotX,RotY,RotZ);
- EffecterList[i] = Effecter(spawn(Effecters[i].ItemClass,
- Parent,,
- Parent.Location + Effecters[i].Position.X * RotX + Effecters[i].Position.Y * RotY + Effecters[i].Position.Z * RotZ,
- ));
- EffecterList[i].init(Effecters[i].ItemName,Parent,Effecters[i].Position,Effecters[i].uuDirection,self,Effecters[i].Parent);
- }
-
- Register();
- SetTimer(msgTimer,true);
- startTime = Level.TimeSeconds;
- lastTime = Level.TimeSeconds;
- lastLocation = Location;
-
- //If there's an FPSLogger triggers it
- fpsLogger = 'FPSLog';
- TriggerEvent(fpsLogger, self, None);
-
-}
-
-simulated function SetSkin(string skinName)
-{
- local int i;
- local texture skinTexture;
-
- for(i = 0; i < RobotSkins.Length; i++)
- if(skinName ~= RobotSkins[i].Name)
- {
- skinTexture = RobotSkins[i].Skin;
- break;
- }
- if((i > 0) && (i == RobotSkins.Length))
- skinTexture = RobotSkins[0].Skin; //i>0 assure [0] element existence
-
- if(skinTexture != none)
- {
- Skins[0] = skinTexture;
- for (i = 0; i < Parts.Length; i++)
- {
- Parts[i].Skins[0] = skinTexture;
- }
- }
-
- if(Role == ROLE_Authority)
- {
- RS_skinName = skinName;
- RS_skinUpdateId++;
- }
-}
-
-// dump joints
-function DumpJoints() {
- local int i;
-
- for (i=0;i<Joints.length;i++)
- log(i@"Name"@JointParts[i].PartName@"Part"@Parts[i]@"Joint"@Joints[i]);
-}
-
-simulated event Destroyed()
-{
- local int i;
-
- // Destory mounted items
- for (i=0;i<SensorList.length;i++) SensorList[i].Destroy();
- for (i=0;i<EffecterList.length;i++) EffecterList[i].Destroy();
- for (i=0;i<CamList.length;i++) CamList[i].Destroy();
-
- if (myHeadlight!=None) myHeadlight.Destroy();
-
- // Destory physical robot
- for (i=0;i<Parts.length;i++) {
- if (Parts[i]!=none) {
- Joints[i].Destroy();
- Parts[i].Destroy();
- }
- }
-
- Unregister();
- converter = None;
- UntriggerEvent(fpsLogger, self, None);
- KSetSimParams(oldKSP);
- if (CollLog!=None)
- CollLog.CloseLog();
- if (PosLog!=None)
- PosLog.CloseLog();
- Super.Destroyed();
-}
-
-// For drawing noise signal
-simulated function DrawHud(Canvas C)
-{
- local int halfX, halfY, i, nLen, r, pos;
-
- // If we are using the camera view (bDrawHud is set in ViewTestPlayerController.uc)
- if(bDrawHud)
- {
- // If the robot does not have any more battery
- if (myLife==batteryLife)
- {
- C.Reset();
- C.Style = ERenderStyle.STY_Particle;
- C.SetPos(0,0);
- C.DrawTile(Material'XGameShaders.ScreenNoisePan', C.SizeX, C.SizeY, 0.0, 0.0, 128, 128);
- C.FontScaleX=4;
- C.FontScaleY=4;
- C.DrawColor.R = 255;
- C.DrawColor.G = 0;
- C.DrawColor.B = 0;
- C.DrawColor.A = 255;
- C.SetPos(C.SizeX/2-80, C.SizeY/2);
- C.DrawText("NO POWER!");
- }
- // Here, we draw the viewports
- else
- {
- C.Reset();
- C.Clear(); // Clears frame & Z buffers
-
- halfX = C.SizeX/2;
- halfY = C.SizeY/2;
-
- // If we need to display the cameras using single view
- if(viewportMode == 0)
- {
- if(CamsToView[0] == -1)
- {
- C.Style = ERenderStyle.STY_Particle;
- C.SetPos(0,0);
- C.DrawTile(Material'XGameShaders.ScreenNoisePan', C.SizeX, C.SizeY, 0.0, 0.0, 128, 128);
- }
- else if(CamsToView[0] == -2)
- {
- C.Style = ERenderStyle.STY_Particle;
- C.SetPos(0,0);
- C.DrawTile(Material'XGameTextures.DOMPLinesBp', C.SizeX, C.SizeY, 0.0, 0.0, 128, 128);
- }
- else
- {
- C.DrawPortal(0, 0, C.SizeX, C.SizeY, CamList[CamsToView[0]], CamList[CamsToView[0]].Location, CamList[CamsToView[0]].Rotation, CamList[CamsToView[0]].CameraFov);
- }
- }
- // If we need to display the cameras using quad view
- else if(viewportMode == 1)
- {
- // Here, we draw all the cameras view, depending on whether they are disabled or enabled.
- // Please note that any DrawPortal call (to draw a camera view) needs to be done BEFORE any DrawTile call (to draw noise for a disabled camera).
- for(i=0; i<4; i++)
- {
- // If the ith viewport is enabled
- if(CamsToView[i] != -1 && CamsToView[i] != -2)
- {
- switch(i)
- {
- // If the ith viewport is viewport 1 (top-left)
- case 0:
- C.DrawPortal(0, 0, halfX-2, halfY-2, CamList[CamsToView[i]], CamList[CamsToView[i]].Location, CamList[CamsToView[i]].Rotation, CamList[CamsToView[i]].CameraFov);
- break;
-
- // If the ith viewport is viewport 2 (top-right)
- case 1:
- C.DrawPortal(halfX+2, 0, halfX-2, halfY-2, CamList[CamsToView[i]], CamList[CamsToView[i]].Location, CamList[CamsToView[i]].Rotation, CamList[CamsToView[i]].CameraFov);
- break;
-
- // If the ith viewport is viewport 3 (bottom-left)
- case 2:
- C.DrawPortal(0, halfY+2, halfX-2, halfY-2, CamList[CamsToView[i]], CamList[CamsToView[i]].Location, CamList[CamsToView[i]].Rotation, CamList[CamsToView[i]].CameraFov);
- break;
-
- // If the ith viewport is viewport 4 (bottom-right)
- case 3:
- C.DrawPortal(halfX+2, halfY+2, halfX-2, halfY-2, CamList[CamsToView[i]], CamList[CamsToView[i]].Location, CamList[CamsToView[i]].Rotation, CamList[CamsToView[i]].CameraFov);
- break;
- }
- }
- }
-
- // Now that all the DrawPortal calls (to draw the camera views) have been made, we can make the DrawTile calls (to draw noise for the disable cameras).
- for(i=0; i<4; i++)
- {
- // If the ith viewport is assigned to a non-existant camera
- if(CamsToView[i] == -1)
- {
- switch(i)
- {
- // If the ith viewport is viewport 1 (top-left)
- case 0:
- C.Style = ERenderStyle.STY_Particle;
- C.SetPos(0,0);
- C.DrawTile(Material'XGameShaders.ScreenNoisePan', halfX-2, halfY-2, 0.0, 0.0, 128, 128);
- break;
-
- // If the ith viewport is viewport 2 (top-right)
- case 1:
- C.Style = ERenderStyle.STY_Particle;
- C.SetPos(halfX+2,0);
- C.DrawTile(Material'XGameShaders.ScreenNoisePan', halfX-2, halfY-2, 0.0, 0.0, 128, 128);
- break;
-
- // If the ith viewport is viewport 3 (bottom-left)
- case 2:
- C.Style = ERenderStyle.STY_Particle;
- C.SetPos(0,halfY+2);
- C.DrawTile(Material'XGameShaders.ScreenNoisePan', halfX-2, halfY-2, 0.0, 0.0, 128, 128);
- break;
-
- // If the ith viewport is viewport 4 (bottom-right)
- case 3:
- C.Style = ERenderStyle.STY_Particle;
- C.SetPos(halfX+2,halfY+2);
- C.DrawTile(Material'XGameShaders.ScreenNoisePan', halfX-2, halfY-2, 0.0, 0.0, 128, 128);
- break;
- }
- }
- // If the ith viewport is disabled
- if(CamsToView[i] == -2)
- {
- switch(i)
- {
- // If the ith viewport is viewport 1 (top-left)
- case 0:
- C.Style = ERenderStyle.STY_Particle;
- C.SetPos(0,0);
- C.DrawTile(Material'XGameTextures.DOMPLinesBp', halfX-2, halfY-2, 0.0, 0.0, 128, 128);
- break;
-
- // If the ith viewport is viewport 2 (top-right)
- case 1:
- C.Style = ERenderStyle.STY_Particle;
- C.SetPos(halfX+2,0);
- C.DrawTile(Material'XGameTextures.DOMPLinesBp', halfX-2, halfY-2, 0.0, 0.0, 128, 128);
- break;
-
- // If the ith viewport is viewport 3 (bottom-left)
- case 2:
- C.Style = ERenderStyle.STY_Particle;
- C.SetPos(0,halfY+2);
- C.DrawTile(Material'XGameTextures.DOMPLinesBp', halfX-2, halfY-2, 0.0, 0.0, 128, 128);
- break;
-
- // If the ith viewport is viewport 4 (bottom-right)
- case 3:
- C.Style = ERenderStyle.STY_Particle;
- C.SetPos(halfX+2,halfY+2);
- C.DrawTile(Material'XGameTextures.DOMPLinesBp', halfX-2, halfY-2, 0.0, 0.0, 128, 128);
- break;
- }
- }
- }
- }
-
- super.DrawHud(C);
- }
- }
-
- if (!bBarCode) return;
-
- nLen = Min(Len(RobotName),16);
-
- // draw head
- C.SetPos(0,C.SizeY-2);
- C.DrawColor.R = 255;
- C.DrawColor.G = 255;
- C.DrawColor.B = 255;
- C.DrawColor.A = 255;
- C.DrawLine(3,1);
-
- C.SetPos(1,C.SizeY-2);
- C.DrawColor.R = 0;
- C.DrawColor.G = 0;
- C.DrawColor.B = 0;
- C.DrawLine(3,1);
-
- C.SetPos(2,C.SizeY-2);
- C.DrawColor.R = 255;
- C.DrawColor.G = 255;
- C.DrawColor.B = 255;
- C.DrawLine(3,1);
-
- // draw bar code
- pos = 3;
- for (i=0;i<nLen/3;i++)
- {
- C.SetPos(pos,C.SizeY-1);
- C.DrawColor.B = Asc(Mid(RobotName,i*3,1));
- C.DrawColor.G = Asc(Mid(RobotName,i*3+1,1));
- C.DrawColor.R = Asc(Mid(RobotName,i*3+2,1));
- C.DrawLine(3,1);
- pos += 1;
- }
- r = nLen-3*(nLen/3);
- if (r==1)
- {
- C.SetPos(pos,C.SizeY-2);
- C.DrawColor.B = Asc(Mid(RobotName,i*3,1));
- C.DrawColor.G = 255;
- C.DrawColor.R = 255;
- C.DrawLine(3,1);
- pos += 1;
- }
- else if (r==2)
- {
- C.SetPos(pos,C.SizeY-2);
- C.DrawColor.B = Asc(Mid(RobotName,i*3,1));
- C.DrawColor.G = Asc(Mid(RobotName,i*3+1,1));
- C.DrawColor.R = 255;
- C.DrawLine(3,1);
- pos += 1;
- }
-
- // draw tail
- C.SetPos(pos,C.SizeY-2);
- C.DrawColor.R = 255;
- C.DrawColor.G = 255;
- C.DrawColor.B = 255;
- C.DrawLine(3,1);
-}
-
-// Call this if you change any parameters (tire, suspension etc.) and they
-// will be passed down to each wheel/joint.
-simulated event KVehicleUpdateParams()
-{
- local KTire Part;
- local KCarWheelJoint WheelJ;
- local KDHinge HingeJ;
- local int i;
- local MisPkgLinkInfo aMisPkgLink;
-
- Super.KVehicleUpdateParams();
-
- for (i=0;i<Parts.length;i++)
- {
- if (Joints[i].IsA('KCarWheelJoint'))
- {
- WheelJ=KCarWheelJoint(Joints[i]);
- WheelJ.bKSteeringLocked = JointParts[i].bSteeringLocked;
-
- WheelJ.KProportionalGap = SteerPropGap;
- WheelJ.KMaxSteerTorque = SteerTorque;
- WheelJ.KMaxSteerSpeed = SteerSpeed;
- WheelJ.KBraking = JointParts[i].BrakeTorque;
-
- if (JointParts[i].bSuspensionLocked) {
- WheelJ.KSuspHighLimit = 0.001;
- WheelJ.KSuspLowLimit = -0.001;
- WheelJ.KSuspStiffness = 200.0;
- WheelJ.KSuspDamping = 100.0;
- }
- else {
- WheelJ.KSuspHighLimit = SuspHighLimit;
- WheelJ.KSuspLowLimit = SuspLowLimit;
- WheelJ.KSuspStiffness = SuspStiffness;
- WheelJ.KSuspDamping = SuspDamping;
- }
- // Sync params with Karma.
- WheelJ.KUpdateConstraintParams();
- }
- else if(Joints[i].IsA('KDHinge'))
- {
- HingeJ = KDHinge(Joints[i]);
-
- aMisPkgLink = getMisPkgLinkInfo(getLinkNumber(string(JointParts[i].PartName)), getMisPkgName(string(JointParts[i].PartName)));
- if(aMisPkgLink != None)
- {
- HingeJ.KMaxTorque = aMisPkgLink.MaxTorque;
- HingeJ.KDesiredAngVel = converter.SpinSpeedToUU(aMisPkgLink.MaxSpeed);
- }
- else
- {
- HingeJ.KMaxTorque = MotorTorque;
- HingeJ.KDesiredAngVel = uuMotorSpeed;
- }
-
- HingeJ.KProportionalGap = HingePropGap;
- HingeJ.KHingeType = HT_CONTROLLED;
- // Sync params with Karma.
- if (Joints[i].IsA('KSlider'))
- KSlider(Joints[i]).UpdateConstraint();
- else
- HingeJ.KUpdateConstraintParams();
- }
-
- if (Parts[i].IsA('KTire'))
- {
- Part=KTire(Parts[i]);
- Part.RollFriction = TireRollFriction;
- Part.LateralFriction = TireLateralFriction;
- Part.RollSlip = TireRollSlip;
- Part.LateralSlip = TireLateralSlip;
- Part.MinSlip = TireMinSlip;
- Part.SlipRate = TireSlipRate;
- Part.Softness = TireSoftness;
- Part.Adhesion = TireAdhesion;
- Part.Restitution = TireRestitution;
- }
- }
-
- KSetMass(ChassisMass);
-}
-
-// Possibly apply force to flip robot over.
-simulated event KApplyForce(out vector Force, out vector Torque)
-{
- local float torqueScale;
@@ Diff output truncated at 60000 characters. @@
More information about the TeamTalk-developers
mailing list