/// <summary> /// update for all ships repairing /// </summary> /// <param name="gameTime"></param> private void UpdateReparingShips(GameTime gameTime) { for (var i = 0; i < mRepairingShipList.Count; i++) { if (mRepairingShipList[i].Hp < mRepairingShipList[i].MaxHp && RessourceManager.GetRessourceFloat("wood") >= mRepairingShipList[i].RepairingValue * 0.01f) { mRepairingShipList[i].Hp += mRepairingShipList[i].RepairingValue * 0.005f; //Wood -= mRepairingShipList[i].RepairValue*0.01f; RessourceManager.AddRessourceFloat("wood", -mRepairingShipList[i].RepairingValue * 0.01f); } else { //that no ship can get to much hP with repairing. if (mRepairingShipList[i].Hp > mRepairingShipList[i].MaxHp) { mRepairingShipList[i].Hp = (int)mRepairingShipList[i].MaxHp; } mRepairingShipList[i].Repairing = false; mRepairingShipList.RemoveAt(i); } } }
/// <summary> /// Calls update() on every ship. Checks for input and manages Selecting /// and the execution of commands. /// </summary> public void Update(GameTime gameTime) { mShipsQuadTree.Clear(); foreach (var shipu in AllShips) { mShipsQuadTree.Insert(shipu); } //general update for all ships for (int i = 0; i < sAllShipList.Count; i++) { sAllShipList[i].UpdateMoving(gameTime); if (sAllShipList[i].Hp <= 0) { sAllShipList.RemoveAt(i); } } //Call Update for every Attacking Ship for (int i = 0; i < mAttackingShipList.Count; i++) { mAttackingShipList[i].Update(gameTime); if (mAttackingShipList[i].Chasing && mAttackingRefreshRate <= 0) { mAttackingRefreshRate = 2; var atkShip = (AShip)mAttackingShipList[i]; atkShip.Move(mPathFinder.CalculatePath(atkShip.Position, mAttackingShipList[i].TargetShip.Position, true)); } else { mAttackingRefreshRate -= gameTime.ElapsedGameTime.TotalSeconds; } //remove not attacking ships var ship = mAttackingShipList[i] as BattleShip; if (ship != null) { var atkShip = ship; if (atkShip.CurrentBState != BattleShip.ShipBattleState.Attacking) { mAttackingShipList.RemoveAt(i); } } else if (mAttackingShipList[i] is TradingShip) { var atkShip = (TradingShip)mAttackingShipList[i]; if (atkShip.CurrentBState != TradingShip.ShipBattleState.Attacking) { mAttackingShipList.RemoveAt(i); } } } //Check for enemy Ships to shoot at while defending(Only defending Ships) for (int i = 0; i < mDefendingShipList.Count; i++) { mDefendingShipList[i].Update(gameTime); //check if there are enemy ships in range if (mDefendingShipList[i].TargetShip == null) { /* old version, as backup... * foreach (var ship in sAllShipList) * { * * var deShip = (AShip) mDefendingShipList[i]; * CircleF rangeCircle = new CircleF(deShip.Position, 100f); * if (rangeCircle.Contains(ship.Position) && !(ship.Owned && deShip.Owned) && !(!ship.Owned && !deShip.Owned)) * { * mDefendingShipList[i].TargetShip = ship; * //deShip.Moving = false; * * break;//first ship to be seen will be attacked * } * } */ //QuadTree test List <AShip> possibleCollisions = new List <AShip>(); mShipsQuadTree.Retrieve(possibleCollisions, (AShip)mDefendingShipList[i]); foreach (var ship in possibleCollisions) { var deShip = (AShip)mDefendingShipList[i]; CircleF rangeCircle = new CircleF(deShip.Position, 150f); if (rangeCircle.Contains(ship.Position) && !(ship.Owned && deShip.Owned) && !(!ship.Owned && !deShip.Owned)) { mDefendingShipList[i].TargetShip = ship; deShip.Moving = false; break;//first ship to be seen will be attacked } } } //remove not defending ships from list var battleShip = mDefendingShipList[i] as BattleShip; if (battleShip != null) { var defShip = battleShip; if (defShip.CurrentBState != BattleShip.ShipBattleState.Defending) { mDefendingShipList.RemoveAt(i); } } else if (mDefendingShipList[i] is TradingShip) { var defShip = (TradingShip)mDefendingShipList[i]; if (defShip.CurrentBState != TradingShip.ShipBattleState.Defending) { mDefendingShipList.RemoveAt(i); } } } //Update and Pathrefreshing for Entering Ships for (int i = 0; i < mEnteringShipList.Count; i++) { //remove not entering ships from list if (mEnteringShipList[i].CurrentBState != BattleShip.ShipBattleState.Entering) { mEnteringShipList.RemoveAt(i); } else { //Restriction to Pathrefreshing for Chases if (mEnteringRefreshRate <= 0) { mEnteringRefreshRate = 2; //check if the targetShips are moving and sets new Paths //aktuell immer, weil targetShip nichtmehr verfolgt wird nachdem es stehen bleibt. if (mEnteringShipList[i].Chasing) { mEnteringShipList[i].Move(mPathFinder.CalculatePath(mEnteringShipList[i].Position, mEnteringShipList[i].TargetShip.Position, true)); } /* * Alternative: zu inteligent wahrscheinlich... * if (mEnteringShipList[i].Chasing && * !mEnteringShipList[i].ShipPath.TargetNode.Equals(mEnteringShipList[i].TargetShip.ShipPath.TargetNode)) * { * mEnteringShipList[i].Move(mPathFinder.CalculatePath(mEnteringShipList[i].Position, * mEnteringShipList[i].TargetShip.ShipPath.TargetNode.Cell.Position,true)); * } */ } else { mEnteringRefreshRate -= gameTime.ElapsedGameTime.TotalSeconds; } mEnteringShipList[i].Update(gameTime); } } //todo: check if hudScreen is in selecting process for attack/defense/enter //only check input if the specified boolean(from hud) is false //update for all ships repairing for (var i = 0; i < mRepairingShipList.Count; i++) { if (mRepairingShipList[i].Hp < mRepairingShipList[i].MaxHp && RessourceManager.GetRessourceFloat("wood") >= mRepairingShipList[i].RepairValue * 0.01f) { mRepairingShipList[i].Hp += mRepairingShipList[i].RepairValue * 0.005f; //Wood -= mRepairingShipList[i].RepairValue*0.01f; RessourceManager.AddRessourceFloat("wood", -mRepairingShipList[i].RepairValue * 0.01f); } else { //that no ship can get to much hP with repairing. if (mRepairingShipList[i].Hp > mRepairingShipList[i].MaxHp) { mRepairingShipList[i].Hp = (int)mRepairingShipList[i].MaxHp; } mRepairingShipList[i].Repairing = false; mRepairingShipList.RemoveAt(i); } } }