/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is AddObjectToMarkMessage) { AddObjectToMarkMessage tmp = (AddObjectToMarkMessage)msg; MarkObjects(tmp.mMarkerProfile_In, tmp.mObjectToMark_In); } else if (msg is RemoveObjectToMarkMessage) { RemoveObjectToMarkMessage temp = (RemoveObjectToMarkMessage)msg; // Find the object to remove. for (Int32 i = 0; i < mMarkers.Count; i++) { GameObject obj = mMarkers[i].pObjectToMark; if (obj == temp.mObjectToRemove_In) { mMarkers.RemoveAt(i); break; } } } }
/// <summary> /// Sends a message to all GameObject currently managed by the GameObjectManager. /// </summary> /// <param name="msg">The message to send.</param> /// <param name="sender">The object sending the message.</param> public void BroadcastMessage(BehaviourMessage msg, GameObject sender) { for (Int32 i = 0; i < mGameObjects.Count; i++) { mGameObjects[i].OnMessage(msg, sender); } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is ObjectPlacement.OnPlaceObjectMessage) { ObjectPlacement.OnPlaceObjectMessage temp = (ObjectPlacement.OnPlaceObjectMessage)msg; // By default assume the object could not be placed. temp.mObjectPlaced_Out = false; // The level needs to have this tile set to be Solid. mSetTileTypeAtPositionMsg.mType_In = Level.Tile.TileTypes.Solid; mSetTileTypeAtPositionMsg.mPosition_In = temp.mPosition_In; WorldManager.pInstance.pCurrentLevel.OnMessage(mSetTileTypeAtPositionMsg, mParentGOH); // Only spawn a tile if we actually changed the tile type. if (mSetTileTypeAtPositionMsg.mType_In != mSetTileTypeAtPositionMsg.mPreviousType_Out) { mParentGOH.pPosition = temp.mPosition_In; temp.mObjectPlaced_Out = true; // Note: We don't need to add this object to the GameObjectManager; the default // ObjectPlacement will handle that when it sees that mOutObjectPlaced is // true. } } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is SetExtractionPointActivateMessage) { // Tell the world that we are activating. GameObjectManager.pInstance.BroadcastMessage(mOnExtractionPointActivatedMsg, mParentGOH); } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { // Which type of message was sent to us? if (msg is Health.ApplyDamageMessage) { mDamageCooldown.Restart(); } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is StatBoostResearch.OnResearchComplete) { mSetStateMsg.mNextState_In = "WaitAtStandingPosition"; pParentGOH.OnMessage(mSetStateMsg); } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is IncrementScoreMessage) { IncrementScoreMessage temp = (IncrementScoreMessage)msg; pScore += temp.mAmount_In; } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { base.OnMessage(ref msg); if (msg is Health.OnZeroHealthMessage) { AdvanceToState("Dead"); } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is SetTargetMessage) { SetTargetMessage temp = (SetTargetMessage)msg; mTarget = temp.mTarget_In; mResearchTimer.Restart(); } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is GetHealthLevelsRemainingMessage) { GetHealthLevelsRemainingMessage temp = (GetHealthLevelsRemainingMessage)msg; temp.mLevelsRemaining = mDef.mLevels.Length - pNextLevel; } else { base.OnMessage(ref msg); } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is PathFollow.OnReachedPathEndMessage) { mSetStateMsg.mNextState_In = "WaitAtStandingPosition"; pParentGOH.OnMessage(mSetStateMsg); } else if (msg is PathFind.OnPathFindFailedMessage) { mSetStateMsg.mNextState_In = "GoToStandingPosition"; pParentGOH.OnMessage(mSetStateMsg); } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is Health.OnZeroHealthMessage) { // When this object dies, disable this behaviour. mParentGOH.SetBehaviourEnabled <PointAndShoot>(false); if (null != mGun) { GameObjectManager.pInstance.Remove(mGun); mGun = null; } } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is SpriteRender.OnAnimationCompleteMessage) { SpriteRender.OnAnimationCompleteMessage temp = (SpriteRender.OnAnimationCompleteMessage)msg; // Once the build up animation finishes, do the search for a target and move the Scout to // that position. Since the Scout appears on the minimap, he will show the player where to // go. if (temp.mAnimationSetName_In == "RaiseArm") { // Spawn some smoke to be more ninja like. GameObject go = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Effects\\Dust\\Dust"); // Grab that attachment point and position the new object there. mGetAttachmentPointMsg.mName_In = "Smoke"; pParentGOH.OnMessage(mGetAttachmentPointMsg); // Put the smoke at the right position relative to the Scout. go.pPosition = mGetAttachmentPointMsg.mPoisitionInWorld_Out; // The Smoke gets pushed onto the GameObjectManager and will delete itself when // it finishes the animation. GameObjectManager.pInstance.Add(go); // Find all the objects that are Allies. /// <todo> /// This needs to be refined further, as this could find Stranded that are already saved, /// as well as other Scouts (or even the one doing the seach!). /// </todo> List <GameObject> objs = GameObjectManager.pInstance.GetGameObjectsOfClassification(MBHEngineContentDefs.GameObjectDefinition.Classifications.ALLY); // There is a chance there are no Stranded left (well not really since it would find itself). if (objs.Count > 0) { // Pick a random Stranded to "scout". GameObject obj = objs[MBHEngine.Math.RandomManager.pInstance.RandomNumber() % objs.Count]; // Move the Scout to the position of the guy he found. pParentGOH.pPosition = obj.pPosition; } // Wait for the Player to arrive. This is just to allow the player to make the connection between // the marking on the minimap and the scout they sent out. mSetStateMsg.mNextState_In = "WaitAtTarget"; pParentGOH.OnMessage(mSetStateMsg); } } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { // Which type of message was sent to us? if (msg is Health.OnZeroHealthMessage) { mIncrementScoreMsg.mAmount_In = 10; GameObjectManager.pInstance.BroadcastMessage(mIncrementScoreMsg, mParentGOH); } else if (msg is PathFind.OnPathFindFailedMessage) { // If we didn't find the path in a single frame, just give up and BLine it for // the target. mForceBLine = true; } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { base.OnMessage(ref msg); if (msg is Health.OnZeroHealthMessage) { AdvanceToState("Dead"); } else if (msg is ExtractionPoint.OnExtractionPointActivatedMessage) { // Store the next extraction point. ExtractionPoint.OnExtractionPointActivatedMessage temp = (ExtractionPoint.OnExtractionPointActivatedMessage)msg; mExtractionPoint = msg.pSender; FSMState curState = GetCurrentState(); // If anyone is in the Safe House, they should make a run for the Extraction point now. if (curState is States.Common.FSMStateGoToStandingPosition || curState is States.Common.FSMStateWaitAtStandingPosition || curState is FSMStatePatrol || curState is FSMStatePauseAtPatrolPoint) { AdvanceToState("GoToExtraction"); } } else if (msg is FSMCivilian.GetExtractionPointMessage) { FSMCivilian.GetExtractionPointMessage temp = (FSMCivilian.GetExtractionPointMessage)msg; temp.mExtractionPoint_Out = mExtractionPoint; } else if (msg is FSMCivilian.GetSafeHouseScoreMessage) { FSMCivilian.GetSafeHouseScoreMessage temp = (FSMCivilian.GetSafeHouseScoreMessage)msg; temp.mSafeHouseScore_Out = mSafeHouseScore; } else if (msg is StrandedPopup.GetIsScoutableMessage) { // Currently the only thing required for a Stranded to be Scoutable, is that // they are currently in the Cower state. This can later be expanded to include // things like distance from the sender. if (GetCurrentState() is States.Common.FSMStateCower) { StrandedPopup.GetIsScoutableMessage temp = (StrandedPopup.GetIsScoutableMessage)msg; temp.mIsScoutable_Out = true; } } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is PathFind.OnPathFindFailedMessage) { PathFind.OnPathFindFailedMessage temp = (PathFind.OnPathFindFailedMessage)msg; // Reason.Blocked is handled by PathFollow Behaviour. if (temp.mReason != PathFind.OnPathFindFailedMessage.Reason.InvalidLocation) { // Can't do much if we can't reach the destination, so just revert to // cower. mSetStateMsg.mNextState_In = "Cower"; pParentGOH.OnMessage(mSetStateMsg); } } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is PathFollow.OnReachedPathEndMessage) { // The player gets a bunch of points for rescuing people! GameObjectManager.pInstance.BroadcastMessage(mIncrementScoreMsg, pParentGOH); GameObjectManager.pInstance.Remove(pParentGOH); } else if (msg is PathFind.OnPathFindFailedMessage) { // Once we reach our destination, sit and wait for a spell. mSetStateMsg.mNextState_In = "Follow"; pParentGOH.OnMessage(mSetStateMsg); } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { // Which type of message was sent to us? if (msg is Health.ApplyDamageMessage) { // We only want to flash if the object is still alive. mParentGOH.OnMessage(mGetHealthMsg); if (mGetHealthMsg.mCurrentHealth_Out > 0) { // The only thing we need to do is set this to zero. // If it was previous expired, this will trigger it to start again. // If it was already running, than this will give us more time before we // hit the mFramesToExpire. mDamageCooldown.pIsPaused = false; mDamageCooldown.Restart(); } } }
/// <summary> /// Sends a message to all behaviours attached to this object. As soon as a behaviour /// handles the message, it will return. /// </summary> /// <param name="msg">The message to send.</param> /// <param name="sender">The GameObject sending the message.</param> /// <returns>The message passed in, likely modified by handling behaviours.</returns> public virtual BehaviourMessage OnMessage(BehaviourMessage msg, GameObject sender) { if (sender == null) { msg.pSender = this; } else { msg.pSender = sender; } for (int i = 0; i < mBehaviours.Count; i++) { mBehaviours[i].OnMessage(ref msg); } return(msg); }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { // Which type of message was sent to us? if (msg is Health.OnZeroHealthMessage) { DebugMessageDisplay.pInstance.AddConstantMessage("GAME OVER - Player Died"); } else if (msg is IncrementGunLevelMessage) { IncrementGunLevelMessage temp = (IncrementGunLevelMessage)msg; mGunLevel = System.Math.Min(mGunLevelInfo.Length - 1, mGunLevel + temp.mIncrementAmount_In); } else if (msg is GetGunLevelsRemainingMessage) { GetGunLevelsRemainingMessage temp = (GetGunLevelsRemainingMessage)msg; temp.mLevelRemaining_In = (mGunLevelInfo.Length - 1) - mGunLevel; } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is PathFollow.OnReachedPathEndMessage) { // Once we reach our destination, sit and wait for a spell. mSetStateMsg.mNextState_In = "PatrolPause"; pParentGOH.OnMessage(mSetStateMsg); } else if (msg is PathFind.OnPathFindFailedMessage) { // It may be a while until we find another valid patrol point if the player // has boxed in the Militant. Stop him from sliding. pParentGOH.pDirection.mForward = Vector2.Zero; // Handle the case where the user places a wall right where the patrol is trying to // reach. FindNextPatrolPoint(); } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (!mExploded) { // Which type of message was sent to us? if (!mManualExplosion && msg is MBHEngine.Behaviour.TileCollision.OnTileCollisionMessage) { Detonate(); } else if (msg is DetonateMessage || msg is Health.OnZeroHealthMessage) { Detonate(); } } if (msg is SetDamageMultiplierMessage) { SetDamageMultiplierMessage temp = (SetDamageMultiplierMessage)msg; mDamageMod = temp.mDamageMod_In; } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is SpriteRender.OnAnimationCompleteMessage) { SpriteRender.OnAnimationCompleteMessage temp = (SpriteRender.OnAnimationCompleteMessage)msg; if (temp.mAnimationSetName_In == "RaiseArm") { // By default just spawn the object where this object is. GameObject go = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Effects\\Dust\\Dust"); // Grab that attachment point and position the new object there. mGetAttachmentPointMsg.mName_In = "Smoke"; pParentGOH.OnMessage(mGetAttachmentPointMsg); Vector2 spawnPos = mGetAttachmentPointMsg.mPoisitionInWorld_Out; go.pPosition = spawnPos; GameObjectManager.pInstance.Add(go); GameObjectManager.pInstance.Remove(pParentGOH); } } }
/// <summary> /// Sends a message to all behaviours attached to this object. As soon as a behaviour /// handles the message, it will return. /// </summary> /// <param name="msg">The message to send.</param> /// <returns>The message passed in, likely modified by handling behaviours.</returns> public virtual BehaviourMessage OnMessage(BehaviourMessage msg) { return(OnMessage(msg, null)); }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted message types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { }
/// <summary> /// Sends a message to all GameObject currently managed by the GameObjectManager. /// </summary> /// <param name="msg">The message to send.</param> public void BroadcastMessage(BehaviourMessage msg) { BroadcastMessage(msg, null); }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { if (msg is AddObjectMessage) { AddObjectMessage temp = (AddObjectMessage)msg; // The template name is how we will categorize items. String newType = temp.mObj_In.pTemplateFileName; // Assume that the object was not added to the list. Boolean added = false; // Index will be needed outside of the loop to figure out where the object // was added. Int32 index = 0; // Loop through ever object in the inventory looking for another object of the // same type so that this new object can be grouped in with it. for (; index < mObjects.Count; index++) { // Objects are grouped by the template that defined them. if (mObjects[index].pTemplateFileName == newType) { // Put the new object at the front of the group. It doesn't need to // be at the front, but it is the quickest/easiest. We may at some point // want it to go at the end of the list, but that won't work in the case // where temp.mDoSelectObj is true. mObjects.Insert(index, temp.mObj_In); // The object has been added so the special handling below can be skipped. added = true; break; // index < mObjects.Count } } // If the object wasn't added above, it means that there are no other objects of this type // yet in the list (including when the list is completely empty). So it needs to be added // to the end of the list. if (!added) { mObjects.Add(temp.mObj_In); } // If at this point there was no selected object, this new object becomes selected by default. if (-1 == mCurrentObject) { mCurrentObject = 0; } else if (true == temp.mDoSelectObj_In) { // The message can specifically request that the object added be selected. Since it was inserted // at the front of its group, we just need to update mCurrentObject to be the current index. mCurrentObject = index; } } else if (msg is GetCurrentObjectMessage) { // Trying to pop with an empty queue is an exception. if (0 != mObjects.Count) { System.Diagnostics.Debug.Assert(mCurrentObject != -1, "mObjects isn't empty but mCurrentObject is undefined. This should never happen."); // Should never happen. if (-1 == mCurrentObject) { return; } GetCurrentObjectMessage temp = (GetCurrentObjectMessage)msg; // Grab the currently selected object. temp.mObj_Out = mObjects[mCurrentObject]; mObjects.RemoveAt(mCurrentObject); // No need to change mCurrentObject as we just removed the object at its index and // so the object that followed it will now become the current object when it inherits // that index in the list. // This can happen when placing the last object in the list while there are still other // types of objects before it. if (mObjects.Count <= mCurrentObject) { mCurrentObject = 0; } // If the list becomes empty set the mCurrentObject back to an undefined so that the // next object added becomes the current object by default. if (0 == mObjects.Count) { mCurrentObject = -1; } } } else if (msg is PeekCurrentObjectMessage) { if (0 != mObjects.Count) { System.Diagnostics.Debug.Assert(mCurrentObject != -1, "mObjects isn't empty but mCurrentObject is undefined. This should never happen."); PeekCurrentObjectMessage temp = (PeekCurrentObjectMessage)msg; if (-1 != mCurrentObject) { temp.mObj_Out = mObjects[mCurrentObject]; String type = mObjects[mCurrentObject].pTemplateFileName; // We need to also return the number of objects of this type in the inventory. // Since they are sorted in groups we just loop until we reach an item of // a different type. for (Int32 i = mCurrentObject; i < mObjects.Count; i++) { // If its the same type, increase the count. if (mObjects[i].pTemplateFileName == type) { temp.mCount_Out++; } else { // As soon as we hit another type, stop looking. break; } } } } } else if (msg is SelectNextItemMessage) { if (0 != mObjects.Count) { System.Diagnostics.Debug.Assert(mCurrentObject != -1, "mObjects isn't empty but mCurrentObject is undefined. This should never happen."); if (-1 != mCurrentObject) { String type = mObjects[mCurrentObject].pTemplateFileName; Int32 count = mObjects.Count; // The loop is slightly odd. We loop for the number of object in the list, but // we don't use i to index into the array. Instead we are incrementing mCurrentObject // as we go and using that to iterate. Once we hit an object of another type we stop // looping and mCurrentObject is left pointing at the next object of a different type. for (Int32 i = 0; i < count; i++) { mCurrentObject++; // Loop back to the start. if (mCurrentObject >= count) { mCurrentObject = 0; } // If we hit another type, we are done. if (mObjects[mCurrentObject].pTemplateFileName != type) { break; } } } } } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { base.OnMessage(ref msg); if (msg is Health.OnZeroHealthMessage) { AdvanceToState("Dead"); } else if (msg is ExtractionPoint.OnExtractionPointActivatedMessage) { // Store the next extraction point. ExtractionPoint.OnExtractionPointActivatedMessage temp = (ExtractionPoint.OnExtractionPointActivatedMessage)msg; mExtractionPoint = msg.pSender; FSMState curState = GetCurrentState(); // If anyone is in the Safe House, they should make a run for the Extraction point now. if (curState is States.Common.FSMStateGoToStandingPosition || curState is States.Common.FSMStateWaitAtStandingPosition || curState is States.Engineer.FSMStateDoRepair || curState is States.Engineer.FSMStateRepair || curState is States.Engineer.FSMStateWaitForRepairChance) { AdvanceToState("GoToExtraction"); } } else if (msg is FSMCivilian.GetExtractionPointMessage) { FSMCivilian.GetExtractionPointMessage temp = (FSMCivilian.GetExtractionPointMessage)msg; temp.mExtractionPoint_Out = mExtractionPoint; } else if (msg is FSMCivilian.GetSafeHouseScoreMessage) { FSMCivilian.GetSafeHouseScoreMessage temp = (FSMCivilian.GetSafeHouseScoreMessage)msg; temp.mSafeHouseScore_Out = mSafeHouseScore; } else if (msg is StrandedPopup.GetIsScoutableMessage) { // Currently the only thing required for a Civilian to be Scoutable, is that // they are currently in the Cower state. This can later be expanded to include // things like distance from the sender. if (GetCurrentState() is States.Common.FSMStateCower) { StrandedPopup.GetIsScoutableMessage temp = (StrandedPopup.GetIsScoutableMessage)msg; temp.mIsScoutable_Out = true; } } else if (msg is SetTileToRepairMessage) { SetTileToRepairMessage temp = (SetTileToRepairMessage)msg; mTileToRepair = temp.mTile_In; } else if (msg is GetTileToRepairMessage) { System.Diagnostics.Debug.Assert(mTileToRepair != null, "Getting mTileToRepair when it has not yet been set."); GetTileToRepairMessage temp = (GetTileToRepairMessage)msg; temp.mTile_Out = mTileToRepair; } }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public virtual void OnMessage(ref BehaviourMessage msg) { }
/// <summary> /// The main interface for communicating between behaviours. Using polymorphism, we /// define a bunch of different messages deriving from BehaviourMessage. Each behaviour /// can then check for particular upcasted messahe types, and either grab some data /// from it (set message) or store some data in it (get message). /// </summary> /// <param name="msg">The message being communicated to the behaviour.</param> public override void OnMessage(ref BehaviourMessage msg) { base.OnMessage(ref msg); if (msg is StrandedPopup.OnPopupClosedMessage) { // This message is broadcast to all GameObjects, so make sure it is actually a popup we // opened before reacting to it. if (msg.pSender == mPopup) { StrandedPopup.OnPopupClosedMessage temp = (StrandedPopup.OnPopupClosedMessage)msg; if (temp.mSelection_In == StrandedPopupDefinition.ButtonTypes.GunUp) { mSetStateMsg.mNextState_In = "ResearchStatBoost"; pParentGOH.OnMessage(mSetStateMsg); } else if (temp.mSelection_In == StrandedPopupDefinition.ButtonTypes.HpUp) { mSetStateMsg.mNextState_In = "ResearchStatBoost"; pParentGOH.OnMessage(mSetStateMsg); } else if (temp.mSelection_In == StrandedPopupDefinition.ButtonTypes.MilitantPatrol) { DebugMessageDisplay.pInstance.AddConstantMessage("Patrol"); mSetStateMsg.mNextState_In = "Patrol"; pParentGOH.OnMessage(mSetStateMsg); } else if (temp.mSelection_In == StrandedPopupDefinition.ButtonTypes.MilitantFollow) { DebugMessageDisplay.pInstance.AddConstantMessage("Follow"); mSetStateMsg.mNextState_In = "Follow"; pParentGOH.OnMessage(mSetStateMsg); } else if (temp.mSelection_In == StrandedPopupDefinition.ButtonTypes.MakeScout) { // Spawn some smoke to be more ninja like. GameObject go = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Effects\\Dust\\Dust"); // Grab that attachment point and position the new object there. mGetAttachmentPointMsg.mName_In = "Smoke"; pParentGOH.OnMessage(mGetAttachmentPointMsg); // Put the smoke at the right position relative to the Civilian. go.pPosition = mGetAttachmentPointMsg.mPoisitionInWorld_Out; // The Smoke gets pushed onto the GameObjectManager and will delete itself when // it finishes the animation. GameObjectManager.pInstance.Add(go); // Spawn the Scout to replace this Civilian. go = GameObjectFactory.pInstance.GetTemplate("GameObjects\\Characters\\Scout\\Scout"); go.pPosition = pParentGOH.pPosition; GameObjectManager.pInstance.Add(go); GameObjectManager.pInstance.Remove(pParentGOH); } else if (temp.mSelection_In == StrandedPopupDefinition.ButtonTypes.ScoutSearch) { mSetStateMsg.mNextState_In = "BeginSearch"; pParentGOH.OnMessage(mSetStateMsg); } else if (temp.mSelection_In == StrandedPopupDefinition.ButtonTypes.EngineerRepair) { DebugMessageDisplay.pInstance.AddConstantMessage("Repair"); mSetStateMsg.mNextState_In = "Repair"; pParentGOH.OnMessage(mSetStateMsg); } // Popups get recycled so if ours closes, we need to make sure to clear our local // reference, else the next object to use it might send messages that we react to. mPopup = null; } } }