public void Execute(GameStartingState state) { List <Player> farmers = state.Game.Players.Values.Where(p => p.Role.Type == RoleType.Farmer).ToList(); List <BuyPoint> riverParcels = state.Game.BuyPoints.Values.Where(p => p.Zone == "river").ToList(); m_log.InfoFormat( "[WATER WARS]: Found {0} farmers and {1} river parcels", farmers.Count, riverParcels.Count); if (farmers.Count == 0) { m_log.InfoFormat("[WATER WARS]: Not allocating any farms since there are no farmers"); return; } riverParcels.Sort( delegate(BuyPoint bp1, BuyPoint bp2) { if (bp1.Location.RegionY > bp2.Location.RegionY) { return(1); } else if (bp1.Location.RegionY < bp2.Location.RegionY) { return(-1); } if (bp1.Location.LocalPosition.Y > bp2.Location.LocalPosition.Y) { return(1); } else if (bp1.Location.LocalPosition.Y < bp2.Location.LocalPosition.Y) { return(-1); } if (bp1.Location.RegionX < bp2.Location.RegionX) { return(1); } else if (bp1.Location.RegionY > bp2.Location.RegionY) { return(-1); } if (bp1.Location.LocalPosition.X < bp2.Location.LocalPosition.X) { return(1); } else if (bp1.Location.LocalPosition.X > bp2.Location.LocalPosition.X) { return(-1); } return(0); }); riverParcels.Reverse(); m_log.InfoFormat("[WATER WARS]: River parcels are in this order"); string tableFormat = "{0,-20} {1,-30} {2,-6} {3,-6} {4,-20}"; m_log.InfoFormat(tableFormat, "Parcel name", "Position", "Glob X", "Glob Y", "Region name"); foreach (BuyPoint bp in riverParcels) { m_log.InfoFormat( tableFormat, bp.Name, bp.Location.LocalPosition, bp.Location.RegionX, bp.Location.RegionY, bp.Location.RegionName); } int allocateToEach = Math.Min(riverParcels.Count / farmers.Count, MAXIMUM_RIVER_PARCEL_ALLOCATION); m_log.InfoFormat("[WATER WARS]: Allocating {0} river parcels to each farmer", allocateToEach); // If there are spare parcels, then allocate river parcels surrounding the middle of the region. int startAllocationIndex = (int)Math.Ceiling((riverParcels.Count - farmers.Count * allocateToEach) / 2.0); m_log.InfoFormat("[WATER WARS]: Starting allocation at river parcel index {0}", startAllocationIndex); foreach (Player farmer in farmers) { int toAllocate = allocateToEach; while (toAllocate > 0) { BuyPoint riverParcel = riverParcels[startAllocationIndex]; m_log.InfoFormat( "[WATER WARS]: Allocating parcel {0} at {1} in {2} to {3}", riverParcel.Name, riverParcel.Location.LocalPosition, riverParcel.Location.RegionName, farmer.Name); state.AllocateParcel(riverParcel, farmer); toAllocate--; startAllocationIndex++; } m_controller.Events.PostModalMessage( farmer.Uuid, string.Format( "As a farmer, you start the game already owning {0} parcels along the river. In the environment, you can click on the farm buildings at each parcel to see which ones you own.", allocateToEach)); } // foreach (Player farmer in farmers) // { // int toAllocate = allocateToEach; // while (toAllocate > 0) // { // BuyPoint riverParcel = riverParcels[WaterWarsUtils.Random.Next(0, riverParcels.Count)]; // if (riverParcel.HasAnyOwner) // continue; // // m_log.InfoFormat( // "[WATER WARS]: Allocating parcel {0} at {1} in {2} to {3}", // riverParcel.Name, riverParcel.Location.LocalPosition, riverParcel.Location.RegionName, farmer.Name); // // state.AllocateParcel(riverParcel, farmer); // toAllocate--; // } // // m_controller.Events.PostModalMessage( // farmer.Uuid, // string.Format( // "As a farmer, you start the game already owning {0} parcels along the river. In the environment, you can click on the farm buildings at each parcel to see which ones you own.", // allocateToEach)); // } }
public void Execute(GameStartingState state) { }