コード例 #1
0
        public Structure SpawnStructure(Structure structure)
        {
            var chunk    = Loc.GetMap().GetChunkForCell(structure.Cell);
            var renderer = InstantiateNewStructureMeshRenderer(structure, chunk.transform);
            //var renderer = InstantiateNewStructureMeshRenderer(structure, transform);

            var structureRenderer = renderer.gameObject.AddComponent <StructureRenderer>();

            structure.Renderer         = structureRenderer;
            structureRenderer.Data     = structure;
            structureRenderer.Renderer = renderer;

            IndexStructure(structure);

            structureRenderer.transform.name = structure.Name + " " + structure.Id;
            structureRenderer.UpdatePosition(chunk);

            if (structure is WorkStructureBase workStructure)
            {
                workStructure.Initialize();
                workStructure.PlaceDefaultOrder();
            }

            return(structure);
        }
コード例 #2
0
        internal bool Place(Cell origin, Faction faction)
        {
            var x = 0;
            var y = 0;

            foreach (var line in FlippedPlan)
            {
                foreach (var character in line)
                {
                    if (character == '.')
                    {
                        x++;
                        continue;
                    }

                    var cell = Loc.GetMap().GetCellAtCoordinate(origin.X + x, origin.Z + y);

                    Loc.GetStructureController().SpawnBlueprint(GetStructure(character), cell, faction);
                    x++;
                }
                x = 0;
                y++;
            }
            return(true);
        }
コード例 #3
0
ファイル: CursorController.cs プロジェクト: EttienneS/karthus
        private bool SelectCreatures(List <CreatureRenderer> creatures, bool selectSimilar)
        {
            if (creatures.Count == 1 && selectSimilar)
            {
                var creature = creatures[0].Data;
                creatures = Loc.GetMap().GetCircle(creature.Cell, DoubleClickRadius)
                            .SelectMany(c => c.Creatures)
                            .Where(c => c.BehaviourName == creature.BehaviourName)
                            .Select(c => c.CreatureRenderer)
                            .ToList();
            }

            foreach (var creature in creatures)
            {
                creature.EnableHighlight(ColorConstants.GreenAccent);
            }

            if (creatures?.Count > 0)
            {
                Loc.GetGameController().ShowCreaturePanel(creatures);
                return(true);
            }

            return(false);
        }
コード例 #4
0
    private void OnDrawGizmos()
    {
        if (Data.UnableToFindPath)
        {
            Gizmos.color = ColorConstants.RedBase;
        }
        else
        {
            Gizmos.color = ColorConstants.GreenBase;
        }
        try
        {
            if (Data.CurrentPathRequest.Ready())
            {
                Cell lastNode = null;
                foreach (var cell in Data.CurrentPathRequest.GetPath().ConvertAll(c => c as Cell))
                {
                    if (lastNode != null)
                    {
                        Gizmos.DrawLine(lastNode.Vector + new Vector3(0, 1, 0), cell.Vector + new Vector3(0, 1, 0));
                    }
                    lastNode = cell;
                }
            }
        }
        catch
        {
        }

        Gizmos.DrawCube(Loc.GetMap().GetCellAtCoordinate(Data.TargetCoordinate.x, Data.TargetCoordinate.z).Vector + new Vector3(0, 1, 0), new Vector3(0.1f, 0.1f, 0.1f));
    }
コード例 #5
0
 private void MoveZoneLabel(ZoneBase zone, ZoneLabel label)
 {
     var(bottomLeft, bottomRight, topLeft, topRight) = Loc.GetMap().GetCorners(zone.ZoneCells.GetCells());
     label.transform.localPosition = new Vector3((bottomLeft.X + bottomRight.X + topLeft.X + topRight.X) / 4f,
                                                 (bottomLeft.Z + bottomRight.Z + topLeft.Z + topRight.Z) / 4f, 0);
     label.transform.localPosition += new Vector3(0.5f, 0.5f);
 }
コード例 #6
0
 private void FindShoreOptions(CreatureData creature)
 {
     _shoreOptions = Loc.GetMap().Cells
                     .Where(c => c.BiomeRegion.Name == "Water")
                     .SelectMany(c => c.NonNullNeighbors)
                     .Where(n => n.PathableWith(creature.Mobility))
                     .OrderBy(c => c.DistanceTo(creature.Cell))
                     .ToList();
 }
コード例 #7
0
 private void EnsureCellsLoaded()
 {
     if (_cells?.Count == 0 && !string.IsNullOrEmpty(_cellString))
     {
         foreach (var xy in _cellString.Split(new[] { ',' }, System.StringSplitOptions.RemoveEmptyEntries))
         {
             var split = xy.Split(':').Select(i => int.Parse(i)).ToList();
             _cells.Add(Loc.GetMap().GetCellAtCoordinate(split[0], split[1]));
         }
     }
 }
コード例 #8
0
    private static string MoveCreature(string args)
    {
        var parts    = args.Split(' ');
        var creature = GetCreature(parts[0]);
        var cell     = Loc.GetMap().GetCellAtCoordinate(float.Parse(parts[1]), float.Parse(parts[2]));

        creature.X = cell.X;
        creature.Z = cell.Z;
        creature.CreatureRenderer.UpdatePosition();

        return($"Move {creature.Name} to {creature.Cell}");
    }
コード例 #9
0
ファイル: CameraController.cs プロジェクト: EttienneS/karthus
        public void Initialize()
        {
            var map = Loc.GetMap();

            ConfigureMinMax(map.MinX, map.MinX, map.MinX, map.MinX);

            newPosition = transform.position;
            newRotation = transform.rotation;
            newZoom     = Camera.transform.localPosition;

            MoveToWorldCenter();
        }
コード例 #10
0
ファイル: Faction.cs プロジェクト: EttienneS/karthus
    internal void AddStructure(Structure structure)
    {
        if (!Structures.Contains(structure))
        {
            Structures.Add(structure);
        }
        structure.FactionName = FactionName;

        if (FactionName != FactionConstants.World)
        {
            DomainCells.AddCells(Loc.GetMap().GetCircle(structure.Cell, 5));
        }
    }
コード例 #11
0
 public static Save MakeSave()
 {
     return(new Save
     {
         MapGenerationData = MapGenerationData.Instance,
         Factions = Loc.GetFactionController().Factions.Values.ToList(),
         Time = Loc.GetTimeManager().Data,
         Items = Loc.GetIdService().ItemIdLookup.Values.ToList(),
         CameraData = new CameraData(Loc.GetCamera()),
         Rooms = Loc.GetZoneController().RoomZones,
         Stores = Loc.GetZoneController().StorageZones,
         Areas = Loc.GetZoneController().AreaZones,
         Chunks = Loc.GetMap().Chunks.Values.Select(s => s.Data).ToList(),
     });
 }
コード例 #12
0
 public Idle(CreatureData creature) : this()
 {
     if (Random.value > 0.7)
     {
         var wanderCircle = Loc.GetMap().GetCircle(creature.Cell, 3).Where(c => c.TravelCost > 0 && c.TravelCost < 10).ToList();
         wanderCircle.Remove(creature.Cell);
         if (wanderCircle.Count > 0)
         {
             AddSubTask(new Move(wanderCircle.GetRandomItem()));
         }
     }
     else
     {
         AddSubTask(new Wait(Random.Range(2, 4), "Wait", AnimationType.Idle));
     }
 }
コード例 #13
0
ファイル: PersonBehavior.cs プロジェクト: EttienneS/karthus
        public CreatureTask GetTask(CreatureData creature)
        {
            var wound = creature.GetWorstWound();

            if (wound != null)
            {
                return(new Heal());
            }
            else if (creature.Cell.Creatures.Count > 1)
            {
                // split up
                return(new Move(Loc.GetMap().TryGetPathableNeighbour(creature.Cell)));
            }

            return(null);
        }
コード例 #14
0
ファイル: ItemController.cs プロジェクト: EttienneS/karthus
    internal void SpawnItem(ItemData data)
    {
        var mesh = Loc.GetGameController().MeshRendererFactory
                   .GetItemMesh(data.Mesh);

        var meshObject = Instantiate(mesh, transform);

        var itemRenderer = meshObject.gameObject.AddComponent <ItemRenderer>();

        itemRenderer.Data = data;
        data.Renderer     = itemRenderer;

        IndexItem(data);

        data.Cell = Loc.GetMap().GetCellAtCoordinate(new Vector3(data.Coords.X, 0, data.Coords.Z));
        itemRenderer.UpdatePosition();
    }
コード例 #15
0
ファイル: GrazerBehavior.cs プロジェクト: EttienneS/karthus
        public CreatureTask GetTask(CreatureData creature)
        {
            var creatures = creature.Awareness.SelectMany(c => c.Creatures);

            var enemies = creatures.Where(c => c.FactionName != creature.FactionName);
            var herd    = creatures.Where(c => c.FactionName == creature.FactionName);

            if (enemies.Any())
            {
                var target = Loc.GetMap().GetCellAttRadian(enemies.GetRandomItem().Cell, 10, Random.Range(1, 360));
                return(new Move(target));
            }
            else if (herd.Any())
            {
                return(new Move(Loc.GetMap().GetCircle(herd.GetRandomItem().Cell, 3).GetRandomItem()));
            }

            return(null);
        }
コード例 #16
0
    public override bool Done(CreatureData creature)
    {
        if (SubTasksComplete(creature))
        {
            if (!creature.Cell.Neighbors.Contains(StructureToRemove.Cell))
            {
                var pathable = Loc.GetMap().TryGetPathableNeighbour(StructureToRemove.Cell);

                if (pathable != null)
                {
                    AddSubTask(new Move(pathable));
                }
                else
                {
                    creature.SuspendTask(true);
                    return(false);
                }
            }

            if (!Decontructed)
            {
                creature.Face(StructureToRemove.Cell);
                AddSubTask(new Wait(StructureToRemove.Cost.Items.Sum(c => c.Value) + 1, "Deconstructing...", AnimationType.Interact));
                Decontructed = true;
                return(false);
            }

            foreach (var item in StructureToRemove.Cost.Items)
            {
                var spawnedItem = Loc.GetItemController().SpawnItem(item.Key, StructureToRemove.Cell);
                spawnedItem.Amount      = item.Value;
                spawnedItem.FactionName = creature.FactionName;
            }

            Loc.GetStructureController().DestroyStructure(StructureToRemove);
            StructureToRemove = null;
            return(true);
        }

        return(false);
    }
コード例 #17
0
        internal bool ValidateStartPos(Cell cellData)
        {
            var x = 0;
            var z = 0;

            foreach (var line in FlippedPlan)
            {
                foreach (var character in line)
                {
                    if (character == '.')
                    {
                        x++;
                        continue;
                    }
                    var cell = Loc.GetMap().GetCellAtCoordinate(cellData.X + x, cellData.Z + z);

                    if (cell.TravelCost > 0)
                    {
                        var currentStructure = cell.Structures.FirstOrDefault();
                        if (currentStructure != null)
                        {
                            var characterStructure = GetStructure(character);
                            if (currentStructure.Buildable && !currentStructure.Name.Equals(characterStructure))
                            {
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        return(false);
                    }

                    x++;
                }
                x = 0;
                z++;
            }
            return(true);
        }
コード例 #18
0
ファイル: CursorController.cs プロジェクト: EttienneS/karthus
        private bool SelectStructures(List <Structure> structures, bool selectSimilar)
        {
            if (structures.Count == 1 && selectSimilar)
            {
                var structure = structures[0];
                structures = Loc.GetMap().GetCircle(structure.Cell, DoubleClickRadius)
                             .SelectMany(c => c.Structures)
                             .Where(s => s.Name == structure.Name)
                             .ToList();
            }

            foreach (var structure in structures)
            {
                structure.ShowOutline();
            }

            if (structures.Count > 0)
            {
                Loc.GetGameController().ShowStructureInfoPanel(structures);
                return(true);
            }
            return(false);
        }
コード例 #19
0
ファイル: CursorController.cs プロジェクト: EttienneS/karthus
        private bool SelectItems(List <ItemData> items, bool selectSimilar)
        {
            if (items.Count == 1 && selectSimilar)
            {
                var item = items[0];
                items = Loc.GetMap().GetCircle(item.Cell, DoubleClickRadius)
                        .SelectMany(c => c.Items)
                        .Where(i => i.Name == item.Name)
                        .ToList();
            }

            foreach (var item in items)
            {
                item.ShowOutline();
            }

            if (items?.Count > 0)
            {
                Loc.GetGameController().ShowItemPanel(items);
                return(true);
            }
            return(false);
        }
コード例 #20
0
ファイル: CursorController.cs プロジェクト: EttienneS/karthus
        private List <Cell> GetSelectedCells()
        {
            if (_selectionStartWorld == Vector3.zero)
            {
                return(new List <Cell>());
            }
            var worldStartPoint = _selectionStartWorld;
            var worldEndPoint   = GetWorldMousePosition().Value;

            var cells = new List <Cell>();

            var startX = Mathf.Clamp(Mathf.Min(worldStartPoint.x, worldEndPoint.x), Loc.GetMap().MinX, Loc.GetMap().MaxX);
            var endX   = Mathf.Clamp(Mathf.Max(worldStartPoint.x, worldEndPoint.x), Loc.GetMap().MinX, Loc.GetMap().MaxX);

            var startZ = Mathf.Clamp(Mathf.Min(worldStartPoint.z, worldEndPoint.z), Loc.GetMap().MinZ, Loc.GetMap().MaxZ);
            var endZ   = Mathf.Clamp(Mathf.Max(worldStartPoint.z, worldEndPoint.z), Loc.GetMap().MinX, Loc.GetMap().MaxZ);

            if (startX == endX && startZ == endZ)
            {
                var point = new Vector3(startX, 0, startZ);

                cells.Add(GetCellForWorldPosition(point));
            }
            else
            {
                for (var selX = startX; selX < endX; selX++)
                {
                    for (var selZ = startZ; selZ < endZ; selZ++)
                    {
                        var point = new Vector3(selX, 0, selZ);
                        cells.Add(GetCellForWorldPosition(point));
                    }
                }
            }

            return(cells.Distinct().ToList());
        }
コード例 #21
0
 private static List <Cell> GetFlammableNeighbours(Cell cell)
 {
     return(Loc.GetMap().GetCircle(cell, 3)
            .Where(c => c.Structures.Any(s => s.Flammable()))
            .ToList());
 }
コード例 #22
0
ファイル: CameraController.cs プロジェクト: EttienneS/karthus
        public void ViewPoint(Vector3 point)
        {
            const int zoomBound = 12;
            var       x         = Mathf.Clamp(point.x, _minX - zoomBound, _maxX);
            var       y         = 1;
            var       z         = Mathf.Clamp(point.z - zoomBound, _minZ - zoomBound, Loc.GetMap().MaxZ);

            transform.position = new Vector3(x, y, z);
        }
コード例 #23
0
ファイル: Cell.cs プロジェクト: EttienneS/karthus
 public static Cell FromPosition(Vector3 position)
 {
     // add half a unit to each position to account for offset (cells are at point 0,0 in the very center)
     position += new Vector3(0.5f, 0, 0.5f);
     return(Loc.GetMap().GetCellAtCoordinate(Mathf.FloorToInt(position.x), Mathf.FloorToInt(position.z)));
 }
コード例 #24
0
ファイル: CursorController.cs プロジェクト: EttienneS/karthus
        private void ShowCursorEffects(List <Cell> selectedCells)
        {
            if (!string.IsNullOrEmpty(_meshName))
            {
                if (selectedCells == null || selectedCells.Count == 0)
                {
                    return;
                }

                foreach (var cell in selectedCells)
                {
                    MeshRenderer cellRenderer;
                    if (!_draggedRenderers.ContainsKey(cell))
                    {
                        cellRenderer = Loc.GetStructureController().InstantiateNewStructureMeshRenderer(_meshName, Loc.GetMap().transform);
                        cellRenderer.transform.position = new Vector3(cell.Vector.x, cell.Vector.y, cell.Vector.z);
                        _draggedRenderers.Add(cell, cellRenderer);
                    }
                    else
                    {
                        cellRenderer = _draggedRenderers[cell];
                    }

                    if (Validate?.Invoke(cell) == false)
                    {
                        cellRenderer.SetAllMaterial(Loc.GetFileController().InvalidBlueprintMaterial);
                    }
                    else
                    {
                        cellRenderer.SetAllMaterial(Loc.GetFileController().BlueprintMaterial);
                    }
                }

                foreach (var cell in _draggedRenderers.Keys.ToList())
                {
                    if (!selectedCells.Contains(cell))
                    {
                        Destroy(_draggedRenderers[cell].gameObject);
                        _draggedRenderers.Remove(cell);
                    }
                }
            }
        }
コード例 #25
0
ファイル: CursorController.cs プロジェクト: EttienneS/karthus
 private static Cell GetCellForWorldPosition(Vector3?pos)
 {
     return(Loc.GetMap().GetCellAtCoordinate(pos.Value - new Vector3(0.5f, 0, 0.5f)));
 }