private void CreateUnit(short playerId, short type, Position pos) { InfoLog.WriteInfo("CreateUnit", EPrefix.Test); Player p = players[playerId]; Unit u = null; ObjectID id = new ObjectID(playerId, p.GenerateObjectID()); InfoLog.WriteInfo(id.ToString() + " dla jednostki: " + type, EPrefix.Test); if (GlobalSettings.Wrapper.harvestersMap.ContainsKey(type)) { u = new UnitHarvester(id, GlobalSettings.Wrapper.harvestersMap[type], pos, this._map, this, GlobalSettings.Wrapper.harvestersMap[type].__Speed); ((UnitHarvester)u).SpiceUnload += new SpiceUnloadDelegate(SpiceUnload); } else if (GlobalSettings.Wrapper.mcvsMap.ContainsKey(type)) { u = new UnitMCV(id, GlobalSettings.Wrapper.mcvsMap[type], pos, this._map, this); } else if (GlobalSettings.Wrapper.tanksMap.ContainsKey(type)) { u = new UnitTank(id, GlobalSettings.Wrapper.tanksMap[type], pos, this._map, this); } else if (GlobalSettings.Wrapper.troopersMap.ContainsKey(type)) { u = new UnitTrooper(id, GlobalSettings.Wrapper.troopersMap[type], pos, this._map, this); } p.AddUnit(u); ClearFogOfWar(u); OnUnitCompleted(u); }
public void TestAStar() { Map map = new Map(); map.LoadMap(Path.Combine("Resources/Maps", "small.map")); Simulation sim = new ClientSimulation(map); Unit u = new UnitTrooper(new ObjectID(1, 1), GlobalSettings.Wrapper.Troopers[0], new Position(0, 0), map, sim); map.Units[0, 1].AddFirst(u); map.Units[1, 1].AddFirst(u); map.Units[2, 1].AddFirst(u); map.Units[3, 0].AddFirst(u); map.Units[4, 1].AddFirst(u); map.Units[3, 2].AddFirst(u); map.Units[4, 2].AddFirst(u); map.Units[3, 3].AddFirst(u); MapInput mi = new MapInput(map); mi.IsMoveable += new MapInput.MoveCheckDelegate(IsMoveable); mi.Start = new Position(0, 0); mi.Goal = new Position(15, 17); Queue <Position> path = AStar.Search <Position>(mi); if (path.Count != 0) { Console.WriteLine("OK"); } }
protected override void onMessageCreate(CreateUnitMessage cum) { InfoLog.WriteInfo("MessageCreate", EPrefix.Test); int cost = 0; Player p = players[cum.IdPlayer]; BoardObjectClass boc = cum.UnitKind; Unit u = null; ObjectID id = new ObjectID(cum.IdPlayer, p.GenerateObjectID()); InfoLog.WriteInfo(id.ToString() + " unit created: " + cum.Type, EPrefix.GObj); if (boc == BoardObjectClass.UnitTank) { if (players[cum.IdPlayer].Credits < (cost = GlobalSettings.Wrapper.tanksMap[cum.UnitType].Cost)) { return; } u = new UnitTank(id, GlobalSettings.Wrapper.tanksMap[cum.UnitType], cum.Position, this._map, this); players[cum.IdPlayer].Credits -= GlobalSettings.Wrapper.tanksMap[cum.UnitType].Cost; } else if (boc == BoardObjectClass.UnitTrooper) { if (players[cum.IdPlayer].Credits < (cost = GlobalSettings.Wrapper.troopersMap[cum.UnitType].Cost)) { return; } u = new UnitTrooper(id, GlobalSettings.Wrapper.troopersMap[cum.UnitType], cum.Position, this._map, this); players[cum.IdPlayer].Credits -= GlobalSettings.Wrapper.troopersMap[cum.UnitType].Cost; } else if (boc == BoardObjectClass.UnitHarvester) { if (players[cum.IdPlayer].Credits < (cost = GlobalSettings.Wrapper.harvestersMap[cum.UnitType].Cost)) { return; } u = new UnitHarvester(id, GlobalSettings.Wrapper.harvestersMap[cum.UnitType], cum.Position, this._map, this, GlobalSettings.Wrapper.harvestersMap[cum.UnitType].__Speed); ((UnitHarvester)u).SpiceUnload += new SpiceUnloadDelegate(SpiceUnload); players[cum.IdPlayer].Credits -= GlobalSettings.Wrapper.harvestersMap[cum.UnitType].Cost; } else if (boc == BoardObjectClass.UnitMCV) { if (players[cum.IdPlayer].Credits < (cost = GlobalSettings.Wrapper.mcvsMap[cum.UnitType].Cost)) { return; } u = new UnitMCV(id, GlobalSettings.Wrapper.mcvsMap[cum.UnitType], cum.Position, this._map, this); players[cum.IdPlayer].Credits -= GlobalSettings.Wrapper.mcvsMap[cum.UnitType].Cost; } else if (boc == BoardObjectClass.UnitSandworm) { u = new UnitSandworm(id, GlobalSettings.Wrapper.sandwormsMap[cum.UnitType], cum.Position, this._map, this, GlobalSettings.Wrapper.sandwormsMap[cum.UnitType].__Speed); Sandworms[id.ObjectId] = (UnitSandworm)u; return; //} else if (boc == BoardObjectClass.UnitTank) { // u = new UnitTank(id, GlobalSettings.Wrapper.tanksMap[cum.UnitType], cum.Position, this._map, this); //} else if (boc == BoardObjectClass.UnitTrooper) { // u = new UnitTrooper(id, GlobalSettings.Wrapper.troopersMap[cum.UnitType], cum.Position, this._map, this); } OnCreditsUpdate(cum.IdPlayer, cost); p.AddUnit(u); ClearFogOfWar(u); OnUnitCompleted(u); }