private void StateChange(SimulationEvent e) { // If the parent dies, kill the docked children //objectProxies = bbClient.GetObjectProxies(); // update my objects record string objectID = ((StringValue)e["ObjectID"]).value; string state = ((StringValue)e["NewState"]).value; List <string> ids; if (state == "Dead" && objectProxies.ContainsKey(objectID)) { ids = ((StringListValue)objectProxies[objectID]["DockedObjects"].GetDataValue()).strings; foreach (string id in ids) { distClient.PutEvent(SimUtility.BuildStateChangeEvent(ref simModel, time, id, "Dead")); } ids = ((StringListValue)objectProxies[objectID]["DockedWeapons"].GetDataValue()).strings; foreach (string id in ids) { distClient.PutEvent(SimUtility.BuildStateChangeEvent(ref simModel, time, id, "Dead")); } } }
private void NewObject(SimulationEvent e) { string objectType = ((StringValue)e["ObjectType"]).value; Console.WriteLine(String.Format("Blackboard gets new object; ID: {0}; Type: {1}", ((StringValue)e["ID"]).value, objectType)); SimulationObject ob = SimulationObjectFactory.BuildObject(ref simModel, objectType); ob.attributes["ID"] = e["ID"]; // REFACTOR: I shouldn't actually do this. I should only initialize the values that I own. //AD: I'm populating the values passed in the NewObject event into the SimulationObject foreach (string attname in ((AttributeCollectionValue)e["Attributes"]).attributes.Keys) { ob.attributes[attname] = ((AttributeCollectionValue)e["Attributes"])[attname]; } blackboard.AddObject(ob); // Initialize StateDB objects if (((StringValue)e["ObjectType"]).value == "Team") { StateDB.Team t = new StateDB.Team(((StringValue)e["ID"]).value, ((StringListValue)((AttributeCollectionValue)e["Attributes"]).attributes["TeamHostility"]).strings); StateDB.teams[t.id] = t; } else if (((StringValue)e["ObjectType"]).value == "DecisionMaker") { string teamID = ((StringValue)((AttributeCollectionValue)e["Attributes"]).attributes["TeamMember"]).value; StateDB.DecisionMaker d = new StateDB.DecisionMaker(((StringValue)e["ID"]).value, StateDB.teams.ContainsKey(teamID) ? StateDB.teams[teamID] : null); StateDB.decisionMakers[d.id] = d; } else if (SimUtility.isPhysicalObject(objectType)) { String linkedRegion = ""; if (e.parameters.ContainsKey("LinkedRegion")) { linkedRegion = ((StringValue)e["LinkedRegion"]).value; } StateDB.AddPhysicalObject(((StringValue)e["ID"]).value, objectType, linkedRegion); } }
private void TransferObject(SimulationEvent e) { string objectID = ((StringValue)e["ObjectID"]).value; SimulationObjectProxy prox = objectProxies[objectID]; string userID = ((StringValue)e["UserID"]).value; string donerUserID = ((StringValue)e["DonorUserID"]).value; prox["OwnerID"].SetDataValue(DataValueFactory.BuildString(userID)); StateDB.physicalObjects[objectID].ownerID = userID; distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel, time, userID, String.Format("Ownership of {0} has been transferred from {1} to {2}", objectID, donerUserID, userID))); distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel, time, donerUserID, String.Format("Ownership of {0} has been transferred from {1} to {2}", objectID, donerUserID, userID))); }
private void TimeTick(SimulationEvent e) { int oldTime = time; DataValue dv = null; dv = e["Time"]; time = ((IntegerValue)dv).value; if (time % 1000 != 0) { return; } foreach (string s in ScoringDB.scores.Keys) { if (lastScore.ContainsKey(s)) { if (ScoringDB.scores[s].scoreValue != lastScore[s]) { lastScore[s] = ScoringDB.scores[s].scoreValue; foreach (string dm in ScoringDB.scores[s].displayDMs) { distClient.PutEvent(SimUtility.BuildScoreUpdateEvent(ref simModel, time, dm, s, ScoringDB.scores[s].scoreValue)); } } } else { lastScore[s] = ScoringDB.scores[s].scoreValue; foreach (string dm in ScoringDB.scores[s].displayDMs) { distClient.PutEvent(SimUtility.BuildScoreUpdateEvent(ref simModel, time, dm, s, ScoringDB.scores[s].scoreValue)); } } } }
private void TimeTick(SimulationEvent e) { time = ((IntegerValue)e["Time"]).value; DataValue dv = null; SimulationObjectProxy targetProx = null; Vec3D targetLoc = new Vec3D(0, 0, 0); SimulationObjectProxy obProx = null; bool selfDefenseStartAttack; string selfDefenseCapability; string selfDefenseTargetID; Dictionary <string, Dictionary <string, List <AttackCollectionValue.AttackValue> > > currentAttackCollection = new Dictionary <string, Dictionary <string, List <AttackCollectionValue.AttackValue> > >(); //[ [TargetID]/[ CapabilityUsed]/[List of Attacks] ] Dictionary <string, List <AttackCollectionValue.AttackValue> > attacksToRemove = new Dictionary <string, List <AttackCollectionValue.AttackValue> >(); // [AttackerID]/[List of attacks to remove] //as you clean up attacks, add them to this list. once done iterating over targets, go through this list and update the attacks in the keys. foreach (string id in objectProxies.Keys) { obProx = objectProxies[id]; //Generate Attack dictionary AttackCollectionValue attacks = (AttackCollectionValue)obProx["CurrentAttacks"].GetDataValue(); foreach (AttackCollectionValue.AttackValue av in attacks.GetCurrentAttacks()) { if (!currentAttackCollection.ContainsKey(av.targetObjectId)) { currentAttackCollection.Add(av.targetObjectId, new Dictionary <string, List <AttackCollectionValue.AttackValue> >()); } if (!currentAttackCollection[av.targetObjectId].ContainsKey(av.capabilityName)) { currentAttackCollection[av.targetObjectId].Add(av.capabilityName, new List <AttackCollectionValue.AttackValue>()); } currentAttackCollection[av.targetObjectId][av.capabilityName].Add(av); //store pointer } selfDefenseStartAttack = ((BooleanValue)obProx["SelfDefenseStartAttack"].GetDataValue()).value; if (selfDefenseStartAttack) { selfDefenseCapability = ((StringValue)obProx["SelfDefenseCapability"].GetDataValue()).value; selfDefenseTargetID = ((StringValue)obProx["SelfDefenseTargetID"].GetDataValue()).value; targetProx = objectProxies[selfDefenseTargetID]; if (((AttackCollectionValue)obProx["CurrentAttacks"].GetDataValue()).GetCurrentAttacks().Count == 0 && ((StringValue)obProx["State"].GetDataValue()).value != "Dead" && ((StringValue)targetProx["State"].GetDataValue()).value != "Dead") { AttackObject(id, selfDefenseTargetID, selfDefenseCapability, 100, true); if (((StringValue)obProx["AttackState"].GetDataValue()).value == "") { SendSelfDefenseAttackStarted(id, selfDefenseTargetID); } } } } foreach (string targetID in objectProxies.Keys) { targetProx = objectProxies[targetID]; string currentState = ((StringValue)objectProxies[targetID]["State"].GetDataValue()).value; dv = targetProx["AttackState"].GetDataValue(); if (((StringValue)dv).value == "BEING_ATTACKED") { if (!currentAttackCollection.ContainsKey(targetID)) { currentAttackCollection.Add(targetID, new Dictionary <string, List <AttackCollectionValue.AttackValue> >()); //this should not happen, or we're in trouble } int capabilitiesCompleted = 0; //this gets incremented as you add to attacksToRemove foreach (String capability in currentAttackCollection[targetID].Keys) { //update attack windows for each attack object? int attackEndTime = -1; foreach (AttackCollectionValue.AttackValue av in currentAttackCollection[targetID][capability]) { if (attackEndTime == -1) { attackEndTime = av.attackStartTime + av.attackTimeWindow; } else { attackEndTime = Math.Min(attackEndTime, av.attackStartTime + av.attackTimeWindow); } } int newDuration = attackEndTime - time; foreach (AttackCollectionValue.AttackValue av in currentAttackCollection[targetID][capability]) { av.attackTimeWindow = attackEndTime - av.attackStartTime;// newDuration; } //check attack window vs current time if (time >= attackEndTime) { //cleanup if needed //add attacks to remove list foreach (AttackCollectionValue.AttackValue av in currentAttackCollection[targetID][capability]) { if (!attacksToRemove.ContainsKey(av.attackingObjectId)) { attacksToRemove.Add(av.attackingObjectId, new List <AttackCollectionValue.AttackValue>()); } attacksToRemove[av.attackingObjectId].Add(av); } //check vulnerabilities VulnerabilityValue targetVul = (VulnerabilityValue)targetProx["Vulnerability"].GetDataValue(); bool attackSuccess = false; List <string> capabilitiesApplied; List <string> attackers = new List <string>(); foreach (VulnerabilityValue.Transition t in targetVul.transitions) { foreach (String cap in t.GetAppliedCapabilities()) { if (!currentAttackCollection[targetID].ContainsKey(cap)) { continue; //workaround for issue at USF; for some reason capability was not added to current attack collection. } foreach (AttackCollectionValue.AttackValue val in currentAttackCollection[targetID][cap]) { string attackerID = val.attackingObjectId; if (!attackers.Contains(attackerID)) { attackers.Add(attackerID); } } } if (t.ConditionsMet()) { capabilitiesApplied = t.GetAppliedCapabilities(); // Send state change string newState = t.state; SimulationEvent sc = SimulationEventFactory.BuildEvent(ref simModel, "StateChange"); ((StringValue)sc["ObjectID"]).value = targetID; ((StringValue)sc["NewState"]).value = newState; ((IntegerValue)sc["Time"]).value = time; distClient.PutEvent(sc); foreach (string attackerID in attackers) { distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel, time, ((StringValue)(objectProxies[attackerID]["OwnerID"].GetDataValue())).value, attackerID + " has succesfully engaged " + targetID)); distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel, time, ((StringValue)(targetProx["OwnerID"].GetDataValue())).value, targetID + " has been succesfully engaged by " + attackerID)); ScoringDB.UpdateScore_StateChange(new ScoringDB.ActorFrame(attackerID, StateDB.physicalObjects[attackerID].speciesName, StateDB.physicalObjects[attackerID].ownerID, StateDB.physicalObjects[attackerID].activeRegions), currentState, t.state, new ScoringDB.ActorFrame(targetID, StateDB.physicalObjects[targetID].speciesName, StateDB.physicalObjects[targetID].ownerID, StateDB.physicalObjects[targetID].activeRegions)); } t.ClearAppliedEffects(); distClient.PutEvent(SimUtility.BuildHistory_AttackedObjectReportEvent(ref simModel, time, targetID, targetLoc, true, t.state)); distClient.PutEvent(SimUtility.BuildAttackSucceededEvent(ref simModel, time, attackers[0], targetID, newState, capabilitiesApplied)); attackSuccess = true; break; } } //send messages if (!attackSuccess) { foreach (String attackerID in attackers) { distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel, time, ((StringValue)(objectProxies[attackerID]["OwnerID"].GetDataValue())).value, attackerID + " has failed in engagement of " + targetID)); distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel, time, ((StringValue)(targetProx["OwnerID"].GetDataValue())).value, targetID + " has been unsuccesfully engaged by " + attackerID)); } foreach (VulnerabilityValue.Transition t in targetVul.transitions) { t.ClearAppliedEffects(); } distClient.PutEvent(SimUtility.BuildHistory_AttackedObjectReportEvent(ref simModel, time, targetID, targetLoc, false, "")); } capabilitiesCompleted++; //if there are more capabilities being applied than this one, don't remove target's attack state. if (currentAttackCollection[targetID].Count - capabilitiesCompleted == 0) {// this occurs when all attacks will be removed in this loop dv = targetProx["AttackState"].GetDataValue(); ((StringValue)dv).value = ""; targetProx["AttackState"].SetDataValue(dv); } } } foreach (string attackerID in attacksToRemove.Keys) { SimulationObjectProxy attackerProxy = objectProxies[attackerID]; if (attackerProxy != null) { AttackCollectionValue acv = attackerProxy["CurrentAttacks"].GetDataValue() as AttackCollectionValue; foreach (AttackCollectionValue.AttackValue attackVal in attacksToRemove[attackerID]) { if (!acv.RemoveAttack(attackVal)) { acv.RemoveAttack(attackVal.capabilityName, attackVal.targetObjectId, attackVal.attackingObjectId, attackVal.attackStartTime); } } attackerProxy["CurrentAttacks"].SetDataValue(acv); if (((BooleanValue)attackerProxy["IsWeapon"].GetDataValue()).value) { distClient.PutEvent(SimUtility.BuildStateChangeEvent(ref simModel, time, attackerID, "Dead")); } } } if (capabilitiesCompleted > 0) {//some attacks were removed, actually remove them from the currentAttackCollection, update attacker list. //update attack lists (this will require some iteration over the attacks. List <string> attackers = null; dv = targetProx["AttackerList"].GetDataValue(); attackers = ((StringListValue)dv).strings; attackers.Clear(); foreach (String capability in currentAttackCollection[targetID].Keys) { foreach (AttackCollectionValue.AttackValue av in currentAttackCollection[targetID][capability]) { if (!attackers.Contains(av.attackingObjectId)) { attackers.Add(av.attackingObjectId); } } } ((StringListValue)dv).strings = attackers; targetProx["AttackerList"].SetDataValue(dv); } } } }
private void AttackObject(string attackerID, string targetID, string capabilityName, int percentageApplied, bool isSelfDefense) { DataValue dv = null; //AD Note: on 9/23/09, we decided that Vulnerabilities would now have an "EngagementDuration", which is the Vulnerability // version of Capability's "AttackDuration". If an EngagementDuration exists, it will override a Capability's AttackDuration. SimulationObjectProxy attackerProx = objectProxies[attackerID]; SimulationObjectProxy targetProx = objectProxies[targetID]; CapabilityValue attackerCap = (CapabilityValue)attackerProx["Capability"].GetDataValue(); VulnerabilityValue targetVul = (VulnerabilityValue)targetProx["Vulnerability"].GetDataValue(); // Check to see if this attack can start if (((StringValue)attackerProx["AttackState"].GetDataValue()).value == "BEING_ATTACKED") { distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel, time, ((StringValue)(attackerProx["OwnerID"].GetDataValue())).value, attackerID + " is being engaged -- it can't initiate an engagement.")); return; } if (targetVul.transitions.Count == 0) { distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel, time, ((StringValue)(attackerProx["OwnerID"].GetDataValue())).value, attackerID + " can't engage " + targetID + " -- object has no vulnerabilities.")); return; } //AD 11/16/2009: New Attack Logic: Allow for partial capabilities to be applied to attacks. AttackCollectionValue attackCollection = (AttackCollectionValue)attackerProx["CurrentAttacks"].GetDataValue(); int attackDuration = -1; AttackCollectionValue.AttackValue newAttack = new AttackCollectionValue.AttackValue(time, attackDuration, targetID, attackerID, capabilityName, percentageApplied, isSelfDefense); string errMsg = String.Empty; attackDuration = ((IntegerValue)attackerProx["AttackDuration"].GetDataValue()).value; int defenseDuration = ((IntegerValue)targetProx["EngagementDuration"].GetDataValue()).value; int attackTimeWindow = attackDuration; bool attackSuccess = true; if (defenseDuration > 0) { attackTimeWindow = defenseDuration; } Console.WriteLine("AttackObject: Attack duration for " + attackerID + " is " + attackDuration.ToString()); Console.WriteLine("AttackObject: Attack duration for attack is " + attackTimeWindow.ToString()); newAttack.attackTimeWindow = attackTimeWindow; if (attackCollection.AddAttack(newAttack, out errMsg) == false) { string msg = "The attack between " + attackerID + " and " + targetID + " encountered the following problem: " + errMsg; distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel, time, ((StringValue)(attackerProx["OwnerID"].GetDataValue())).value, msg)); attackSuccess = false; } else if (errMsg != String.Empty) { string msg = "The attack between " + attackerID + " and " + targetID + " encountered the following problem: " + errMsg; distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel, time, ((StringValue)(attackerProx["OwnerID"].GetDataValue())).value, msg)); } else //success { dv = targetProx["AttackState"].GetDataValue(); ((StringValue)dv).value = "BEING_ATTACKED"; targetProx["AttackState"].SetDataValue(dv); dv = targetProx["AttackerList"].GetDataValue(); ((StringListValue)dv).strings.Add(attackerID); targetProx["AttackerList"].SetDataValue(dv); } if (!attackSuccess) { attackerProx["CurrentAttacks"].SetDataValue(attackCollection); //set below if attackSuccess is true return; } //End new attack logic. // Vec3D attackerPosition = new Vec3D((LocationValue)attackerProx["Location"].GetDataValue()); Vec3D targetPosition = new Vec3D((LocationValue)targetProx["Location"].GetDataValue()); double distance = attackerPosition.ScalerDistanceTo(targetPosition); //FIX find actual diatance int appliedIntensity = -1; List <CapabilityValue.Effect> capabilities = attackerCap.GetOrderedEffectsByCapability(capabilityName); foreach (CapabilityValue.Effect eff in capabilities) { if (eff.name == capabilityName && distance <= eff.range) { int r = random.Next(0, 100); if (r <= ((int)(eff.probability * 100))) { appliedIntensity = Convert.ToInt32(Math.Round(((double)eff.intensity * (double)newAttack.percentageApplied / 100), MidpointRounding.AwayFromZero)); 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. break; //break because we only want to apply the first range found that satisfied the distance restraint } } attackerProx["CurrentAttacks"].SetDataValue(attackCollection); targetProx["Vulnerability"].SetDataValue((DataValue)targetVul); distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel, time, ((StringValue)(attackerProx["OwnerID"].GetDataValue())).value, attackerID + " has engaged " + targetID)); distClient.PutEvent(SimUtility.BuildSystemMessageEvent(ref simModel, time, ((StringValue)(targetProx["OwnerID"].GetDataValue())).value, targetID + " has been engaged by " + attackerID)); distClient.PutEvent(SimUtility.BuildHistory_AttackerObjectReportEvent(ref simModel, time, attackerID, attackerPosition, targetID, targetPosition, capabilityName, appliedIntensity)); }
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); * * } * * }*/ }
/* * private CapabilityValue.Effect FindCapabilityEffect(CapabilityValue cap, VulnerabilityValue vuln) * { * List<string> vulnNames = new List<string>(); * * foreach (VulnerabilityValue.Transition t in vuln.transitions) * { * foreach (VulnerabilityValue.TransitionCondition tc in t.conditions) * { * if (!vulnNames.Contains(tc.capability)) * { * vulnNames.Add(tc.capability); * } * } * } * * foreach (CapabilityValue.Effect e in cap.effects) * { * if (vulnNames.Contains(e.name)) * { * return e; * } * } * return null; * }*/ private void TimeTick(SimulationEvent e) { if (objectProxies == null) { objectProxies = bbClient.GetObjectProxies(); } time = ((IntegerValue)e["Time"]).value; DataValue dv = null; SimulationObjectProxy obProx = null, targetProx = null; Vec3D myLoc; Vec3D targetLoc; string targetID; bool isWeapon = false; bool pursueStarted; CapabilityValue capabilities; VulnerabilityValue vulnerabilities; CapabilityValue.Effect effect; double distance; LocationValue location; foreach (string id in objectProxies.Keys) { obProx = objectProxies[id]; // update the StateDB info if (StateDB.physicalObjects[id].ownerID == "") { string owner = ((StringValue)obProx["OwnerID"].GetDataValue()).value; if (StateDB.decisionMakers.ContainsKey(owner)) { StateDB.physicalObjects[id].ownerID = owner; } } if (StateDB.physicalObjects[id].speciesName == "") { string speciesName = ((StringValue)obProx["ClassName"].GetDataValue()).value; StateDB.physicalObjects[id].speciesName = speciesName; } if (StateDB.physicalObjects[id].ownerID != "" && StateDB.physicalObjects[id].teamName == "") { if (StateDB.decisionMakers[StateDB.physicalObjects[id].ownerID].team != null) { StateDB.physicalObjects[id].teamName = StateDB.decisionMakers[StateDB.physicalObjects[id].ownerID].team.id; } } if (((StringValue)obProx["AttackState"].GetDataValue()).value == "BEING_ATTACKED") { continue; } AttackCollectionValue attCV = (AttackCollectionValue)obProx["CurrentAttacks"].GetDataValue(); if (attCV.GetCurrentSelfDefenseAttacks().Count == 0) //if (((StringValue)obProx["AttackTargetID"].GetDataValue()).value == "") { dv = obProx["SelfDefenseStartAttack"].GetDataValue(); ((BooleanValue)dv).value = false; obProx["SelfDefenseStartAttack"].SetDataValue(dv); dv = obProx["SelfDefenseCapability"].GetDataValue(); ((StringValue)dv).value = ""; obProx["SelfDefenseCapability"].SetDataValue(dv); dv = obProx["SelfDefenseTargetID"].GetDataValue(); ((StringValue)dv).value = ""; obProx["SelfDefenseTargetID"].SetDataValue(dv); } if (((BooleanValue)obProx["SelfDefenseStartAttack"].GetDataValue()).value == true) { continue; } isWeapon = ((BooleanValue)obProx["IsWeapon"].GetDataValue()).value; pursueStarted = ((BooleanValue)obProx["PursueStarted"].GetDataValue()).value; targetID = ((StringValue)obProx["PursueTargetID"].GetDataValue()).value; capabilities = (CapabilityValue)obProx["Capability"].GetDataValue(); if (isWeapon && pursueStarted && objectProxies.ContainsKey(targetID)) { targetProx = objectProxies[targetID]; location = (LocationValue)obProx["Location"].GetDataValue(); if (!location.exists) { continue; } myLoc = new Vec3D(location); location = (LocationValue)targetProx["Location"].GetDataValue(); if (!location.exists) { continue; } targetLoc = new Vec3D(location); distance = myLoc.ScalerDistanceTo(targetLoc); vulnerabilities = (VulnerabilityValue)targetProx["Vulnerability"].GetDataValue(); //string cap = FindCapability(capabilities, vulnerabilities); effect = SimUtility.FindCapabilityEffect(capabilities, vulnerabilities); if (effect != null && distance < effect.range) { dv = obProx["SelfDefenseStartAttack"].GetDataValue(); ((BooleanValue)dv).value = true; obProx["SelfDefenseStartAttack"].SetDataValue(dv); dv = obProx["SelfDefenseCapability"].GetDataValue(); ((StringValue)dv).value = effect.name; obProx["SelfDefenseCapability"].SetDataValue(dv); dv = obProx["SelfDefenseTargetID"].GetDataValue(); ((StringValue)dv).value = targetID; obProx["SelfDefenseTargetID"].SetDataValue(dv); } else if (effect == null && distance < 1) { distClient.PutEvent(SimUtility.BuildStateChangeEvent(ref simModel, time, id, "Dead")); } continue; } string ownerID = ((StringValue)obProx["OwnerID"].GetDataValue()).value; if (StateDB.decisionMakers.ContainsKey(ownerID)) { StateDB.DecisionMaker thisDM = StateDB.decisionMakers[ownerID]; List <string> targets = ((StringListValue)obProx["TargetsInRange"].GetDataValue()).strings; //if (targets.Count == 0) //{ // continue; //} foreach (string target in targets) { SimulationObjectProxy obProx2 = objectProxies[target]; string ownerID2 = ((StringValue)obProx2["OwnerID"].GetDataValue()).value; if (!StateDB.decisionMakers.ContainsKey(ownerID2)) { continue; } StateDB.DecisionMaker thatDM = StateDB.decisionMakers[ownerID2]; vulnerabilities = (VulnerabilityValue)obProx2["Vulnerability"].GetDataValue(); effect = SimUtility.FindCapabilityEffect(capabilities, vulnerabilities); if (effect != null && thisDM.isHostile(thatDM) && !thisDM.isHuman) { dv = obProx["SelfDefenseStartAttack"].GetDataValue(); ((BooleanValue)dv).value = true; obProx["SelfDefenseStartAttack"].SetDataValue(dv); dv = obProx["SelfDefenseCapability"].GetDataValue(); ((StringValue)dv).value = effect.name; obProx["SelfDefenseCapability"].SetDataValue(dv); dv = obProx["SelfDefenseTargetID"].GetDataValue(); ((StringValue)dv).value = target; obProx["SelfDefenseTargetID"].SetDataValue(dv); break; } } } } }