Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add max beds and house client id #8

Merged
merged 3 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ House::House(Map& map) :
rent(0),
townid(0),
guildhall(false),
clientid(0),
beds(0),
map(&map),
exit(0,0,0)
{
Expand Down
2 changes: 2 additions & 0 deletions source/house.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class House {

uint32_t id;
int rent;
int clientid;
int beds;
//HouseDoorList doorList;
std::string name;
uint32_t townid;
Expand Down
16 changes: 13 additions & 3 deletions source/iomap_otbm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void Item::serializeItemAttributes_OTBM(const IOMap& maphandle, NodeFileWriteHan

void Item::serializeItemCompact_OTBM(const IOMap& maphandle, NodeFileWriteHandle& stream) const
{
stream.addU16(id);
stream.addU16(g_items[id].clientID);

/* This is impossible
const ItemType& iType = g_items[id];
Expand All @@ -238,7 +238,7 @@ void Item::serializeItemCompact_OTBM(const IOMap& maphandle, NodeFileWriteHandle
bool Item::serializeItemNode_OTBM(const IOMap& maphandle, NodeFileWriteHandle& file) const
{
file.addNode(OTBM_ITEM);
file.addU16(id);
file.addU16(g_items[id].clientID);
if(maphandle.version.otbm == MAP_OTBM_1) {
const ItemType& iType = g_items[id];
if(iType.stackable || iType.isSplash() || iType.isFluidContainer()) {
Expand Down Expand Up @@ -370,7 +370,7 @@ bool Container::unserializeItemNode_OTBM(const IOMap& maphandle, BinaryNode* nod
bool Container::serializeItemNode_OTBM(const IOMap& maphandle, NodeFileWriteHandle& file) const
{
file.addNode(OTBM_ITEM);
file.addU16(id);
file.addU16(g_items[id].clientID);
if(maphandle.version.otbm == MAP_OTBM_1) {
// In the ludicrous event that an item is a container AND stackable, we have to do this. :p
const ItemType& iType = g_items[id];
Expand Down Expand Up @@ -1179,6 +1179,14 @@ bool IOMapOTBM::loadHouses(Map& map, pugi::xml_document& doc)
warning("House %d has no town! House was removed.", house->id);
map.houses.removeHouse(house);
}

if((attribute = houseNode.attribute("clientid"))) {
house->clientid = attribute.as_uint();
}

if((attribute = houseNode.attribute("beds"))) {
house->beds = attribute.as_uint();
}
}
return true;
}
Expand Down Expand Up @@ -1761,6 +1769,8 @@ bool IOMapOTBM::saveHouses(Map& map, pugi::xml_document& doc)

houseNode.append_attribute("townid") = house->townid;
houseNode.append_attribute("size") = static_cast<int32_t>(house->size());
houseNode.append_attribute("clientid") = house->clientid;
houseNode.append_attribute("beds") = house->beds;
}
return true;
}
Expand Down
20 changes: 20 additions & 0 deletions source/palette_house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ EditHouseDialog::EditHouseDialog(wxWindow* parent, Map* map, House* house) :
house_name = wxstr(house->name);
house_id = i2ws(house->id);
house_rent = i2ws(house->rent);
house_clientid = i2ws(house->clientid);
house_beds = i2ws(house->beds);

// House options
tmpsizer = newd wxStaticBoxSizer(wxHORIZONTAL, this, "Name");
Expand All @@ -482,6 +484,16 @@ EditHouseDialog::EditHouseDialog(wxWindow* parent, Map* map, House* house) :
tmpsizer->Add(id_field);
sizer->Add(tmpsizer, wxSizerFlags().Border(wxALL, 20));

tmpsizer = newd wxStaticBoxSizer(wxHORIZONTAL, this, "Client ID");
clientid_field = newd wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxSize(160,20), 0, wxTextValidator(wxFILTER_NUMERIC, &house_clientid));
tmpsizer->Add(clientid_field);
sizer->Add(tmpsizer, wxSizerFlags().Border(wxALL, 20));

tmpsizer = newd wxStaticBoxSizer(wxHORIZONTAL, this, "Max beds");
beds_field = newd wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxSize(160,20), 0, wxTextValidator(wxFILTER_NUMERIC, &house_beds));
tmpsizer->Add(beds_field);
sizer->Add(tmpsizer, wxSizerFlags().Border(wxALL, 20));

// House options
guildhall_field = newd wxCheckBox(this, wxID_ANY, "Guildhall", wxDefaultPosition);

Expand Down Expand Up @@ -509,6 +521,12 @@ void EditHouseDialog::OnClickOK(wxCommandEvent& WXUNUSED(event))
long new_house_rent;
house_rent.ToLong(&new_house_rent);

long new_house_clientid;
house_clientid.ToLong(&new_house_clientid);

long new_house_beds;
house_beds.ToLong(&new_house_beds);

if(new_house_rent < 0) {
g_gui.PopupDialog(this, "Error", "House rent cannot be less than 0.", wxOK);
return;
Expand Down Expand Up @@ -536,6 +554,8 @@ void EditHouseDialog::OnClickOK(wxCommandEvent& WXUNUSED(event))
// Transfer to house
what_house->name = nstr(house_name);
what_house->rent = new_house_rent;
what_house->clientid = new_house_clientid;
what_house->beds = new_house_beds;
what_house->guildhall = guildhall_field->GetValue();

EndModal(1);
Expand Down
4 changes: 3 additions & 1 deletion source/palette_house.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ class EditHouseDialog : public wxDialog
Map* map;
House* what_house;

wxString house_name, house_id, house_rent;
wxString house_name, house_id, house_rent, house_clientid, house_beds;

wxTextCtrl* name_field;
wxTextCtrl* id_field;
wxTextCtrl* rent_field;
wxTextCtrl* clientid_field;
wxTextCtrl* beds_field;
wxCheckBox* guildhall_field;

DECLARE_EVENT_TABLE();
Expand Down
Loading