Exemplo n.º 1
0
        public DwarfGame()
        {
            GameState.Game = this;
            Content.RootDirectory = "Content";
            StateManager = new GameStateManager(this);
            Graphics = new GraphicsDeviceManager(this);
            Window.Title = "DwarfCorp";
            Window.AllowUserResizing = false;
            TextureManager = new TextureManager(Content, GraphicsDevice);
            GameSettings.Load();
            Graphics.IsFullScreen = GameSettings.Default.Fullscreen;
            Graphics.PreferredBackBufferWidth = GameSettings.Default.ResolutionX;
            Graphics.PreferredBackBufferHeight = GameSettings.Default.ResolutionY;

            try
            {
                Graphics.ApplyChanges();
            }
            catch(NoSuitableGraphicsDeviceException exception)
            {
                Console.Error.WriteLine(exception.Message);
            }
        }
Exemplo n.º 2
0
        public void CreateStatics(ContentManager content)
        {
            FixedInstanceArray pinetree = new FixedInstanceArray("pine", PrimitiveLibrary.BatchBillboardPrimitives["pine"], TextureManager.GetTexture(ContentPaths.Entities.Plants.pine), (int)(50 * GameSettings.Default.NumMotes), BlendState.AlphaBlend)
            {
                ShouldRebuild = true
            };

            AddInstances("pine", pinetree);

            FixedInstanceArray palmTree = new FixedInstanceArray("palm", PrimitiveLibrary.BatchBillboardPrimitives["palm"], TextureManager.GetTexture(ContentPaths.Entities.Plants.palm), (int)(50 * GameSettings.Default.NumMotes), BlendState.AlphaBlend)
            {
                ShouldRebuild = true
            };

            AddInstances("palm", palmTree);

            FixedInstanceArray snowPine = new FixedInstanceArray("snowpine", PrimitiveLibrary.BatchBillboardPrimitives["snowpine"], TextureManager.GetTexture(ContentPaths.Entities.Plants.snowpine), (int)(50 * GameSettings.Default.NumMotes), BlendState.AlphaBlend)
            {
                ShouldRebuild = true
            };

            AddInstances("snowpine", snowPine);


            CreateBillboard("berrybush", content, (int)(300 * GameSettings.Default.NumMotes));
            CreateBillboard("cactus", content, (int)(300 * GameSettings.Default.NumMotes));
            CreateBillboard("grass", content, (int)(300 * GameSettings.Default.NumMotes));
            CreateBillboard("frostgrass", content, (int)(300 * GameSettings.Default.NumMotes));
            CreateBillboard("flower", content, (int)(300 * GameSettings.Default.NumMotes));
            CreateBillboard("deadbush", content, (int)(300 * GameSettings.Default.NumMotes));
            CreateBillboard("vine", content, (int)(300 * GameSettings.Default.NumMotes));
            CreateBillboard("gnarled", content, (int)(300 * GameSettings.Default.NumMotes));
            CreateBillboard("mushroom", content, (int)(300 * GameSettings.Default.NumMotes));
        }
Exemplo n.º 3
0
 public NamedImageFrame(string name, Rectangle sourceRect)
 {
     AssetName  = name;
     Image      = TextureManager.GetTexture(name);
     SourceRect = sourceRect;
 }
Exemplo n.º 4
0
 public NamedImageFrame(string name, int frameSize, int x, int y)
 {
     AssetName  = name;
     Image      = TextureManager.GetTexture(name);
     SourceRect = new Rectangle(x * frameSize, y * frameSize, frameSize, frameSize);
 }
Exemplo n.º 5
0
 private void OnDeserialized(StreamingContext context)
 {
     Image = TextureManager.GetTexture(AssetName);
 }
Exemplo n.º 6
0
        public void Initialize(GraphicsDevice graphics, ContentManager content)
        {
            if (!m_initialized)
            {
                Texture2D spriteSheet = TextureManager.GetTexture(ContentPaths.Entities.Furniture.bedtex);
                OldBoxPrimitive.BoxTextureCoords boxCoords = new OldBoxPrimitive.BoxTextureCoords(spriteSheet.Width, spriteSheet.Height,
                                                                                                  new OldBoxPrimitive.FaceData(new Rectangle(0, 24, 24, 16), true),
                                                                                                  new OldBoxPrimitive.FaceData(new Rectangle(72, 24, 24, 16), true),
                                                                                                  new OldBoxPrimitive.FaceData(new Rectangle(24, 0, 48, 24), false),
                                                                                                  new OldBoxPrimitive.FaceData(new Rectangle(0, 0, 1, 1), true),
                                                                                                  new OldBoxPrimitive.FaceData(new Rectangle(24, 24, 48, 16), true),
                                                                                                  new OldBoxPrimitive.FaceData(new Rectangle(24, 40, 48, 16), true));
                BoxPrimitives["bed"] = new OldBoxPrimitive(graphics, 0.8f, 0.5f, 1.8f, boxCoords);

                Texture2D bookSheet = TextureManager.GetTexture(ContentPaths.Entities.Furniture.bookshelf);
                OldBoxPrimitive.BoxTextureCoords bookshelfTexture = new OldBoxPrimitive.BoxTextureCoords(bookSheet.Width, bookSheet.Height,
                                                                                                         new OldBoxPrimitive.FaceData(new Rectangle(0, 20, 20, 32), true),
                                                                                                         new OldBoxPrimitive.FaceData(new Rectangle(28, 20, 20, 32), true),
                                                                                                         new OldBoxPrimitive.FaceData(new Rectangle(20, 0, 8, 20), false),
                                                                                                         new OldBoxPrimitive.FaceData(new Rectangle(0, 0, 1, 1), true),
                                                                                                         new OldBoxPrimitive.FaceData(new Rectangle(20, 20, 8, 32), true),
                                                                                                         new OldBoxPrimitive.FaceData(new Rectangle(20, 52, 8, 32), true));
                BoxPrimitives["bookshelf"] = new OldBoxPrimitive(graphics, 20.0f / 32.0f, 32.0f / 32.0f, 8.0f / 32.0f, bookshelfTexture);

                m_initialized = false;


                Texture2D sheetTiles = TextureManager.GetTexture(ContentPaths.Terrain.terrain_tiles);
                OldBoxPrimitive.BoxTextureCoords crateCoords = new OldBoxPrimitive.BoxTextureCoords(sheetTiles.Width, sheetTiles.Height, 32, 32,
                                                                                                    new Point(7, 0),
                                                                                                    new Point(7, 0),
                                                                                                    new Point(8, 0),
                                                                                                    new Point(7, 0),
                                                                                                    new Point(7, 0),
                                                                                                    new Point(7, 0));
                BoxPrimitives["crate"] = new OldBoxPrimitive(graphics, 0.9f, 0.9f, 0.9f, crateCoords);
                m_initialized          = false;

                Texture2D     treeSheet      = TextureManager.GetTexture(ContentPaths.Entities.Plants.pine);
                Texture2D     snowpineSheet  = TextureManager.GetTexture(ContentPaths.Entities.Plants.snowpine);
                Texture2D     palmSheet      = TextureManager.GetTexture(ContentPaths.Entities.Plants.palm);
                List <Matrix> treeTransforms = new List <Matrix>();
                List <Color>  treeTints      = new List <Color>();
                treeTransforms.Add(Matrix.Identity);
                treeTransforms.Add(Matrix.CreateRotationY(1.57f));
                treeTints.Add(Color.White);
                treeTints.Add(Color.White);

                BatchBillboardPrimitives["pine"]     = new BatchBillboardPrimitive(graphics, treeSheet, treeSheet.Width, treeSheet.Height, new Point(0, 0), treeSheet.Width / 32.0f, treeSheet.Height / 32.0f, false, treeTransforms, treeTints, treeTints);
                BatchBillboardPrimitives["snowpine"] = new BatchBillboardPrimitive(graphics, snowpineSheet, snowpineSheet.Width, snowpineSheet.Height, new Point(0, 0), snowpineSheet.Width / 32.0f, snowpineSheet.Height / 32.0f, false, treeTransforms, treeTints, treeTints);
                BatchBillboardPrimitives["palm"]     = new BatchBillboardPrimitive(graphics, palmSheet, palmSheet.Width, palmSheet.Height, new Point(0, 0), palmSheet.Width / 32.0f, palmSheet.Height / 32.0f, false, treeTransforms, treeTints, treeTints);



                List <string> motes = new List <string>
                {
                    "berrybush",
                    "cactus",
                    "frostgrass",
                    "flower",
                    "grass",
                    "deadbush",
                    "mushroom",
                    "vine",
                    "gnarled"
                };

                foreach (string mote in motes)
                {
                    CreateIntersecting(mote, ProgramData.CreatePath("Entities", "Plants", mote), graphics, content);
                }
            }
        }
Exemplo n.º 7
0
        public Terrain2D(DwarfGame game)
        {
            Bloom = new BloomComponent(game)
            {
                Settings = BloomSettings.PresetSettings[0]
            };
            CaveScale     = 0.08f;
            HeightScale   = 0.01f;
            CaveThreshold = 0.5f;
            LavaHeight    = 0.6f;
            TileSize      = 64;
            Noise         = new Perlin(1928);
            Texture2D tiles = TextureManager.GetTexture(ContentPaths.Terrain.terrain_tiles);

            Substrate = new TerrainElement
            {
                Image = new ImageFrame(tiles, 32, 4, 2),
                Name  = "Rock"
            };

            Soil = new TerrainElement
            {
                Image = new ImageFrame(tiles, 32, 2, 0),
                Name  = "Dirt"
            };


            Grass = new TerrainElement
            {
                Image = new ImageFrame(tiles, 32, 3, 0),
                Name  = "Grass"
            };


            Lava = new TerrainElement
            {
                Image = new ImageFrame(tiles, 32, 0, 7),
                Name  = "Lava"
            };

            Cave = new TerrainElement
            {
                Image = new ImageFrame(tiles, 32, 1, 0),
                Name  = "Rock2"
            };



            Ores = new List <TerrainElement>
            {
                new TerrainElement
                {
                    Image          = new ImageFrame(tiles, 32, 3, 1),
                    Name           = "Gold",
                    SpawnScale     = 0.05f,
                    SpawnThreshold = 0.9f
                },
                new TerrainElement
                {
                    Image          = new ImageFrame(tiles, 32, 7, 1),
                    Name           = "Mana",
                    SpawnScale     = 0.04f,
                    SpawnThreshold = 0.9f
                }
            };

            Bloom.Initialize();
        }
Exemplo n.º 8
0
        public static RoomData InitializeData()
        {
            Dictionary <ResourceLibrary.ResourceType, ResourceAmount> bedroomResources = new Dictionary <ResourceLibrary.ResourceType, ResourceAmount>();
            ResourceAmount woodRequired = new ResourceAmount
            {
                ResourceType = ResourceLibrary.Resources[ResourceLibrary.ResourceType.Wood],
                NumResources = 1
            };

            bedroomResources[ResourceLibrary.ResourceType.Wood] = woodRequired;

            List <RoomTemplate> bedroomTemplates = new List <RoomTemplate>();

            RoomTile[,] bedTemplate =
            {
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.Wall | RoomTile.Edge,
                    RoomTile.Pillow,
                    RoomTile.Bed
                },
                {
                    RoomTile.None,
                    RoomTile.Open,
                    RoomTile.None
                }
            };

            RoomTile[,] bedAccessories =
            {
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.Chair,
                    RoomTile.None
                }
            };
            RoomTemplate bed = new RoomTemplate(PlacementType.All, bedTemplate, bedAccessories);

            RoomTile[,] lampTemplate =
            {
                {
                    RoomTile.None,
                    RoomTile.Wall | RoomTile.Edge
                },
                {
                    RoomTile.Wall | RoomTile.Edge,
                    RoomTile.Lamp
                }
            };

            RoomTile[,] lampAccessories =
            {
                {
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None
                }
            };

            RoomTemplate lamp = new RoomTemplate(PlacementType.All, lampTemplate, lampAccessories);

            bedroomTemplates.Add(lamp);
            bedroomTemplates.Add(bed);
            Texture2D roomIcons = TextureManager.GetTexture(ContentPaths.GUI.room_icons);

            return(new RoomData(BedRoomName, 0, "BrownTileFloor", bedroomResources, bedroomTemplates, new ImageFrame(roomIcons, 16, 2, 1))
            {
                Description = "Dwarves relax and rest here",
                CanBuildAboveGround = false
            });
        }
Exemplo n.º 9
0
        public static RoomData InitializeData()
        {
            RoomTile[,] lampTemplate =
            {
                {
                    RoomTile.None,
                    RoomTile.Wall | RoomTile.Edge
                },
                {
                    RoomTile.Wall | RoomTile.Edge,
                    RoomTile.Lamp
                }
            };

            RoomTile[,] lampAccessories =
            {
                {
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None
                }
            };

            RoomTemplate   lamp         = new RoomTemplate(PlacementType.All, lampTemplate, lampAccessories);
            ResourceAmount woodRequired = new ResourceAmount
            {
                ResourceType = ResourceLibrary.Resources[ResourceLibrary.ResourceType.Wood],
                NumResources = 1
            };
            Dictionary <ResourceLibrary.ResourceType, ResourceAmount> commonRoomResources = new Dictionary <ResourceLibrary.ResourceType, ResourceAmount>();

            commonRoomResources[ResourceLibrary.ResourceType.Wood] = woodRequired;

            ResourceAmount stoneRquired = new ResourceAmount
            {
                ResourceType = ResourceLibrary.Resources[ResourceLibrary.ResourceType.Stone],
                NumResources = 1
            };

            commonRoomResources[ResourceLibrary.ResourceType.Stone] = stoneRquired;


            List <RoomTemplate> commonRoomTemplates = new List <RoomTemplate>();

            RoomTile[,] tableTemps =
            {
                {
                    RoomTile.None,
                    RoomTile.Open,
                    RoomTile.None
                },
                {
                    RoomTile.Open,
                    RoomTile.Table,
                    RoomTile.Open
                },
                {
                    RoomTile.None,
                    RoomTile.Open,
                    RoomTile.None
                }
            };

            RoomTile[,] tableAcc =
            {
                {
                    RoomTile.None,
                    RoomTile.Chair,
                    RoomTile.None
                },
                {
                    RoomTile.Chair,
                    RoomTile.None,
                    RoomTile.Chair
                },
                {
                    RoomTile.None,
                    RoomTile.Chair,
                    RoomTile.None
                }
            };
            RoomTemplate table = new RoomTemplate(PlacementType.All, tableTemps, tableAcc);

            commonRoomTemplates.Add(lamp);
            commonRoomTemplates.Add(table);
            Texture2D roomIcons = TextureManager.GetTexture(ContentPaths.GUI.room_icons);

            return(new RoomData(CommonRoomName, 1, "CobblestoneFloor", commonRoomResources, commonRoomTemplates, new ImageFrame(roomIcons, 16, 2, 0))
            {
                Description = "Dwarves come here to socialize and drink",
                CanBuildAboveGround = false
            });
        }
Exemplo n.º 10
0
        public static RoomData InitializeData()
        {
            Dictionary <Resource.ResourceTags, Quantitiy <Resource.ResourceTags> > roomResources = new Dictionary <Resource.ResourceTags, Quantitiy <Resource.ResourceTags> >()
            {
                { Resource.ResourceTags.Stone, new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Stone) },
                { Resource.ResourceTags.Fuel, new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Fuel) },
            };

            List <RoomTemplate> workshopTemplates = new List <RoomTemplate>();

            RoomTile[,] template =
            {
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.Wall | RoomTile.Edge,
                    RoomTile.KitchenTable,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                }
            };

            RoomTile[,] accessories =
            {
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.Barrel,
                    RoomTile.None
                }
            };


            RoomTile[,] stovetemp =
            {
                {
                    RoomTile.Open,
                    RoomTile.Open,
                    RoomTile.Open
                },
                {
                    RoomTile.Open,
                    RoomTile.Stove,
                    RoomTile.Open
                },
                {
                    RoomTile.Open,
                    RoomTile.Open,
                    RoomTile.Open
                }
            };

            RoomTile[,] stoveacc =
            {
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                }
            };

            RoomTemplate barrel = new RoomTemplate(PlacementType.All, template, accessories)
            {
                Probability = 0.2f
            };

            RoomTemplate stove = new RoomTemplate(PlacementType.All, stovetemp, stoveacc)
            {
                Probability = 1.0f
            };

            workshopTemplates.Add(stove);
            workshopTemplates.Add(barrel);

            Texture2D roomIcons = TextureManager.GetTexture(ContentPaths.GUI.room_icons);

            return(new RoomData(KitchenName, 2, "BlueTileFloor", roomResources, workshopTemplates, new ImageFrame(roomIcons, 16, 3, 2))
            {
                Description = "Cooking is done here",
                CanBuildAboveGround = false
            });
        }
Exemplo n.º 11
0
        public static RoomData InitializeData()
        {
            RoomTile[,] lampTemplate =
            {
                {
                    RoomTile.None,
                    RoomTile.Wall | RoomTile.Edge
                },
                {
                    RoomTile.Wall | RoomTile.Edge,
                    RoomTile.Lamp
                }
            };

            RoomTile[,] lampAccessories =
            {
                {
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None
                }
            };

            RoomTemplate lamp = new RoomTemplate(PlacementType.All, lampTemplate, lampAccessories);
            Dictionary <Resource.ResourceTags, Quantitiy <Resource.ResourceTags> > roomResources = new Dictionary <Resource.ResourceTags, Quantitiy <Resource.ResourceTags> >()
            {
                { Resource.ResourceTags.Wood, new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Wood) },
                { Resource.ResourceTags.Stone, new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Stone) },
            };


            List <RoomTemplate> commonRoomTemplates = new List <RoomTemplate>();

            RoomTile[,] tableTemps =
            {
                {
                    RoomTile.None,
                    RoomTile.Open,
                    RoomTile.None
                },
                {
                    RoomTile.Open,
                    RoomTile.Table,
                    RoomTile.Open
                },
                {
                    RoomTile.None,
                    RoomTile.Open,
                    RoomTile.None
                }
            };

            RoomTile[,] tableAcc =
            {
                {
                    RoomTile.None,
                    RoomTile.Chair,
                    RoomTile.None
                },
                {
                    RoomTile.Chair,
                    RoomTile.None,
                    RoomTile.Chair
                },
                {
                    RoomTile.None,
                    RoomTile.Chair,
                    RoomTile.None
                }
            };
            RoomTemplate table = new RoomTemplate(PlacementType.All, tableTemps, tableAcc);

            commonRoomTemplates.Add(lamp);
            commonRoomTemplates.Add(table);
            Texture2D roomIcons = TextureManager.GetTexture(ContentPaths.GUI.room_icons);

            return(new RoomData(CommonRoomName, 1, "CobblestoneFloor", roomResources, commonRoomTemplates, new ImageFrame(roomIcons, 16, 2, 0))
            {
                Description = "Dwarves come here to socialize and drink",
                CanBuildAboveGround = false
            });
        }
Exemplo n.º 12
0
        public static void Initialize()
        {
            if (staticsInitialized)
            {
                return;
            }

            CraftItems = new Dictionary <string, CraftItem>()
            {
                {
                    "Bear Trap",
                    new CraftItem()
                    {
                        Name              = "Bear Trap",
                        Description       = "Triggers on enemies, doing massive damage before being destroyed",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Metal, 4)
                        },
                        Image         = new ImageFrame(TextureManager.GetTexture(ContentPaths.Entities.DwarfObjects.beartrap), 32, 0, 0),
                        BaseCraftTime = 20,
                        Prerequisites = new List <CraftItem.CraftPrereq>()
                        {
                            CraftItem.CraftPrereq.OnGround
                        }
                    }
                },
                {
                    "Lamp",
                    new CraftItem()
                    {
                        Name              = "Lamp",
                        Description       = "Dwarves need to see sometimes too!",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Fuel, 1)
                        },
                        Image         = new ImageFrame(TextureManager.GetTexture(ContentPaths.Entities.Furniture.interior_furniture), 32, 0, 1),
                        BaseCraftTime = 10,
                        Prerequisites = new List <CraftItem.CraftPrereq>()
                        {
                            CraftItem.CraftPrereq.OnGround
                        }
                    }
                },
                {
                    "Wooden Ladder",
                    new CraftItem()
                    {
                        Name              = "Wooden Ladder",
                        Description       = "Allows dwarves to climb up and down",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Wood, 1)
                        },
                        Image         = new ImageFrame(TextureManager.GetTexture(ContentPaths.Entities.Furniture.interior_furniture), 32, 2, 0),
                        BaseCraftTime = 10,
                        Prerequisites = new List <CraftItem.CraftPrereq>()
                        {
                            CraftItem.CraftPrereq.NearWall
                        }
                    }
                },
                {
                    "Stone Ladder",
                    new CraftItem()
                    {
                        Name              = "Stone Ladder",
                        Description       = "Allows dwarves to climb up and down",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Stone, 1)
                        },
                        Image         = new ImageFrame(TextureManager.GetTexture(ContentPaths.Entities.Furniture.interior_furniture), 32, 2, 8),
                        BaseCraftTime = 10,
                        Prerequisites = new List <CraftItem.CraftPrereq>()
                        {
                            CraftItem.CraftPrereq.NearWall
                        }
                    }
                },
                {
                    "Metal Ladder",
                    new CraftItem()
                    {
                        Name              = "Metal Ladder",
                        Description       = "Allows dwarves to climb up and down",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Metal, 1)
                        },
                        Image         = new ImageFrame(TextureManager.GetTexture(ContentPaths.Entities.Furniture.interior_furniture), 32, 3, 8),
                        BaseCraftTime = 10,
                        Prerequisites = new List <CraftItem.CraftPrereq>()
                        {
                            CraftItem.CraftPrereq.NearWall
                        }
                    }
                },
                {
                    "Wooden Door",
                    new CraftItem()
                    {
                        Name              = "Wooden Door",
                        Description       = "Keep monsters out, and dwarves in.",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Wood, 1)
                        },
                        Image         = new ImageFrame(TextureManager.GetTexture(ContentPaths.Entities.Furniture.interior_furniture), 32, 3, 1),
                        BaseCraftTime = 10,
                        Prerequisites = new List <CraftItem.CraftPrereq>()
                        {
                            CraftItem.CraftPrereq.NearWall
                        }
                    }
                },
                {
                    "Stone Door",
                    new CraftItem()
                    {
                        Name              = "Stone Door",
                        Description       = "Keep monsters out, and dwarves in.",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Stone, 1)
                        },
                        Image         = new ImageFrame(TextureManager.GetTexture(ContentPaths.Entities.Furniture.interior_furniture), 32, 0, 8),
                        BaseCraftTime = 10,
                        Prerequisites = new List <CraftItem.CraftPrereq>()
                        {
                            CraftItem.CraftPrereq.NearWall
                        }
                    }
                },
                {
                    "Metal Door",
                    new CraftItem()
                    {
                        Name              = "Metal Door",
                        Description       = "Keep monsters out, and dwarves in.",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Metal, 1)
                        },
                        Image         = new ImageFrame(TextureManager.GetTexture(ContentPaths.Entities.Furniture.interior_furniture), 32, 1, 8),
                        BaseCraftTime = 10,
                        Prerequisites = new List <CraftItem.CraftPrereq>()
                        {
                            CraftItem.CraftPrereq.NearWall
                        }
                    }
                },
                {
                    "Trinket",
                    new CraftItem()
                    {
                        Name              = "Trinket",
                        Description       = "Get creative juices flowing and make a work of art.",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Material, 3)
                        },
                        Image           = new NamedImageFrame(ContentPaths.Entities.DwarfObjects.crafts, 32, 0, 1),
                        BaseCraftTime   = 15,
                        Type            = CraftItem.CraftType.Resource,
                        ResourceCreated = "Trinket"
                    }
                },
                {
                    "Gem-set Trinket",
                    new CraftItem()
                    {
                        Name              = "Gem-set Trinket",
                        Description       = "Encrust a work of art with gems.",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Encrustable, 1),
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Gem, 1)
                        },
                        Image           = new NamedImageFrame(ContentPaths.Entities.DwarfObjects.crafts, 32, 1, 1),
                        BaseCraftTime   = 15,
                        Type            = CraftItem.CraftType.Resource,
                        ResourceCreated = "Gem-set Trinket"
                    }
                },
                {
                    "Meal",
                    new CraftItem()
                    {
                        Name              = "Meal",
                        Description       = "Take raw food and cook something",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.RawFood, 1),
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.RawFood, 1),
                        },
                        Image           = new NamedImageFrame(ContentPaths.Entities.Resources.resources, 32, 5, 2),
                        BaseCraftTime   = 15,
                        Type            = CraftItem.CraftType.Resource,
                        ResourceCreated = "Meal",
                        CraftLocation   = "Cutting Board"
                    }
                },
                {
                    "Bread",
                    new CraftItem()
                    {
                        Name              = "Bread",
                        Description       = "Turn bakeable food into bread.",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Bakeable, 1)
                        },
                        Image           = new NamedImageFrame(ContentPaths.Entities.Resources.resources, 32, 6, 2),
                        BaseCraftTime   = 15,
                        Type            = CraftItem.CraftType.Resource,
                        ResourceCreated = "Bread",
                        CraftLocation   = "Stove"
                    }
                },
                {
                    "Ale",
                    new CraftItem()
                    {
                        Name              = "Ale",
                        Description       = "Turn brewable food into alcohol",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Brewable, 1)
                        },
                        Image           = new NamedImageFrame(ContentPaths.Entities.Resources.resources, 32, 4, 2),
                        BaseCraftTime   = 15,
                        Type            = CraftItem.CraftType.Resource,
                        ResourceCreated = "Ale",
                        CraftLocation   = "Barrel"
                    }
                },
                {
                    "Turret",
                    new CraftItem()
                    {
                        Name              = "Turret",
                        Description       = "Crossbow automatically targets enemies with magical power.",
                        RequiredResources = new List <Quantitiy <Resource.ResourceTags> >()
                        {
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Metal, 2),
                            new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Magical, 1),
                        },
                        Image         = new ImageFrame(TextureManager.GetTexture(ContentPaths.Entities.Furniture.interior_furniture), 32, 1, 7),
                        BaseCraftTime = 30,
                        Prerequisites = new List <CraftItem.CraftPrereq>()
                        {
                            CraftItem.CraftPrereq.OnGround
                        }
                    }
                }
            };

            staticsInitialized = true;
        }
Exemplo n.º 13
0
        public static RoomData InitializeData()
        {
            List <RoomTemplate> trainingTemplates = new List <RoomTemplate>();

            RoomTile[,] targetTemp =
            {
                {
                    RoomTile.Open,
                    RoomTile.Open,
                    RoomTile.Open
                },
                {
                    RoomTile.Open,
                    RoomTile.Strawman,
                    RoomTile.Open
                },
                {
                    RoomTile.Open,
                    RoomTile.Open,
                    RoomTile.Open
                }
            };

            RoomTile[,] strawAcc =
            {
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.Target
                },
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                }
            };

            RoomTemplate straw = new RoomTemplate(PlacementType.All, targetTemp, strawAcc);

            RoomTile[,] lampTemplate =
            {
                {
                    RoomTile.None,
                    RoomTile.Wall | RoomTile.Edge
                },
                {
                    RoomTile.Wall | RoomTile.Edge,
                    RoomTile.Lamp
                }
            };

            RoomTile[,] lampAccessories =
            {
                {
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None
                }
            };

            RoomTemplate lamp = new RoomTemplate(PlacementType.All, lampTemplate, lampAccessories);

            trainingTemplates.Add(lamp);
            trainingTemplates.Add(straw);
            Dictionary <Resource.ResourceTags, Quantitiy <Resource.ResourceTags> > roomResources = new Dictionary <Resource.ResourceTags, Quantitiy <Resource.ResourceTags> >()
            {
                { Resource.ResourceTags.Stone, new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Stone) },
            };

            Texture2D roomIcons = TextureManager.GetTexture(ContentPaths.GUI.room_icons);

            return(new RoomData(TrainingRoomName, 3, "CobblestoneFloor", roomResources, trainingTemplates, new ImageFrame(roomIcons, 16, 3, 0))
            {
                Description = "Military dwarves train here"
            });
        }
Exemplo n.º 14
0
        public void Initialize(EmployeeClass dwarfClass)
        {
            Physics.Orientation = Physics.OrientMode.RotateY;
            Sprite = new CharacterSprite(Graphics, Manager, "Fairy Sprite", Physics, Matrix.CreateTranslation(new Vector3(0, 0.5f, 0)));
            foreach (Animation animation in dwarfClass.Animations)
            {
                Sprite.AddAnimation(animation.Clone());
            }
            Sprite.LightsWithVoxels = false;

            Hands = new Grabber("hands", Physics, Matrix.Identity, new Vector3(0.1f, 0.1f, 0.1f), Vector3.Zero);

            Sensors = new EnemySensor(Manager, "EnemySensor", Physics, Matrix.Identity, new Vector3(20, 5, 20), Vector3.Zero);

            AI = new CreatureAI(this, "Fairy AI", Sensors, PlanService);

            Attacks = new List <Attack>()
            {
                new Attack(Stats.CurrentClass.Attacks[0])
            };


            Inventory = new Inventory("Inventory", Physics)
            {
                Resources = new ResourceContainer
                {
                    MaxResources = 128
                }
            };

            Matrix shadowTransform = Matrix.CreateRotationX((float)Math.PI * 0.5f);

            shadowTransform.Translation = new Vector3(0.0f, -0.5f, 0.0f);

            Shadow = new Shadow(Manager, "Shadow", Physics, shadowTransform, new SpriteSheet(ContentPaths.Effects.shadowcircle));
            List <Point> shP = new List <Point>
            {
                new Point(0, 0)
            };
            Animation shadowAnimation = new Animation(Graphics, new SpriteSheet(ContentPaths.Effects.shadowcircle), "sh", 32, 32, shP, false, Color.Black, 1, 0.7f, 0.7f, false);

            Shadow.AddAnimation(shadowAnimation);
            shadowAnimation.Play();
            Shadow.SetCurrentAnimation("sh");
            Physics.Tags.Add("Dwarf");



            DeathParticleTrigger = new ParticleTrigger("star_particle", Manager, "Death Gibs", Physics, Matrix.Identity, Vector3.One, Vector3.Zero)
            {
                TriggerOnDeath = true,
                TriggerAmount  = 5,
                SoundToPlay    = ContentPaths.Audio.wurp,
            };

            NoiseMaker.Noises["Hurt"] = new List <string>
            {
                ContentPaths.Audio.tinkle
            };


            NoiseMaker.Noises["Chew"] = new List <string>
            {
                ContentPaths.Audio.tinkle
            };

            NoiseMaker.Noises["Jump"] = new List <string>
            {
                ContentPaths.Audio.tinkle
            };

            MinimapIcon minimapIcon = new MinimapIcon(Physics, new ImageFrame(TextureManager.GetTexture(ContentPaths.GUI.map_icons), 16, 0, 0));

            //new LightEmitter("Light Emitter", Sprite, Matrix.Identity, Vector3.One, Vector3.One, 255, 150);
            new Bobber(0.25f, 3.0f, MathFunctions.Rand(), Sprite);

            Stats.FullName = TextGenerator.GenerateRandom("$firstname");
            //Stats.LastName = "The Fairy";

            Stats.CanSleep = false;
            Stats.CanEat   = false;
        }
Exemplo n.º 15
0
        public DwarfGUI(DwarfGame game, SpriteFont defaultFont, SpriteFont titleFont, SpriteFont smallFont, InputManager input)
        {
            IndicatorManager.DefaultFont = defaultFont;
            EnableMouseEvents            = true;
            IsMouseVisible = true;
            MouseMode      = GUISkin.MousePointer.Pointer;
            SmallFont      = smallFont;
            Graphics       = game.GraphicsDevice;
            this.game      = game;
            RootComponent  = new GUIComponent(this, null)
            {
                LocalBounds = new Rectangle(0, 0, 0, 0)
            };

            DefaultFont = defaultFont;
            Skin        = new GUISkin(TextureManager.GetTexture(ContentPaths.GUI.gui_widgets), 32, 32, TextureManager.GetTexture(ContentPaths.GUI.pointers), 16, 16);
            Skin.SetDefaults();
            TitleFont          = titleFont;
            GlobalOffset       = Vector2.Zero;
            FocusComponent     = null;
            Input              = input;
            DrawAfter          = new List <GUIComponent>();
            DefaultTextColor   = new Color(48, 27, 0);
            DefaultStrokeColor = Color.Transparent;
            DebugDraw          = false;
            ToolTipManager     = new ToolTipManager(this);
            LastScrollWheel    = 0;
            LastMouseX         = 0;
            LastMouseY         = 0;
        }
Exemplo n.º 16
0
        public static SpellTree CreateSpellTree()
        {
            Texture2D icons = TextureManager.GetTexture(ContentPaths.GUI.icons);


            SpellTree toReturn = new SpellTree()
            {
                RootSpells = new List <SpellTree.Node>()
                {
                    new SpellTree.Node()
                    {
                        Spell            = new InspectSpell(InspectSpell.InspectType.InspectEntity),
                        ResearchProgress = 10.0f,
                        ResearchTime     = 10.0f,
                        Children         = new List <SpellTree.Node>()
                        {
                            new SpellTree.Node()
                            {
                                Spell = new BuffSpell(
                                    new Creature.StatBuff(30.0f, new CreatureStats.StatNums()
                                {
                                    Dexterity    = 2.0f,
                                    Strength     = 2.0f,
                                    Wisdom       = 2.0f,
                                    Intelligence = 2.0f,
                                    Charisma     = 0.0f,
                                    Constitution = 0.0f,
                                    Size         = 0.0f
                                })
                                {
                                    Particles = "star_particle", SoundOnStart = ContentPaths.Audio.powerup, SoundOnEnd = ContentPaths.Audio.wurp
                                }
                                    )
                                {
                                    Name        = "Minor Inspire",
                                    Description = "Makes the selected creatures work harder for 30 seconds (+2 to DEX, STR, INT and WIS)",
                                    Hint        = "Click and drag to select creatures"
                                },
                                ResearchProgress = 0.0f,
                                ResearchTime     = 30.0f,

                                Children = new List <SpellTree.Node>()
                                {
                                    new SpellTree.Node()
                                    {
                                        Spell = new BuffSpell(
                                            new Creature.StatBuff(60.0f, new CreatureStats.StatNums()
                                        {
                                            Dexterity    = 5.0f,
                                            Strength     = 5.0f,
                                            Wisdom       = 5.0f,
                                            Intelligence = 5.0f,
                                            Charisma     = 0.0f,
                                            Constitution = 0.0f,
                                            Size         = 0.0f
                                        })
                                        {
                                            Particles = "star_particle", SoundOnStart = ContentPaths.Audio.powerup, SoundOnEnd = ContentPaths.Audio.wurp
                                        }
                                            )
                                        {
                                            Name        = "Major Inspire",
                                            Description = "Makes the selected creatures work harder for 60 seconds (+5 to DEX, STR, INT and WIS)",
                                            Hint        = "Click and drag to select creatures"
                                        },
                                        Children = new List <SpellTree.Node>()
                                        {
                                            new SpellTree.Node()
                                            {
                                                Spell = new CreateEntitySpell("Fairy", false)
                                                {
                                                    Name        = "Magic Helper",
                                                    Description = "Creates a magical helper employee who persists for 30 seconds",
                                                    Hint        = "Click to spawn a helper"
                                                },
                                                ResearchProgress = 0.0f,
                                                ResearchTime     = 150.0f
                                            }
                                        },
                                        ResearchProgress = 0.0f,
                                        ResearchTime     = 60.0f,
                                    },
                                    new SpellTree.Node()
                                    {
                                        Spell = new BuffSpell(new Creature.ThoughtBuff(30.0f, Thought.ThoughtType.Magic)
                                        {
                                            SoundOnStart = ContentPaths.Audio.powerup
                                        })
                                        {
                                            Name        = "Minor Happiness",
                                            Description = "Makes the selected creatures happy for 30 seconds.",
                                            Hint        = "Click and drag to select creatures",
                                            Image       = new ImageFrame(TextureManager.GetTexture(ContentPaths.GUI.icons), 32, 5, 2)
                                        },
                                        ResearchTime     = 60.0f,
                                        ResearchProgress = 0.0f,
                                        Children         = new List <SpellTree.Node>()
                                        {
                                            new SpellTree.Node()
                                            {
                                                Spell = new BuffSpell(new Creature.ThoughtBuff(60.0f, Thought.ThoughtType.Magic)
                                                {
                                                    SoundOnStart = ContentPaths.Audio.powerup
                                                })
                                                {
                                                    Name        = "Major Happiness",
                                                    Description = "Makes the selected creatures happy for 60 seconds.",
                                                    Hint        = "Click and drag to select creatures",
                                                    Image       = new ImageFrame(TextureManager.GetTexture(ContentPaths.GUI.icons), 32, 5, 2)
                                                },
                                                ResearchTime     = 120.0f,
                                                ResearchProgress = 0.0f
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    new SpellTree.Node()
                    {
                        Spell            = new InspectSpell(InspectSpell.InspectType.InspectBlock),
                        ResearchProgress = 25.0f,
                        ResearchTime     = 25.0f,
                        Children         = new List <SpellTree.Node>()
                        {
                            new SpellTree.Node()
                            {
                                Spell            = new PlaceBlockSpell("Dirt", false),
                                ResearchProgress = 0.0f,
                                ResearchTime     = 50.0f,

                                Children = new List <SpellTree.Node>()
                                {
                                    new SpellTree.Node()
                                    {
                                        ResearchProgress = 0.0f,
                                        ResearchTime     = 100.0f,
                                        Spell            = new PlaceBlockSpell("Stone", false),

                                        Children = new List <SpellTree.Node>()
                                        {
                                            new SpellTree.Node()
                                            {
                                                ResearchProgress = 0.0f,
                                                ResearchTime     = 150.0f,
                                                Spell            = new DestroyBlockSpell()
                                            }
                                        }
                                    }
                                }
                            },
                            new SpellTree.Node()
                            {
                                Spell = new PlaceBlockSpell("Magic", false)
                                {
                                    Image       = new ImageFrame(TextureManager.GetTexture(ContentPaths.GUI.icons), 32, 2, 3),
                                    Description = "Creates a temporary magic wall."
                                },
                                ResearchProgress = 0.0f,
                                ResearchTime     = 50.0f,

                                Children = new List <SpellTree.Node>()
                                {
                                    new SpellTree.Node()
                                    {
                                        ResearchProgress = 0.0f,
                                        ResearchTime     = 100.0f,
                                        Spell            = new PlaceBlockSpell("Iron", true),
                                        Children         = new List <SpellTree.Node>()
                                        {
                                            new SpellTree.Node()
                                            {
                                                ResearchProgress = 0.0f,
                                                ResearchTime     = 150.0f,
                                                Spell            = new PlaceBlockSpell("Gold", true)
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    new SpellTree.Node()
                    {
                        Spell = new BuffSpell(new Creature.OngoingHealBuff(2, 10)
                        {
                            Particles = "heart", SoundOnStart = ContentPaths.Audio.powerup, SoundOnEnd = ContentPaths.Audio.wurp
                        })
                        {
                            Name        = "Minor Heal",
                            Description = "Heals 2 damage per second for 10 seconds",
                            Hint        = "Click and drag to select creatures",
                            Image       = new ImageFrame(TextureManager.GetTexture(ContentPaths.GUI.icons), 32, 3, 2)
                        },
                        ResearchProgress = 0.0f,
                        ResearchTime     = 30.0f,
                        Children         = new List <SpellTree.Node>()
                        {
                            new SpellTree.Node()
                            {
                                Spell = new BuffSpell(new Creature.OngoingHealBuff(5, 10)
                                {
                                    Particles = "heart", SoundOnStart = ContentPaths.Audio.powerup, SoundOnEnd = ContentPaths.Audio.wurp
                                })
                                {
                                    Name        = "Major Heal",
                                    Description = "Heals 5 damage per second for 10 seconds",
                                    Hint        = "Click and drag to select creatures",
                                    Image       = new ImageFrame(TextureManager.GetTexture(ContentPaths.GUI.icons), 32, 3, 2)
                                },
                                ResearchProgress = 0.0f,
                                ResearchTime     = 150.0f
                            }
                        }
                    }
                }
            };


            foreach (SpellTree.Node spell in toReturn.RootSpells)
            {
                spell.SetupParentsRecursive();
            }

            return(toReturn);
        }
Exemplo n.º 17
0
        private void LoadThreaded()
        {
            // Ensure we're using the invariant culture.
            Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
            LoadStatus = LoadingStatus.Loading;
            SetLoadingMessage("Initializing ...");

            while (GraphicsDevice == null)
            {
                Thread.Sleep(100);
            }
            Thread.Sleep(1000);

#if CREATE_CRASH_LOGS
            try
#endif
#if !DEBUG
            try
            {
#endif
            bool fileExists = !string.IsNullOrEmpty(ExistingFile);

            SetLoadingMessage("Creating Sky...");

            Sky = new SkyRenderer(
                TextureManager.GetTexture(ContentPaths.Sky.moon),
                TextureManager.GetTexture(ContentPaths.Sky.sun),
                Content.Load <TextureCube>(ContentPaths.Sky.day_sky),
                Content.Load <TextureCube>(ContentPaths.Sky.night_sky),
                TextureManager.GetTexture(ContentPaths.Gradients.skygradient),
                Content.Load <Model>(ContentPaths.Models.sphereLowPoly),
                Content.Load <Effect>(ContentPaths.Shaders.SkySphere),
                Content.Load <Effect>(ContentPaths.Shaders.Background));

            #region Reading game file

            if (fileExists)
            {
                SetLoadingMessage("Loading " + ExistingFile);

                gameFile = SaveGame.CreateFromDirectory(ExistingFile);
                if (gameFile == null)
                {
                    throw new InvalidOperationException("Game File does not exist.");
                }

                // Todo: REMOVE THIS WHEN THE NEW SAVE SYSTEM IS COMPLETE.
                if (gameFile.Metadata.Version != Program.Version && !Program.CompatibleVersions.Contains(gameFile.Metadata.Version))
                {
                    throw new InvalidOperationException(String.Format("Game file is from version {0}. Compatible versions are {1}.", gameFile.Metadata.Version,
                                                                      TextGenerator.GetListString(Program.CompatibleVersions)));
                }
                Sky.TimeOfDay = gameFile.Metadata.TimeOfDay;
                Time          = gameFile.Metadata.Time;
                WorldOrigin   = gameFile.Metadata.WorldOrigin;
                WorldScale    = gameFile.Metadata.WorldScale;
                WorldSize     = gameFile.Metadata.NumChunks;
                GameID        = gameFile.Metadata.GameID;

                if (gameFile.Metadata.OverworldFile != null && gameFile.Metadata.OverworldFile != "flat")
                {
                    SetLoadingMessage("Loading world " + gameFile.Metadata.OverworldFile);
                    Overworld.Name = gameFile.Metadata.OverworldFile;
                    DirectoryInfo worldDirectory =
                        Directory.CreateDirectory(DwarfGame.GetWorldDirectory() +
                                                  ProgramData.DirChar + Overworld.Name);
                    var overWorldFile = new NewOverworldFile(worldDirectory.FullName);
                    Overworld.Map  = overWorldFile.Data.Data;
                    Overworld.Name = overWorldFile.Data.Name;
                }
                else
                {
                    SetLoadingMessage("Generating flat world..");
                    Overworld.CreateUniformLand(GraphicsDevice);
                }
            }

            #endregion

            #region Initialize static data

            {
                Vector3 origin  = new Vector3(WorldOrigin.X, 0, WorldOrigin.Y);
                Vector3 extents = new Vector3(1500, 1500, 1500);
                CollisionManager = new CollisionManager(new BoundingBox(origin - extents, origin + extents));

                CraftLibrary = new CraftLibrary();

                new PrimitiveLibrary(GraphicsDevice, Content);
                NewInstanceManager = new NewInstanceManager(GraphicsDevice, new BoundingBox(origin - extents, origin + extents),
                                                            Content);

                Color[] white = new Color[1];
                white[0] = Color.White;
                pixel    = new Texture2D(GraphicsDevice, 1, 1);
                pixel.SetData(white);

                Tilesheet                  = TextureManager.GetTexture(ContentPaths.Terrain.terrain_tiles);
                AspectRatio                = GraphicsDevice.Viewport.AspectRatio;
                DefaultShader              = new Shader(Content.Load <Effect>(ContentPaths.Shaders.TexturedShaders), true);
                DefaultShader.ScreenWidth  = GraphicsDevice.Viewport.Width;
                DefaultShader.ScreenHeight = GraphicsDevice.Viewport.Height;
                VoxelLibrary.InitializeDefaultLibrary(GraphicsDevice, Tilesheet);
                GrassLibrary.InitializeDefaultLibrary();
                DecalLibrary.InitializeDefaultLibrary();

                bloom = new BloomComponent(Game)
                {
                    Settings = BloomSettings.PresetSettings[5]
                };
                bloom.Initialize();


                fxaa = new FXAA();
                fxaa.Initialize();

                SoundManager.Content = Content;
                if (PlanService != null)
                {
                    PlanService.Restart();
                }

                JobLibrary.Initialize();
                MonsterSpawner = new MonsterSpawner(this);
                EntityFactory.Initialize(this);
            }

            #endregion


            SetLoadingMessage("Creating Planner ...");
            PlanService = new PlanService();

            SetLoadingMessage("Creating Shadows...");
            Shadows = new ShadowRenderer(GraphicsDevice, 1024, 1024);

            SetLoadingMessage("Creating Liquids ...");

            #region liquids

            WaterRenderer = new WaterRenderer(GraphicsDevice);

            LiquidAsset waterAsset = new LiquidAsset
            {
                Type        = LiquidType.Water,
                Opactiy     = 0.8f,
                Reflection  = 1.0f,
                WaveHeight  = 0.1f,
                WaveLength  = 0.05f,
                WindForce   = 0.001f,
                BumpTexture = TextureManager.GetTexture(ContentPaths.Terrain.water_normal),
                BaseTexture = TextureManager.GetTexture(ContentPaths.Terrain.cartoon_water),
                MinOpacity  = 0.4f,
                RippleColor = new Vector4(0.6f, 0.6f, 0.6f, 0.0f),
                FlatColor   = new Vector4(0.3f, 0.3f, 0.9f, 1.0f)
            };
            WaterRenderer.AddLiquidAsset(waterAsset);


            LiquidAsset lavaAsset = new LiquidAsset
            {
                Type        = LiquidType.Lava,
                Opactiy     = 0.95f,
                Reflection  = 0.0f,
                WaveHeight  = 0.1f,
                WaveLength  = 0.05f,
                WindForce   = 0.001f,
                MinOpacity  = 0.8f,
                BumpTexture = TextureManager.GetTexture(ContentPaths.Terrain.water_normal),
                BaseTexture = TextureManager.GetTexture(ContentPaths.Terrain.lava),
                RippleColor = new Vector4(0.5f, 0.4f, 0.04f, 0.0f),
                FlatColor   = new Vector4(0.9f, 0.7f, 0.2f, 1.0f)
            };

            WaterRenderer.AddLiquidAsset(lavaAsset);

            #endregion

            SetLoadingMessage("Generating Initial Terrain Chunks ...");

            if (!fileExists)
            {
                GameID = MathFunctions.Random.Next(0, 1024);
            }

            ChunkGenerator = new ChunkGenerator(VoxelLibrary, Seed, 0.02f, this.WorldScale)
            {
                SeaLevel = SeaLevel
            };


            #region Load Components

            if (fileExists)
            {
                ChunkManager = new ChunkManager(Content, this, Camera,
                                                GraphicsDevice,
                                                ChunkGenerator, WorldSize.X, WorldSize.Y, WorldSize.Z);

                ChunkRenderer = new ChunkRenderer(this, Camera, GraphicsDevice, ChunkManager.ChunkData);

                SetLoadingMessage("Loading Terrain...");
                gameFile.ReadChunks(ExistingFile);
                ChunkManager.ChunkData.LoadFromFile(gameFile, SetLoadingMessage);

                ChunkManager.ChunkData.SetMaxViewingLevel(gameFile.Metadata.Slice > 0
                        ? gameFile.Metadata.Slice
                        : ChunkManager.ChunkData.MaxViewingLevel, ChunkManager.SliceMode.Y);

                SetLoadingMessage("Loading Entities...");
                gameFile.LoadPlayData(ExistingFile, this);
                Camera = gameFile.PlayData.Camera;
                ChunkManager.camera  = Camera;
                ChunkRenderer.camera = Camera;
                DesignationDrawer    = gameFile.PlayData.Designations;

                Vector3 origin  = new Vector3(WorldOrigin.X, 0, WorldOrigin.Y);
                Vector3 extents = new Vector3(1500, 1500, 1500);
                CollisionManager = new CollisionManager(new BoundingBox(origin - extents, origin + extents));

                if (gameFile.PlayData.Resources != null)
                {
                    foreach (var resource in gameFile.PlayData.Resources)
                    {
                        if (!ResourceLibrary.Resources.ContainsKey(resource.Key))
                        {
                            ResourceLibrary.Add(resource.Value);
                        }
                    }
                }
                ComponentManager = new ComponentManager(gameFile.PlayData.Components, this);

                foreach (var component in gameFile.PlayData.Components.SaveableComponents)
                {
                    if (!ComponentManager.HasComponent(component.GlobalID) &&
                        ComponentManager.HasComponent(component.Parent.GlobalID))
                    {
                        // Logically impossible.
                        throw new InvalidOperationException("Component exists in save data but not in manager.");
                    }
                }

                Factions = gameFile.PlayData.Factions;
                ComponentManager.World = this;

                Sky.TimeOfDay = gameFile.Metadata.TimeOfDay;
                Time          = gameFile.Metadata.Time;
                WorldOrigin   = gameFile.Metadata.WorldOrigin;
                WorldScale    = gameFile.Metadata.WorldScale;

                // Restore native factions from deserialized data.
                Natives = new List <Faction>();
                foreach (Faction faction in Factions.Factions.Values)
                {
                    if (faction.Race.IsNative && faction.Race.IsIntelligent && !faction.IsRaceFaction)
                    {
                        Natives.Add(faction);
                    }
                }

                Diplomacy = gameFile.PlayData.Diplomacy;

                GoalManager = new Goals.GoalManager();
                GoalManager.Initialize(gameFile.PlayData.Goals);

                TutorialManager = new Tutorial.TutorialManager(Program.CreatePath("Content", "tutorial.txt"));
                TutorialManager.SetFromSaveData(gameFile.PlayData.TutorialSaveData);
            }
            else
            {
                Time = new WorldTime();
                // WorldOrigin is in "map" units. Convert to voxels
                var globalOffset = new Vector3(WorldOrigin.X, 0, WorldOrigin.Y) * WorldScale;

                Camera = new OrbitCamera(this,
                                         new Vector3(VoxelConstants.ChunkSizeX,
                                                     VoxelConstants.ChunkSizeY - 1.0f,
                                                     VoxelConstants.ChunkSizeZ) + new Vector3(WorldOrigin.X, 0, WorldOrigin.Y) * WorldScale,
                                         new Vector3(VoxelConstants.ChunkSizeY, VoxelConstants.ChunkSizeY - 1.0f,
                                                     VoxelConstants.ChunkSizeZ) + new Vector3(WorldOrigin.X, 0, WorldOrigin.Y) * WorldScale +
                                         Vector3.Up * 10.0f + Vector3.Backward * 10,
                                         MathHelper.PiOver4, AspectRatio, 0.1f,
                                         GameSettings.Default.VertexCullDistance);

                ChunkManager = new ChunkManager(Content, this, Camera,
                                                GraphicsDevice,
                                                ChunkGenerator, WorldSize.X, WorldSize.Y, WorldSize.Z);

                ChunkRenderer = new ChunkRenderer(this, Camera, GraphicsDevice, ChunkManager.ChunkData);


                var chunkOffset = GlobalVoxelCoordinate.FromVector3(globalOffset).GetGlobalChunkCoordinate();
                //var chunkOffset = ChunkManager.ChunkData.RoundToChunkCoords(globalOffset);
                //globalOffset.X = chunkOffset.X * VoxelConstants.ChunkSizeX;
                //globalOffset.Y = chunkOffset.Y * VoxelConstants.ChunkSizeY;
                //globalOffset.Z = chunkOffset.Z * VoxelConstants.ChunkSizeZ;

                WorldOrigin     = new Vector2(globalOffset.X, globalOffset.Z);
                Camera.Position = new Vector3(0, 10, 0) + globalOffset;
                Camera.Target   = new Vector3(0, 10, 1) + globalOffset;

                // If there's no file, we have to initialize the first chunk coordinate
                if (gameFile == null)     // Todo: Always true?
                {
                    ChunkManager.GenerateInitialChunks(
                        GlobalVoxelCoordinate.FromVector3(globalOffset).GetGlobalChunkCoordinate(),
                        SetLoadingMessage);
                }

                ComponentManager = new ComponentManager(this);
                ComponentManager.SetRootComponent(new Body(ComponentManager, "root", Matrix.Identity,
                                                           Vector3.Zero, Vector3.Zero, false));

                if (Natives == null)     // Todo: Always true??
                {
                    FactionLibrary library = new FactionLibrary();
                    library.Initialize(this, CompanyMakerState.CompanyInformation);
                    Natives = new List <Faction>();
                    for (int i = 0; i < 10; i++)
                    {
                        Natives.Add(library.GenerateFaction(this, i, 10));
                    }
                }

                #region Prepare Factions

                foreach (Faction faction in Natives)
                {
                    faction.World = this;

                    if (faction.RoomBuilder == null)
                    {
                        faction.RoomBuilder = new RoomBuilder(faction, this);
                    }

                    if (faction.CraftBuilder == null)
                    {
                        faction.CraftBuilder = new CraftBuilder(faction, this);
                    }
                }

                Factions = new FactionLibrary();
                if (Natives != null && Natives.Count > 0)
                {
                    Factions.AddFactions(this, Natives);
                }

                Factions.Initialize(this, CompanyMakerState.CompanyInformation);
                Point playerOrigin = new Point((int)(WorldOrigin.X), (int)(WorldOrigin.Y));

                Factions.Factions["Player"].Center         = playerOrigin;
                Factions.Factions["The Motherland"].Center = new Point(playerOrigin.X + 50, playerOrigin.Y + 50);

                #endregion

                Diplomacy = new Diplomacy(this);
                Diplomacy.Initialize(Time.CurrentDate);

                // Initialize goal manager here.
                GoalManager = new Goals.GoalManager();
                GoalManager.Initialize(new List <Goals.Goal>());

                TutorialManager = new Tutorial.TutorialManager(Program.CreatePath("Content", "tutorial.txt"));
                TutorialManager.TutorialEnabled = !GameSettings.Default.TutorialDisabledGlobally;
                Tutorial("new game start");
            }

            Camera.World = this;
            //Drawer3D.Camera = Camera;


            #endregion

            ChunkManager.camera = Camera;

            SetLoadingMessage("Creating Particles ...");
            ParticleManager = new ParticleManager(GraphicsDevice, ComponentManager);

            SetLoadingMessage("Creating GameMaster ...");
            Master = new GameMaster(Factions.Factions["Player"], Game, ComponentManager, ChunkManager,
                                    Camera, GraphicsDevice);

            if (gameFile != null)
            {
                if (gameFile.PlayData.Spells != null)
                {
                    Master.Spells = gameFile.PlayData.Spells;
                }
                if (gameFile.PlayData.Tasks != null)
                {
                    Master.TaskManager = gameFile.PlayData.Tasks;
                }
            }

            if (Master.Faction.Economy.Company.Information == null)
            {
                Master.Faction.Economy.Company.Information = new CompanyInformation();
            }

            CreateInitialEmbarkment();
            foreach (var chunk in ChunkManager.ChunkData.ChunkMap)
            {
                chunk.CalculateInitialSunlight();
            }
            VoxelHelpers.InitialReveal(ChunkManager.ChunkData, new VoxelHandle(
                                           ChunkManager.ChunkData.GetChunkEnumerator().FirstOrDefault(), new LocalVoxelCoordinate(0, VoxelConstants.ChunkSizeY - 1, 0)));

            foreach (var chunk in ChunkManager.ChunkData.ChunkMap)
            {
                ChunkManager.InvalidateChunk(chunk);
            }

            ChunkManager.StartThreads();
            SetLoadingMessage("Presimulating ...");
            ShowingWorld = false;
            OnLoadedEvent();

            Thread.Sleep(1000);
            ShowingWorld = true;

            SetLoadingMessage("Complete.");

            // GameFile is no longer needed.
            gameFile   = null;
            LoadStatus = LoadingStatus.Success;
#if !DEBUG
        }

        catch (Exception exception)
        {
            Game.CaptureException(exception);
            LoadingException = exception;
            LoadStatus       = LoadingStatus.Failure;
        }
#endif
        }
Exemplo n.º 18
0
        private void GenerateData(GraphicsDevice device, float sizeX, float sizeY, float resolution)
        {
            if (banners.ContainsKey(Logo))
            {
                return;
            }

            int        numCellsX   = (int)(sizeX / resolution);
            int        numCellsY   = (int)(sizeY / resolution);
            int        numVerts    = (numCellsX + 1) * (numCellsY + 1);
            int        numIndices  = numCellsX * numCellsY * 6;
            float      aspectRatio = sizeX / sizeY;
            const int  height      = 36;
            int        width       = (int)(aspectRatio * height);
            BannerData data        = new BannerData()
            {
                Mesh    = new VertexBuffer(device, ExtendedVertex.VertexDeclaration, numVerts, BufferUsage.None),
                Indices = new IndexBuffer(device, typeof(short), numIndices, BufferUsage.None),
                Texture = new RenderTarget2D(device, width, height),
                Verts   = new ExtendedVertex[numVerts],
                SizeX   = sizeX,
                SizeY   = sizeY,
                Idx     = new ushort[numIndices]
            };

            banners[Logo] = data;
            for (int i = 0, y = 0; y <= numCellsY; y++)
            {
                for (int x = 0; x <= numCellsX; x++, i++)
                {
                    data.Verts[i] = new ExtendedVertex(new Vector3(0, y * resolution - sizeY * 0.5f, 0), Color.White, Color.White,
                                                       new Vector2((float)x / (float)numCellsX, 1.0f - (float)y / (float)numCellsY), new Vector4(0, 0, 1, 1));
                }
            }

            for (ushort ti = 0, vi = 0, y = 0; y < numCellsY; y++, vi++)
            {
                for (int x = 0; x < numCellsX; x++, ti += 6, vi++)
                {
                    data.Idx[ti]     = vi;
                    data.Idx[ti + 3] = data.Idx[ti + 2] = (ushort)(vi + 1);
                    data.Idx[ti + 4] = data.Idx[ti + 1] = (ushort)(vi + numCellsX + 1);
                    data.Idx[ti + 5] = (ushort)(vi + numCellsX + 2);
                }
            }
            var oldView = device.Viewport;

            data.Mesh.SetData(data.Verts);
            data.Indices.SetData(data.Idx);
            device.SetRenderTarget(data.Texture);
            device.Viewport = new Viewport(0, 0, width, height); // Must set viewport after target bound.
            device.Clear(new Color(Logo.LogoBackgroundColor * 0.5f + Logo.LogoSymbolColor * 0.5f));
            Texture2D logoBg = TextureManager.GetTexture("newgui/logo-bg");
            Texture2D logoFg = TextureManager.GetTexture("newgui/logo-fg");
            int       bgIdx  = Logo.LogoBackground.Tile;
            int       bgX    = (bgIdx % (logoBg.Width / 32)) * 32;
            int       bgY    = (bgIdx / (logoBg.Width / 32)) * 32;
            int       fgIdx  = Logo.LogoSymbol.Tile;
            int       fgX    = (fgIdx % (logoFg.Width / 32)) * 32;
            int       fgY    = (fgIdx / (logoFg.Width / 32)) * 32;

            DwarfGame.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, Drawer2D.PointMagLinearMin,
                                        DepthStencilState.None, RasterizerState.CullNone);
            Drawer2D.DrawRect(DwarfGame.SpriteBatch, new Rectangle(1, 1, width - 1, height - 2), Color.Black, 2);
            DwarfGame.SpriteBatch.Draw(logoBg, new Rectangle(width / 2 - 16, height / 2 - 16, 32, 32), new Rectangle(bgX, bgY, 32, 32), new Color(Logo.LogoBackgroundColor));
            DwarfGame.SpriteBatch.Draw(logoFg, new Rectangle(width / 2 - 16, height / 2 - 16, 32, 32), new Rectangle(fgX, fgY, 32, 32), new Color(Logo.LogoSymbolColor));
            DwarfGame.SpriteBatch.End();
            device.SetRenderTarget(null);
            device.Indices = null;
            device.SetVertexBuffer(null);
            device.Viewport = oldView;
        }
Exemplo n.º 19
0
        public void Initialize()
        {
            Physics.Orientation = Physics.OrientMode.RotateY;
            Sprite = new CharacterSprite(Graphics, Manager, "Goblin Sprite", Physics, Matrix.CreateTranslation(new Vector3(0, 0.1f, 0)));
            foreach (Animation animation in Stats.CurrentClass.Animations)
            {
                Sprite.AddAnimation(animation.Clone());
            }



            Hands = new Grabber("hands", Physics, Matrix.Identity, new Vector3(0.1f, 0.1f, 0.1f), Vector3.Zero);

            Sensors = new EnemySensor(Manager, "EnemySensor", Physics, Matrix.Identity, new Vector3(20, 5, 20), Vector3.Zero);

            AI = new CreatureAI(this, "Goblin AI", Sensors, PlanService);

            Attacks = new List <Attack>()
            {
                new Attack(Stats.CurrentClass.Attacks[0])
            };

            Inventory = new Inventory("Inventory", Physics)
            {
                Resources = new ResourceContainer
                {
                    MaxResources = 16
                }
            };

            Matrix shadowTransform = Matrix.CreateRotationX((float)Math.PI * 0.5f);

            shadowTransform.Translation = new Vector3(0.0f, -0.5f, 0.0f);

            SpriteSheet shadowTexture = new SpriteSheet(ContentPaths.Effects.shadowcircle);

            Shadow = new Shadow(Manager, "Shadow", Physics, shadowTransform, shadowTexture);
            List <Point> shP = new List <Point>
            {
                new Point(0, 0)
            };
            Animation shadowAnimation = new Animation(Graphics, new SpriteSheet(ContentPaths.Effects.shadowcircle), "sh", 32, 32, shP, false, Color.Black, 1, 0.7f, 0.7f, false);

            Shadow.AddAnimation(shadowAnimation);
            shadowAnimation.Play();
            Shadow.SetCurrentAnimation("sh");
            Physics.Tags.Add("Goblin");

            DeathParticleTrigger = new ParticleTrigger("blood_particle", Manager, "Death Gibs", Physics, Matrix.Identity, Vector3.One, Vector3.Zero)
            {
                TriggerOnDeath = true,
                TriggerAmount  = 3,
                SoundToPlay    = ContentPaths.Entities.Goblin.Audio.goblinhurt1
            };
            Flames = new Flammable(Manager, "Flames", Physics, this);


            NoiseMaker.Noises["Hurt"] = new List <string>
            {
                ContentPaths.Entities.Goblin.Audio.goblinhurt1,
                ContentPaths.Entities.Goblin.Audio.goblinhurt2,
                ContentPaths.Entities.Goblin.Audio.goblinhurt3,
                ContentPaths.Entities.Goblin.Audio.goblinhurt4,
            };


            MinimapIcon minimapIcon = new MinimapIcon(Physics, new ImageFrame(TextureManager.GetTexture(ContentPaths.GUI.map_icons), 16, 3, 0));



            NoiseMaker.Noises["Chew"] = new List <string>
            {
                ContentPaths.Audio.chew
            };

            NoiseMaker.Noises["Jump"] = new List <string>
            {
                ContentPaths.Audio.jump
            };

            Stats.FullName = TextGenerator.GenerateRandom("$goblinname");
            //Stats.LastName = TextGenerator.GenerateRandom("$goblinfamily");
            Stats.Size = 4;
        }
Exemplo n.º 20
0
        public static RoomData InitializeData()
        {
            Dictionary <ResourceLibrary.ResourceType, ResourceAmount> roomResources = new Dictionary
                                                                                      <ResourceLibrary.ResourceType, ResourceAmount>()
            {
                { ResourceLibrary.ResourceType.Stone, new ResourceAmount(ResourceLibrary.ResourceType.Stone) },
                { ResourceLibrary.ResourceType.Mana, new ResourceAmount(ResourceLibrary.ResourceType.Mana) },
            };

            List <RoomTemplate> libraryTemplates = new List <RoomTemplate>();

            RoomTile[,] lampTemplate =
            {
                {
                    RoomTile.None,
                    RoomTile.Wall | RoomTile.Edge
                },
                {
                    RoomTile.Wall | RoomTile.Edge,
                    RoomTile.Lamp
                }
            };

            RoomTile[,] lampAccessories =
            {
                {
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None
                }
            };

            RoomTile[,]  bookshlf =
            {
                {
                    RoomTile.None,
                    RoomTile.Wall | RoomTile.Edge
                },
                {
                    RoomTile.None,
                    RoomTile.BookShelf
                }
            };

            RoomTile[,] bookshlfAcc =
            {
                {
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None
                }
            };

            RoomTemplate lamp = new RoomTemplate(PlacementType.All, lampTemplate, lampAccessories);

            RoomTile[,] bookTemp =
            {
                {
                    RoomTile.None,
                    RoomTile.Open,
                    RoomTile.None
                },
                {
                    RoomTile.Open,
                    RoomTile.BookTable,
                    RoomTile.Open
                },
                {
                    RoomTile.None,
                    RoomTile.Open,
                    RoomTile.None
                }
            };

            RoomTile[,] bookAcc =
            {
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                },
                {
                    RoomTile.None,
                    RoomTile.None,
                    RoomTile.None
                }
            };

            RoomTemplate book = new RoomTemplate(PlacementType.Random, bookTemp, bookAcc);


            libraryTemplates.Add(new RoomTemplate(PlacementType.Random, bookshlf, bookshlfAcc)
            {
                Probability = 0.15f
            });
            libraryTemplates.Add(lamp);
            libraryTemplates.Add(book);
            Texture2D roomIcons = TextureManager.GetTexture(ContentPaths.GUI.room_icons);

            return(new RoomData(LibraryRoomName, 4, "BlueTileFloor", roomResources, libraryTemplates, new ImageFrame(roomIcons, 16, 0, 1))
            {
                Description = "Wizards do magical research here. Also holds mana crystals to charge magic spells.",
                CanBuildAboveGround = false
            });
        }