public static void Tick(int tick) { if (tick > nextEventAt + 2000) { nextEventAt = tick + 1000 * (randInt(13, 37)); simModel = modelReader.readModel("C:\\Program Files\\Aptima\\DDD 4.0\\Client\\SimulationModel.xml"); } else if (Math.Truncate(tick / 1000.0) == Math.Truncate(nextEventAt / 1000.0)) {// do something now // first update nextEventTime nextEventAt += 1000 * randInt(3, 20); if (allUnits.Keys.Count > 0) { string[] keyArray = new string[allUnits.Keys.Count]; allUnits.Keys.CopyTo(keyArray, 0); string unitToUse = keyArray[randInt(keyArray.Length)]; SimulationEvent simEvent; switch (randInt(2)) { case 0: //move a unit Location whereToGo = allUnits[unitToUse].newLocation(); Console.WriteLine("Moving " + unitToUse + " from (" + allUnits[unitToUse].position.X + "," + allUnits[unitToUse].position.Y + ") to (" + whereToGo.X.ToString() + "," + whereToGo.Y.ToString() + ")"); // Generate a moveObject request simEvent = SimulationEventFactory.BuildEvent(ref simModel, "MoveObjectRequest"); simEvent["UserID"] = DataValueFactory.BuildString("red dm"); simEvent["ObjectID"] = DataValueFactory.BuildString(unitToUse); simEvent["DestinationLocation"] = DataValueFactory.BuildLocation((double)whereToGo.X, (double)whereToGo.Y, 0.0, true); simEvent["Throttle"] = DataValueFactory.BuildDouble(randInt(75, 101) / 100.0); simEvent["Time"] = DataValueFactory.BuildInteger(tick + 3000);// '+3000" is not magic -- just a clumsy attempt to avoid a race condition EventGetter.Network.PutEvent(simEvent); break; case 1: //attack a unit string myTarget = Target.GetRandom(); if ("" != myTarget) { Console.WriteLine("Using " + unitToUse + " to attack " + myTarget); //generate an attack request simEvent = SimulationEventFactory.BuildEvent(ref simModel, "AttackObjectRequest"); simEvent["UserID"] = DataValueFactory.BuildString("red dm"); simEvent["ObjectID"] = DataValueFactory.BuildString(unitToUse); simEvent["TargetObjectID"] = DataValueFactory.BuildString(myTarget); simEvent["CapabilityName"] = DataValueFactory.BuildString("Missile"); simEvent["Time"] = DataValueFactory.BuildInteger(tick + 3000);// '+3000" is not magic -- just a clumsy attempt to avoid a race condition EventGetter.Network.PutEvent(simEvent); } break; } } } }