/* * Method: GetCommodityBasePriceAlterations * * Get the price alterations for cargo items bought and sold in this system * * > alterations = system:GetCommodityBasePriceAlterations() * * Return: * * alterations - a table. The keys are <Constants.EquipType> strings for * each cargo. The values are numbers that indicate the * percentage change to each cargo base price. Loosely, * positive values make the commodity more expensive, * indicating it is in demand, while negative values make the * commodity cheaper, indicating a surplus. * * Availability: * * alpha 10 * * Status: * * experimental */ static int l_starsystem_get_commodity_base_price_alterations(lua_State *l) { LUA_DEBUG_START(l); StarSystem *s = LuaStarSystem::CheckFromLua(1); lua_newtable(l); for (int e = Equip::FIRST_COMMODITY; e <= Equip::LAST_COMMODITY; e++) { lua_pushstring(l, EnumStrings::GetString("EquipType", e)); lua_pushnumber(l, s->GetCommodityBasePriceModPercent(e)); lua_rawset(l, -3); } LUA_DEBUG_END(l, 1); return 1; }
/* * Method: GetCommodityBasePriceAlterations * * Get the price alterations for cargo items bought and sold in this system * * > alteration = system:GetCommodityBasePriceAlterations(cargo_item) * * Parameters: * * cargo_item - The cargo item for which one wants to know the alteration * Return: * * percentage - percentage change to the cargo base price. Loosely, * positive values make the commodity more expensive, * indicating it is in demand, while negative values make the * commodity cheaper, indicating a surplus. * * Availability: * * June 2014 * * Status: * * experimental */ static int l_starsystem_get_commodity_base_price_alterations(lua_State *l) { PROFILE_SCOPED() LUA_DEBUG_START(l); StarSystem *s = LuaObject<StarSystem>::CheckFromLua(1); LuaTable equip(l, 2); if (!equip.CallMethod<bool>("IsValidSlot", "cargo")) { luaL_error(l, "GetCommodityBasePriceAlterations takes a valid cargo item as argument."); return 0; } equip.PushValueToStack("l10n_key"); // For now let's just use this poor man's hack. GalacticEconomy::Commodity e = static_cast<GalacticEconomy::Commodity>( LuaConstants::GetConstantFromArg(l, "CommodityType", -1)); lua_pop(l, 1); lua_pushnumber(l, s->GetCommodityBasePriceModPercent(e)); LUA_DEBUG_END(l, 1); return 1; }
void SystemInfoView::UpdateEconomyTab() { /* Economy info page */ StarSystem *s = m_system.Get(); std::string data; /* if (s->m_econType) { data = "Economy: "; std::vector<std::string> v; if (s->m_econType & ECON_AGRICULTURE) v.push_back("Agricultural"); if (s->m_econType & ECON_MINING) v.push_back("Mining"); if (s->m_econType & ECON_INDUSTRY) v.push_back("Industrial"); data += string_join(v, ", "); data += "\n"; } m_econInfo->SetText(data); */ /* imports and exports */ std::vector<std::string> crud; data = std::string("#ff0")+std::string(Lang::MAJOR_IMPORTS)+std::string("\n"); for (int i=1; i<Equip::TYPE_MAX; i++) { if (s->GetCommodityBasePriceModPercent(i) > 10) crud.push_back(std::string("#fff")+Equip::types[i].name); } if (crud.size()) data += string_join(crud, "\n")+"\n"; else data += std::string("#777")+std::string(Lang::NONE)+std::string("\n"); m_econMajImport->SetText(data); crud.clear(); data = std::string("#ff0")+std::string(Lang::MINOR_IMPORTS)+std::string("\n"); for (int i=1; i<Equip::TYPE_MAX; i++) { if ((s->GetCommodityBasePriceModPercent(i) > 2) && (s->GetCommodityBasePriceModPercent(i) <= 10)) crud.push_back(std::string("#777")+Equip::types[i].name); } if (crud.size()) data += string_join(crud, "\n")+"\n"; else data += std::string("#777")+std::string(Lang::NONE)+std::string("\n"); m_econMinImport->SetText(data); crud.clear(); data = std::string("#ff0")+std::string(Lang::MAJOR_EXPORTS)+std::string("\n"); for (int i=1; i<Equip::TYPE_MAX; i++) { if (s->GetCommodityBasePriceModPercent(i) < -10) crud.push_back(std::string("#fff")+Equip::types[i].name); } if (crud.size()) data += string_join(crud, "\n")+"\n"; else data += std::string("#777")+std::string(Lang::NONE)+std::string("\n"); m_econMajExport->SetText(data); crud.clear(); data = std::string("#ff0")+std::string(Lang::MINOR_EXPORTS)+std::string("\n"); for (int i=1; i<Equip::TYPE_MAX; i++) { if ((s->GetCommodityBasePriceModPercent(i) < -2) && (s->GetCommodityBasePriceModPercent(i) >= -10)) crud.push_back(std::string("#777")+Equip::types[i].name); } if (crud.size()) data += string_join(crud, "\n")+"\n"; else data += std::string("#777")+std::string(Lang::NONE)+std::string("\n"); m_econMinExport->SetText(data); crud.clear(); data = std::string("#ff0")+std::string(Lang::ILLEGAL_GOODS)+std::string("\n"); for (int i=1; i<Equip::TYPE_MAX; i++) { if (!Polit::IsCommodityLegal(s, Equip::Type(i))) crud.push_back(std::string("#777")+Equip::types[i].name); } if (crud.size()) data += string_join(crud, "\n")+"\n"; else data += std::string("#777")+std::string(Lang::NONE)+std::string("\n"); m_econIllegal->SetText(data); m_econInfoTab->ResizeRequest(); }