public void manageArrival(StateGameLayer.Troop troop) { if (!troop.EnemyTroop.isDead()) { int beforeBattleTroopHP = troop.HitPoints; int beforeBattleEnemyHP = troop.EnemyTroop.HitPoints; int attackTroop = Math.Max(troop.Damage - troop.EnemyTroop.Defense, 0); int shieldsEnemy = troop.EnemyTroop.Shields; troop.EnemyTroop.Shields = Math.Max(troop.EnemyTroop.Shields - attackTroop, 0); attackTroop = Math.Max(attackTroop - shieldsEnemy, 0); troop.EnemyTroop.HitPoints = troop.EnemyTroop.HitPoints - attackTroop; int attackEnemy = Math.Max(troop.EnemyTroop.Damage - troop.Defense, 0); int shieldsTroop = troop.Shields; troop.Shields = Math.Max(troop.Shields - attackEnemy, 0); attackEnemy = Math.Max(attackEnemy - shieldsTroop, 0); troop.HitPoints = troop.HitPoints - attackEnemy; troop.EnemyTroop.recalculateElements(beforeBattleEnemyHP); troop.recalculateElements(beforeBattleTroopHP); troop.EnemyTroop.StartTime = 0; } if (troop.EnemyTroop.isDead()) { removeLaser(troop.EnemyTroop); troop.Fighting = false; troop.EnemyTroop = null; troop.EnemyEngaged = false; } }
public bool manageArrival(StateGameLayer.Troop troop, int Target) { bool troopDie = true; if (troop.ObjectType != stateGame.factory.factories[Target].ObjectType) { int beforeBattleFactoryHP = stateGame.factory.factories[Target].HitPoints; int beforeBattleTroopHP = troop.HitPoints; int attackTroop = Math.Max(troop.Damage - stateGame.factory.factories[Target].Defense, 0); int shieldsFactory = stateGame.factory.factories[Target].Shields + (stateGame.factory.factories[Target].Shields / 20) * stateGame.factory.factories[Target].Elements; stateGame.factory.factories[Target].Shields = Math.Max(stateGame.factory.factories[Target].Shields - attackTroop, 0); attackTroop = Math.Max(attackTroop - shieldsFactory, 0); stateGame.factory.factories[Target].HitPoints = stateGame.factory.factories[Target].HitPoints - attackTroop; int attackFactory = Math.Max(stateGame.factory.factories[Target].Damage + (stateGame.factory.factories[Target].Damage / 20) * stateGame.factory.factories[Target].Elements - troop.Defense, 0); int shieldsTroop = troop.Shields; troop.Shields = Math.Max(troop.Shields - attackFactory, 0); attackFactory = Math.Max(attackFactory - shieldsTroop, 0); troop.HitPoints = troop.HitPoints - attackFactory; stateGame.factory.factories[Target].recalculateElements(beforeBattleFactoryHP); troop.recalculateElements(beforeBattleTroopHP); if (stateGame.factory.factories[Target].isDead() && !troop.isDead()) { stateGame.factory.factories[Target].Elements = troop.Elements; stateGame.factory.factories[Target].Elements = Math.Min(stateGame.factory.factories[Target].Elements, stateGame.factory.factories[Target].MaxElements); stateGame.factory.factories[Target].ObjectType = troop.ObjectType; stateGame.factory.factories[Target].HitPoints = stateGame.factory.factories[Target].MaxHitPoints; stateGame.factory.factories[Target].Shields = stateGame.factory.factories[Target].MaxShields; stateGame.factory.factories[Target].Selected = false; troop.HitPoints = 0; troopDie = false; stateGame.factory.change = true; } else if (stateGame.factory.factories[Target].isDead() && troop.isDead()) { stateGame.factory.factories[Target].HitPoints = stateGame.factory.factories[Target].MaxHitPoints / 10; troopDie = true; } } else { stateGame.factory.factories[Target].Elements += troop.Elements; stateGame.factory.factories[Target].Elements = Math.Min(stateGame.factory.factories[Target].Elements, stateGame.factory.factories[Target].MaxElements); troop.HitPoints = 0; troopDie = false; } if (troop.isDead()) { stateGame.factory.factories[Target].UnderAttack = false; if(troopDie) return true; } return false; }
public void removeLaser(StateGameLayer.Troop toRemove) { for (int i = 0; i < stateGame.lasers.Count; i++) { if (stateGame.lasers[i].laserTroop == toRemove) { stateGame.lasers.RemoveAt(i); } } }
public bool isArrivedAtTarget(StateGameLayer.Troop me, RenderingState renderingState) { //return (Vector3.Distance(CurrentPos, myTarget.CurrentPos) == 0); BoundingSphere boundingSphere = renderingState.BoundingSpherePlanet; //calculate bounding sphere model ship renderingState.boundingSphereModelShipRed.Center = me.CurrentPos; //calculate bounding sphere model planet boundingSphere.Center = me.myTarget.CurrentPos; //if collision boundingSphere.Radius *= me.myTarget.scaleFactor; return renderingState.boundingSphereModelShipRed.Intersects(boundingSphere); }
public void addLaser(Vector3 laserPos, StateGameLayer.Troop toAdd) { bool insert = true; for (int i = 0; i < stateGame.lasers.Count; i++) { if (stateGame.lasers[i].laserTroop == toAdd) insert = false; } if (insert) { stateGame.lasers.Add(new StateGameLayer.Laser(laserPos, toAdd)); } }
public int search(StateGameLayer.Factory searchTarget) { for (int i = 0; i < stateGame.factory.factories.Count; ++i) { if (stateGame.factory.factories[i].compareFactory(searchTarget)) return i; } return -1; }
public bool checkCollision(StateGameLayer.Troop me, RenderingState renderingState, StateGameLayer.Troop enemy) { float distance = Vector3.Distance(me.CurrentPos, enemy.CurrentPos); return distance < 200; }
public void addTroop(int owner, Vector3 position, int elements, StateGameLayer.Factory targetFactory, int maxHitPoints, int damage, int defense, int shields) { if (owner == 1 || owner == 2) stateGame.troops.Add(new StateGameLayer.Troop(owner, position, elements, targetFactory, maxHitPoints / troopStatsFactor, damage / troopStatsFactor, defense / troopStatsFactor, shields / troopStatsFactor)); }
private bool checkTroopsCollision(RenderingState renderingState, StateGameLayer.Troop toCheck) { foreach (StateGameLayer.Troop i in stateGame.troops) { if(i.ObjectType != toCheck.ObjectType && checkCollision(toCheck, renderingState, i)) { toCheck.Fighting = true; toCheck.StartTime = 0; toCheck.EnemyEngaged = true; toCheck.EnemyTroop = i; ++toCheck.EnemyTroop.SmartEnemyCounter; } } return false; }
//check if troop collision with another factory public float troopCollisionFactoryNoTarget(StateGameLayer.Troop me, RenderingState renderingState, List<StateGameLayer.Factory> factories, Vector3 posCurrent) { for (int i = 0; i < factories.Count; i++) { if (factories[i] != me.myTarget) { BoundingSphere boundingSphere = renderingState.BoundingSpherePlanet; renderingState.boundingSphereModelShipRed.Center = me.CurrentPos; //calculate bounding sphere model planet boundingSphere.Center = factories[i].CurrentPos; boundingSphere.Radius *= factories[i].scaleFactor; if (renderingState.boundingSphereModelShipRed.Intersects(boundingSphere)) if (Vector3.Distance(boundingSphere.Center, posCurrent) > boundingSphere.Radius + renderingState.boundingSphereModelShipRed.Radius + 1) return boundingSphere.Radius; } } return 0; }
private StateGameLayer.Factory findNearestFactory(StateGameLayer.Factory start, List<StateGameLayer.Factory> searchList) { /* * Search in "searchList" for the nearest factory to "start". */ float min = 100000; StateGameLayer.Factory nearestFactory = null; foreach (StateGameLayer.Factory i in searchList) { if (Vector3.Distance(start.Center, i.Center) < min) { min = Vector3.Distance(start.Center, i.Center); nearestFactory = i; } } return nearestFactory; }
private StateGameLayer.Factory findFurthestFactory(StateGameLayer.Factory start, List<StateGameLayer.Factory> searchList) { float max = 0; StateGameLayer.Factory furthestFactory = start; foreach (StateGameLayer.Factory i in searchList) { if (Vector3.Distance(start.Center, i.Center) > max) { max = Vector3.Distance(start.Center, i.Center); furthestFactory = i; } } return furthestFactory; }