/// <summary> /// Default constructor. /// </summary> public Exit() { ++_numExits; _description = String.Empty; _exitFlags = 0; _key = 0; _keyword = String.Empty; _targetRoom = null; _indexNumber = 0; }
/// <summary> /// Creates a room from a room template. /// </summary> /// <param name="room"></param> public Room(RoomTemplate room) { Area = room.Area; BaseRoomFlags = room.BaseRoomFlags; Current = room.Current; CurrentDirection = room.CurrentDirection; CurrentRoomFlags = room.CurrentRoomFlags; Description = room.Description; ExitData = room.ExitData; ExtraDescriptions = room.ExtraDescriptions; FallChance = room.FallChance; Light = room.Light; TerrainType = room.TerrainType; Title = room.Title; IndexNumber = room.IndexNumber; WorldmapTerrainType = room.WorldmapTerrainType; }
/// <summary> /// Updates the data in the window. We pass in a room and a direction /// because we may or may not change the data depending on whether we /// click OK or Cancel. /// </summary> /// <param name="room"></param> /// <param name="direction"></param> public void UpdateWindowContents(RoomTemplate room, Exit.Direction direction) { _room = room; _direction = direction; Exit exit = _room.ExitData[(int)direction]; if (exit != null) { lblEditStatus.Text = "Editing " + direction.ToString() + " exit in room " + room.IndexNumber.ToString() + "."; txtDescription.Text = exit.Description; txtFlags.Text = exit.ExitFlags.ToString(); txtKeyIndexNumber.Text = exit.Key.ToString(); txtKeyword.Text = exit.Keyword; txtIndexNumber.Text = exit.IndexNumber.ToString(); } else { lblEditStatus.Text = "Creating new " + direction.ToString() + " exit in room " + room.IndexNumber.ToString() + "."; } }
/// <summary> /// Gets whether this particular Reset applies to the given room. Used mainly for room-only resets. /// </summary> /// <param name="room"></param> /// <returns></returns> public bool IsRoomReset(RoomTemplate room) { switch (_command) { default: return false; case 'S': case '*': return false; case 'M': case 'O': case 'G': case 'R': case 'F': if (_arg3 == room.IndexNumber) { return true; } return false; case 'E': if (_arg4 == room.IndexNumber) { return true; } return false; case 'P': if (_arg5 == room.IndexNumber) { return true; } return false; case 'D': if (_arg1 == room.IndexNumber) { return true; } return false; } }
/// <summary> /// Generates a zone file. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void generateZoneToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "xml files (*.xml)|*.xml"; if (dialog.ShowDialog() == DialogResult.OK) { int vnum = Int32.Parse(txtStartVnum.Text); Area area = new Area(); area.AreaFlags[Area.AREA_WORLDMAP.Group] = Area.AREA_WORLDMAP.Vector; area.Width = _bitmap.Width; area.Height = _bitmap.Height; area.Author = txtAuthor.Text; area.Builders = txtAuthor.Text; area.Name = txtZoneName.Text; for (int y = 0; y < _bitmap.Height; y++) { for (int x = 0; x < _bitmap.Width; x++) { Color col = _bitmap.GetPixel(x, y); MiniRoomTemplate temp = GetTemplate(col); RoomTemplate room = new RoomTemplate(); room.Title = temp.Title; room.Description = temp.Description; room.TerrainType = temp.Terrain; room.IndexNumber = vnum + x + (y * _bitmap.Width); // Only add exits and add the room to the zone if the room is not impassable. // // TODO: Don't create exits that point to impassable rooms. Color pixel; MiniRoomTemplate target; if (room.TerrainType != TerrainType.underground_impassable || (x == 0 && y == 0)) { if (x > 0) { pixel = _bitmap.GetPixel(x-1, y); target = GetTemplate(pixel); if (target.Terrain != TerrainType.underground_impassable) { Exit exit = new Exit(); exit.IndexNumber = vnum + x + (y * _bitmap.Width) - 1; room.ExitData[(int)Exit.Direction.west] = exit; } } if (x < (_bitmap.Width - 1)) { pixel = _bitmap.GetPixel(x+1, y); target = GetTemplate(pixel); if (target.Terrain != TerrainType.underground_impassable) { Exit exit = new Exit(); exit.IndexNumber = vnum + x + (y * _bitmap.Width) + 1; room.ExitData[(int)Exit.Direction.east] = exit; } } if (y > 0) { pixel = _bitmap.GetPixel(x, y-1); target = GetTemplate(pixel); if (target.Terrain != TerrainType.underground_impassable) { Exit exit = new Exit(); exit.IndexNumber = vnum + x + ((y - 1) * _bitmap.Width); room.ExitData[(int)Exit.Direction.north] = exit; } } if( y < (_bitmap.Height - 1 )) { pixel = _bitmap.GetPixel(x, y+1); target = GetTemplate(pixel); if (target.Terrain != TerrainType.underground_impassable) { Exit exit = new Exit(); exit.IndexNumber = vnum + x + ((y + 1) * _bitmap.Width); room.ExitData[(int)Exit.Direction.south] = exit; } } area.Rooms.Add(room); } } } area.Save(dialog.FileName); } }
/// <summary> /// If in graphical client mode, returns the character pair representing foreground /// and background terrain types. /// /// Otherwise, returns the colorized ASCII string representing that map square. /// </summary> /// <param name="room"></param> /// <param name="graphicalClient"></param> /// <returns></returns> public static string GetMapCharacters(RoomTemplate room, bool graphicalClient) { int offset = 64; if (graphicalClient) { // Convert terrain type to terminal-friendly characters. char val1 = (char)(room.TerrainType + offset); char val2 = (char)offset; if (room.WorldmapTerrainType != 0) { val2 = (char)(room.WorldmapTerrainType + offset); } else { // Set default overlays for certain terrain types (trees, mountains, hills). switch (room.TerrainType) { default: break; case TerrainType.city: // Neutral city by default. val2 = (char)(41 + offset); break; case TerrainType.forest: // Oak tree by default. val2 = (char)(42 + offset); break; case TerrainType.hills: // Green hills by default. val2 = (char)(19 + offset); break; case TerrainType.jungle: val2 = (char)(31 + offset); break; case TerrainType.mountain: val2 = (char)(37 + offset); break; case TerrainType.road: val2 = (char)(55 + offset); // TODO: Determine tile type based on roads nearby, or populate the map with better data. // for example, these are the road tiles available in the Basternae client: // //_foregroundTile[52] = new wxBitmap( pathPrefix + _("road_ew.png"), wxBITMAP_TYPE_PNG ) ; //_foregroundTile[53] = new wxBitmap( pathPrefix + _("road_ns.png"), wxBITMAP_TYPE_PNG ) ; //_foregroundTile[54] = new wxBitmap( pathPrefix + _("road_4way.png"), wxBITMAP_TYPE_PNG ) ; //_foregroundTile[55] = new wxBitmap( pathPrefix + _("road_corner_ne.png"), wxBITMAP_TYPE_PNG ) ; //_foregroundTile[56] = new wxBitmap( pathPrefix + _("road_corner_nw.png"), wxBITMAP_TYPE_PNG ) ; //_foregroundTile[57] = new wxBitmap( pathPrefix + _("road_corner_se.png"), wxBITMAP_TYPE_PNG ) ; //_foregroundTile[58] = new wxBitmap( pathPrefix + _("road_corner_sw.png"), wxBITMAP_TYPE_PNG ) ; //_foregroundTile[59] = new wxBitmap( pathPrefix + _("road_tshape_e.png"), wxBITMAP_TYPE_PNG ) ; //_foregroundTile[60] = new wxBitmap( pathPrefix + _("road_tshape_n.png"), wxBITMAP_TYPE_PNG ) ; //_foregroundTile[61] = new wxBitmap( pathPrefix + _("road_tshape_s.png"), wxBITMAP_TYPE_PNG ) ; //_foregroundTile[62] = new wxBitmap( pathPrefix + _("road_tshape_w.png"), wxBITMAP_TYPE_PNG ) ; break; } } return val1.ToString() + val2.ToString(); } if (room.WorldmapTerrainType == 0) { switch (room.TerrainType) { default: return "&+w.&n"; case TerrainType.city: return "&+W^&n"; case TerrainType.field: return "&+G.&n"; case TerrainType.forest: return "&+g*&n"; case TerrainType.hills: return "&+y^&n"; case TerrainType.jungle: return "&+G*&n"; case TerrainType.lava: return "&+r#&n"; case TerrainType.mountain: return "&+yM&n"; case TerrainType.ocean: case TerrainType.unswimmable_water: return "&-b&+B~&n"; case TerrainType.underground_wild: return "&+m.&n"; case TerrainType.underground_unswimmable_water: case TerrainType.underground_ocean: return "&-b&+L~&n"; case TerrainType.underground_frozen: return "&+W.&n"; case TerrainType.tundra: return "&+W.&n"; case TerrainType.underground_swimmable_water: case TerrainType.swimmable_water: return "&-B &n"; case TerrainType.swamp: return "&+G#&n"; case TerrainType.road: return "&+w+&n"; case TerrainType.glacier: return "&+W#&n"; case TerrainType.desert: return "&+Y~&n"; } } else { return "&-L &n"; } }
/// <summary> /// Saves current window contents, creates a new room, navigates to it, and returns the number. /// This can be called from the edit window itself or from elsewhere, such as creating rooms /// from within exit editing. Navigating to the created room is optional, and inadvisable /// when creating rooms from exits. /// </summary> /// <returns></returns> public int AddNewRoom(bool navigate) { // We need to store current index so we can return to it later if need be. int selectedIndex = roomList.SelectedIndex; ApplyWindowContents(); RoomTemplate room = new RoomTemplate(); if (_area.HighRoomIndexNumber >= 0) { room.IndexNumber = _area.HighRoomIndexNumber + 1; } _area.Rooms.Add(room); _area.RebuildIndexes(); UpdateRoomList(); SetControlAvailability(); // Navigate either to the new room or the original room we were editing. if (navigate) { roomList.SelectedIndex = roomList.Items.Count - 1; UpdateWindowContents(room); } else { roomList.SelectedIndex = selectedIndex; } _parent.UpdateStatusBar(); _parent.UpdateRoomMap(); return room.IndexNumber; }
private void UpdateWindowContents(RoomTemplate room) { txtName.Text = room.Title; txtIndexNumber.Text = room.IndexNumber.ToString(); txtDescription.Text = room.Description; txtFlags.Text = room.BaseRoomFlags[0].ToString(); txtFlags2.Text = room.BaseRoomFlags[1].ToString(); cbCurrentDir.SelectedIndex = room.CurrentDirection; cbTerrain.SelectedItem = room.TerrainType.ToString(); UpdateExitButtons(room); lstExtraDesc.Items.Clear(); foreach (ExtendedDescription desc in room.ExtraDescriptions) { lstExtraDesc.Items.Add(desc); } txtCurrent.Text = room.Current.ToString(); txtFallChance.Text = room.FallChance.ToString(); SecondaryTerrainType mapSector = (SecondaryTerrainType)room.WorldmapTerrainType; cbMapSector.Text = mapSector.ToString(); }
private void UpdateExitButtons(RoomTemplate room) { if (room.ExitData[(int)Exit.Direction.north] == null) { btnn.ForeColor = System.Drawing.Color.Gray; } else { btnn.ForeColor = System.Drawing.Color.Black; } if (room.ExitData[(int)Exit.Direction.northwest] == null) { btnnw.ForeColor = System.Drawing.Color.Gray; } else { btnnw.ForeColor = System.Drawing.Color.Black; } if (room.ExitData[(int)Exit.Direction.northeast] == null) { btnne.ForeColor = System.Drawing.Color.Gray; } else { btnne.ForeColor = System.Drawing.Color.Black; } if (room.ExitData[(int)Exit.Direction.south] == null) { btns.ForeColor = System.Drawing.Color.Gray; } else { btns.ForeColor = System.Drawing.Color.Black; } if (room.ExitData[(int)Exit.Direction.southeast] == null) { btnse.ForeColor = System.Drawing.Color.Gray; } else { btnse.ForeColor = System.Drawing.Color.Black; } if (room.ExitData[(int)Exit.Direction.southwest] == null) { btnsw.ForeColor = System.Drawing.Color.Gray; } else { btnsw.ForeColor = System.Drawing.Color.Black; } if (room.ExitData[(int)Exit.Direction.east] == null) { btne.ForeColor = System.Drawing.Color.Gray; } else { btne.ForeColor = System.Drawing.Color.Black; } if (room.ExitData[(int)Exit.Direction.west] == null) { btnw.ForeColor = System.Drawing.Color.Gray; } else { btnw.ForeColor = System.Drawing.Color.Black; } if (room.ExitData[(int)Exit.Direction.up] == null) { btnup.ForeColor = System.Drawing.Color.Gray; } else { btnup.ForeColor = System.Drawing.Color.Black; } if (room.ExitData[(int)Exit.Direction.down] == null) { btndn.ForeColor = System.Drawing.Color.Gray; } else { btndn.ForeColor = System.Drawing.Color.Black; } }
private void btnClone_Click(object sender, EventArgs e) { if (roomList.SelectedIndex == -1 || roomList.SelectedIndex > (roomList.Items.Count - 1)) { MessageBox.Show("Cannot clone an object without a valid object selected."); return; } ApplyWindowContents(); RoomTemplate room = new RoomTemplate(_area.Rooms[roomList.SelectedIndex]); if (_area.HighObjIndexNumber >= 0) { room.IndexNumber = _area.HighRoomIndexNumber + 1; } _area.Rooms.Add(room); _area.RebuildIndexes(); UpdateRoomList(); SetControlAvailability(); roomList.SelectedIndex = roomList.Items.Count - 1; UpdateWindowContents(room); _parent.UpdateStatusBar(); }
/// <summary> /// Copy constructor. Copies room data but does not copy exit data. /// </summary> /// <param name="room"></param> public RoomTemplate(RoomTemplate room) { this._controlledBy = room._controlledBy; this.Area = room.Area; this.BaseRoomFlags = new int[room.BaseRoomFlags.Length]; room.BaseRoomFlags.CopyTo(this.BaseRoomFlags, 0); this.Current = room.Current; this.CurrentDirection = room.CurrentDirection; this.CurrentRoomFlags = new int[room.CurrentRoomFlags.Length]; room.CurrentRoomFlags.CopyTo(this.CurrentRoomFlags, 0); this.Description = room.Description; this.ExitData = new Exit[Limits.MAX_DIRECTION]; this.ExtraDescriptions = new List<ExtendedDescription>(room.ExtraDescriptions); this.FallChance = room.FallChance; this.IndexNumber = Area.HighRoomIndexNumber + 1; this.Light = room.Light; this.TerrainType = room.TerrainType; this.Title = room.Title; this.WorldmapTerrainType = room.WorldmapTerrainType; ++_numRooms; }