Exemplo n.º 1
0
    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();
        }
      }
    }
Exemplo n.º 2
0
 /// <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;
 }
Exemplo n.º 3
0
 /// <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;
 }
Exemplo n.º 4
0
 /// <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();
 }