public void PlacePlayer(int n, Player player) { foreach (var res in Db.Instance.Resources) { player.ResourceStockpiles[res.Value] += res.Value.StartWith; } Players.Add(player); Tile loc = Map.StartLocations[n]; int x = loc.X; int y = loc.Y; // Place buildings foreach (var bldgEntry in Db.Instance.Buildings.Where(p => p.Value.BuiltOnStart)) { bool tileOk = false; int c = 0; Tile t = null; // Get random location around center while (!tileOk) { int rx = x + (int)(random.NextDouble() * 8) - 4; int ry = y + (int)(random.NextDouble() * 8) - 4; t = Map.Tiles[rx, ry]; if (!Building.CanPlace(Map, t)) { c++; if (c > 100) { Logger.Log("Unable to place building " + bldgEntry.Key + " - no free space", "MapGen"); break; } } else { tileOk = true; } } if (tileOk) { Building bldg = new Building(); bldg.Initialize(bldgEntry.Value, this, player, t); bldg.InitializeGraphics(); bldg.Completed(false); } } // Place units foreach (var unitEntry in Db.Instance.Units.Where(p => p.Value.GivenOnStart > 0)) { for (int i = 0; i < unitEntry.Value.GivenOnStart; i++) { int rx = x + (int)(random.NextDouble() * 8) - 4; int ry = y + (int)(random.NextDouble() * 8) - 4; Tile t = Map.Tiles[rx, ry]; Unit u = new Unit(); u.Initialize(unitEntry.Value, this, player, t.MapPosition); u.InitializeGraphics(); } } }
/// <summary> /// Creates a new instance of the Unit class using the serialized data /// </summary> /// <param id="mt">MessageType defining the extend of deserialization which is to be performed</param> /// <param id="line">String array containing the serialized data</param> /// <param id="position">Current position in the array</param> /// <param id="context">Context of the serialized data, game where this INetworkSerializable object is in</param> /// <returns>Unit created using the provided serialized data</returns> public static Unit Create(MessageType mt, string[] line, ref int position, WildmenGame context) { Unit u = new Unit(); u.Deserialize(mt, line, ref position, context); u.game = context; u.InitializeGraphics(); return u; }
/// <summary> /// Creates a unit of given entry at given position with given owner /// </summary> /// <param id="entry">Db entry of the unit</param> /// <param id="position">Position if the unit</param> /// <param id="owner">Owner of the unit</param> /// <returns>The created unit</returns> public IScriptUnit CreateUnit(IScriptDbEntry entry, Vector2 position, IScriptPlayer owner) { Unit u = new Unit(); u.Initialize((EntryDb)entry, this, (Player)owner, position); u.InitializeGraphics(); u.CancelOrders(); SendData(Network.MakeServerMessage(MessageType.GameObjCreate, u)); return u; }
/// <summary> /// Constructor of this class /// </summary> /// <param name="unit">Unit, the death effect should be created from</param> public UnitDeathEffect(Unit unit) { owner = unit.Owner; color = owner.PlayerColor; unitEntry = (UnitDb)unit.Entry; position = unit.Position + unit.AlignmentOffset; tile = unit.NearestTile; Speed = 10; Duration = 10; Graphical = true; }
/// <summary> /// Will spawn a new unit /// </summary> public override void Step() { if (spawner.Health == 0 || spawner.Removed) { Active = false; } else if (game.IsServer) { Unit u = new Unit(); u.Initialize(Spawnee, game, owner, spawnPoint); u.InitializeGraphics(); u.CancelOrders(); game.SendData(Network.MakeServerMessage(MessageType.GameObjCreate, u)); } base.Step(); }
public bool ShamanAvailable() { // If shaman is dead or not existing, look for new shaman if (shaman == null || shaman.Removed || shaman.Health == 0) { shaman = null; shaman = Units.FirstOrDefault( p => ((UnitDb)p.Entry).Shaman && !p.Removed && p.Health != 0); } // If there is a shaman, player isn't defeated if (shaman != null) return true; // If there's no shaman spawn place, look for new one if (shamanSpawn == null || shamanSpawn.Removed || shamanSpawn.Health == 0 || !shamanSpawn.Constructed) { var shamanSpawnCandidates = Buildings.Where( p => !p.Removed && p.Health != 0 && ((BuildingDb)p.Entry).Spawns != null && ((BuildingDb)p.Entry).Spawns.Any( q => q.Entry.Shaman)); // Try spawn sites that are already constructed shamanSpawn = shamanSpawnCandidates.FirstOrDefault(p => p.Constructed); // If we found one, player isn't defeated if (shamanSpawn != null) return true; // Player has no spawn site return false; } // Player has a working spawn place and isn't defeated return true; }
public void Unassign(Unit unit) { Units.Remove(unit); game.GameObjectListChanged = true; }
// public void Assign(Unit unit) { Units.Add(unit); unit.Owner = this; game.GameObjectListChanged = true; }
/// <summary> /// Unassigns unit from this Tile /// </summary> public void Unassign(Unit unit) { this.Units.Remove(unit); }
/// <summary> /// Assigns unit to this Tile /// </summary> public void Assign(Unit unit) { this.Units.Add(unit); }