/// <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; }
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> /// 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(); }