示例#1
0
        public void GetOrderedEffectsByCapabilityTest()
        {
            CapabilityValue target = new CapabilityValue(); // TODO: Initialize to an appropriate value

            CapabilityValue.Effect ef = new CapabilityValue.Effect("Capability1", 1000.0, 10, 1);
            target.effects.Add(ef);
            ef = new CapabilityValue.Effect("Capability2", 2000.0, 20, 1);
            target.effects.Add(ef);
            ef = new CapabilityValue.Effect("Capability1", 2000.0, 20, 1);
            target.effects.Add(ef);
            ef = new CapabilityValue.Effect("Capability1", 500.0, 5, 0.5);
            target.effects.Add(ef);
            ef = new CapabilityValue.Effect("Capability2", 555.0, 6, 0.6);
            target.effects.Add(ef);
            ef = new CapabilityValue.Effect("Capability1", 5000.0, 50, 1);
            target.effects.Add(ef);

            //this shows that the function returns the correctly ordered list for Capability1
            List <CapabilityValue.Effect> actual;

            actual = target.GetOrderedEffectsByCapability("Capability1");
            Assert.AreEqual(actual.Count, 4);
            Assert.AreEqual(actual[0].range, 500.0);
            Assert.AreEqual(actual[1].range, 1000.0);
            Assert.AreEqual(actual[0].intensity, 5);
            Assert.AreEqual(actual[1].intensity, 10);

            //this shows that the function returns the correctly ordered list for Capability2
            actual = target.GetOrderedEffectsByCapability("Capability2");
            Assert.AreEqual(actual.Count, 2);
            Assert.AreEqual(actual[0].range, 555.0);
            Assert.AreEqual(actual[1].range, 2000.0);
            Assert.AreEqual(actual[0].intensity, 6);
            Assert.AreEqual(actual[1].intensity, 20);

//this shows that removal from the returned list doesn't affect the structure of the internal list.
            actual.RemoveAt(1);

            actual = target.effects;
            Assert.AreEqual(actual.Count, 6);
            Assert.AreEqual(actual[0].range, 1000.0);
            Assert.AreEqual(actual[1].range, 2000.0);
            Assert.AreEqual(actual[0].intensity, 10);
            Assert.AreEqual(actual[1].intensity, 20);
        }
示例#2
0
        public void TestAttackProcessorSimAttackObjectLogic()
        {
            //SETUP
            CapabilityValue target = new CapabilityValue();

            CapabilityValue.Effect ef = new CapabilityValue.Effect("Capability1", 1000.0, 10, 1);
            target.effects.Add(ef);
            ef = new CapabilityValue.Effect("Capability2", 2000.0, 20, 1);
            target.effects.Add(ef);
            ef = new CapabilityValue.Effect("Capability1", 2000.0, 20, 1);
            target.effects.Add(ef);
            ef = new CapabilityValue.Effect("Capability1", 500.0, 5, 0.5);
            target.effects.Add(ef);
            ef = new CapabilityValue.Effect("Capability2", 555.0, 6, 0.6);
            target.effects.Add(ef);
            ef = new CapabilityValue.Effect("Capability1", 5000.0, 50, 1);
            target.effects.Add(ef);

            double[] ranges = { 200.0, 800.0, 1500.0, 5000.0 };
            int[]    expectedIntensities = { 5, 10, 20, 50 };

            //TEST
            for (int x = 0; x < ranges.Length; x++)//double distance in ranges)
            {
                List <CapabilityValue.Effect> capabilities = target.GetOrderedEffectsByCapability("Capability1");
                bool testComplete = false;
                foreach (CapabilityValue.Effect eff in capabilities)
                {
                    if (eff.name == "Capability1" && ranges[x] <= eff.range)
                    {
                        //int r = random.Next(0, 100);
                        //if (r <= ((int)(eff.probability * 100)))
                        //{
                        //appliedIntensity = (int)(eff.intensity * newAttack.percentageApplied / 100);
                        //newAttack.appliedIntensity = appliedIntensity;
                        //targetVul.ApplyEffect(eff.name, appliedIntensity, distance, ref random);

                        //}
                        //break outside of the if because if the probability failed, you dont want a second chance with a different range.
                        Assert.AreEqual(eff.intensity, expectedIntensities[x]);
                        testComplete = true;
                        break; //break because we only want to apply the first range found that satisfied the distance restraint
                    }
                }
                Assert.IsTrue(testComplete, System.String.Format("Incorrect value when testing for range {0}", ranges[x]));
            }
            List <CapabilityValue.Effect> capability = target.GetOrderedEffectsByCapability("Capability1");
            bool testCompleted = false;

            foreach (CapabilityValue.Effect eff in capability)
            {
                if (eff.name == "Capability1" && 6000 <= eff.range)
                {
                    //int r = random.Next(0, 100);
                    //if (r <= ((int)(eff.probability * 100)))
                    //{
                    //appliedIntensity = (int)(eff.intensity * newAttack.percentageApplied / 100);
                    //newAttack.appliedIntensity = appliedIntensity;
                    //targetVul.ApplyEffect(eff.name, appliedIntensity, distance, ref random);

                    //}
                    //break outside of the if because if the probability failed, you dont want a second chance with a different range.

                    testCompleted = true;
                    break; //break because we only want to apply the first range found that satisfied the distance restraint
                }
            }
            Assert.IsFalse(testCompleted, System.String.Format("Incorrect value when testing for range {0}", 6000));
        }
        private void TimeTick(SimulationEvent e)
        {
            int       oldTime = time;
            DataValue dv      = null;


            //Vec3D curVec = new Vec3D(0, 0, 0);
            //Vec3D destVec = new Vec3D(0, 0, 0);
            //Vec3D velVec = new Vec3D(0, 0, 0);

            Vec3D loc1  = new Vec3D(0, 0, 0);
            Vec3D loc2  = new Vec3D(0, 0, 0);
            Vec3D next1 = new Vec3D(0, 0, 0);
            Vec3D next2 = new Vec3D(0, 0, 0);

            Vec3D vel1 = new Vec3D(0, 0, 0);
            Vec3D vel2 = new Vec3D(0, 0, 0);

            dv   = e["Time"];
            time = ((IntegerValue)dv).value;

            double dTime = ((double)(time - oldTime)) / 1000;
            SimulationObjectProxy obProx1 = null;
            SimulationObjectProxy obProx2 = null;


            List <string> ids = new List <string>(objectProxies.Keys);

            string id1;

            SimulationEvent collision = null;
            double          distance;
            double?         d;

            while (ids.Count > 0)
            {
                id1 = ids[0];
                ids.Remove(id1);


                foreach (string id2 in ids)
                {
                    d = ObjectDistances.GetScalarDistanceBetweenObjects(id1, id2);

                    if (d == null)
                    {
                        // Don't look for collisions if they aren't on the screen
                        continue;
                    }
                    distance = d.Value;

                    double objectSize1 = 0;
                    double objectSize2 = 0;
                    obProx1 = objectProxies[id1];
                    obProx2 = objectProxies[id2];


                    //// Don't look for collisions if they aren't on the screen

                    dv = obProx1["Location"].GetDataValue();
                    //if (!((LocationValue)dv).exists)
                    //{
                    //    continue;
                    //}
                    loc1.Set((LocationValue)dv);
                    dv = obProx2["Location"].GetDataValue();
                    //if (!((LocationValue)dv).exists)
                    //{
                    //    continue;
                    //}
                    loc2.Set((LocationValue)dv);

                    if (((BooleanValue)obProx1["DockedToParent"].GetDataValue()).value)
                    {
                        continue;
                    }
                    if (((BooleanValue)obProx2["DockedToParent"].GetDataValue()).value)
                    {
                        continue;
                    }

                    // Don't look for collisions if they are owned by the same player
                    if (StateDB.physicalObjects[id1].ownerID == StateDB.physicalObjects[id2].ownerID)
                    {
                        continue;
                    }
                    // Don't look for collisions if they are on the same team
                    if (StateDB.physicalObjects[id1].teamName == StateDB.physicalObjects[id2].teamName)
                    {
                        continue;
                    }
                    //Don't look for collisions if they are not hostile
                    if (StateDB.teams.ContainsKey(StateDB.physicalObjects[id1].teamName) &&
                        StateDB.teams.ContainsKey(StateDB.physicalObjects[id2].teamName))
                    {
                        if (!StateDB.teams[StateDB.physicalObjects[id1].teamName].hostility.Contains(StateDB.teams[StateDB.physicalObjects[id2].teamName].id) &&
                            !StateDB.teams[StateDB.physicalObjects[id2].teamName].hostility.Contains(StateDB.teams[StateDB.physicalObjects[id1].teamName].id))
                        {//only continue if both teams are not hostile to one another
                            continue;
                        }
                    }

                    CapabilityValue.Effect eff = null;

                    // check ranges and add objects to target lists for self defense sim
                    CapabilityValue    cap1 = ((CapabilityValue)obProx1["Capability"].GetDataValue());
                    VulnerabilityValue vul1 = ((VulnerabilityValue)obProx1["Vulnerability"].GetDataValue());
                    CapabilityValue    cap2 = ((CapabilityValue)obProx2["Capability"].GetDataValue());
                    VulnerabilityValue vul2 = ((VulnerabilityValue)obProx2["Vulnerability"].GetDataValue());
                    //double distance = loc1.ScalerDistanceTo(loc2);


                    eff = SimUtility.FindCapabilityEffect(cap1, vul2);
                    dv  = obProx1["TargetsInRange"].GetDataValue();
                    //AD: TODO need a "TargetsInSensorRange"? which can drive the ViewPro loops
                    if (eff != null && distance <= eff.range &&
                        ((StringValue)obProx2["State"].GetDataValue()).value != "Dead")
                    {
                        if (!((StringListValue)dv).strings.Contains(id2))
                        {
                            ((StringListValue)dv).strings.Add(id2);
                        }
                    }
                    else
                    {
                        if (((StringListValue)dv).strings.Contains(id2))
                        {
                            ((StringListValue)dv).strings.Remove(id2);
                        }
                    }
                    obProx1["TargetsInRange"].SetDataValue(dv);

                    eff = SimUtility.FindCapabilityEffect(cap2, vul1);
                    dv  = obProx2["TargetsInRange"].GetDataValue();
                    if (eff != null && distance <= eff.range &&
                        ((StringValue)obProx1["State"].GetDataValue()).value != "Dead")
                    {
                        if (!((StringListValue)dv).strings.Contains(id1))
                        {
                            ((StringListValue)dv).strings.Add(id1);
                        }
                    }
                    else
                    {
                        if (((StringListValue)dv).strings.Contains(id1))
                        {
                            ((StringListValue)dv).strings.Remove(id1);
                        }
                    }
                    obProx2["TargetsInRange"].SetDataValue(dv);


                    // Don't look for collisions if they are dead

                    if (((StringValue)obProx1["State"].GetDataValue()).value == "Dead")
                    {
                        continue;
                    }
                    if (((StringValue)obProx2["State"].GetDataValue()).value == "Dead")
                    {
                        continue;
                    }


                    // Don't look for collisions if they are too small to collide

                    dv          = obProx1["Size"].GetDataValue();
                    objectSize1 = ((DoubleValue)dv).value;
                    if (objectSize1 <= 0.000001)
                    {
                        continue;
                    }
                    dv          = obProx2["Size"].GetDataValue();
                    objectSize2 = ((DoubleValue)dv).value;
                    if (objectSize2 <= 0.000001)
                    {
                        continue;
                    }

                    dv = obProx1["Velocity"].GetDataValue();
                    vel1.Set((VelocityValue)dv);
                    dv = obProx2["Velocity"].GetDataValue();
                    vel2.Set((VelocityValue)dv);
                    if (vel1.X == 0 && vel2.X == 0 && vel1.Y == 0 && vel2.Y == 0 && vel1.Z == 0 && vel2.Z == 0)
                    {
                        continue;
                    }

                    next1 = loc1.Add(vel1.Multiply(dTime));
                    next2 = loc2.Add(vel2.Multiply(dTime));

                    if (next1.ScalerDistanceTo(next2) < (objectSize1 + objectSize2))
                    {
                        collision = SimulationEventFactory.BuildEvent(ref simModel, "ObjectCollision");
                        ((StringValue)collision["ObjectID1"]).value = id1;
                        ((StringValue)collision["ObjectID2"]).value = id2;
                        ((IntegerValue)collision["Time"]).value     = time;
                        distClient.PutEvent(collision);
                    }
                }
            }

            /*foreach (string id1 in objectProxies.Keys)
             * {
             *  foreach (string id2 in objectProxies.Keys)
             *  {
             *      if (id1 == id2)
             *      {
             *          continue;
             *      }
             *      obProx1 = objectProxies[id1];
             *      obProx2 = objectProxies[id1];
             *
             *      dv = obProx1["Location"].GetDataValue();
             *      loc1.Set((LocationValue)dv);
             *      dv = obProx2["Location"].GetDataValue();
             *      loc2.Set((LocationValue)dv);
             *
             *  }
             *
             * }*/
        }