Beispiel #1
0
        /// <summary>
        /// Constructor for the GameWorld class
        /// </summary>
        /// <param name="width">The width of the world</param>
        /// <param name="height">The height of the world</param>
        public GameWorld(int width, int height)
        {
            instance = this;

            gameWidth  = width;
            gameHeight = height;

            // Init the time, graph, grid- and tilessystem
            time = new Time();
            materialCollection = new MaterialCollector(true);
            graph = new Graph();
            grid  = new GridSystem();
            tiles = new TileSystem();

            // Initializations for the tiles-, gridsystem and graph
            tiles.initTiles();
            grid.initGrid();

            // A temp NPC to test stuff with
            Gatherer npc = new Gatherer(new Vector2D(20, 100), // Position
                                        20,                    // Bounding Radius
                                        new Vector2D(0, 0),    // Velocity
                                        80,                    // Max Speed
                                        Vector2D.Up,           // Heading
                                        1,                     // Mass
                                        new Vector2D(15, 15),  // Scale
                                        0.05f,                 // Turnrate
                                        10,                    // Max Force
                                        15,                    // Carry Capacity
                                        Material.WOOD.id);     // MatID

            //Gatherer npc2 = new Gatherer(new Vector2D(60, 100), // Position
            //                                    20, // Bounding Radius
            //                                    new Vector2D(0, 0), // Velocity
            //                                    80, // Max Speed
            //                                    Vector2D.Left, // Heading
            //                                    1, // Mass
            //                                    new Vector2D(15, 15), // Scale
            //                                    0.05f, // Turnrate
            //                                    10, // Max Force
            //                                    15, // Carry Capacity
            //                                    2); // MatID

            StorageBuilding storage = new StorageBuilding(new Vector2D(400, 200), new Vector2D(40, 40));

            graph.initGraph();
            tiles.AddResources();

            // Setting the path for the npc to follow
            //npc.path.Set(Path.GetPathTo(tiles.tiles[TileSystem.GetIndexOfTile(npc.position)], Material.WOOD));
            //npc2.path.Set(Path.GetPathTo(tiles.tiles[TileSystem.GetIndexOfTile(npc2.position)], Material.STONE));

            // Adding the npc to the world
            entities.Add(npc);
            //entities.Add(npc2);

            storage.SetEntranceEdge();

            buildings.Add(storage);
        }
Beispiel #2
0
        //Lua script;

        /// <summary>
        /// The constructor of this class
        /// </summary>
        /// <param name="pos">The position of the entity</param>
        /// <param name="rad">The bounding radius of the entity</param>
        /// <param name="vel">The current velocity of the entity</param>
        /// <param name="maxSpd">The max speed of the entity</param>
        /// <param name="heading">The current heading of the entity</param>
        /// <param name="mass">The mass of the entity</param>
        /// <param name="scale">The scale of the entity</param>
        /// <param name="turnRate">The turn rate of the entity</param>
        /// <param name="maxForce">The max force the entity can endure</param>
        /// <param name="carryCap">The carry capacity of the entity</param>
        /// <param name="matID">THe id of the material this entity should chase after</param>
        public Gatherer(Vector2D pos, float rad, Vector2D vel, float maxSpd, Vector2D heading, float mass, Vector2D scale, float turnRate, float maxForce, int carryCap, int matID) : base(pos, rad, vel, maxSpd, heading, mass, scale, turnRate, maxForce)
        {
            entityType    = Entity_Types.GATHERER;
            carryCapacity = carryCap;
            this.matID    = matID;
            //script = new Lua();
            //script.LoadCLRPackage();
            //script.DoFile("./Scripts/Print.lua");
            inventory = new MaterialCollector();
            vehicle.addSteeringFactor = new Seek();
            state.SetState(GatherResourceState.instance);
        }
Beispiel #3
0
    public void Init()
    {
        if (health == null)
        {
            health = GetComponentInChildren <HealthComponent>();
        }

        if (collector == null)
        {
            collector = GetComponentInChildren <MaterialCollector>();
        }
    }
Beispiel #4
0
    static void BuildRelease(BuildTarget target)
    {
        MaterialCollector.BuildMaterialCollection();

        string targetString = "";
        string releaseName  = "";

        switch (target)
        {
        case BuildTarget.StandaloneOSXIntel64:
            releaseName  = BuildSettings.Instance.osx_exe;
            targetString = "Mac";
            break;

        case BuildTarget.StandaloneLinux64:
            releaseName  = BuildSettings.Instance.linux_exe;
            targetString = "Linux";
            break;

        case BuildTarget.StandaloneWindows:
            releaseName  = BuildSettings.Instance.win_exe;
            targetString = "Win";
            break;

        case BuildTarget.StandaloneWindows64:
            releaseName  = BuildSettings.Instance.win_exe;
            targetString = "Win x64";
            break;

        default:
            break;
        }

        string path = "Build/" + BuildSettings.Instance.content_version + "/" + targetString + "/";

        if (Directory.Exists(path))
        {
            Directory.Delete(path, true);
        }

        string[] levels = new string[] { "Assets/Scenes/Map Mode.unity" };
        EditorUserBuildSettings.SetPlatformSettings("Standalone", "CopyPDBFiles", "false");
        UnityEngine.Debug.Log(BuildPipeline.BuildPlayer(levels, path + releaseName, target, BuildOptions.None));
        CopyExtras(path);

        using (ZipFile zip = new ZipFile())
        {
            zip.AddDirectory(path);
            zip.Save("Build/" + BuildSettings.Instance.title + " " + BuildSettings.Instance.content_version + " " + targetString + ".zip");
        }
    }
Beispiel #5
0
    private void OnGUI()
    {
        if (GUILayout.Button("Read Raws"))
        {
            var client = new RemoteClient();
            if (!client.Connect())
            {
                return;
            }
            client.SuspendGame();
            var getCreatureRaws  = new RemoteFunction <EmptyMessage, CreatureRawList>(client, "GetCreatureRaws", "RemoteFortressReader");
            var materialListCall = new RemoteFunction <EmptyMessage, MaterialList>(client, "GetMaterialList", "RemoteFortressReader");
            var itemListCall     = new RemoteFunction <EmptyMessage, MaterialList>(client, "GetItemList", "RemoteFortressReader");
            var unitListCall     = new RemoteFunction <EmptyMessage, UnitList>(client, "GetUnitList", "RemoteFortressReader");
            client.ResumeGame();
            creatureRaws = getCreatureRaws.Execute().creature_raws;
            var ExistingMatList  = AssetDatabase.LoadAssetAtPath <MaterialRaws>("Assets/Resources/MaterialRaws.asset");
            var ExistingItemList = AssetDatabase.LoadAssetAtPath <ItemRaws>("Assets/Resources/ItemRaws.asset");
            MaterialRaws.Instance.MaterialList = materialListCall.Execute().material_list;
            ItemRaws.Instance.ItemList         = itemListCall.Execute().material_list;
            units = unitListCall.Execute().creature_list;
            if (ExistingMatList == null)
            {
                AssetDatabase.CreateAsset(MaterialRaws.Instance, "Assets/Resources/MaterialRaws.asset");
            }
            if (ExistingItemList == null)
            {
                AssetDatabase.CreateAsset(ItemRaws.Instance, "Assets/Resources/ItemRaws.asset");
            }
            AssetDatabase.SaveAssets();
            Debug.Log(string.Format("Pulled {0} creature raws from DF.", creatureRaws.Count));
            if (MaterialCollection.Instance == null)
            {
                MaterialCollector.BuildMaterialCollection();
            }
            MaterialCollection.Instance.PopulateMatTextures();
            client.Disconnect();
            //foreach (var raw in creatureRaws)
            //{
            //    raw.creature_id = BodyDefinition.GetCorrectedCreatureID(raw);
            //}
            RefilterList();
        }
        if (creatureRaws != null)
        {
            EditorGUI.BeginChangeCheck();
            filter            = EditorGUILayout.TextField(filter);
            filterToken       = EditorGUILayout.Toggle("Token", filterToken);
            filterName        = EditorGUILayout.Toggle("Name", filterName);
            filterDescription = EditorGUILayout.Toggle("Description", filterDescription);
            filterParts       = EditorGUILayout.Toggle("Parts", filterParts);

            bodyCategoryFilter = (CreatureBody.BodyCategory)EditorGUILayout.EnumPopup(bodyCategoryFilter);

            if (EditorGUI.EndChangeCheck())
            {
                RefilterList();
            }
            EditorGUILayout.Space();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Sort by name"))
            {
                creatureRaws.Sort((x, y) => x.creature_id.CompareTo(y.creature_id));
                RefilterList();
            }
            if (GUILayout.Button("Sort by size"))
            {
                creatureRaws.Sort((x, y) => x.adultsize.CompareTo(y.adultsize));
                RefilterList();
            }
            if (GUILayout.Button("Sort by index"))
            {
                creatureRaws.Sort((x, y) => x.index.CompareTo(y.index));
                RefilterList();
            }
            GUILayout.EndHorizontal();

            showRaces = EditorGUILayout.Foldout(showRaces, "Races");
            if (showRaces)
            {
                raceScroll = EditorGUILayout.BeginScrollView(raceScroll);
                foreach (var creature in filteredRaws)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(string.Format("{0} ({1})", creature.creature_id, creature.name[0]));
                    EditorGUILayout.BeginVertical();
                    foreach (var caste in creature.caste)
                    {
                        if (GUILayout.Button(string.Format("{0} ({1})", caste.caste_id, caste.caste_name[0])))
                        {
                            var creatureBase = new GameObject().AddComponent <CreatureBody>();
                            creatureBase.name  = caste.caste_name[0];
                            creatureBase.race  = creature;
                            creatureBase.caste = caste;
                            creatureBase.MakeBody();
                            Selection.SetActiveObjectWithContext(creatureBase, null);
                        }
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndScrollView();
                if (GUILayout.Button("Dump Part Categories"))
                {
                    var path = EditorUtility.SaveFilePanel("Save bodypart list", "", "Bodyparts.csv", "csv");
                    if (!string.IsNullOrEmpty(path))
                    {
                        Dictionary <string, Dictionary <string, ChildCount> > parts = new Dictionary <string, Dictionary <string, ChildCount> >();
                        foreach (var creature in filteredRaws)
                        {
                            foreach (var caste in creature.caste)
                            {
                                if (bodyCategoryFilter != CreatureBody.BodyCategory.None && bodyCategoryFilter != CreatureBody.FindBodyCategory(caste))
                                {
                                    continue;
                                }

                                for (int i = 0; i < caste.body_parts.Count; i++)
                                {
                                    var part = caste.body_parts[i];
                                    //this is an internal part, and doesn't need modeling.
                                    if (part.flags[(int)BodyPartFlags.BodyPartRawFlags.INTERNAL])
                                    {
                                        continue;
                                    }
                                    if (!parts.ContainsKey(part.category))
                                    {
                                        parts[part.category] = new Dictionary <string, ChildCount>();
                                    }

                                    Dictionary <string, int> childCounts = new Dictionary <string, int>();

                                    foreach (var sub in caste.body_parts)
                                    {
                                        if (sub.parent != i)
                                        {
                                            continue;
                                        }
                                        if (sub.flags[(int)BodyPartFlags.BodyPartRawFlags.INTERNAL])
                                        {
                                            continue;
                                        }
                                        if (!childCounts.ContainsKey(sub.category))
                                        {
                                            childCounts[sub.category] = 1;
                                        }
                                        else
                                        {
                                            childCounts[sub.category]++;
                                        }
                                    }

                                    foreach (var item in childCounts)
                                    {
                                        if (!parts[part.category].ContainsKey(item.Key))
                                        {
                                            parts[part.category][item.Key] = new ChildCount();
                                        }
                                        if (parts[part.category][item.Key].min > item.Value)
                                        {
                                            parts[part.category][item.Key].min = item.Value;
                                        }
                                        if (parts[part.category][item.Key].max < item.Value)
                                        {
                                            parts[part.category][item.Key].max = item.Value;
                                        }
                                    }
                                }
                            }
                        }
                        using (var writer = new StreamWriter(path))
                        {
                            foreach (var parent in parts)
                            {
                                writer.Write("\"" + parent.Key + "\",");
                                foreach (var child in parent.Value)
                                {
                                    writer.Write(string.Format("\"{0}\",{1},{2},", child.Key, child.Value.min, child.Value.max));
                                }
                                writer.WriteLine();
                            }
                        }
                    }
                }
                if (GUILayout.Button("Place all races"))
                {
                    var          watch        = System.Diagnostics.Stopwatch.StartNew();
                    CreatureBody prevCreature = null;
                    foreach (var creature in filteredRaws)
                    {
                        var creatureBase = new GameObject().AddComponent <CreatureBody>();
                        creatureBase.name  = creature.caste[0].caste_name[0];
                        creatureBase.race  = creature;
                        creatureBase.caste = creature.caste[0];
                        creatureBase.MakeBody();
                        if (prevCreature != null)
                        {
                            creatureBase.transform.position = new Vector3(prevCreature.transform.position.x + prevCreature.bounds.max.x - creatureBase.bounds.min.x, 0, 0);
                        }
                        prevCreature = creatureBase;
                    }
                    watch.Stop();
                    Debug.Log(string.Format("Took {0}ms to create {1} creatures, averaging {2}ms per creature.", watch.ElapsedMilliseconds, filteredRaws.Count, (float)watch.ElapsedMilliseconds / filteredRaws.Count));
                }
            }
            showUnits = EditorGUILayout.Foldout(showUnits, "Units");
            if (showUnits)
            {
                unitScroll = EditorGUILayout.BeginScrollView(unitScroll);
                foreach (var unit in units)
                {
                    string name = unit.name;
                    if (string.IsNullOrEmpty(name))
                    {
                        name = creatureRaws[unit.race.mat_type].caste[unit.race.mat_index].caste_name[0];
                    }
                    if (!string.IsNullOrEmpty(filter) && (filterParts || filterName))
                    {
                        bool matched = false;
                        if (filterName)
                        {
                            matched = name.ToUpper().Contains(filter.ToUpper());
                        }
                        if (filterParts)
                        {
                            foreach (var item in unit.inventory)
                            {
                                if (!ItemRaws.Instance.ContainsKey(item.item.type))
                                {
                                    continue;
                                }
                                matched = ItemRaws.Instance[item.item.type].id.ToUpper().Contains(filter.ToUpper());
                                if (matched)
                                {
                                    break;
                                }
                            }
                        }
                        if (!matched)
                        {
                            continue;
                        }
                    }
                    if (GUILayout.Button(name))
                    {
                        var creatureBase = new GameObject().AddComponent <CreatureBody>();
                        creatureBase.name  = name;
                        creatureBase.race  = creatureRaws[unit.race.mat_type];
                        creatureBase.caste = creatureRaws[unit.race.mat_type].caste[unit.race.mat_index];
                        creatureBase.unit  = unit;
                        creatureBase.MakeBody();
                        creatureBase.UpdateUnit(unit);
                        Selection.SetActiveObjectWithContext(creatureBase, null);
                    }
                }
                EditorGUILayout.EndScrollView();
                if (GUILayout.Button("Place all units"))
                {
                    var          watch        = System.Diagnostics.Stopwatch.StartNew();
                    CreatureBody prevCreature = null;
                    foreach (var unit in units)
                    {
                        string name = unit.name;
                        if (string.IsNullOrEmpty(name))
                        {
                            name = creatureRaws[unit.race.mat_type].caste[unit.race.mat_index].caste_name[0];
                        }
                        if (!string.IsNullOrEmpty(filter) && (filterParts || filterName))
                        {
                            bool matched = false;
                            if (filterToken)
                            {
                                matched = creatureRaws[unit.race.mat_type].creature_id.ToUpper().Contains(filter.ToUpper());
                            }
                            if (filterName)
                            {
                                matched = name.ToUpper().Contains(filter.ToUpper());
                            }
                            if (filterParts)
                            {
                                foreach (var item in unit.inventory)
                                {
                                    if (!ItemRaws.Instance.ContainsKey(item.item.type))
                                    {
                                        continue;
                                    }
                                    matched = ItemRaws.Instance[item.item.type].id.ToUpper().Contains(filter.ToUpper());
                                    if (matched)
                                    {
                                        break;
                                    }
                                }
                            }
                            if (!matched)
                            {
                                continue;
                            }
                        }
                        var creatureBase = new GameObject().AddComponent <CreatureBody>();
                        creatureBase.name  = name;
                        creatureBase.race  = creatureRaws[unit.race.mat_type];
                        creatureBase.caste = creatureRaws[unit.race.mat_type].caste[unit.race.mat_index];
                        creatureBase.unit  = unit;
                        creatureBase.MakeBody();
                        creatureBase.UpdateUnit(unit);
                        creatureBase.transform.localRotation = Quaternion.identity;
                        if (prevCreature != null)
                        {
                            creatureBase.transform.position = new Vector3(prevCreature.transform.position.x + prevCreature.bounds.max.x - creatureBase.bounds.min.x, 0, 0);
                        }
                        prevCreature = creatureBase;
                    }
                    watch.Stop();
                    Debug.Log(string.Format("Took {0}ms to create {1} creatures, averaging {2}ms per creature.", watch.ElapsedMilliseconds, filteredRaws.Count, (float)watch.ElapsedMilliseconds / filteredRaws.Count));
                }
            }
        }
    }
Beispiel #6
0
    static void BuildRelease(BuildTarget target, bool isDebug = false)
    {
        MaterialCollector.BuildMaterialCollection();

        string targetString = "";
        string releaseName  = "";

        BuildSettings.Instance.build_date = System.DateTime.Now.ToString("yyy-MM-dd");
        EditorUtility.SetDirty(BuildSettings.Instance);
        AssetDatabase.SaveAssets();

        switch (target)
        {
        case BuildTarget.StandaloneOSX:
            releaseName  = BuildSettings.Instance.osx_exe;
            targetString = "Mac";
            break;

        case BuildTarget.StandaloneLinux64:
            releaseName  = BuildSettings.Instance.linux_exe;
            targetString = "Linux";
            break;

        case BuildTarget.StandaloneWindows:
            releaseName  = BuildSettings.Instance.win_exe;
            targetString = "Win";
            break;

        case BuildTarget.StandaloneWindows64:
            releaseName  = BuildSettings.Instance.win_exe;
            targetString = "Win x64";
            break;

        default:
            break;
        }

        string path = "Build/" + (isDebug ? BuildSettings.Instance.build_date : BuildSettings.Instance.content_version) + "/" + targetString + (isDebug ? "_debug" : "") + "/";

        if (Directory.Exists(path))
        {
            Directory.Delete(path, true);
        }

        string[] levels = new string[] { "Assets/Scenes/Map Mode.unity" };
        EditorUserBuildSettings.SetPlatformSettings("Standalone", "CopyPDBFiles", "false");
        var options = BuildOptions.None;

        if (isDebug)
        {
            options |= BuildOptions.AllowDebugging;
        }
        UnityEngine.Debug.Log(BuildPipeline.BuildPlayer(levels, path + releaseName, target, options));
        CopyExtras(path);

        using (ZipFile zip = new ZipFile())
        {
            zip.AddDirectory(path);
            zip.Save("Build/" + BuildSettings.Instance.title + " " + (isDebug ? BuildSettings.Instance.build_date : BuildSettings.Instance.content_version) + " " + targetString + (isDebug ? "_debug" : "") + ".zip");
        }
    }
Beispiel #7
0
 public static void PreBuild(BuildManifestObject manifest)
 {
     MaterialCollector.BuildMaterialCollection();
     RenderTexture.active = null; //Attempt at cloud build error fixing.
 }