bool ValidateCargo(unsigned int client) { std::wstring playerName = Players.GetActiveCharacterName(client); std::list<CARGO_INFO> cargo; int holdSize = 0; HkEnumCargo(playerName, cargo, holdSize); for (std::list<CARGO_INFO>::const_iterator it = cargo.begin(); it != cargo.end(); ++it) { const CARGO_INFO & item = *it; bool flag = false; pub::IsCommodity(item.iArchID, flag); // Some commodity present. if (flag) return false; } return true; }
void Siege::SiegeGunDeploy(uint client, const wstring &args) { // Abort processing if this is not a "heavy lifter" uint shiparch; pub::Player::GetShipID(client, shiparch); if (set_construction_shiparch != 0 && shiparch != set_construction_shiparch) { PrintUserCmdText(client, L"ERR Need deployment ship"); return; } uint ship; pub::Player::GetShip(client, ship); if (!ship) { PrintUserCmdText(client, L"ERR Not in space"); return; } // If the ship is moving, abort the processing. Vector dir1; Vector dir2; pub::SpaceObj::GetMotion(ship, dir1, dir2); if (dir1.x>5 || dir1.y>5 || dir1.z>5) { PrintUserCmdText(client, L"ERR Ship is moving"); return; } int min = 100; int max = 5000; int randomsiegeint = min + (rand() % (int)(max - min + 1)); string randomname = "Siege Cannon AX-" + randomsiegeint; // Check for conflicting base name if (GetPlayerBase(CreateID(PlayerBase::CreateBaseNickname(randomname).c_str()))) { PrintUserCmdText(client, L"ERR Deployment error, please reiterate."); return; } // Check that the ship has the requires commodities. int hold_size; list<CARGO_INFO> cargo; HkEnumCargo((const wchar_t*)Players.GetActiveCharacterName(client), cargo, hold_size); for (map<uint, uint>::iterator i = construction_items.begin(); i != construction_items.end(); ++i) { bool material_available = false; uint good = i->first; uint quantity = i->second; for (list<CARGO_INFO>::iterator ci = cargo.begin(); ci != cargo.end(); ++ci) { if (ci->iArchID == good && ci->iCount >= (int)quantity) { material_available = true; pub::Player::RemoveCargo(client, ci->iID, quantity); } } if (material_available == false) { PrintUserCmdText(client, L"ERR Construction failed due to insufficient raw material."); for (i = construction_items.begin(); i != construction_items.end(); ++i) { const GoodInfo *gi = GoodList::find_by_id(i->first); if (gi) { PrintUserCmdText(client, L"| %ux %s", i->second, HkGetWStringFromIDS(gi->iIDSName).c_str()); } } return; } } wstring charname = (const wchar_t*)Players.GetActiveCharacterName(client); AddLog("NOTICE: Base created %s by %s (%s)", randomname.c_str(), wstos(charname).c_str(), wstos(HkGetAccountID(HkGetAccountByCharname(charname))).c_str()); wstring password = L"hastesucks"; wstring basename = stows(randomname); PlayerBase *newbase = new PlayerBase(client, password, basename); player_bases[newbase->base] = newbase; newbase->basetype = "siegegun"; newbase->basesolar = "depot"; newbase->baseloadout = "depot"; newbase->defense_mode = 1; for (map<string, ARCHTYPE_STRUCT>::iterator iter = mapArchs.begin(); iter!=mapArchs.end(); iter++) { ARCHTYPE_STRUCT &thearch = iter->second; if (iter->first == newbase->basetype) { newbase->invulnerable = thearch.invulnerable; newbase->logic = thearch.logic; } } newbase->Spawn(); newbase->Save(); PrintUserCmdText(client, L"OK: Siege Cannon deployed"); PrintUserCmdText(client, L"Default administration password is %s", password.c_str()); }