示例#1
0
    public BlockMeshData(BlockScheme blockScheme, Vector3Int blockSize, int startIndex)
    {
        this.cubeScheme = blockScheme;
        this.sizeX      = blockSize.x;
        this.sizeY      = blockSize.y;
        this.sizeZ      = blockSize.z;
        if (blockScheme != null)
        {
            this.x = blockScheme.position.x;
            this.y = blockScheme.position.y;
            this.z = blockScheme.position.z;
        }
        this.triIndexStart = startIndex;
        this.triIndexEnd   = startIndex;

        // Front quad
        LeftBottomP  = new Vector3(x, y, z + sizeZ);
        LeftUpperP   = new Vector3(x, y + sizeY, z + sizeZ);
        RightBottomP = new Vector3(x + sizeX, y, z + sizeZ);
        RightUpperP  = new Vector3(x + sizeX, y + sizeY, z + sizeZ);

        // Back quad
        BackleftBottomP  = new Vector3(x, y, z);
        BackLeftUpperP   = new Vector3(x, y + sizeY, z);
        BackRightBottomP = new Vector3(x + sizeX, y, z);
        BackRightUpperP  = new Vector3(x + sizeX, y + sizeY, z);
    }
示例#2
0
    public static Color GetSchemeColor(BlockScheme scheme)
    {
        List <Population> pops = new List <Population>();

        foreach (string flag in scheme.flags)
        {
            foreach (string popGroup in flag.Split('_'))
            {
                foreach (string popName in popGroup.Split('-'))
                {
                    Population pop = GameManager.instance.populationManager.GetPopulationByCodename(popName);
                    if (pop != null)
                    {
                        pops.Add(pop);
                    }
                }
            }
        }
        switch (pops.Count)
        {
        case 1:
            return(pops[0].color);

        case 2:
            return(Color.Lerp(pops[0].color, pops[1].color, 0.5f));

        default:
            return(GameManager.instance.library.defaultContainerColor);
        }
    }
示例#3
0
    private bool checkChildBlock(Vector3Int p, BlockScheme parent)
    {
        if (p.x < 0)
        {
            return(parent.neigbors.leftNeighbor);
        }
        if (p.y < 0)
        {
            return(parent.neigbors.bottomNeighbor);
        }
        if (p.z < 0)
        {
            return(parent.neigbors.backNeighbor);
        }
        if (p.x >= scheme.GetLength(0))
        {
            return(parent.neigbors.rightNeighbor);
        }
        if (p.y >= scheme.GetLength(1))
        {
            return(parent.neigbors.topNeighbor);
        }
        if (p.z >= scheme.GetLength(2))
        {
            return(parent.neigbors.frontNeighbor);
        }

        if (this.scheme[p.x, p.y, p.z] == null)
        {
            return(false);
        }

        return(true);
    }
    static public void ConvertBlock(Block block, BlockScheme newBlock)
    {
        Vector3Int coord = block.gridCoordinates;

        block.Destroy();
        GameManager.instance.gridManagement.SpawnBlock(newBlock.ID, coord);
    }
示例#5
0
 public BlockScheme(BlockScheme[,,] children, BlockScheme parent, Vector3Int position, Vector3Int size)
 {
     this.children = children;
     this.position = position;
     this.size     = size;
     this.visible  = true;
     this.parent   = parent;
 }
示例#6
0
    public static List <List <string> > GetFlags(BlockScheme blockScheme)
    {
        List <List <string> > list = new List <List <string> >();

        foreach (string flag in blockScheme.flags)
        {
            list.Add(UnpackFlag(flag));
        }

        return(list);
    }
    IEnumerator AddTooltipsWhenPossible(Tooltip tt, BlockScheme scheme)
    {
        yield return(new WaitUntil(delegate { return GameManager.instance.localization.GetLanguages().Count > 0; }));

        List <Tooltip.Entry> entries = Tooltip.GetBuildingTooltip(scheme);

        foreach (Tooltip.Entry entry in entries)
        {
            tt.AddLocalizedLine(entry);
        }
        yield return(true);
    }
示例#8
0
    public Neighbors getChildNeighbors(int x, int y, int z, BlockScheme parent)
    {
        Neighbors neighbors = new Neighbors(
            checkChildBlock(new Vector3Int(x, y, z + 1), parent),
            checkChildBlock(new Vector3Int(x, y, z - 1), parent),
            checkChildBlock(new Vector3Int(x, y + 1, z), parent),
            checkChildBlock(new Vector3Int(x, y - 1, z), parent),
            checkChildBlock(new Vector3Int(x + 1, y, z), parent),
            checkChildBlock(new Vector3Int(x - 1, y, z), parent));

        return(neighbors);
    }
示例#9
0
    public static List <string> GetRawFlags(BlockScheme blockScheme)
    {
        List <List <string> > flags = GetFlags(blockScheme);

        List <string> list = new List <string>();

        foreach (List <string> parameters in flags)
        {
            list.Add(parameters[0]);
        }

        return(list);
    }
示例#10
0
    public GameObject CreateBlockFromId(int blockId)
    {
        BlockScheme scheme = GameManager.instance.library.GetBlockByID(blockId);

        if (scheme == null)
        {
            Logger.Warn("BlockScheme index not found - index : " + blockId); return(null);
        }

        GameObject newBlockGO = Instantiate(GameManager.instance.library.blockPrefab);
        Block      newBlock   = newBlockGO.GetComponent <Block>();

        newBlock.scheme = scheme;
        LoadBlock(newBlock);
        return(newBlockGO);
    }
示例#11
0
 public void computeChildNeighbors(BlockScheme parent)
 {
     for (int x = 0; x < parent.children.GetLength(0); x++)
     {
         for (int y = 0; y < parent.children.GetLength(1); y++)
         {
             for (int z = 0; z < parent.children.GetLength(2); z++)
             {
                 if (parent.children[x, y, z] != null && parent.children[x, y, z].visible)
                 {
                     NeighborsDetection nd = new NeighborsDetection(parent.children);
                     parent.children[x, y, z].neigbors = nd.getChildNeighbors(x, y, z, parent);
                 }
             }
         }
     }
 }
示例#12
0
    public void splitBlock(BlockScheme blockScheme, Vector3Int cubeSize = null)
    {
        Vector3Int position = blockScheme.position.add(this.worldPosition);

        for (int x = position.x; x < position.x + this.blockSize.x; x++)
        {
            for (int y = position.y; y < position.y + this.blockSize.y; y++)
            {
                for (int z = position.z; z < position.z + this.blockSize.z; z++)
                {
                    BlockMeshDataInterpreter.buildingGameObject(
                        BlockMeshDataInterpreter.oneSimpleCube(Vector3Int.one),
                        new Vector3(x, y, z),
                        false, true, null);
                }
            }
        }
    }
示例#13
0
    void SaveBlock(string[] dataLine)
    {
        if (dataLine.Length == 12)
        {
            BlockScheme block = ScriptableObject.CreateInstance <BlockScheme>();

            // Ints
            block.ID          = int.Parse(dataLine[1]);
            block.consumption = int.Parse(dataLine[2]);
            block.sensibility = int.Parse(dataLine[3]);

            // Flags
            block.flags = dataLine[4].Split(new char[] { '/' }, System.StringSplitOptions.RemoveEmptyEntries);

            // Booleans
            block.isMovable        = bool.Parse(dataLine[5]);
            block.isDestroyable    = bool.Parse(dataLine[6]);
            block.isBuyable        = bool.Parse(dataLine[7]);
            block.canBuildAbove    = bool.Parse(dataLine[8]);
            block.relyOnSpatioport = bool.Parse(dataLine[9]);
            block.fireProof        = bool.Parse(dataLine[10]);
            block.riotProof        = bool.Parse(dataLine[11]);

            string finalName = "Block_" + dataLine[0] + ".asset";

            // Link preservation
            UnityEngine.Object previousBlock = AssetDatabase.LoadAssetAtPath(Paths.GetBlockFolder(folderName) + "/" + finalName, typeof(BlockScheme));
            if (previousBlock != null)
            {
                BlockScheme previousScheme = (BlockScheme)previousBlock;
                block.model = previousScheme.model;
                block.sound = previousScheme.sound;
            }


            AssetDatabase.CreateAsset(block, Paths.GetBlockFolder(folderName) + "/" + finalName);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        else
        {
            Debug.LogWarning("Your file is not properly setup, there is only " + dataLine.Length + " elements in each lines. Where there should be 12");
        }
    }
示例#14
0
    public static CityManager.BuildingType GetCategory(BlockScheme scheme)
    {
        string[] rawFlags = GetRawFlags(scheme).ToArray();

        // Habitation
        if (rawFlags.Contains("House"))
        {
            return(CityManager.BuildingType.Habitation);
        }

        // Occupators
        if (rawFlags.Contains("Occupator") || rawFlags.Contains("Extractor") || rawFlags.Contains("Barrack"))
        {
            return(CityManager.BuildingType.Occupators);
        }

        // Services
        return(CityManager.BuildingType.Services);
    }
示例#15
0
    public BlockScheme makeScheme(Vector3Int position)
    {
        if (childDimensions == null)
        {
            this.childDimensions = childrenDimensions();
        }
        Vector3Int size = blockSize.div(this.childDimensions);

        BlockScheme[,,] children = new BlockScheme[childDimensions.x, childDimensions.y, childDimensions.z];
        BlockScheme parent = new BlockScheme(children, null, position, blockSize);

        for (int x = 0; x < children.GetLength(0); x++)
        {
            for (int y = 0; y < children.GetLength(1); y++)
            {
                for (int z = 0; z < children.GetLength(2); z++)
                {
                    children[x, y, z] = new BlockScheme(null, parent, position.add(new Vector3Int(x, y, z).multiply(size)), size);
                }
            }
        }
        return(parent);
    }
示例#16
0
    void Update()
    {
        Vector2 rotation = new Vector2(Input.GetAxisRaw("Mouse X"), -Input.GetAxisRaw("Mouse Y")) * rotationSpeed * Time.deltaTime;
        Vector2 dir      = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")).normalized;
        bool    running  = Input.GetKey(KeyCode.LeftShift);

        float targetSpeed = (running ? runSpeed : walkSpeed) * dir.magnitude;

        currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedSmoothVelocity, speedSmoothTime);
        transform.Translate(transform.forward * currentSpeed * Time.deltaTime, Space.World);

        if (dir != Vector2.zero)
        {
            float targetRotation = Mathf.Atan2(dir.x, dir.y) * Mathf.Rad2Deg;
            transform.eulerAngles = Vector2.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref turnSmoothVelocity, turnSmoothTime);
        }

        float speedNormalized = (running ? 1 : .5f) * dir.magnitude;

        // Set animation type
        animator.SetFloat("speed", speedNormalized, speedSmoothTime, Time.deltaTime);

        cam.transform.Rotate(0, rotation.x, 0, Space.World);
        cam.transform.Rotate(rotation.y, 0, 0, Space.Self);

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            RaycastHit h;
            if (Physics.Raycast(cam.transform.position, cam.transform.forward, out h))
            {
                GameObject something = h.collider.gameObject;

                if (h.collider.gameObject.tag == "building")
                {
                    BlockScheme b = Town.buildings[something].setBlockInvisible(h.point);
                    Destroy(something);
                    GameObject newBuilding = Town.buildings[something].reBuild();
                    Town.buildings[something].splitBlock(b);
                    BlockRewind.block       = b;
                    BlockRewind.building    = Town.buildings[something];
                    BlockRewind.buildingGO  = newBuilding;
                    BlockRewind.isRecording = true;
                    addForce(h.point);
                }
                if (h.collider != null && something.tag == "enemy_body_part")
                {
                    something.transform.root.GetComponent <Enemy>().kill(forcePushEnemy, h.point);
                    //h.collider.gameObject.GetComponent<Enemy_Part>().push(forcePushEnemy, h.point);
                }
            }
        }

        if (Input.GetKey(KeyCode.Z))
        {
            forceMagnitude += 100;
            forceUI.GetComponent <Text>().text = forceMagnitude.ToString();
        }

        if (Input.GetKey(KeyCode.X))
        {
            forceMagnitude -= 100;
            forceUI.GetComponent <Text>().text = forceMagnitude.ToString();
        }

        if (Input.GetKeyDown(KeyCode.B))
        {
            cam.GetComponent <MotionBlur>().enabled = !GetComponent <MotionBlur>().enabled;
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
    }
示例#17
0
    //Return true if a block is placable here, false if it isn't
    public bool IsPlaceable(Vector3Int coordinates, bool shouldDisplayInformation, BlockScheme scheme)
    {
        if (coordinates.x < 0 || coordinates.y < 0 || coordinates.z < 0)
        {
            if (shouldDisplayInformation)
            {
                GameManager.instance.cursorManagement.CursorError("cannotBuildOutOfMap");
            }
            return(false);
        }
        if (coordinates.y > maxHeight)
        {
            if (shouldDisplayInformation)
            {
                GameManager.instance.cursorManagement.CursorError("maxHeightReached");
            }
            return(false);
        }
        Vector3Int groundPosition = GetLowestFreeSlot(new Vector2Int(coordinates.x, coordinates.z));

        if (groundPosition.y < minHeight)
        {
            if (shouldDisplayInformation)
            {
                GameManager.instance.cursorManagement.CursorError.Invoke("cannotBuildOnWater");
            }
            return(false);
        }
        if (groundPosition.y >= maxHeight)
        {
            if (shouldDisplayInformation)
            {
                GameManager.instance.cursorManagement.CursorError("maxHeightReached");
            }
            return(false);
        }
        if (GetSlotType(groundPosition) != blockType.FREE)
        {
            if (shouldDisplayInformation)
            {
                GameManager.instance.cursorManagement.CursorError.Invoke("cannotBuildHere");
            }
            return(false);
        }
        GameObject gameObjectUnderPos = grid[groundPosition.x, groundPosition.y - 1, groundPosition.z];

        if (gameObjectUnderPos != null)
        {
            if (gameObjectUnderPos.GetComponent <BridgeInfo>() != null)
            {
                if (shouldDisplayInformation)
                {
                    GameManager.instance.cursorManagement.CursorError.Invoke("cannotBuildOverBridge");
                }
                return(false);
            }
            Block blockUnderPos = gameObjectUnderPos.GetComponent <Block>();
            if (blockUnderPos != null)
            {
                if (!blockUnderPos.scheme.canBuildAbove && (coordinates.y != groundPosition.y - 1))
                {
                    if (shouldDisplayInformation)
                    {
                        GameManager.instance.cursorManagement.CursorError.Invoke("cannotBuildAboveThis");
                    }
                    return(false);
                }
                if (!blockUnderPos.scheme.isMovable && coordinates.y == groundPosition.y - 1)
                {
                    if (shouldDisplayInformation)
                    {
                        GameManager.instance.cursorManagement.CursorError.Invoke("cannotBuildHere");
                    }
                    return(false);
                }
            }
        }
        GameObject gameObjectOnPos = grid[coordinates.x, coordinates.y, coordinates.z];

        if (gameObjectOnPos != null)
        {
            if (gameObjectOnPos.GetComponent <BridgeInfo>() != null)
            {
                if (shouldDisplayInformation)
                {
                    GameManager.instance.cursorManagement.CursorError.Invoke("cannotBuildOverBridge");
                }
                return(false);
            }
            Block blockOnPos = gameObjectOnPos.GetComponent <Block>();
            if (blockOnPos != null && !scheme.canBuildAbove)
            {
                if (shouldDisplayInformation)
                {
                    GameManager.instance.cursorManagement.CursorError.Invoke("cannotPlaceThisBlockHere");
                }
                return(false);
            }
        }
        return(true);
    }
示例#18
0
    void LoadActionFunctions()
    {
        actionFunctions.Clear();
        actionFunctions.Add(
            "INCREASE_ENERGY_CONSUMPTION_FOR_BUILDING", (args, context) => {
            Block block = null;
            try {
                block = (Block)context[GetArgument(args, "building")];
            }
            catch (System.Exception) {
                Throw("Impossible cast in " + args + "\n");
            }
            int duration = System.Convert.ToInt32(GetArgument(args, "duration"));
            int amount   = System.Convert.ToInt32(GetArgument(args, "amount"));

            ConsequencesManager.GenerateConsumptionModifier(block, amount, duration);
        }
            );
        actionFunctions.Add(
            "INCREASE_MOOD_FOR_POPULATION", (args, context) => {
            Population pop = GameManager.instance.populationManager.GetPopulationByCodename(GetArgument(args, "population"));
            if (pop == null)
            {
                List <string> pops = new List <string>();
                foreach (Population existingPop in GameManager.instance.populationManager.populationTypeList)
                {
                    pops.Add(existingPop.codeName);
                }
                Throw("Invalid population name :\n " + args + "\nPick one from the following : " + string.Join(", ", pops.ToArray()));
            }
            int duration = System.Convert.ToInt32(GetArgument(args, "duration"));
            int amount   = System.Convert.ToInt32(GetArgument(args, "amount"));

            int eventId = ((ObjectInteger)context["_EVENT_ID"]).ToInt();

            ConsequencesManager.GenerateMoodModifier(pop, amount, duration, eventId);
        }
            );
        actionFunctions.Add(
            "INCREASE_FOOD_CONSUMPTION_FOR_POPULATION", (args, context) => {
            Population pop = GameManager.instance.populationManager.GetPopulationByCodename(GetArgument(args, "population"));
            if (pop == null)
            {
                List <string> pops = new List <string>();
                foreach (Population existingPop in GameManager.instance.populationManager.populationTypeList)
                {
                    pops.Add(existingPop.codeName);
                }
                Throw("Invalid population name :\n " + args + "\nPick one from the following : " + string.Join(", ", pops.ToArray()));
            }
            int duration = System.Convert.ToInt32(GetArgument(args, "duration"));
            float amount = System.Convert.ToSingle(GetArgument(args, "amount"));

            ConsequencesManager.GenerateFoodConsumptionModifier(pop, amount, duration);
        }
            );
        actionFunctions.Add(
            "DECREASE_FOOD_CONSUMPTION_FOR_POPULATION", (args, context) => {
            Population pop = GameManager.instance.populationManager.GetPopulationByCodename(GetArgument(args, "population"));
            if (pop == null)
            {
                List <string> pops = new List <string>();
                foreach (Population existingPop in GameManager.instance.populationManager.populationTypeList)
                {
                    pops.Add(existingPop.codeName);
                }
                Throw("Invalid population name :\n " + args + "\nPick one from the following : " + string.Join(", ", pops.ToArray()));
            }
            int duration = System.Convert.ToInt32(GetArgument(args, "duration"));
            float amount = System.Convert.ToSingle(GetArgument(args, "amount"));

            ConsequencesManager.GenerateFoodConsumptionModifier(pop, -amount, duration);
        }
            );
        actionFunctions.Add(
            "INCREASE_HOUSE_NOTATION", (args, context) => {
            House house = null;
            try {
                house = (House)context[GetArgument(args, "house")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }
            float amount = System.Convert.ToSingle(GetArgument(args, "amount"));
            int duration = System.Convert.ToInt32(GetArgument(args, "duration"));

            ConsequencesManager.ChangeHouseNotation(house, amount, duration);
        }
            );
        actionFunctions.Add(
            "DECREASE_MOOD_FOR_POPULATION", (args, context) => {
            Population pop = GameManager.instance.populationManager.GetPopulationByCodename(GetArgument(args, "population"));
            if (pop == null)
            {
                List <string> pops = new List <string>();
                foreach (Population existingPop in GameManager.instance.populationManager.populationTypeList)
                {
                    pops.Add(existingPop.codeName);
                }
                Throw("Invalid population name :\n " + args + "\nPick one from the following : " + string.Join(", ", pops.ToArray()));
            }
            int duration = System.Convert.ToInt32(GetArgument(args, "duration"));
            int amount   = System.Convert.ToInt32(GetArgument(args, "amount"));

            int eventId = ((ObjectInteger)context["_EVENT_ID"]).ToInt();

            ConsequencesManager.GenerateMoodModifier(pop, -amount, duration, eventId);
        }
            );
        actionFunctions.Add(
            "ADD_FLAG_MODIFIER_ON_BUILDING_FOR_DURATION", (args, context) => {
            Block block = null;
            try {
                block = (Block)context[GetArgument(args, "building")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }
            int duration        = System.Convert.ToInt32(GetArgument(args, "duration"));
            string flagModifier = GetArgument(args, "flagModifier");

            ConsequencesManager.ModifyFlag(block, flagModifier, duration);
        }
            );
        actionFunctions.Add(
            "ADD_FLAG_ON_BUILDING_FOR_DURATION", (args, context) => {
            Block block = null;
            try {
                block = (Block)context[GetArgument(args, "building")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }
            int duration = System.Convert.ToInt32(GetArgument(args, "duration"));
            string flag  = GetArgument(args, "flag");

            ConsequencesManager.GenerateTempFlag(block, flag, duration);
        }
            );
        actionFunctions.Add(
            "ADD_FLAG_ON_BUILDING", (args, context) => {
            Block block = null;
            try {
                block = (Block)context[GetArgument(args, "building")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }
            string flag = GetArgument(args, "flag");
            ConsequencesManager.GenerateFlag(block, flag);
        }
            );
        actionFunctions.Add(
            "ADD_STATE_ON_BUILDING", (args, context) => {
            Block block = null;
            try {
                block = (Block)context[GetArgument(args, "building")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }

            State state = (State)System.Enum.Parse(typeof(State), GetArgument(args, "state"));

            ConsequencesManager.AddState(block, state);
        }
            );
        actionFunctions.Add(
            "ADD_SETTLERS_TO_NEXT_WAVE", (args, context) => {
            Population pop = GameManager.instance.populationManager.GetPopulationByCodename(GetArgument(args, "population"));
            if (pop == null)
            {
                List <string> pops = new List <string>();
                foreach (Population existingPop in GameManager.instance.populationManager.populationTypeList)
                {
                    pops.Add(existingPop.codeName);
                }
                Throw("Invalid population name :\n " + args + "\nPick one from the following : " + string.Join(", ", pops.ToArray()));
            }
            int amount = System.Convert.ToInt32(GetArgument(args, "amount"));

            ConsequencesManager.AddSettlerBonusForNextWave(pop, amount);
        }
            );
        actionFunctions.Add(
            "DESTROY_BUILDING", (args, context) => {
            Block block = null;
            try {
                block = (Block)context[GetArgument(args, "building")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }
            ConsequencesManager.DestroyBlock(block);
        }
            );
        actionFunctions.Add(
            "CHANGE_BUILDING_SCHEME", (args, context) => {
            Block block = null;
            try {
                block = (Block)context[GetArgument(args, "building")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }

            BlockScheme scheme = null;
            try {
                scheme = (BlockScheme)context[GetArgument(args, "scheme")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }

            int id           = System.Convert.ToInt32(GetArgument(args, "id"));
            BlockScheme into = GameManager.instance.library.GetBlockByID(id);
            ConsequencesManager.ConvertBlock(block, into);
        }
            );
        actionFunctions.Add(
            "LAY_MULTIPLE_SCHEME_ON_POSITION", (args, context) => {
            BlockScheme scheme = null;
            try {
                scheme = (BlockScheme)context[GetArgument(args, "scheme")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }

            int amount          = System.Convert.ToInt32(GetArgument(args, "amount"));
            Vector3Int position = ((ObjectPosition)context[GetArgument(args, "position")]).ToVector3Int();

            ConsequencesManager.SpawnBlocksAtLocation(amount, scheme.ID, new Vector2Int(position.x, position.z));
        }
            );
        actionFunctions.Add(
            "LAY_SCHEME_ON_POSITION", (args, context) => {
            args = AddArgument(args, "amount:1");
            actionFunctions["LAY_MULTIPLE_SCHEME_ON_POSITION"](args, context);
        }
            );
        actionFunctions.Add(
            "REMOVE_FLAG_FROM_BUILDING", (args, context) => {
            Block block = null;
            try {
                block = (Block)context[GetArgument(args, "building")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }
            string flag = GetArgument(args, "flag");

            ConsequencesManager.DestroyFlag(block, System.Type.GetType(flag));
        }
            );
        actionFunctions.Add(
            "REMOVE_FLAG_FROM_BUILDING_FOR_DURATION", (args, context) => {
            Block block = null;
            try {
                block = (Block)context[GetArgument(args, "building")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }
            int duration = System.Convert.ToInt32(GetArgument(args, "duration"));
            string flag  = GetArgument(args, "flag");
            ConsequencesManager.DestroyFlagTemporarily(block, System.Type.GetType(flag), duration);
        }
            );
        actionFunctions.Add(
            "GAME_OVER", (args, context) => {
            GameManager.instance.ExitToMenu();
        }
            );
        actionFunctions.Add(
            "TRIGGER_EVENT", (args, context) => {
            int eventId = System.Convert.ToInt32(GetArgument(args, "id"));
            GameManager.instance.eventManager.TriggerEvent(eventId);
        }
            );
        actionFunctions.Add(
            "DECLARE_EVENT", (args, context) => {
            int eventId          = System.Convert.ToInt32(GetArgument(args, "id"));
            context["_EVENT_ID"] = new ObjectInteger(eventId);
        }
            );
        actionFunctions.Add(
            "DECLARE_ACHIEVEMENT", (args, context) => {
            int eventId = System.Convert.ToInt32(GetArgument(args, "id"));
            context["_ACHIEVEMENT_ID"] = new ObjectInteger(eventId);
        }
            );
        actionFunctions.Add(
            "ECHO", (args, context) => {
            Debug.Log("[SCRIPT ECHO] " + args);
        }
            );
        actionFunctions.Add(
            "UNLOCK_ACHIEVEMENT", (args, context) => {
            int achievementId = System.Convert.ToInt32(GetArgument(args, "id"));
            GameManager.instance.achievementManager.achiever.UnlockAchievement(achievementId);
        }
            );
    }
示例#19
0
    void LoadDataFunctions()
    {
        dataFunctions.Clear();
        dataFunctions.Add(
            "RANDOM_BUILDING", (args, ctx) => {
            int id      = System.Convert.ToInt32(GetArgument(args, "id"));
            Block block = ConsequencesManager.GetRandomBuildingOfId(id);
            if (block == null)
            {
                Throw("Could not find any building of ID " + id.ToString());
            }
            return(block);
        }
            );
        dataFunctions.Add(
            "BUILDING_COUNT", (args, ctx) => {
            int id    = System.Convert.ToInt32(GetArgument(args, "scheme_id"));
            int count = GameManager.instance.systemManager.AllBlocks.FindAll(o => o.scheme.ID == id).Count;
            return(new ObjectInteger(count));
        }
            );
        dataFunctions.Add(
            "MOOD", (args, ctx) => {
            Population pop = GameManager.instance.populationManager.GetPopulationByCodename(GetArgument(args, "population"));
            if (pop == null)
            {
                List <string> pops = new List <string>();
                foreach (Population existingPop in GameManager.instance.populationManager.populationTypeList)
                {
                    pops.Add(existingPop.codeName);
                }
                Throw("Invalid population name :\n " + args + "\nPick one from the following : " + string.Join(", ", pops.ToArray()));
            }
            return(new ObjectInteger(Mathf.RoundToInt(GameManager.instance.populationManager.GetAverageMood(pop))));
        }
            );
        dataFunctions.Add(
            "CITIZEN_COUNT", (args, ctx) => {
            Population pop = GameManager.instance.populationManager.GetPopulationByCodename(GetArgument(args, "population"));
            if (pop == null)
            {
                List <string> pops = new List <string>();
                foreach (Population existingPop in GameManager.instance.populationManager.populationTypeList)
                {
                    pops.Add(existingPop.codeName);
                }
                Throw("Invalid population name :\n " + args + "\nPick one from the following : " + string.Join(", ", pops.ToArray()));
            }
            return(new ObjectInteger(GameManager.instance.populationManager.populations[pop].citizens.Count));
        }
            );
        dataFunctions.Add(
            "RANDOM_HOUSE", (args, ctx) =>
        {
            Population pop = GameManager.instance.populationManager.GetPopulationByCodename(GetArgument(args, "population"));
            if (pop == null)
            {
                List <string> pops = new List <string>();
                foreach (Population existingPop in GameManager.instance.populationManager.populationTypeList)
                {
                    pops.Add(existingPop.codeName);
                }
                Throw("Invalid population name :\n " + args + "\nPick one from the following : " + string.Join(", ", pops.ToArray()));
            }
            House house = ConsequencesManager.GetRandomHouseOf(pop);
            if (house == null)
            {
                Throw("Could not find house belonging to pop " + pop.codeName);
            }
            return(house);
        }
            );
        dataFunctions.Add(
            "RANDOM_POSITION", (args, ctx) =>
        {
            Vector2Int coords2D = GameManager.instance.gridManagement.GetRandomCoordinates();
            Vector3Int coords   = new Vector3Int(coords2D.x, GameManager.instance.gridManagement.minHeight, coords2D.y);

            return(new ObjectPosition()
            {
                x = coords.x,
                y = coords.y,
                z = coords.z
            });
        }
            );
        dataFunctions.Add(
            "SCHEME", (args, ctx) =>
        {
            int id             = System.Convert.ToInt32(GetArgument(args, "id"));
            BlockScheme scheme = GameManager.instance.library.GetBlockByID(id);
            if (scheme == null)
            {
                Throw("Invalid scheme id :" + id.ToString());
            }
            return(scheme);
        }
            );
        dataFunctions.Add(
            "BUILDING_FROM_HOUSE", (args, ctx) =>
        {
            House house = null;
            try {
                house = (House)ctx[GetArgument(args, "house")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }

            return(house.block);
        }
            );
        dataFunctions.Add(
            "POSITION_FROM_BUILDING", (args, ctx) =>
        {
            Block block = null;
            try {
                block = (Block)ctx[GetArgument(args, "building")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }

            return(new ObjectPosition()
            {
                x = block.gridCoordinates.x,
                y = block.gridCoordinates.y,
                z = block.gridCoordinates.z
            });
        }
            );
        dataFunctions.Add(
            "SCHEME_FROM_BUILDING", (args, ctx) =>
        {
            Block block = null;
            try {
                block = (Block)ctx[GetArgument(args, "building")];
            }
            catch (System.Exception e) {
                Throw("Impossible cast in " + args + "\n" + e.ToString());
            }

            return(block.scheme);
        }
            );
    }
示例#20
0
    public static List <Entry> GetBuildingTooltip(BlockScheme scheme, List <Entry> _entries = null)
    {
        List <Entry> entries = new List <Entry>();

        entries.Add(new Entry("block" + scheme.ID.ToString(), "blockName", informationType.Neutral));
        entries.Add(new Entry("block" + scheme.ID.ToString(), "blockDescription", informationType.Neutral));
        entries.Add(new Entry(entryType.LineBreak));

        // Porting previous block tooltip entries to this list
        if (_entries != null)
        {
            foreach (Entry tte in _entries)
            {
                entries.Add(tte);
            }
            entries.Add(new Entry(entryType.LineBreak));
        }

        // Flag reading to get the block bonuses and maluses
        foreach (List <string> flag in FlagReader.GetFlags(scheme))
        {
            string name = flag[0];
            flag.Remove(name);
            string[] parameters = flag.ToArray();

            for (int i = 0; i < parameters.Length; i++)
            {
                string popInfo = "";
                bool   wasPop  = false;
                foreach (string popName in parameters[i].Split('-'))
                {
                    if (GameManager.instance.populationManager.GetPopulationByCodename(popName) != null)
                    {
                        if (popInfo.Length > 0)
                        {
                            popInfo += " " + GameManager.instance.localization.GetLineFromCategory("stats", "orSeparator") + " ";
                        }
                        popInfo += GameManager.instance.localization.GetLineFromCategory("populationType", popName);
                        wasPop   = true;
                    }
                }
                if (wasPop)
                {
                    parameters[i] = popInfo;
                }
            }

            entries.Add(new Entry(
                            name.ToLower(), "flagParameter", FlagReader.IsPositive(name) ? informationType.Positive : informationType.Negative, parameters
                            ));
        }

        // Conditional unlocking
        ConditionalUnlocks unlocker = GameManager.instance.cityManager.conditionalUnlocker;

        if (!unlocker.CanBeUnlocked(scheme.ID))
        {
            entries.Add(new Entry(entryType.LineBreak));

            // Bold line
            entries.Add(new Entry(
                            "toUnlockThisBuildingYouMust", "conditionalUnlock", informationType.Neutral
                            )
            {
                formatters = new string[1] {
                    "b"
                }
            });

            // Condition (= <= >= < >)
            foreach (ScriptInterpreter.FormattedComparison condition in unlocker.GetFormattedUnlockConditions(scheme.ID))
            {
                // If Int, no need to tranlate it

                entries.Add(new Entry(
                                condition.oprtr, "conditionalUnlock", informationType.Negative,
                                condition.lefthandData.GetLocalization(GameManager.instance.localization),
                                condition.righthandData.GetLocalization(GameManager.instance.localization)
                                ));
            }
        }

        return(entries);
    }