Exemple #1
0
    void RecruitSoldiers(RecruitmentCamp camp)
    {
        int count = camp.current;

        AddSoldiers(count);
        camp.SetCurrent(0);
    }
Exemple #2
0
    void ShowMovementCursor(Tile tile)
    {
        hoveredTile = tile;
        movementCursor.transform.position = tile.transform.position;

        if (tile.hasMonsters)
        {
            movementCursor.transform.Find("Standard").gameObject.SetActive(false);
            movementCursor.transform.Find("Flag").gameObject.SetActive(false);
            movementCursor.transform.Find("Fight").gameObject.SetActive(true);
            movementCursor.SetActive(true);
            return;
        }
        ;

        RecruitmentCamp camp = tile.GetRecruitmentCamp();

        if (camp != null && camp.current > 0)
        {
            movementCursor.transform.Find("Standard").gameObject.SetActive(false);
            movementCursor.transform.Find("Flag").gameObject.SetActive(true);
            movementCursor.transform.Find("Fight").gameObject.SetActive(false);
            movementCursor.SetActive(true);
            return;
        }

        movementCursor.transform.Find("Standard").gameObject.SetActive(true);
        movementCursor.transform.Find("Flag").gameObject.SetActive(false);
        movementCursor.transform.Find("Fight").gameObject.SetActive(false);
        movementCursor.SetActive(true);
    }
Exemple #3
0
    void GenerateMap()
    {
        tileContainer = new Tile[mapHeight, mapWidth];
        mapDX         = mapWidth / 2;
        mapDY         = mapHeight / 2;
        for (var j = 0; j < mapHeight; j++)
        {
            for (var i = 0; i < mapWidth; i++)
            {
                int x = i - mapDX;
                int y = j - mapDY;

                float      pX         = x * tilePrefab.transform.localScale.x;
                float      pZ         = y * tilePrefab.transform.localScale.z;
                Vector3    position   = new Vector3(pX, 0.0f, pZ);
                Quaternion rotation   = new Quaternion();
                Tile       groundTile = Instantiate(tilePrefab, position, rotation, worldMap.transform) as Tile;
                groundTile.gamePosition = new Vector2i(x, y);
                groundTile.GetComponent <Renderer>().material.color = new Color(0.375f, 0.375f, 0.375f);
                groundTile.passable = terrainPassable[y + mapDY, x + mapDX];

                if (!terrainPassable[y + mapDY, x + mapDX])
                {
                    Instantiate(obstaclePrefab, groundTile.transform);
                }
                if (PersistentData.state != PersistentData.State.ExitingCombat)
                {
                    if (camps[y + mapDY, x + mapDX] > 0)
                    {
                        RecruitmentCamp camp = Instantiate(recruitmentCampPrefab, groundTile.transform);
                        camp.transform.position = position;
                        camp.SetMax(10);
                        camp.SetCurrent(5);
                        camp.gamePosition = new Vector2i(x, y);
                        recruitmentCamps.Add(camp);
                    }

                    if (monsters[y + mapDY, x + mapDX] > -1)
                    {
                        int id    = monsters[y + mapDY, x + mapDX];
                        int count = monsterGroups[id].GetGroupCount();
                        monsterGroups[id].gamePosition = new Vector2i(x, y);
                        GameObject mgPrefab = GetMonsterGroupPrefab(count);
                        GameObject mgIcon   = Instantiate(mgPrefab, groundTile.transform);
                        mgIcon.transform.localScale = new Vector3(1.0f, 10.0f, 1.0f);
                        groundTile.hasMonsters      = true;
                    }
                }

                tileContainer[y + mapDY, x + mapDX] = groundTile;
            }
        }
    }
Exemple #4
0
    void NextStep()
    {
        if (nextTile && nextTile.hasMonsters)
        {
            followingPath = false;
            EnterCombat();
            return;
        }

        if (nextTile)
        {
            RecruitmentCamp camp = nextTile.GetRecruitmentCamp();
            if (camp != null && camp.current > 0)
            {
                RecruitSoldiers(camp);
            }
        }

        if (stopFollowing)
        {
            followingPath = false;
            if (nextStep > 0)
            {
                UpdatePath();
            }
            return;
        }

        if (nextStep == currentPath.Count - 1)
        {
            followingPath = false;
            if (nextStep > 0)
            {
                UpdatePath();
            }
            return;
        }

        if (player.movementCurrent == 0)
        {
            followingPath = false;
            if (nextStep > 0)
            {
                UpdatePath();
            }
            return;
        }

        SetPlayerMovement(player.movementCurrent - 1);
        Vector2i currentPosition = currentPath[nextStep].position;

        nextStep++;
        Vector2i nextPosition = currentPath[nextStep].position;

        nextTile            = tileContainer[nextPosition.y + mapHeight / 2, nextPosition.x + mapWidth / 2];
        player.gamePosition = nextTile.gamePosition;

        Vector2i direction = nextPosition - currentPosition;
        float    angle     = Vector3.SignedAngle(new Vector3(direction.x, 0.0f, direction.y), transform.forward, transform.up);

        player.transform.rotation = Quaternion.Euler(0.0f, -angle, 0.0f);

        // check if the next path marker is the arrow or the turn number and remove it
        if (pathDisplay.transform.childCount > 0)
        {
            GameObject nextArrow         = pathDisplay.transform.GetChild(0).gameObject;
            Vector2i   nextArrowPosition = new Vector2i((int)nextArrow.transform.position.x, (int)nextArrow.transform.position.z);
            if (nextArrowPosition.x == nextPosition.x && nextArrowPosition.y == nextPosition.y)
            {
                Destroy(nextArrow);
                return;
            }
        }

        if (pathTurnsContainer.transform.childCount > 0)
        {
            GameObject nextTurn         = pathTurnsContainer.transform.GetChild(0).gameObject;
            Vector2i   nextTurnPosition = new Vector2i((int)nextTurn.transform.position.x, (int)nextTurn.transform.position.z);
            if (nextTurnPosition.x == nextPosition.x && nextTurnPosition.y == nextPosition.y)
            {
                Destroy(nextTurn);
                return;
            }
        }
    }
Exemple #5
0
    void Start()
    {
        state = State.Playing;

        Creatures.PrepareCreatures();

        playerArmies = new List <Army>();
        if (PersistentData.state == PersistentData.State.ExitingCombat)
        {
            MonsterGroup pa = PersistentData.playerArmy;
            for (int i = 0; i < pa.armyCount; i++)
            {
                AddSoldiers(pa.armies[i].count);
            }
            ;
        }
        else
        {
            AddSoldiers(5);
            AddSoldiers(5);
            AddSoldiers(5);
        }

        recruitmentCamps = new List <RecruitmentCamp>();

        if (PersistentData.state == PersistentData.State.ExitingCombat)
        {
            monsterGroups     = PersistentData.monsterGroups.ToArray();
            monsterGroupCount = PersistentData.monsterGroups.Count;
        }
        else
        {
            PrepareMonsterGroups();
        }

        GenerateMap();

        if (PersistentData.state == PersistentData.State.ExitingCombat)
        {
            List <SavedCamp> camps = PersistentData.recruitmentCamps;

            for (int i = 0; i < camps.Count; i++)
            {
                SavedCamp       camp  = camps[i];
                RecruitmentCamp rCamp = Instantiate(recruitmentCampPrefab, tileContainer[camp.gamePosition.y + mapDY, camp.gamePosition.x + mapDX].transform);
                rCamp.transform.position = tileContainer[camp.gamePosition.y + mapDY, camp.gamePosition.x + mapDX].transform.position;
                rCamp.SetMax(camp.max);
                rCamp.SetCurrent(camp.current);
                rCamp.gamePosition = camp.gamePosition;
                recruitmentCamps.Add(rCamp);
            }

            for (int i = 0; i < monsterGroupCount; i++)
            {
                MonsterGroup group    = monsterGroups[i];
                int          count    = group.GetGroupCount();
                GameObject   mgPrefab = GetMonsterGroupPrefab(count);
                GameObject   mgIcon   = Instantiate(mgPrefab, tileContainer[group.gamePosition.y + mapDY, group.gamePosition.x + mapDX].transform);
                mgIcon.transform.localScale = new Vector3(1.0f, 10.0f, 1.0f);
                tileContainer[group.gamePosition.y + mapDY, group.gamePosition.x + mapDX].hasMonsters = true;
            }
        }

        mainCamera = Camera.main.gameObject.GetComponent <CameraController>();
        mainCamera.SetConstraint(
            -mapWidth / 2 * tilePrefab.transform.localScale.x + 4,
            mapWidth / 2 * tilePrefab.transform.localScale.x + 4,
            5,
            5,
            -mapHeight / 2 * tilePrefab.transform.localScale.z - 3,
            mapHeight / 2 * tilePrefab.transform.localScale.z - 3
            );

        if (PersistentData.state == PersistentData.State.ExitingCombat)
        {
            Vector2i position = PersistentData.playerPosition;
            player.SetPosition(position.x, position.y);
        }
        else
        {
            player.SetPosition(3, -4);
        }

        pathfinder = new Pathfinder();
        pathfinder.SetTerrain(terrainPassable);

        if (PersistentData.state == PersistentData.State.ExitingCombat)
        {
            currentDay   = PersistentData.day;
            currentWeek  = PersistentData.week;
            currentMonth = PersistentData.month;
        }
        else
        {
            currentDay   = 1;
            currentWeek  = 1;
            currentMonth = 1;
        }

        if (PersistentData.state == PersistentData.State.ExitingCombat)
        {
            SetPlayerMovement(PersistentData.movementPoints);
        }
        else
        {
            SetPlayerMovement(6);
        }

        monthValue.text   = currentMonth.ToString();
        weekValue.text    = currentWeek.ToString();
        dayValue.text     = currentDay.ToString();
        weekdayValue.text = ((WeekDay)currentDay).ToString();

        if (monsterGroupCount == 0)
        {
            victory.gameObject.SetActive(true);
        }

        PersistentData.state = PersistentData.State.WorldMap;

#if UNITY_EDITOR
        DynamicGI.UpdateEnvironment();
#endif
    }