/// <summary> /// /// </summary> /// <param name="_testo"></param> /// <returns></returns> public override bool Equals(object _testo) { TransformF _test = (TransformF)_testo; return((mPositionX == _test.mPositionX) && (mPositionY == _test.mPositionY) && (mPositionZ == _test.mPositionZ)); }
/// <summary> /// /// </summary> /// <returns></returns> public TransformF copy() { TransformF t = new TransformF(mPositionX, mPositionY, mPositionZ, mOrientationX, mOrientationY, mOrientationZ, MAngle); return(t); }
public virtual SceneObject respawnTurret(SimDataBlock datablock, string classname, TransformF transform, string isstatic, string respawn) { ObjectCreator tch = new ObjectCreator(classname); tch["datablock"] = datablock; tch["static"] = isstatic; tch["respawn"] = respawn; SceneObject turret = tch.Create(); turret.setTransform(transform); ((SimGroup) "MissionGroup").add(turret); return turret; }
public override int onThrow(ShapeBase player, int amount) { if (amount == 0) amount = 1; if (this["maxInventory"] != string.Empty) { if (amount > this["maxInventory"].AsInt()) amount = this["maxInventory"].AsInt(); } if (amount == 0) return 0; player.decInventory(this, amount); TransformF rot = new TransformF(player.getEulerRotation()); ObjectCreator tc_obj = new ObjectCreator("AITurretShape", string.Empty); tc_obj["datablock"] = this.getName(); tc_obj["rotation"] = "0 0 1 " + rot.mPositionZ; tc_obj["count"] = "1"; tc_obj["sourceObject"] = player; tc_obj["client"] = player["client"]; tc_obj["isAiControlled"] = true; AITurretShape obj = tc_obj.Create(); ((SimSet) "MissionGroup").pushToBack(obj); //todo change to csharp obj.addToIgnoreList(player); GameConnection client = player["client"]; if (client.isObject()) { if (client["ownedTurrets"] == string.Empty) client["ownedTurrets"] = new ObjectCreator("SimSet", string.Empty).Create().AsString(); SimSet SimSet_id = client["ownedTurrets"]; int countofitems = SimSet_id.getCount(); for (uint i = 0; i < countofitems; i++) { AITurretShape turret = SimSet_id.getObject(i); turret.addToIgnoreList(obj); obj.addToIgnoreList(turret); } SimSet_id.pushToBack(obj); } return obj; }
public static UInt32 Spawn(string name, TransformF spawnpoint) { ObjectCreator npcScriptObject = new ObjectCreator("AIPlayer", "", typeof(CustomDemoPlayer)); npcScriptObject["dataBlock"] = "DemoPlayer"; npcScriptObject["path"] = ""; AIPlayer npc = npcScriptObject.Create(); if (npc != 0) { ((SimSet)"MissionCleanup").pushToBack(npc); npc.setShapeName(name); npc.setTransform(spawnpoint); } return npc; }
public static void RadiusDamage(GameBase sourceobject, Point3F position, float radius, float damage, string damageType, float impulse) { // Use the container system to iterate through all the objects // within our explosion radius. We'll apply damage to all ShapeBase // objects. Dictionary<uint, float> r = tst.console.initContainerRadiusSearch(position, radius, (uint) SceneObjectTypesAsUint.ShapeBaseObjectType); float halfRadius = radius/(float) 2.0; foreach (ShapeBase targetObject in r.Keys) { // Calculate how much exposure the current object has to // the explosive force. The object types listed are objects // that will block an explosion. If the object is totally blocked, // then no damage is applied. UInt32 mask = (uint) SceneObjectTypesAsUint.TerrainObjectType | (uint) SceneObjectTypesAsUint.StaticShapeObjectType | (uint) SceneObjectTypesAsUint.VehicleObjectType; float coverage = tst.Util.calcExplosionCoverage(new Point3F(position), targetObject, mask); if (!coverage.AsBool()) continue; float dist = r[targetObject]; // Calculate a distance scale for the damage and the impulse. // Full damage is applied to anything less than half the radius away, // linear scale from there. float distScale = (float) ((dist < halfRadius) ? 1.0 : 1 - ((dist - halfRadius)/halfRadius)); // Apply the damage targetObject.damage(sourceobject, position, (((damage)*coverage*distScale)), damageType); // Apply the impulse if (!impulse.AsBool()) continue; TransformF impulseVec = new TransformF(targetObject.getWorldBoxCenter()) - new TransformF(position); impulseVec = impulseVec.normalizeSafe(); impulseVec = impulseVec.vectorScale(impulse*distScale); targetObject.applyImpulse(new Point3F(position), impulseVec.GetPosition()); } }
public override void onWetFire(ShapeBase obj, int slot) { if (!this["projectile"].isObject()) { console.error("WeaponImage::onFire() - Invalid projectile datablock"); return; } // Decrement inventory ammo. The image's ammo state is updated // automatically by the ammo inventory hooks. if (!this["infiniteAmmo"].AsBool()) obj.decInventory(this["ammo"], 1); // Get the player's velocity, we'll then add it to that of the projectile int numProjectiles = this["projectileNum"].AsInt(); if (numProjectiles == 0) numProjectiles = 1; TransformF muzzleVector = new TransformF(); for (int i = 0; i < numProjectiles; i++) { if (this["wetProjectileSpread"].AsBool()) { // We'll need to "skew" this projectile a little bit. We start by // getting the straight ahead aiming point of the gun Point3F vec = obj.getMuzzleVector(slot); // Then we'll create a spread matrix by randomly generating x, y, and z // points in a circle Random r = new Random(); TransformF matrix = new TransformF(); matrix.mPositionX = (float) ((r.NextDouble() - .5)*2*Math.PI*this["wetProjectileSpread"].AsFloat()); matrix.mPositionY = (float) ((r.NextDouble() - .5)*2*Math.PI*this["wetProjectileSpread"].AsFloat()); matrix.mPositionZ = (float) ((r.NextDouble() - .5)*2*Math.PI*this["wetProjectileSpread"].AsFloat()); TransformF mat = math.MatrixCreateFromEuler(matrix); muzzleVector = math.MatrixMulVector(mat, vec); } else muzzleVector = new TransformF(obj.getMuzzleVector(slot)); Point3F objectVelocity = obj.getVelocity(); muzzleVector = muzzleVector.vectorScale(this["wetProjectile.muzzleVelocity"].AsFloat()); objectVelocity = objectVelocity.vectorScale(this["wetProjectile.velInheritFactor"].AsFloat()); Point3F muzzleVelocity = muzzleVector.GetPosition() + objectVelocity; ObjectCreator tch = new ObjectCreator(this["projectileType"]); tch["dataBlock"] = this["wetProjectile"]; tch["initialVelocity"] = muzzleVelocity; tch["initialPosition"] = obj.getMuzzlePoint(slot); tch["sourceObject"] = obj; tch["sourceSlot"] = slot; tch["client"] = obj["client"]; tch["sourceClass"] = obj.getClassName(); Item projectile = tch.Create(); ((SimSet) "MissionCleanup").pushToBack(projectile); } }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <param name="scalar"></param> /// <returns></returns> public static TransformF vectorScale(TransformF point, float scalar) { return(point * scalar); }
/// <summary> /// /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <returns></returns> public static float vectorDot(TransformF p1, Point3F p2) { return(p1.mPositionX * p2.x + p1.mPositionY * p2.y + p1.mPositionZ * p2.z); }
/// <summary> /// Return the integer character code value corresponding to the first character in the given string. /// ) /// /// </summary> public TransformF dnt_testcase_15(TransformF chr){ return new TransformF ( m_ts.fn_dnt_testcase_15(chr.AsString())); }
public void setDamageDirection(GameBase sourceObject, TransformF damagePos) { if (sourceObject.isObject()) damagePos = console.isField(sourceObject, "initialPosition") ? new TransformF(sourceObject["initialPosition"]) : sourceObject.getTransform(); TransformF dp = damagePos; Point3F wbc = getWorldBoxCenter(); TransformF damagevec = dp - new TransformF(wbc); damagevec = damagevec.normalizeSafe(); GameConnection client = this["client"]; if (!client.isObject()) return; ShapeBase cameraobject = client.getCameraObject(); TransformF inverseTransform = cameraobject.getInverseTransform(); damagevec = math.MatrixMulVector(inverseTransform, damagevec.GetPosition()); float[] components = new float[6]; string[] directions = new string[6]; directions[0] = "Left"; directions[1] = "Right"; directions[2] = "Bottom"; directions[3] = "Front"; directions[4] = "Bottom"; directions[5] = "Top"; components[0] = -damagevec.mPositionX; components[1] = damagevec.mPositionX; components[2] = -damagevec.mPositionY; components[3] = damagevec.mPositionY; components[4] = -damagevec.mPositionZ; components[5] = damagevec.mPositionZ; string damagedirection = string.Empty; float max = 0; for (int i = 0; i < 6; i++) { if (components[i] <= max) continue; damagedirection = directions[i]; max = components[i]; } if (console.isObject(client)) // Util._commandToClient(client, console.addTaggedString("setDamageDirection"), damagedirection); console.commandToClient(client, console.addTaggedString("setDamageDirection"), new[] {damagedirection}); }
public bool play3D(string profile, TransformF location){ return pInvokes.m_ts.fnGameConnection_play3D(_ID, profile, location.AsString()); }
/// <summary> /// @brief Multiply the vector by the transform assuming that w=0. This function will multiply the given vector by the given transform such that translation will not affect the vector. @param transform A transform. @param vector A vector. @return The transformed vector. @ingroup Matrices) /// </summary> public Point3F MatrixMulVector(TransformF transform, Point3F vector){ return new Point3F ( m_ts.fn_MatrixMulVector(transform.AsString(), vector.AsString())); }
public static void serverCmdflipCar(GameConnection client) { Player player = client["player"]; Vehicle car = player.getControlObject(); if (car.getClassName() != "WheeledVehicle") return; TransformF carpos = car.getTransform(); carpos += new TransformF(0, 0, 3); car.setTransform(carpos); }
public bool setNodeTransform(string name, TransformF txfm, bool isWorld = false){ return pInvokes.m_ts.fnTSShapeConstructor_setNodeTransform(_ID, name, txfm.AsString(), isWorld); }
public void pushFront(TransformF transform, float speed = 1.0f, string type = "Normal", string path = "Linear"){ pInvokes.m_ts.fnPathCamera_pushFront(_ID, transform.AsString(), speed, type, path); }
public static void AudioServerPlay3D(string profile, TransformF transform) { foreach (GameConnection clientid in tst.ClientGroup) clientid.play3D(profile, transform); }
/// <summary> /// @brief Used on the server to play a 3D sound that is not attached to any object. @param profile The SFXProfile that defines the sound to play. @param location The position and orientation of the 3D sound given in the form of \"x y z ax ay az aa\". @tsexample function ServerPlay3D(%profile,%transform) { // Play the given sound profile at the given position on every client // The sound will be transmitted as an event, not attached to any object. for(%idx = 0; %idx ClientGroup.getCount(); %idx++) ClientGroup.getObject(%idx).play3D(%profile,%transform); } @endtsexample) /// </summary> public bool play3D(string gameconnection, string profile, TransformF location){ return m_ts.fnGameConnection_play3D(gameconnection, profile, location.AsString()); }
/// <summary> /// .) /// </summary> public void addItemWithTransform(string forest, string data, TransformF trans, float scale){ m_ts.fnForest_addItemWithTransform(forest, data, trans.AsString(), scale); }
/// <summary> /// Set the camera to orbit around the given object, or if none is given, around the given point. @param orbitObject The object to orbit around. If no object is given (0 or blank string is passed in) use the orbitPoint instead @param orbitPoint The point to orbit around when no object is given. In the form of \"x y z ax ay az aa\" such as returned by SceneObject::getTransform(). @param minDistance The minimum distance allowed to the orbit object or point. @param maxDistance The maximum distance allowed from the orbit object or point. @param initDistance The initial distance from the orbit object or point. @param ownClientObj [optional] Are we orbiting an object that is owned by us? Default is false. @param offset [optional] An offset added to the camera's position. Default is no offset. @param locked [optional] Indicates the camera does not receive input from the player. Default is false. @see Camera::setOrbitObject() @see Camera::setOrbitPoint()) /// </summary> public bool setOrbitMode(string camera, string orbitObject, TransformF orbitPoint, float minDistance, float maxDistance, float initDistance, bool ownClientObj = false, Point3F offset = null , bool lockedx = false){ if (offset== null) {offset = new Point3F(0.0f, 0.0f, 0.0f);} return m_ts.fnCamera_setOrbitMode(camera, orbitObject, orbitPoint.AsString(), minDistance, maxDistance, initDistance, ownClientObj, offset.AsString(), lockedx); }
public bool mountObject(string objB, int slot, TransformF txfm = null ){ if (txfm== null) {txfm = new TransformF("0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000");} return pInvokes.m_ts.fnSceneObject_mountObject(_ID, objB, slot, txfm.AsString()); }
public bool addPrimitive(string meshName, string type, string paramsx, TransformF txfm, string nodeName){ return pInvokes.m_ts.fnTSShapeConstructor_addPrimitive(_ID, meshName, type, paramsx, txfm.AsString(), nodeName); }
public void setTransform(TransformF txfm){ pInvokes.m_ts.fnSceneObject_setTransform(_ID, txfm.AsString()); }
/// <summary> /// @brief Multiply the given point by the given transform assuming that w=1. This function will multiply the given vector such that translation with take effect. @param transform A transform. @param point A vector. @return The transformed vector. @ingroup Matrices) /// </summary> public Point3F MatrixMulPoint(TransformF transform, Point3F point){ return new Point3F ( m_ts.fn_MatrixMulPoint(transform.AsString(), point.AsString())); }
public virtual bool verifyObject(GameBase gobj, SceneObject entrance, SceneObject exit) { ShapeBase obj = gobj._ID; // Bail out early if we couldn't find an exit for this teleporter. if (!exit.isObject()) { console.error(string.Format("Cound not find an exit for {0}", console.GetVarString(entrance + ".name"))); return false; } if (!obj.isMemberOfClass("Player")) return false; // If the entrance is once sided, make sure the object // approached it from it's front. if (entrance["oneSided"].AsBool()) { TransformF forwardvector = new TransformF(entrance.getForwardVector()); Point3F velocity = obj.getVelocity(); float dotProduct = TransformF.vectorDot(forwardvector, velocity); if (dotProduct > 0) return false; // If we are coming directly from another teleporter and it happens // to be bidirectional, We need to avoid ending sending objects through // an infinite loop. if (obj["isTeleporting"].AsBool()) return false; // We only want to teleport players // So bail out early if we have found any // other object. if (entrance["timeOfLastTeleport"].AsInt() > 0 && entrance["teleporterCooldown"].AsInt() > 0) { int currentTime = console.getSimTime(); int timedifference = currentTime - entrance["timeOfLastTeleport"].AsInt(); SimDataBlock db = console.getDatablock(entrance); if (timedifference <= db["teleporterCooldown"].AsInt()) return false; } } return true; }
/// <summary> /// @brief Multiply the two matrices. @param left First transform. @param right Right transform. @return Concatenation of the two transforms. @ingroup Matrices ) /// </summary> public TransformF MatrixMultiply(TransformF left, TransformF right){ return new TransformF ( m_ts.fn_MatrixMultiply(left.AsString(), right.AsString())); }
public static void serverCmdcarUnmountObj(GameConnection client, Player obj) { obj.unmount(); obj.setControlObject(obj); TransformF ejectpos = obj.getTransform(); ejectpos += new TransformF(0, 0, 5); obj.setTransform(ejectpos); Vehicle mvehicle = obj["mVehicle"]; Point3F ejectvel = mvehicle.getVelocity(); ejectvel += new Point3F(0, 0, 10); ejectvel = ejectvel.vectorScale(((SimDataBlock) (obj.getDataBlock()))["mass"].AsFloat()); obj.applyImpulse(ejectpos.GetPosition(), ejectvel); }
/// <summary> /// /// </summary> /// <returns></returns> public TransformF copy() { TransformF t = new TransformF(mPositionX, mPositionY, mPositionZ, mOrientationX, mOrientationY, mOrientationZ, MAngle); return t; }
public bool addNode(string name, string parentName, TransformF txfm = null , bool isWorld = false){ if (txfm== null) {txfm = new TransformF(0,0,0,0,0,1,0);} return pInvokes.m_ts.fnTSShapeConstructor_addNode(_ID, name, parentName, txfm.AsString(), isWorld); }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <param name="scalar"></param> /// <returns></returns> public static TransformF vectorScale(TransformF point, float scalar) { return point*scalar; }
public bool checkDeployPos(TransformF txfm){ return pInvokes.m_ts.fnShapeBaseData_checkDeployPos(_ID, txfm.AsString()); }
/// <summary> /// /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <returns></returns> public static float vectorDot(TransformF p1, Point3F p2) { return (p1.mPositionX*p2.x + p1.mPositionY*p2.y + p1.mPositionZ*p2.z); }
public virtual TransformF PointInSpawnSphere(Player objectToSpawn, SpawnSphere spawnSphere) { bool spawnLocationFound = false; int attemptsToSpawn = 0; TransformF spherLocationP3F = new TransformF(); while (!spawnLocationFound && attemptsToSpawn < 5) { spherLocationP3F = spawnSphere.getTransform(); Random r = new Random(); float angleY = (float) tMath.mDegToRad((r.NextDouble()*100)*tMath.M_2PI_F); float angleXZ = (float) tMath.mDegToRad((r.NextDouble()*100)*tMath.M_2PI_F); int radius = spawnSphere["radius"].AsInt(); spherLocationP3F.mPositionX += (float) (Math.Cos(angleY)*Math.Sin(angleXZ)*(r.Next(radius*-1, radius))); spherLocationP3F.mPositionY += (float) (Math.Cos(angleXZ)*(r.Next(radius*-1, radius))); spawnLocationFound = true; // Now have to check that another object doesn't already exist at this spot. // Use the bounding box of the object to check if where we are about to spawn in is // clear. TransformF boundingboxsize = new TransformF(((SimDataBlock) objectToSpawn.getDataBlock())["boundingBox"]); float searchRadius = boundingboxsize.mPositionX; float boxSizeY = boundingboxsize.mPositionY; if (boxSizeY > searchRadius) searchRadius = boxSizeY; List<UInt32> objectsfound = console.ContainerRadiusSearch(spherLocationP3F.GetPosition(), searchRadius, (UInt32) SceneObjectTypesAsUint.PlayerObjectType, false); if (objectsfound.Count > 0) spawnLocationFound = false; attemptsToSpawn++; } if (!spawnLocationFound) { spherLocationP3F = spawnSphere.getTransform(); console.warn("WARNING: Could not spawn player after 5 times"); } return spherLocationP3F; }
public void setOrbitPoint(TransformF orbitPoint, float minDistance, float maxDistance, float initDistance, Point3F offset = null , bool lockedx = false){ if (offset== null) {offset = new Point3F(0.0f, 0.0f, 0.0f);} pInvokes.m_ts.fnCamera_setOrbitPoint(_ID, orbitPoint.AsString(), minDistance, maxDistance, initDistance, offset.AsString(), lockedx); }