예제 #1
0
 public BuildRoomOrder(Room toBuild, Faction faction)
 {
     ToBuild = toBuild;
     PutResources = new Dictionary<ResourceLibrary.ResourceType, ResourceAmount>();
     VoxelOrders = new List<BuildVoxelOrder>();
     IsBuilt = false;
     Faction = faction;
 }
예제 #2
0
 public ShipmentOrder(float time, Room destination)
 {
     BuyOrder = new List<ResourceAmount>();
     SellOrder = new List<ResourceAmount>();
     OrderTotal = 0.0f;
     OrderTimer = new Timer(time, true);
     Destination = destination;
     HasSentResources = false;
 }
예제 #3
0
        public static RoomTile[,] CreateFromRoom(Room room, ChunkManager chunks)
        {
            BoundingBox box0 = room.GetBoundingBox();
            BoundingBox box = new BoundingBox(box0.Min + Vector3.Up, box0.Max + Vector3.Up);
            BoundingBox bigBox = new BoundingBox(box0.Min + Vector3.Up + new Vector3(-1, 0, -1), box0.Max + Vector3.Up + new Vector3(1, 0, 1));
            int nr = Math.Max((int) (box.Max.X - box.Min.X), 1);
            int nc = Math.Max((int) (box.Max.Z - box.Min.Z), 1);

            RoomTile[,] toReturn = new RoomTile[nr + 2, nc + 2];

            Dictionary<Point, Voxel> voxelDict = new Dictionary<Point, Voxel>();
            List<Voxel> voxelsInRoom = chunks.GetVoxelsIntersecting(bigBox);
            foreach(Voxel vox in voxelsInRoom)
            {
                voxelDict[new Point((int)(vox.Position.X - box.Min.X) + 1, (int)(vox.Position.Z - box.Min.Z) + 1)] = vox;
            }

            for(int r = 0; r < nr + 2; r++)
            {
                for(int c = 0; c < nc + 2; c++)
                {
                    toReturn[r, c] = RoomTile.Edge;
                }
            }

            foreach(KeyValuePair<Point, Voxel> voxPair in voxelDict)
            {
                Voxel vox = voxPair.Value;
                Point p = voxPair.Key;

                if(vox.IsEmpty && p.X > 0 && p.X < nr + 1 && p.Y > 0 && p.Y < nc + 1)
                {
                    toReturn[p.X, p.Y] = RoomTile.Open;
                }
                else if(vox.TypeName != "empty")
                {
                    toReturn[p.X, p.Y] = RoomTile.Wall;
                }
            }

            return toReturn;
        }
예제 #4
0
        void destroyDialog_OnClosed(Dialog.ReturnStatus status, Room room)
        {
            if (status == Dialog.ReturnStatus.Ok)
            {
                DesignatedRooms.Remove(room);

                List<BuildVoxelOrder> existingDesignations = GetDesignationsAssociatedWithRoom(room);
                BuildRoomOrder buildRoomDes = null;
                foreach (BuildVoxelOrder des in existingDesignations)
                {
                    des.Order.VoxelOrders.Remove(des);
                    buildRoomDes = des.Order;
                }

                BuildDesignations.Remove(buildRoomDes);

                room.Destroy();
            }
        }
예제 #5
0
 public bool IsBuildDesignation(Room r)
 {
     return BuildDesignations.Any(room => room.ToBuild == r);
 }
예제 #6
0
 public List<BuildVoxelOrder> GetDesignationsAssociatedWithRoom(Room room)
 {
     return (from roomDesignation in BuildDesignations
         from des in roomDesignation.VoxelOrders
         where des.ToBuild == room
         select des).ToList();
 }
예제 #7
0
 public BuildVoxelOrder GetBuildDesignation(Room v)
 {
     return (from room in BuildDesignations
         where room.ToBuild == v
         where room.VoxelOrders.Count > 0
         select room.VoxelOrders[0]).FirstOrDefault();
 }
예제 #8
0
        public void AddShipDesignation(ResourceAmount resource, Room port)
        {
            // TODO: Reimplement
            /*
            List<Body> componentsToShip = new List<Body>();

            foreach (Stockpile s in Stockpiles)
            {
                for (int i = componentsToShip.Count; i < resource.NumResources; i++)
                {
                    Body r = s.FindItemWithTag(resource.ResourceType.ResourceName, componentsToShip);

                    if (r != null)
                    {
                        componentsToShip.Add(r);
                    }
                }
            }

            ShipDesignations.Add(new ShipOrder(resource, port));
            */
        }
예제 #9
0
 public BuildVoxelOrder(BuildRoomOrder order, Room toBuild, Voxel voxel)
 {
     Order = order;
     ToBuild = toBuild;
     Voxel = voxel;
 }
예제 #10
0
        public static void GenerateRoomComponentsTemplate(Room room, ComponentManager componentManager, Microsoft.Xna.Framework.Content.ContentManager content, GraphicsDevice graphics)
        {
            RoomTile[,] currentTiles = RoomTemplate.CreateFromRoom(room, room.Chunks);
            float[,] rotations = new float[currentTiles.GetLength(0), currentTiles.GetLength(1)];
            foreach (RoomTemplate template in room.RoomData.Templates)
            {
                for (int r = -2; r < currentTiles.GetLength(0) + 1; r++)
                {
                    for (int c = -2; c < currentTiles.GetLength(1) + 1; c++)
                    {
                        for (int rotation = 0; rotation < 5; rotation++)
                        {
                            if (MathFunctions.RandEvent(template.Probability))
                            {
                                template.PlaceTemplate(ref currentTiles, ref rotations, r, c);
                                template.RotateClockwise(1);
                            }
                        }
                    }
                }
            }

            BoundingBox box = room.GetBoundingBox();

            int thingsMade = 0;
            for(int r = 0; r < currentTiles.GetLength(0); r++)
            {
                for(int c = 0; c < currentTiles.GetLength(1); c++)
                {
                    RoomTile tile = currentTiles[r, c];
                    Body createdComponent = null;
                    Vector3 noise =
                        VertexNoise.GetNoiseVectorFromRepeatingTexture(box.Min +
                                                                       new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1));
                    switch(tile)
                    {
                        case RoomTile.Wheat:
                            createdComponent = EntityFactory.CreateEntity<Body>("Wheat", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                            thingsMade++;
                            break;

                        case RoomTile.Mushroom:
                            createdComponent = EntityFactory.CreateEntity<Body>("Mushroom", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                            thingsMade++;
                            break;

                        case RoomTile.Table:
                            createdComponent = EntityFactory.CreateEntity<Body>("Table", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                            thingsMade++;
                            break;
                        case RoomTile.Lamp:
                            createdComponent = EntityFactory.CreateEntity<Body>("Lamp", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                            thingsMade++;
                            break;
                        case RoomTile.Flag:
                            createdComponent = EntityFactory.CreateEntity<Body>("Flag", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                            thingsMade++;
                            break;
                        case RoomTile.Chair:
                            createdComponent = EntityFactory.CreateEntity<Body>("Chair", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                            thingsMade++;
                            break;
                        case RoomTile.BookTable:
                            createdComponent = EntityFactory.CreateEntity<Body>(MathFunctions.RandEvent(0.5f) ? "BookTable" : "PotionTable", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                            thingsMade++;
                            break;
                        case RoomTile.Anvil:
                            createdComponent = EntityFactory.CreateEntity<Body>("Anvil", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                            thingsMade++;
                            break;
                        case RoomTile.Forge:
                            createdComponent = EntityFactory.CreateEntity<Body>("Forge", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                            thingsMade++;
                            break;
                        case RoomTile.Target:
                            createdComponent = EntityFactory.CreateEntity<Body>("Target", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                            thingsMade++;
                            break;
                        case RoomTile.Strawman:
                            createdComponent = EntityFactory.CreateEntity<Body>("Strawman", box.Min + new Vector3(r + 0.5f - 1, 1.5f, c + 0.5f - 1) + noise);
                            thingsMade++;
                            break;
                        case RoomTile.BookShelf:
                            createdComponent = EntityFactory.CreateEntity<Body>("Bookshelf", box.Min + new Vector3(r - 1 + 0.5f, 1.5f, c - 1 + 0.5f) + noise);
                            thingsMade++;
                            break;
                        case RoomTile.Pillow:

                            for(int dx = -1; dx < 2; dx++)
                            {
                                for(int dy = -1; dy < 2; dy++)
                                {
                                    if(Math.Abs(dx) + Math.Abs(dy) != 1 || r + dx < 0 || r + dx >= currentTiles.GetLength(0) || c + dy < 0 || c + dy >= currentTiles.GetLength(1))
                                    {
                                        continue;
                                    }

                                    if(currentTiles[r + dx, c + dy] != RoomTile.Bed)
                                    {
                                        continue;
                                    }

                                    createdComponent = EntityFactory.CreateEntity<Body>("Bed", box.Min + new Vector3(r - 1 + 0.5f, 1.5f, c - 1 + 0.5f) + noise);
                                    /*
                                    float angle = (float) Math.Atan2(dx, dy);

                                    Vector3 translation = createdComponent.LocalTransform.Translation;
                                    Matrix bedRotation = Matrix.CreateRotationY(angle);
                                    createdComponent.LocalTransform = Matrix.CreateTranslation(new Vector3(-0.5f, 0, -0.5f)) * bedRotation * Matrix.CreateTranslation(new Vector3(0.5f, 0, 0.5f)) * Matrix.CreateTranslation(translation);
                                    createdComponent.BoundingBoxPos = Vector3.Transform(createdComponent.BoundingBoxPos, bedRotation);
                                    createdComponent.BoundingBox.Min = Vector3.Transform(createdComponent.BoundingBox.Min - translation, bedRotation) + translation;
                                    createdComponent.BoundingBox.Max = Vector3.Transform(createdComponent.BoundingBox.Max - translation, bedRotation) + translation;
                                     */
                                    break;
                                }
                            }

                            thingsMade++;
                            break;
                        default:
                            break;
                    }

                    if(createdComponent != null)
                    {
                        createdComponent.LocalTransform = Matrix.CreateRotationY(-(rotations[r, c] + (float)Math.PI * 0.5f)) * createdComponent.LocalTransform;
                        Vector3 endPos = createdComponent.LocalTransform.Translation;
                        Matrix offsetTransform = createdComponent.LocalTransform;
                        offsetTransform.Translation += new Vector3(0, -1, 0);
                        createdComponent.LocalTransform = offsetTransform;
                        createdComponent.AnimationQueue.Add(new EaseMotion(0.8f, offsetTransform, endPos));
                        room.AddBody(createdComponent);
                        PlayState.ParticleManager.Trigger("puff", endPos + new Vector3(0.5f, 0.5f, 0.5f), Color.White, 10);
                    }
                }
            }
        }
예제 #11
0
 public ShipOrder(ResourceAmount resource, Room port)
 {
     Resource = resource;
     Port = port;
     Assignments = new List<Task>();
 }
예제 #12
0
 public bool IsBuildDesignation(Room r)
 {
     return(BuildDesignations.Any(room => room.ToBuild == r));
 }