WorldMap world; //This is a reference to the WorldMap this cell is a part of #endregion Fields #region Constructors /// <summary> /// Creates a new cell. /// </summary> /// <param name="X">The X coordinate of the upper left corner of the cell.</param> /// <param name="Y">The Y coordinate of the upper left corner of the cell.</param> /// <param name="Z">The Z coordinate of the upper left corner of the cell.</param> /// <param name="cellID">The (unique) cell id in the WorldMap context.</param> /// <param name="world">The WorldMap this cell is a part of.</param> public Cell(int X, int Y, int Z, int cellID, WorldMap world) { this.X = X; this.Y = Y; this.Z = Z; this.world = world; this.CellID = cellID; }
/// <summary> /// Initialize a new map object. /// </summary> public Map(Creature player, WorldMap wm, MessageHandler _out, FactionManager facman, SQLiteConnection dbconn, int vp_height, int vp_width) { this.Player = player; this.wm = wm; this._out = _out; this.dbconn = dbconn; this.vp_height = vp_height; this.vp_width = vp_width; sun_level_changed = true; CreatureList = new Inventory<Creature>(); ItemList = new Inventory<Item>(); //LightSources = new Dictionary<string, LightSource>(); this.facman = facman; tcod_map = new TCODMap(3 * wm.CELL_WIDTH, 3 * wm.CELL_HEIGHT); light_tint = new int[vp_width, vp_height]; cells = new Cell[3, 3, 3]; centerAndLoad(player); }
public static void ExportHeightmapAsBitmap(WorldMap wm, TCODHeightMap map, string filename) { TCODHeightMap m2 = new TCODHeightMap(wm.GLOBAL_WIDTH, wm.GLOBAL_HEIGHT); m2.copy(map); m2.add(1.0f); m2.scale(128); Debug.WriteLine("EXPORT A: " + map.getValue(10, 10)); Debug.WriteLine("EXPORT B: " + m2.getValue(10, 10)); Bitmap bmp = new Bitmap(wm.GLOBAL_WIDTH, wm.GLOBAL_HEIGHT); int val = 0; int argb = 0xFF; for (int x = 0; x < wm.GLOBAL_WIDTH; x++) { for (int y = 0; y < wm.GLOBAL_HEIGHT; y++) { val = (int) m2.getValue(x, y); bmp.SetPixel(x, y, Color.FromArgb((0xFF<<24)+(val<<16)+(val<<8)+val)); } } bmp.Save(filename,System.Drawing.Imaging.ImageFormat.Bmp); }
public void InitNew(string profile_name, uint map_seed) { string path = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Game)).CodeBase); path = path.Remove(0, 6); string newPath = System.IO.Path.Combine(path, "profiles", profile_name); Directory.CreateDirectory(newPath); ProfilePath = newPath; InitDB(newPath); rand = new Random(); facman = new FactionManager(); Faction player_faction = new Faction("Player", "The player"); player_faction.Init(facman); //Faction human_faction = new Faction("Humans", "The surviors of their self-made cathastrophe."); Faction test_faction = new Faction("TESTFAC", "TEST FACTION PLEASE IGNORE"); //human_faction.Init(facman); test_faction.Init(facman); //human_faction.AddRelation(test_faction, FactionRelation.Hostile); test_faction.AddRelation(player_faction, FactionRelation.Hostile); root.setBackgroundFlag(TCODBackgroundFlag.Default); player = new Player(1300, 1300, 35, "Player", "A ragged and scruffy-looking individual.", '@', new Body(BODY_DEF_HUMAN), new CharStats(10, 10, 10)); player.Init(TCODColor.yellow, Out, player_faction, new Objects.Action(ActionType.Idle, null, player, 0.0d)); Out.SendMessage("Welcome to [insert game name here]!", Message.MESSAGE_WELCOME); Out.SendMessage("You wake up in a damp and shoddy shack. Or maybe a patch of dirt. Depends on the games' version."); //Default map parameters int[] parameters = new int[7]; parameters[0] = 200; //CellWidth parameters[1] = 200; //CellHeight parameters[2] = 20; //CellDepth parameters[3] = 10; //CellsX parameters[4] = 10; //CellsY parameters[5] = 6; //CellsZ parameters[6] = 45; //GroundLevel wm = new WorldMap(map_seed, dbconn, parameters); map = new Map(player, wm, Out, facman, dbconn, MAIN_HEIGHT - 2, WINDOW_WIDTH - 2); RenderLoadingScreen(); player.SetPosition(player.X, player.Y, map.DropObject(player.X, player.Y, player.Z + 1)); map.AddCreature(player); //testai = new AICreature(1301, 1301, 31, "TEST", "TEST CREATURE PLEASE IGNORE", 'A', new Body(BODY_DEF_HUMAN), new CharStats(10,10,10)); //testai.Init(TCODColor.orange, Out, test_faction, new Objects.Action(ActionType.Idle, null, testai, 0.0d), new WalkerAI(rand.Next(0, 100000000)), map); //testai_guid = testai.GUID; //map.AddCreature(testai); dummy = new Creature(1299, 1299, 31, "TEST", "A Training Dummy.", 'D', new Body(BODY_DEF_HUMAN), new CharStats(10, 10, 10)); dummy.Init(TCODColor.turquoise, Out); map.AddCreature(dummy); List<FireMode> gl_fm = new List<FireMode>(); gl_fm.Add(FireMode.Semi); gl_fm.Add(FireMode.Burst2); testgun = new Firearm(1299, 1301, 31, "Glock 17C", "A semi-automatic pistol manufactured by Austrian Glock Ges. m.b.H. Large parts of it are manufactured from extremely resilient high-strengh polymer and it chambers NATO standard 9x19mm Parabellum rounds. It has a magazine capacity of 17 rounds. The C Variant features slots cut into the barrel and slide compensating for muzzle rise and recoil. It is one of the most commonly used firearms in US law enforcement and enjoys great popularity in the gun community.", 'F', 5.0d, new Caliber(9d, 19d), GunType.Pistol, gl_fm, 17); testgun.Init(TCODColor.grey, Out); testmag = new Magazine(1301, 1299, 31, "9mm Clip", "TEST MAG PLEASE IGNORE.", 'M', 0.75d, 30, 30, new Caliber(5.56d, 45.0d), AmmoModifier.Regular); testmag.Init(TCODColor.brass, Out); Item temp = new Item(1302, 1300, 31, "Apple", "A tasty red apple. Possibly Braeburn.", 'F', 0.3d); temp.Init(TCODColor.red, Out); LightSource p_torch = new LightSource(1300, 1300, 31, 50, 10, "Torch", "A torch.", '!', 1.0d); p_torch.Init(TCODColor.orange, Out); map.AddItem(testgun); map.AddItem(testmag); map.AddItem(temp); map.AddItem(p_torch); //AICreature testai2 = new AICreature(290, 290, 15, "TEST2", "TEST CREATURE PLEASE IGNORE", 'B'); //testai2.Init(TCODColor.orange, Out, test_faction, new Objects.Action(ActionType.Idle, null, testai, 0.0d), new WalkerAI(rand.Next(0, 10000000)), map); //map.AddCreature(testai2); //Item test_item = new Item(1299, 1299, map.DropObject(1299, 1299, 35), "Shimmering rock", "A shining polished rock which seems to change color when you look at it.", (char)'*'); //LightSource test_item = new LightSource(1299, 1299, map.DropObject(1299, 1299, 35), 12, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*'); //test_item_guid = test_item.GUID; //test_item.Init(TCODColor.red, Out); //test_item.Activate(); //map.AddItem(test_item); LightSource test_item2 = new LightSource(1295, 1310, map.DropObject(1299, 1299, 35), 50, 10, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*', 1.0d); test_item2.Init(TCODColor.blue, Out); test_item2.Activate(); map.AddItem(test_item2); LightSource test_item3 = new LightSource(1315, 1283, map.DropObject(1299, 1299, 35), 50, 10, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*', 1.0d); test_item3.Init(TCODColor.green, Out); test_item3.Activate(); map.AddItem(test_item3); LightSource test_item4 = new LightSource(1315, 1319, map.DropObject(1299, 1299, 35), 50, 10, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*', 1.0d); test_item4.Init(TCODColor.orange, Out); test_item4.Activate(); map.AddItem(test_item4); LightSource test_item5 = new LightSource(1291, 1283, map.DropObject(1299, 1299, 35), 50, 10, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*', 1.0d); test_item5.Init(TCODColor.red, Out); test_item5.Activate(); map.AddItem(test_item5); LightSource test_item6 = new LightSource(1305, 1300, map.DropObject(1299, 1299, 35), 50, 10, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*', 1.0d); test_item6.Init(TCODColor.pink, Out); test_item6.Activate(); map.AddItem(test_item6); LightSource test_item7 = new LightSource(1291, 1293, map.DropObject(1299, 1299, 35), 50, 10, "Shimmering Rock", "A shining polished rock which seems to change color when you look at it.", (char)'*', 1.0d); test_item7.Init(TCODColor.violet, Out); test_item7.Activate(); map.AddItem(test_item7); }
public void InitLoad(string profile_name) { string path = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Game)).CodeBase); path = path.Remove(0, 6); string newPath = System.IO.Path.Combine(path, "profiles", profile_name); ProfilePath = newPath; //Initialize the database(s) InitDB(newPath); facman = new FactionManager(); rand = new Random(); //Load the data from the save.dat FileStream fstream = new FileStream(System.IO.Path.Combine(ProfilePath, "save.dat"), FileMode.Open); StreamReader sreader = new StreamReader(fstream); string pdat = "00", fdat = "00"; int[] wm_param = new int[7]; string[] temp; while (!sreader.EndOfStream) { temp = sreader.ReadLine().Split('='); switch (temp[0]) { case "Version": if (temp[1] != currentVersionCode) throw new Exception("Error while loading profile: save.dat not at current version"); break; case "MapSeed": if (!UInt32.TryParse(temp[1], out seed)) throw new Exception("Error while loading profile: MapSeed is not a number."); break; case "FactionData": fdat = temp[1]; break; case "PlayerData": pdat = temp[1]; break; case "CellWidth": if (!Int32.TryParse(temp[1], out wm_param[0])) throw new Exception("Error while loading profile: CellWidth is not a number."); break; case "CellHeight": if (!Int32.TryParse(temp[1], out wm_param[1])) throw new Exception("Error while loading profile: CellHeight is not a number."); break; case "CellDepth": if (!Int32.TryParse(temp[1], out wm_param[2])) throw new Exception("Error while loading profile: CellDepth is not a number."); break; case "CellsX": if (!Int32.TryParse(temp[1], out wm_param[3])) throw new Exception("Error while loading profile: CellsX is not a number."); break; case "CellsY": if (!Int32.TryParse(temp[1], out wm_param[4])) throw new Exception("Error while loading profile: CellsY is not a number."); break; case "CellsZ": if (!Int32.TryParse(temp[1], out wm_param[5])) throw new Exception("Error while loading profile: CellsZ is not a number."); break; case "GroundLevel": if (!Int32.TryParse(temp[1], out wm_param[6])) throw new Exception("Error while loading profile: GroundLevel is not a number."); break; } } //Deserialize player Faction _fac; byte[] data; MemoryStream mstream = new MemoryStream(); BinaryFormatter deserializer = new BinaryFormatter(); data = Util.ConvertDBString(fdat); //Write the converted byte array into the MemoryStream (and reset it to origin) mstream.Write(data, 0, data.Length); mstream.Seek(0, SeekOrigin.Begin); //Deserialize the faction object itself _fac = (Faction)deserializer.Deserialize(mstream); _fac.Init(facman); mstream.SetLength(0); mstream.Seek(0, SeekOrigin.Begin); data = Util.ConvertDBString(pdat); //Write the converted byte array into the MemoryStream (and reset it to origin) mstream.Write(data, 0, data.Length); mstream.Seek(0, SeekOrigin.Begin); //Deserialize the player player = (Player)deserializer.Deserialize(mstream); player.Init(TCODColor.yellow, Out, _fac, new Objects.Action(ActionType.Idle, null, player, 0.0d)); //SETUP MAP AND WORLDMAP, ADD PLAYER wm = new WorldMap(seed, dbconn, wm_param); map = new Map(player, wm, Out, facman, dbconn, MAIN_HEIGHT - 2, WINDOW_WIDTH - 2); RenderLoadingScreen(); player.SetPosition(player.X, player.Y, map.DropObject(player.X, player.Y, player.Z + 1)); map.AddCreature(player); Out.SendMessage("Profile " + ProfileName + " successfully loaded. Last played: " + File.GetLastWriteTime(Path.Combine(ProfilePath, "save.dat")) + "."); mstream.Close(); sreader.Close(); fstream.Close(); }