/// <summary> /// This method will attempt to add the entity at the given location. /// </summary> /// <param name="entity"></param> /// <param name="x">x coordinate in gamespace of where the entity should be inserted</param> /// <param name="y">y coordinate in gamespace of where the entity should be inserted</param> /// <returns>true if the entity is inserted successfully, false otherwise</returns> public bool addEntity(Entity entity, float x, float y) { bool success = false; if (x < 0 || x >= gw.map.width || y < 0 || y >= gw.map.height) { return(false); } // The coordinates of the Cell the entity is being inserted into. int xC = (int)Math.Floor(x); int yC = (int)Math.Floor(y); Cell c = gw.map.getCell(xC, yC); /** Try Inserting into GameWorld first **/ if (entity.entityType == Entity.EntityType.Unit) { // Insert into gameworld if the target cell is empty if (c.isValid) { Unit u = (Unit)entity; c.setUnit(u); // Insert into the cell gw.getUnits().Add(u); // Insert into the Unit list u.setCell(c); u.x = (float)xC + 0.5f; u.y = (float)yC + 0.5f; success = true; visMapLogic.updateVisMap(u); } } else if (entity.getEntityType() == Entity.EntityType.Building) { Building b = (Building)entity; b.setOrginCell(c); b.health = 0; success = gw.insert(b, c); if (success) { ///Player pays for building costs scenario.getPlayer().player_resources[0] -= b.stats.waterCost; scenario.getPlayer().player_resources[1] -= b.stats.lumberCost; scenario.getPlayer().player_resources[2] -= b.stats.foodCost; scenario.getPlayer().player_resources[3] -= b.stats.metalCost; visMapLogic.updateVisMap(b); } } // If insert into GameWorld was a success, insert into right player if (success) { scenario.insertEntityIntoPlayer(entity); } return(success); }
/// <summary> /// This method will attempt to add the entity at the given location. /// </summary> /// <param name="entity"></param> /// <param name="x">x coordinate in gamespace of where the entity should be inserted</param> /// <param name="y">y coordinate in gamespace of where the entity should be inserted</param> /// <returns>true if the entity is inserted successfully, false otherwise</returns> public bool addEntity(Entity entity, float x, float y) { bool success = false; if (x < 0 || x >= gw.map.width || y < 0 || y >= gw.map.height) { //System.Console.Out.WriteLine("Retyrb fakse fir addedbtuty"); return(false); } // The coordinates of the Cell the entity is being inserted into. int xC = (int)Math.Floor(x); int yC = (int)Math.Floor(y); Cell c = gw.map.getCell(xC, yC); /** Try Inserting into GameWorld first **/ if (entity.entityType == Entity.EntityType.Unit) { // Insert into gameworld if the target cell is empty if (c.isValid) { System.Console.Out.WriteLine("valid add entity"); Unit u = (Unit)entity; c.setUnit(u); // Insert into the cell gw.getUnits().Add(u); // Insert into the Unit list u.setCell(c); u.x = (float)xC + 0.5f; u.y = (float)yC + 0.5f; success = true; visMapLogic.updateVisMap(u); // Update the Cells that the unit is observing. updateCellsUnitIsObserving(u); // Notify all observers of the cell that a unit has moved onto it. c.notify(new ZRTSModel.GameEvent.Event(c, u, u, ZRTSModel.GameEvent.Event.EventType.MoveEvent)); } } else if (entity.getEntityType() == Entity.EntityType.Building) { Building b = (Building)entity; b.setOrginCell(c); success = gw.insert(b, c); if (success) { ///Player pays for building costs scenario.getPlayer().player_resources[0] -= b.stats.waterCost; scenario.getPlayer().player_resources[1] -= b.stats.lumberCost; scenario.getPlayer().player_resources[2] -= b.stats.foodCost; scenario.getPlayer().player_resources[3] -= b.stats.metalCost; visMapLogic.updateVisMap(b); } } // If insert into GameWorld was a success, insert into right player if (success) { //System.Console.Out.WriteLine("Success fullying "); scenario.insertEntityIntoPlayer(entity); } return(success); }