diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework3/Fisher/ExampleSimulationProgramFisher.java b/assignments/src/MV3500Cohort2021JulySeptember/homework3/Fisher/ExampleSimulationProgramFisher.java index b222016da067ac41753403c16edc3e5d5d623a08..e28aed24f90a1ba471c2d00cba46a98fbb0552ac 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework3/Fisher/ExampleSimulationProgramFisher.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework3/Fisher/ExampleSimulationProgramFisher.java @@ -4,9 +4,13 @@ package MV3500Cohort2021JulySeptember.homework3.Fisher; /** * Copyright (c) 2008-2021, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved. * This work is provided under a BSD open-source license, see project license.html and license.txt - * @author brutzman@nps.edu + * @author adfis + * + * This simulation has two entities moving towards each other and when they + * collide a detonation happens. */ +import edu.nps.moves.dis7.enumerations.ForceID; import edu.nps.moves.dis7.enumerations.VariableRecordType; import edu.nps.moves.dis7.pdus.CommentPdu; import edu.nps.moves.dis7.pdus.EntityID; @@ -62,9 +66,19 @@ public class ExampleSimulationProgramFisher EntityID entityID_1 = new EntityID(); entityID_1.setSiteID(1).setApplicationID(2).setEntityID(3); // made-up example ID; // TODO someday, use enumerations; is there a unique site triplet for MOVES Institute? + + EntityID entityID_2 = new EntityID(); + entityID_2.setSiteID(4).setApplicationID(5).setEntityID(6); EntityStatePdu entityStatePdu_1 = pduFactory.makeEntityStatePdu(); entityStatePdu_1.setEntityID(entityID_1); + entityStatePdu_1.setForceId(ForceID.FRIENDLY); + + EntityStatePdu entityStatePdu_2 = pduFactory.makeEntityStatePdu(); + entityStatePdu_2.setEntityID(entityID_2); + entityStatePdu_2.getEntityLocation().setX(10); + entityStatePdu_2.setForceId(ForceID.OPPOSING); + FirePdu firePdu_1a = pduFactory.makeFirePdu(); // for entity 1 first weapon (if any) FirePdu firePdu_1b = pduFactory.makeFirePdu(); // for entity 1 second weapon (if any) @@ -97,7 +111,7 @@ public class ExampleSimulationProgramFisher // Where is my entity? Insert changes in position; this sample only changes X position. entityStatePdu_1.getEntityLocation().setX(entityStatePdu_1.getEntityLocation().getX() + 1.0); // 1m per timestep - + entityStatePdu_2.getEntityLocation().setX(entityStatePdu_2.getEntityLocation().getX() - 1.0); // decide whether to fire, and then update the firePdu. Hmmm, you might want a target to shoort at! // etc. etc. your code goes here for your simulation of interest @@ -129,7 +143,7 @@ public class ExampleSimulationProgramFisher System.out.println ("sending PDUs for simulation step " + simulationLoopCount + ", monitor loopback to confirm sent"); // Below is the PDU that comes out as "Comment" in the info - sendAllPdusForLoopTimestep(entityStatePdu_1, firePdu_1a, detonationPdu, timeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3); + sendAllPdusForLoopTimestep(entityStatePdu_1, entityStatePdu_2, firePdu_1a, timeStepComment, narrativeMessage1, narrativeMessage2, narrativeMessage3); System.out.println ("... [PDUs successfully sent for this loop]"); @@ -137,6 +151,7 @@ public class ExampleSimulationProgramFisher // loop now finished, check whether to terminate if simulation complete, otherwise continue if (simulationComplete || (simulationLoopCount > 10000)) // for example; including fail-safe condition is good { + sendSinglePdu(detonationPdu); System.out.println ("... [Termination condition met, simulationComplete=" + simulationComplete + "]"); // ", final loopCount=" + loopCount + break; } @@ -309,23 +324,27 @@ public class ExampleSimulationProgramFisher * @param commentType enumeration value describing purpose of the narrative comment * @param comments String array of narrative comments */ - public void sendAllPdusForLoopTimestep(EntityStatePdu entityStatePdu, + public void sendAllPdusForLoopTimestep(EntityStatePdu entityStatePdu1, + EntityStatePdu entityStatePdu2, FirePdu firePdu, - DetonationPdu detonationPdu, + //DetonationPdu detonationPdu, VariableRecordType commentType, // vararg... variable-length set of String comments can optionally follow String... comments) { - if (entityStatePdu != null) - sendSinglePdu(entityStatePdu); + if (entityStatePdu1 != null) + sendSinglePdu(entityStatePdu1); + + if (entityStatePdu2 != null) + sendSinglePdu(entityStatePdu2); if (firePdu != null) sendSinglePdu(firePdu); // bang - if (detonationPdu != null) - sendSinglePdu(detonationPdu); - + //if (detonationPdu != null) + // sendSinglePdu(detonationPdu); + // if ((comments != null) && (comments.length > 0)) { ArrayList<String> newCommentsList = new ArrayList<>(); @@ -385,7 +404,7 @@ public class ExampleSimulationProgramFisher thisProgram.runSimulation (); // ... your simulation execution code goes in there ... - pduRecorder.end(); + //pduRecorder.end(); thisProgram.tearDownNetworkInterface(); // make sure no processes are left lingering