bool HouseTransferItem::onTradeEvent(TradeEvents_t event, Player* owner) { House* house; switch(event){ case ON_TRADE_TRANSFER: { house = getHouse(); if(house){ house->executeTransfer(this, owner); } g_game.internalRemoveItem(this, 1); break; } case ON_TRADE_CANCEL: { house = getHouse(); if(house){ house->resetTransferItem(); } break; } default: break; } return true; }
int HouseLevelSpec::computeReligionLevel(House &house) { int res = 0; if (house.hasServiceAccess(S_TEMPLE_MERCURE)) { res++; } if (house.hasServiceAccess(S_TEMPLE_VENUS)) { res++; } if (house.hasServiceAccess(S_TEMPLE_MARS)) { res++; } if (house.hasServiceAccess(S_TEMPLE_NEPTUNE)) { res++; } if (house.hasServiceAccess(S_TEMPLE_CERES)) { res++; } return res; }
float HouseLevelSpec::evaluateEducationNeed(House &house, const ServiceType service) { float res = 0; int houseLevel = house.getLevelSpec().getHouseLevel(); int minLevel = HouseSpecHelper::getInstance().getHouseLevelSpec(houseLevel+1)._minEducationLevel; if (minLevel == 1) { // need school or library if (service != S_COLLEGE) { res = (float)( 100 - std::max(house.getServiceAccess(S_SCHOOL), house.getServiceAccess(S_LIBRARY)) ); } } else if (minLevel == 2) { // need school and library if (service != S_COLLEGE) { res = (float)( 100 - house.getServiceAccess(service) ); } } else if (minLevel == 3) { // need school and library and college res = (float)( 100 - house.getServiceAccess(service) ); } // std::cout << "education need: " << service << " " << res << std::endl; return res; }
bool IOMapSerialize::updateAuctions() { Database* db = Database::getInstance(); DBQuery query; time_t now = time(NULL); query << "SELECT `house_id`, `player_id`, `bid` FROM `house_auctions` WHERE `endtime` < " << now; DBResult* result; if(!(result = db->storeQuery(query.str()))) return true; bool success = true; House* house = NULL; do { query.str(""); query << "DELETE FROM `house_auctions` WHERE `house_id` = " << result->getDataInt("house_id"); if(!(house = Houses::getInstance()->getHouse(result->getDataInt( "house_id"))) || !db->query(query.str())) { success = false; continue; } house->setOwner(result->getDataInt("player_id")); Houses::getInstance()->payHouse(house, now, result->getDataInt("bid")); } while(result->next()); result->free(); return success; }
boolean Floor::handle_xml_tag(Tag tag, xml_node *node) { switch (tag) { case ON_FLOOR_TAG: case INSIDE_TAG: // new on 040803 // following called reset_items prior to 240203 just_add_items(xml_load_sprites(node),xml_get_attribute_int(node,L"TopLevel",0)); // new on 110803 to add to screen if pasting in the floor by itself // rewritten on 171202 to just do above rather than below // Sprites *floor_items = xml_load_sprites(node); // if (floor_items != NULL) { //Sprites *remaining = floor_items; //while (remaining != NULL) { // // new on 101099 if priority of item is fixed then don't reset it // // so Marty, for example, loads in with correct priority // add_item(remaining->first(),FALSE); // // FALSE replaced !remaining->first()->priority_fixed() above on 211199 since priority is now saved correctly // remaining = remaining->rest(); //}; //floor_items->recursively_propagate_changes(); //floor_items->activate(); // floor_items->remove_all(); // delete floor_items; // }; current_priority = xml_get_attribute_int(node,L"Z",max_long); return(TRUE); case PREVIOUS_MOUSE_TAG: set_previous_mouse((Mouse *) xml_get_sprite(node,previous_mouse,MOUSE_WITH_HAMMER)); // args added on 070103 return(TRUE); case MAIN_BOX_TAG: body_cubby = (Cubby *) xml_get_sprite(node,body_cubby,CUBBY); if (body_cubby != NULL) { // new on 090203 - not clear if better to use set_body_cubby instead but it does much more body_cubby->increment_ref_count(); }; return(body_cubby != NULL); case ALTERNATIVES_FOR_MY_BOX_TAG: alternative_body_cubbies = xml_load_sprites(node); return(alternative_body_cubbies != NULL); case INITIAL_ROBOT_TAG: set_initial_robot((Robot *) xml_get_sprite(node,initial_robot,ROBOT)); return(initial_robot != NULL); case HOUSE_LOCATION_TAG: { House *house = house_at_location(node); if (house == NULL) return(FALSE); room = house->pointer_to_room(); return(room != NULL); }; case NO_MORE_TAGS: // commented out on 041103 since this causes problem when jumping between segments in time travel and is only an optimization anyway // toolbox_status = (ToolboxCacheStatus) xml_get_attribute_int(node,L"ToolBoxStatusCode",TOOLBOX_CACHE_STATUS_UNINITIALIZED); floor_id = xml_get_attribute_int(node,L"FloorID",floor_id); at_left_wall = xml_get_attribute_int(node,L"AtLeftWall",0); // prior to 210404 at_left_wall at_right_wall = xml_get_attribute_int(node,L"AtRightWall",0); // prior to 210404 at_right_wall at_front_wall = xml_get_attribute_int(node,L"AtFrontWall",0); // prior to 210404 at_front_wall return(TRUE); // had been commented out on 090404 to fall through to call to super -- trying to fix time travel bug with containment region // restored 090404 since Floor is "self contained" default: // return(FALSE); // extra_xml?? 051102 return(Visible_Background::handle_xml_tag(tag,node)); // new on 090404 - though super doesn't do much better... }; };
void HousePalettePanel::OnListBoxDoubleClick(wxCommandEvent& event) { House* house = reinterpret_cast<House*>(event.GetClientData()); // I find it extremly unlikely that one actually wants the exit at 0,0,0, so just treat it as the null value if(house && house->getExit() != Position(0,0,0)) { gui.CenterOnPosition(house->getExit()); } }
House* Houses::getHouseByPlayerId(uint32_t playerId) { for(HouseMap::iterator it = houseMap.begin(); it != houseMap.end(); ++it){ House* house = it->second; if(house->getHouseOwner() == playerId){ return house; } } return NULL; }
void RadarClass::destroy() { House* owner = getOwner(); StructureClass::destroy(); if(!owner->hasRadar()) { owner->changeRadar(false); } }
void Commands::sellHouse(Player& player, const std::string& param) { Player* tradePartner = g_game.getPlayerByName(param); if (!tradePartner || tradePartner == &player) { player.sendCancel("Trade player not found."); return; } if (!Position::areInRange<2, 2, 0>(tradePartner->getPosition(), player.getPosition())) { player.sendCancel("Trade player is too far away."); return; } if (!tradePartner->isPremium()) { player.sendCancel("Trade player does not have a premium account."); return; } HouseTile* houseTile = dynamic_cast<HouseTile*>(player.getTile()); if (!houseTile) { player.sendCancel("You must stand in your house to initiate the trade."); return; } House* house = houseTile->getHouse(); if (!house || house->getOwner() != player.getGUID()) { player.sendCancel("You don't own this house."); return; } if (Houses::getInstance().getHouseByPlayerId(tradePartner->getGUID())) { player.sendCancel("Trade player already owns a house."); return; } if (IOLoginData::hasBiddedOnHouse(tradePartner->getGUID())) { player.sendCancel("Trade player is currently the highest bidder of an auctioned house."); return; } Item* transferItem = house->getTransferItem(); if (!transferItem) { player.sendCancel("You can not trade this house."); return; } transferItem->getParent()->setParent(&player); if (!g_game.internalStartTrade(&player, tradePartner, transferItem)) { house->resetTransferItem(); } }
void Commands::sellHouse(Player* player, const std::string& cmd, const std::string& param) { House* house = Houses::getInstance().getHouseByPlayerId(player->guid); if (!house) { player->sendCancel("You do not own any house."); return; } Player* tradePartner = g_game.getPlayerByName(param); if (!(tradePartner && tradePartner != player)) { player->sendCancel("Trade player not found."); return; } if (tradePartner->level < 1) { player->sendCancel("Trade player level is too low."); return; } if (!Position::areInRange<2, 2, 0>(tradePartner->getPosition(), player->getPosition())) { player->sendCancel("Trade player is too far away."); return; } if (!tradePartner->isPremium()) { player->sendCancel("Trade player does not have a premium account."); return; } if (Houses::getInstance().getHouseByPlayerId(tradePartner->guid)) { player->sendCancel("Trade player already owns a house."); return; } if (IOLoginData::getInstance()->hasBiddedOnHouse(tradePartner->guid)) { player->sendCancel("Trade player is currently the highest bidder of an auctioned house."); return; } Item* transferItem = house->getTransferItem(); if (!transferItem) { player->sendCancel("You can not trade this house."); return; } transferItem->getParent()->setParent(player); if (!g_game.internalStartTrade(player, tradePartner, transferItem)) { house->resetTransferItem(); } }
bool IOMapSerialize::saveMap() { int64_t start = OTSYS_TIME(); Database* db = Database::getInstance(); std::ostringstream query; //Start the transaction DBTransaction transaction; if (!transaction.begin()) { return false; } //clear old tile data if (!db->executeQuery("DELETE FROM `tile_store`")) { return false; } DBInsert stmt; stmt.setQuery("INSERT INTO `tile_store` (`house_id`, `data`) VALUES "); PropWriteStream stream; for (const auto& it : Houses::getInstance().getHouses()) { //save house items House* house = it.second; for (HouseTile* tile : house->getTiles()) { saveTile(stream, tile); size_t attributesSize; const char* attributes = stream.getStream(attributesSize); if (attributesSize > 0) { query << house->getId() << ',' << db->escapeBlob(attributes, attributesSize); if (!stmt.addRow(query)) { return false; } } stream.clear(); } } if (!stmt.execute()) { return false; } //End the transaction bool success = transaction.commit(); std::cout << "> Saved house items in: " << (OTSYS_TIME() - start) / (1000.) << " s" << std::endl; return success; }
void Commands::buyHouse(Player* player, const std::string& cmd, const std::string& param) { if (!player->isPremium()) { player->sendCancelMessage(RET_YOUNEEDPREMIUMACCOUNT); return; } Position pos = player->getPosition(); pos = getNextPosition(player->direction, pos); Tile* tile = g_game.getTile(pos.x, pos.y, pos.z); if (!tile) { player->sendCancel("You have to be looking at the door of the house you would like to buy."); return; } HouseTile* houseTile = dynamic_cast<HouseTile*>(tile); if (!houseTile) { player->sendCancel("You have to be looking at the door of the house you would like to buy."); return; } House* house = houseTile->getHouse(); if (!house || !house->getDoorByPosition(pos)) { player->sendCancel("You have to be looking at the door of the house you would like to buy."); return; } if (house->getHouseOwner()) { player->sendCancel("This house alreadly has an owner."); return; } for (const auto& it : Houses::getInstance().getHouses()) { if (it.second->getHouseOwner() == player->guid) { player->sendCancel("You are already the owner of a house."); return; } } uint64_t price = house->getHouseTiles().size() * g_config.getNumber(ConfigManager::HOUSE_PRICE); if (!g_game.removeMoney(player, price)) { player->sendCancel("You do not have enough money."); return; } house->setHouseOwner(player->guid); player->sendTextMessage(MSG_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in the bank."); }
static Target create( const Option& o ) { House* house = new House( &o ); TargetValue* THIS = new TargetValue( house ); house->setTHIS(THIS); Target target = THIS; house->build(o); // Added to level in build() // l.addFeature( target ); return target; }
float HouseLevelSpec::evaluateReligionNeed(House &house, const ServiceType service) { int houseLevel = house.getLevelSpec().getHouseLevel(); int minLevel = HouseSpecHelper::getInstance().getHouseLevelSpec(houseLevel+1)._minReligionLevel; return (float)minLevel; }
int HouseLevelSpec::computeFoodLevel(House &house) { int res = 0; GoodStore& goodStore = house.getGoodStore(); if (goodStore.getCurrentQty(G_WHEAT) > 0) { res++; } if (goodStore.getCurrentQty(G_FISH) > 0) { res++; } if (goodStore.getCurrentQty(G_MEAT) > 0) { res++; } if (goodStore.getCurrentQty(G_FRUIT) > 0) { res++; } if (goodStore.getCurrentQty(G_VEGETABLE) > 0) { res++; } return res; }
void printHouse(House house) { //print the house information using //the dot operator cout<<"House Color: "<<house.getColor() <<"\nNumber Bathrooms: " <<house.getNumBath() <<"\nNumberBedrooms: " <<house.getSqft()<<endl; cout<<"Total Square feet: " <<house.getSqft()<<endl; cout<<endl<<endl; //since it is a void function, //I do not need a return statement }
void mouse(int button, int state, int x, int y) { if (state == GLUT_DOWN) { int view[4]; // double modelview[16]; double proj[16]; glGetIntegerv(GL_VIEWPORT, view); glGetDoublev(GL_PROJECTION_MATRIX, proj); int realy = view[3] - (GLint)y - 1; int check = gluUnProject(x, realy, -1, WorldT, proj, view, objectNear, objectNear + 1, objectNear + 2); cout << "unprojected near co-ords are "; for (int i = 0; i<4; i++) { cout << objectNear[i] << " "; } cout << "\n"; check = gluUnProject(x, realy, 1, WorldT, proj, view, objectFar, objectFar + 1, objectFar + 2); cout << "unprojected far co-ords are "; for (int i = 0; i<4; i++) { cout << objectFar[i] << " "; } cout << "\n"; //prepare for collision test by making a ray Vector d(objectFar[0], objectFar[1], objectFar[2]); Vector p(objectNear[0], objectNear[1], objectNear[2]); Ray ray1; //this is the ray cast ray1.SetOrigin(p); //initialise ray with origin and direction vector ray1.SetDirection(d - p); if (myhouse.isBoundSphereIntersect(ray1)) cout << "hit" << endl; else cout << "miss" << endl; glutPostRedisplay(); } }
bool Commands::sellHouse(Creature* creature, const std::string& cmd, const std::string& param) { Player* player = creature->getPlayer(); if(player){ House* house = Houses::getInstance().getHouseByPlayerId(player->getGUID()); if(!house){ player->sendCancel("You do not own any house."); return false; } Player* tradePartner = g_game.getPlayerByName(param); if(!(tradePartner && tradePartner != player)){ player->sendCancel("Trade player not found."); return false; } if(tradePartner->getPlayerInfo(PLAYERINFO_LEVEL) < 1){ player->sendCancel("Trade player level is too low."); return false; } if(Houses::getInstance().getHouseByPlayerId(tradePartner->getGUID())){ player->sendCancel("Trade player already owns a house."); return false; } if(!Position::areInRange<2,2,0>(tradePartner->getPosition(), player->getPosition())){ player->sendCancel("Trade player is too far away."); return false; } Item* transferItem = house->getTransferItem(); if(!transferItem){ player->sendCancel("You can not trade this house."); return false; } transferItem->getParent()->setParent(player); if(g_game.internalStartTrade(player, tradePartner, transferItem)){ return true; } else{ house->resetTransferItem(); } } return false; }
bool IOMapSerialize::loadHouses() { Database* db = Database::getInstance(); DBQuery query; query << "SELECT * FROM `houses` WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID); DBResult* result; if(!(result = db->storeQuery(query.str()))) return false; House* house = NULL; do { if(!(house = Houses::getInstance()->getHouse(result->getDataInt("id")))) continue; house->setRentWarnings(result->getDataInt("warnings")); house->setLastWarning(result->getDataInt("lastwarning")); house->setPaidUntil(result->getDataInt("paid")); house->setOwner(result->getDataInt("owner")); if(result->getDataInt("clear")) house->setPendingTransfer(true); } while(result->next()); result->free(); for(HouseMap::iterator it = Houses::getInstance()->getHouseBegin(); it != Houses::getInstance()->getHouseEnd(); ++it) { if(!(house = it->second) || !house->getId() || !house->getOwner()) continue; query.str(""); query << "SELECT `listid`, `list` FROM `house_lists` WHERE `house_id` = " << house->getId(); query << " AND `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID); if(!(result = db->storeQuery(query.str()))) continue; do house->setAccessList(result->getDataInt("listid"), result->getDataString("list")); while(result->next()); result->free(); } return true; }
void HousePalettePanel::OnClickEditHouse(wxCommandEvent& event) { if(house_list->GetCount() == 0) return; if(map == nullptr) return; House* house = reinterpret_cast<House*>(house_list->GetClientData(house_list->GetSelection())); if(house) { wxDialog* d = newd EditHouseDialog(gui.root, map, house); int ret = d->ShowModal(); if(ret == 1) { // Something changed, change name of house house_list->SetString(house_list->GetSelection(), wxstr(house->getDescription())); refresh_timer.Start(300, true); } } }
int main() { House house; Player player; player.moveTo(house.getRoom("living room")); InputHandler input; generateControls(input, player); do { input.updateInput(); } while (!input.isEndSignal); std::cout << "Thanks for playing." << std::endl; return 0; }
void Commands::getHouse(Player* player, const std::string& cmd, const std::string& param) { std::string name = param; uint32_t guid; if (!IOLoginData::getInstance()->getGuidByName(guid, name)) { return; } std::ostringstream str(name); House* house = Houses::getInstance().getHouseByPlayerId(guid); if (house) { str << " owns house: " << house->getName() << "."; } else { str << " does not own any house."; } player->sendTextMessage(MSG_STATUS_CONSOLE_BLUE, str.str()); }
int HouseLevelSpec::computeWaterLevel(House &house, std::string &oMissingRequirement) { // no water=0, well=1, fountain=2 int res = 0; if (house.hasServiceAccess(S_FOUNTAIN)) { res = 2; } else if (house.hasServiceAccess(S_WELL)) { res = 1; oMissingRequirement = _("need fountain"); } else { oMissingRequirement = _("need water"); } return res; }
int HouseLevelSpec::computeMonthlyConsumption(House &house, const GoodType goodType) { int res = 0; if (_requiredGoods[goodType] != 0) { res = house.getMaxHabitants() * _requiredGoods[goodType]; } return res; }
int main() { House* myHouse = new House(); ifstream RoomInfo; RoomInfo.open("roomInfo.txt"); string roomline; while (getline(RoomInfo, roomline)) { myHouse->addRoom(roomline); } myHouse->printRoomNames(); cout << "the area of my house is " << myHouse->calculateArea() << " square feet" << endl; cin.get(); return 0; }
void IOLoginData::updateHouseOwners() { Database* db = Database::getInstance(); std::ostringstream query; DBResult* result; query << "SELECT `id`, `highest_bidder`, `last_bid` FROM `houses` WHERE `owner` = 0 AND `bid_end` != 0 AND `bid_end` < " << time(nullptr); if ((result = db->storeQuery(query.str()))) { do { House* house = Houses::getInstance().getHouse(result->getDataInt("id")); if (house) { DBResult* result2; query.str(""); query << "SELECT `balance` FROM `players` WHERE `id` = " << result->getDataInt("highest_bidder"); bool canPay = false; if ((result2 = db->storeQuery(query.str()))) { if (result2->getDataInt("balance") >= result->getDataInt("last_bid")) { canPay = true; } db->freeResult(result2); } if (canPay) { query.str(""); query << "UPDATE `players` SET `balance` = `balance` - " << result->getDataInt("last_bid") << " WHERE `id` = " << result->getDataInt("highest_bidder"); db->executeQuery(query.str()); house->setHouseOwner(result->getDataInt("highest_bidder")); } query.str(""); query << "UPDATE `houses` SET `last_bid` = 0, `bid_end` = 0, `highest_bidder` = 0, `bid` = 0 WHERE `id` = " << result->getDataInt("id"); db->executeQuery(query.str()); } } while (result->next()); db->freeResult(result); } }
std::string getHousePrintNum(House &house) { switch (house.getKind()) { case HouseKind::Row: return getID(house.num); case HouseKind::Col: case HouseKind::Box: { std::stringstream ss; ss << house.num; return ss.str(); } } }
int HouseLevelSpec::computeEntertainmentLevel(House &house) { int res = 0; if (house.hasServiceAccess(S_THEATER)) { res += 10; } if (house.hasServiceAccess(S_AMPHITHEATER)) { res += 20; } if (house.hasServiceAccess(S_COLLOSSEUM)) { res += 30; } if (house.hasServiceAccess(S_HIPPODROME)) { res += 40; } return res; }
bool IOMapSerialize::loadHouseInfo() { Database& db = Database::getInstance(); DBResult_ptr result = db.storeQuery("SELECT `id`, `owner`, `paid`, `warnings` FROM `houses`"); if (!result) { return false; } do { House* house = g_game.map.houses.getHouse(result->getNumber<uint32_t>("id")); if (house) { house->setOwner(result->getNumber<uint32_t>("owner"), false); house->setPaidUntil(result->getNumber<time_t>("paid")); house->setPayRentWarnings(result->getNumber<uint32_t>("warnings")); } } while (result->next()); result = db.storeQuery("SELECT `house_id`, `listid`, `list` FROM `house_lists`"); if (result) { do { House* house = g_game.map.houses.getHouse(result->getNumber<uint32_t>("house_id")); if (house) { house->setAccessList(result->getNumber<uint32_t>("listid"), result->getString("list")); } } while (result->next()); } return true; }
bool IOMapSerialize::loadHouseInfo() { Database* db = Database::getInstance(); DBResult* result = db->storeQuery("SELECT `id`, `owner`, `paid`, `warnings` FROM `houses`"); if (!result) { return false; } do { House* house = Houses::getInstance().getHouse(result->getDataInt("id")); if (house) { house->setOwner(result->getDataInt("owner"), false); house->setPaidUntil(result->getDataInt("paid")); house->setPayRentWarnings(result->getDataInt("warnings")); } } while (result->next()); db->freeResult(result); result = db->storeQuery("SELECT `house_id`, `listid`, `list` FROM `house_lists`"); if (result) { do { House* house = Houses::getInstance().getHouse(result->getDataInt("house_id")); if (house) { house->setAccessList(result->getDataInt("listid"), result->getDataString("list")); } } while (result->next()); db->freeResult(result); } return true; }