Exemplo n.º 1
0
        public Building Load(BuildingPrefab a_prefab)
        {
            // Properties
            Building.Properties properties = new Building.Properties();
            properties.health = a_prefab.health;
            properties.power = a_prefab.powerUsage;
            properties.buildTime = a_prefab.buildTime;
            properties.cost = a_prefab.cost;
            properties.miniSize = new Vector2(6f, 6f);
            properties.ID = a_prefab.ID;

            // Type
            Building building = null;
            switch (a_prefab.type)
            {
                case Building.Type.HEADQUARTERS:
                    building = new Headquarters(properties, a_prefab.model, a_prefab.texture);
                    break;

                case Building.Type.POWERFACTORY:
                    building = new PowerFactory(properties, a_prefab.model, a_prefab.texture);
                    break;

                case Building.Type.UNITFACTORY:
                    building = new UnitFactory(properties, a_prefab.model, a_prefab.texture);
                    break;

                default:
                    building = new Building(properties, a_prefab.model, a_prefab.texture);
                    break;
            }

            return building;
        }
Exemplo n.º 2
0
        public static void SavePlayerBuildings(JsonWriter writer, Building[] buildings)
        {
            if (writer == null) return;

            writer.WritePropertyName ("Buildings");
            writer.WriteStartArray();
            foreach (Building building in buildings) {
                SaveWorldObject(writer, building);
            }
            writer.WriteEndArray();
        }
Exemplo n.º 3
0
Arquivo: Dozer.cs Projeto: JJJohan/RTS
        public override void Process()
        {
            if (m_building != null)
            {
                if (!m_building.Built())
                {
                    if (Vector2.Distance(Main.Vec3to2(m_building.Position()), Main.Vec3to2(Position())) < Radius() * 6)
                    {
                        Stop();
                        if (!Moving())
                        {
                            m_building.Build();
                        }
                    }
                }
                else
                {
                    m_building = null;
                }
            }

            base.Process();
        }
Exemplo n.º 4
0
 public static Building[] findResourceStores(ResourceType type, Player player)
 {
     Building[] buildings =  GameObject.FindObjectsOfType(typeof(Building)) as Building[];
     Building[] validBuildings = new Building[buildings.Length];
     int freeValidBuildingsSlot = 0;
     for (int i = 0; i < buildings.Length; i++) {
         if (buildings[i].gameObject.activeInHierarchy && buildings[i].IsOwnedBy(player) && buildings[i].resourceStoreType == type) {
             validBuildings[freeValidBuildingsSlot] = buildings[i];
             freeValidBuildingsSlot++;
         }
     }
     return validBuildings;
 }
Exemplo n.º 5
0
 public static Building findClosestResourceStore(Building[] validBuildings, Unit unit)
 {
     Vector3 unitPosition = unit.gameObject.transform.position;
     float closestBuildingDistance = 0.0f;
     Building closestBuilding = null;
     for (int i = 0; i < validBuildings.Length; i++) {
         if (validBuildings[i]) {
             float distance = Vector3.Distance(unitPosition, validBuildings[i].gameObject.transform.position);
             if (closestBuilding) {
                 if (distance < closestBuildingDistance) {
                     closestBuilding = validBuildings[i];
                     closestBuildingDistance = distance;
                 }
             } else {
                 closestBuilding = validBuildings[i];
                 closestBuildingDistance = distance;
             }
         } else {
             break;
         }
     }
     return closestBuilding;
 }
Exemplo n.º 6
0
Arquivo: Dozer.cs Projeto: JJJohan/RTS
        public override void SetDestination(Vector3 a_pos)
        {
            m_building = null;

            base.SetDestination(a_pos);
        }
Exemplo n.º 7
0
Arquivo: Dozer.cs Projeto: JJJohan/RTS
 public void Build(ref Building a_building)
 {
     m_building = a_building;
 }
Exemplo n.º 8
0
Arquivo: Dozer.cs Projeto: JJJohan/RTS
 public Dozer(Properties a_properties, Mesh a_mesh, Texture2D a_texture)
     : base(a_properties, a_mesh, a_texture)
 {
     m_building = null;
     m_type = Type.DOZER;
 }
Exemplo n.º 9
0
Arquivo: Input.cs Projeto: JJJohan/RTS
        // Fetch array of building corners
        private static Vector3[] GetCorners(Building a_building)
        {
            Bounds bounds = a_building.GetObject().collider.bounds;
            Vector3[] corners = new Vector3[4];
            //corners[0] = a_building.Position() + new Vector3(-bounds.size.x * 0.5f, 0f, -bounds.size.z * 0.5f);
            //corners[1] = a_building.Position() + new Vector3(bounds.size.x * 0.5f, 0f, -bounds.size.z * 0.5f);
            //corners[2] = a_building.Position() + new Vector3(-bounds.size.x * 0.5f, 0f, bounds.size.z * 0.5f);
            //corners[3] = a_building.Position() + new Vector3(bounds.size.x * 0.5f, 0f, bounds.size.z * 0.5f);
            corners[0] = a_building.Position() + new Vector3(-bounds.size.x * 0.5f, 0f, 0f);
            corners[1] = a_building.Position() + new Vector3(bounds.size.x * 0.5f, 0f, 0f);
            corners[2] = a_building.Position() + new Vector3(0f, 0f, -bounds.size.z * 0.5f);
            corners[3] = a_building.Position() + new Vector3(0f, 0f, bounds.size.z * 0.5f);

            return corners;
        }