Files
dsrc/sku.0/sys.server/compiled/game/script/terminal/terminal_city.script
T
PrisonCamp 2c8a2c1d47 Fixed the following:
You can now rename your beast as much as you would like.
Police officers will no longer harass corpses.
Static NPC's conversing will now successfully converse with one another.
When a player dies, the pet will go invulnerable and be immediately packed up.
When respecing professions, your weapon will now be unequiped.
Fixed the chat system for some NPC's.
You can now only mount your vehicle from less than 5 meters.
Quest items that can be clicked on cannot be used from less than 5 meters.
Added a message to the QaSetup script, notifying the QA that they have received their items.
2015-01-30 16:23:48 -08:00

3749 lines
123 KiB
Plaintext

/* Title: terminal_city.script
* Description: script for city control terminal
*/
//------------------------------------------------
// Includes
//------------------------------------------------
include library.city;
include library.prose;
include library.sui;
include library.utils;
include library.money;
include library.player_structure;
include java.util.Vector;
//------------------------------------------------
// Constants
//------------------------------------------------
const string STF = "city/city";
const string_id SID_CITY_HACKS = new string_id(STF, "city_hacks");
const string_id SID_CITY_FORCE_UPDATE = new string_id(STF, "force_update");
const string_id SID_CITY_RANK_UP = new string_id(STF, "rank_up");
const string_id SID_CITY_RANK_DOWN = new string_id(STF, "rank_down");
const string_id SID_CITY_FIX_MAYOR = new string_id(STF, "fix_mayor");
const string_id SID_CITY_MAKE_MAYOR = new string_id(STF, "make_mayor");
const string_id SID_CITY_REVOKE_CITIZENSHIP = new string_id(STF, "revoke_citizenship");
const string_id SID_CITY_REMOVE_OLD_TRAINERS = new string_id(STF, "remove_trainers");
const string_id SID_CLONE_DATA_WIPED = new string_id(STF, "clone_data_wiped");
const string_id SID_SHUTTLE_DATA_WIPED = new string_id(STF, "clone_data_wiped");
const string_id SID_CITY_RESET_CLONE_DATA = new string_id(STF, "reset_clone_data");
const string_id SID_CITY_RESET_SHUTTLE_DATA = new string_id(STF, "reset_shuttle_data");
const string_id SID_CITY_MODIFY_STRUCTURE_LIST = new string_id(STF, "modify_structure_list");
const string_id SID_CLEAR_STRUCTURE_VARS = new string_id(STF, "clear_structure_vars");
const string_id SID_CITY_INFO = new string_id(STF, "city_info");
const string_id SID_CITY_STATUS = new string_id(STF, "city_status");
const string_id SID_NON_CITIZEN_CITY_STATUS = new string_id(STF, "non_citizen_city_status");
const string_id SID_CITY_CITIZENS = new string_id(STF, "city_citizens");
const string_id SID_CITY_STRUCTURES = new string_id(STF, "city_structures");
const string_id SID_CITY_RANK = new string_id(STF, "city_rank");
const string_id SID_CITY_MAINT_REPORT = new string_id(STF, "city_maint");
const string_id SID_CITY_MANAGEMENT = new string_id(STF, "city_management");
const string_id SID_CITY_NAME = new string_id(STF, "city_name");
const string_id SID_CITY_MILITIA = new string_id(STF, "city_militia");
const string_id SID_CITY_REGISTER = new string_id(STF, "city_register");
const string_id SID_CITY_UNREGISTER = new string_id(STF, "city_unregister");
const string_id SID_CITY_SPECIALIZATIONS = new string_id(STF, "city_specializations");
const string_id SID_CITY_VISITOR_MOTD = new string_id(STF, "city_visitor_message");
const string_id SID_CITY_CITIZEN_MOTD = new string_id(STF, "city_citizen_message");
const string_id SID_TREASURY_MANAGEMENT = new string_id(STF, "treasury_management");
const string_id SID_TREASURY_STATUS = new string_id(STF, "treasury_status");
const string_id SID_TREASURY_DEPOSIT = new string_id(STF, "treasury_deposit");
const string_id SID_TREASURY_WITHDRAW = new string_id(STF, "treasury_withdraw");
const string_id SID_TREASURY_TAXES = new string_id(STF, "treasury_taxes");
const string_id SID_NAME_CHANGED = new string_id(STF, "name_changed");
const string_id SID_OBSCENE = new string_id("player_structure", "obscene");
const string_id SID_NOT_UNIQUE = new string_id("player_structure", "cityname_not_unique");
const string_id SID_CANT_FIND_PLAYER = new string_id(STF, "cant_find_player");
const string_id SID_NOT_CITIZEN = new string_id(STF, "not_citizen");
const string_id SID_ADDED_MILITIA = new string_id(STF, "added_militia");
const string_id SID_REMOVED_MILITIA = new string_id(STF, "removed_militia");
const string_id SID_ADDED_MILITIA_TARGET = new string_id(STF, "added_militia_target");
const string_id SID_REMOVED_MILITIA_TARGET = new string_id(STF, "removed_militia_target");
const string_id SID_NO_MONEY = new string_id(STF, "no_money");
const string_id SID_TAX_OUT_OF_RANGE = new string_id(STF, "tax_out_of_range");
const string_id SID_INCOME_TAX = new string_id(STF, "set_income_tax");
const string_id SID_PROPERTY_TAX = new string_id(STF, "set_property_tax");
const string_id SID_SALES_TAX = new string_id(STF, "set_sales_tax");
const string_id SID_TRAVEL_FEE = new string_id(STF, "set_travel_fee");
const string_id SID_GARAGE_TAX = new string_id(STF, "set_garage_tax");
const string_id SID_CANT_TAX = new string_id(STF, "cant_tax");
const string_id SID_CANT_REGISTER = new string_id(STF, "cant_register");
const string_id SID_CANT_REGISTER_RANK = new string_id(STF, "cant_register_rank");
const string_id SID_REGISTERED = new string_id(STF, "registered");
const string_id SID_UNREGISTERED = new string_id(STF, "unregistered");
const string_id SID_CANT_MILITIA = new string_id(STF, "cant_militia");
const string_id SID_NO_RANK_TAXES = new string_id(STF, "no_rank_taxes");
const string_id SID_NO_RANK_SPEC = new string_id(STF, "no_rank_spec");
const string_id SID_NO_SPECS = new string_id(STF, "no_specs");
const string_id SID_SPEC_SET = new string_id(STF, "spec_set");
const string_id SID_SPEC_TIME = new string_id(STF, "spec_time");
const string_id SID_WITHDRAW_LIMITS = new string_id(STF, "withdraw_limits");
const string_id SID_WITHDRAW_DAILY = new string_id(STF, "withdraw_daily");
const string_id SID_NO_SHUTTLEPORT = new string_id(STF, "no_shuttleport");
const string_id PUBLIC_ELECTION_SUBJECT = new string_id( STF, "public_election_subject" );
const string_id PUBLIC_ELECTION_BODY = new string_id( STF, "public_election_body" );
const string CITY_SPECS = "datatables/city/specializations.iff";
const string[] TAX_STRING = { "income", "property", "sales", "travel", "garage" };
const int[] TAX_MIN = { 0, 0, 0, 1, 0 };
const int[] TAX_MAX = { 2000, 50, 20, 500, 30 };
const string_id SID_CITY_ZONE = new string_id(STF, "zone");
const string_id SID_CITY_UNZONE = new string_id(STF, "unzone");
const string_id SID_ZONING_ENABLED = new string_id(STF, "zoning_enabled");
const string_id SID_ZONING_DISABLED = new string_id(STF, "zoning_disabled");
const string_id SID_ZONING_SKILL = new string_id(STF, "zoning_skill");
const string_id TREASURY_WITHDRAW_SUBJECT = new string_id( STF, "treasury_withdraw_subject" );
const string_id TREASURY_WITHDRAW_BODY = new string_id( STF, "treasury_withdraw_body" );
const string_id TREASURY_DEPOSIT_SUBJECT = new string_id( STF, "treasury_deposit_subject");
const string_id TREASURY_DEPOSIT_BODY = new string_id( STF, "treasury_deposit_body");
const string_id TAX_INCOME_SUBJECT = new string_id( STF, "tax_income_subject" );
const string_id TAX_INCOME_BODY = new string_id( STF, "tax_income_body" );
const string_id TAX_PROPERTY_SUBJECT = new string_id( STF, "tax_property_subject" );
const string_id TAX_PROPERTY_BODY = new string_id( STF, "tax_property_body" );
const string_id TAX_SALES_SUBJECT = new string_id( STF, "tax_sales_subject" );
const string_id TAX_SALES_BODY = new string_id( STF, "tax_sales_body" );
const string_id TAX_TRAVEL_SUBJECT = new string_id( STF, "tax_travel_subject" );
const string_id TAX_TRAVEL_BODY = new string_id( STF, "tax_travel_body" );
const string_id GARAGE_FEE_SUBJECT = new string_id( STF, "garage_fee_subject");
const string_id GARAGE_FEE_BODY = new string_id( STF, "garage_fee_body" );
const string_id SID_YOU_WITHDRAW_FROM_TREASURY = new string_id( STF, "you_withdraw_from_treasury");
const string_id SID_SUI_CONFIRM_REMOVE_TITLE = new string_id( STF, "sui_confirm_remove_title");
const string_id SID_REVOKE_CITIZEN_WARNING = new string_id(STF, "revoke_citizenship_warning");
const string PROFESSION_TRAINER_SCRIPT = "npc.skillteacher.trainer_spawner";
// Mayor Safe House System
const string_id SID_SAFE_HOUSE_PROMPT = new string_id(STF, "safe_house_citizen_prompt");
const string_id SID_REMOVE_SAFE_HOUSE_CITIZEN_BODY = new string_id(STF, "remove_safe_citizen_body");
const string_id SID_ADD_SAFE_HOUSE_CITIZEN_BODY = new string_id(STF, "add_safe_citizen_body");
const string_id SID_REMOVE_SAFE_HOUSE_CITIZEN_SUBJECT = new string_id(STF, "remove_safe_citizen_subject");
const string_id SID_ADD_SAFE_HOUSE_CITIZEN_SUBJECT = new string_id(STF, "add_safe_citizen_subject");
const string_id SID_CITY_CITIZEN_PROTECTION = new string_id(STF, "city_citizen_protection");
// Factional Alignment
const string_id SID_ALIGN_IMPERIAL = new string_id(STF, "align_imperial");
const string_id SID_ALIGN_REBEL = new string_id(STF, "align_rebel");
const string_id SID_ALIGN_NEUTRAL = new string_id(STF, "align_neutral");
// GCW Region Defender
const string_id SID_BEGIN_GCW_REGION_DEFENDER = new string_id(STF, "begin_gcw_region_defender");
const string_id SID_END_GCW_REGION_DEFENDER = new string_id(STF, "end_gcw_region_defender");
//------------------------------------------------
// OnObjectMenuRequest
//------------------------------------------------
//SERVER_MENU1 = Mayor Menu - Change City Specializations
//SERVER_MENU2 = Mayor Menu - Change City Zoning
//SERVER_MENU3 = Citizen/Mayor - See Maintenance Report
//SERVER_MENU4 = God Menu - Force Update of City
//SERVER_MENU5 = Citizen Menu - Revoke Citizenship
//SERVER_MENU6 = God Menu - Force Rank Up
//SERVER_MENU7 = God Menu - Force Rank Down
//SERVER_MENU8 = Mayor Menu - Re-establish Citizenship
//SERVER_MENU9 = God Menu - Make Player Mayor
//SERVER_MENU10 = Mayor Menu - Remove old Skill Trainers
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
{
// Get city info.
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
if(!cityExists(city_id))
return SCRIPT_CONTINUE;
obj_id mayor = cityGetLeader(city_id);
if(!city.isCitizenOfCity(player, city_id) && (player != mayor) && !isGod(player))
{
//we need to allow non-citizens to see some information.
//they get to see the City Status page.
//int menu = mi.addRootMenu(menu_info_types.CITY_STATUS, SID_NON_CITIZEN_CITY_STATUS);
return SCRIPT_CONTINUE;
}
// Add the city info menu.
int menu = mi.addRootMenu(menu_info_types.ITEM_USE, SID_CITY_INFO);
mi.addSubMenu(menu, menu_info_types.CITY_STATUS, SID_CITY_STATUS);
mi.addSubMenu(menu, menu_info_types.CITY_CITIZENS, SID_CITY_CITIZENS);
mi.addSubMenu(menu, menu_info_types.CITY_STRUCTURES, SID_CITY_STRUCTURES);
mi.addSubMenu(menu, menu_info_types.CITY_RANK, SID_CITY_RANK);
mi.addSubMenu(menu, menu_info_types.SERVER_MENU3, SID_CITY_MAINT_REPORT);
mi.addSubMenu(menu, menu_info_types.CITY_TREASURY, SID_TREASURY_STATUS);
mi.addSubMenu(menu, menu_info_types.CITY_TREASURY_DEPOSIT, SID_TREASURY_DEPOSIT);
//allow the player to revoke citizenship
if(city.isCitizenOfCity(player, city_id) && (player != mayor))
mi.addSubMenu(menu, menu_info_types.SERVER_MENU5, SID_CITY_REVOKE_CITIZENSHIP);
// Add the city management menu.
if(player == mayor || isGod(player))
{
menu = mi.addRootMenu(menu_info_types.CITY_MANAGEMENT, SID_CITY_MANAGEMENT);
mi.addSubMenu(menu, menu_info_types.CITY_NAME, SID_CITY_NAME);
if(!city.isCityRegistered(city_id))
mi.addSubMenu(menu, menu_info_types.CITY_REGISTER, SID_CITY_REGISTER);
else
mi.addSubMenu(menu, menu_info_types.CITY_REGISTER, SID_CITY_UNREGISTER);
if(city.isCityZoned(city_id))
mi.addSubMenu(menu, menu_info_types.SERVER_MENU2, SID_CITY_UNZONE);
else
mi.addSubMenu(menu, menu_info_types.SERVER_MENU2, SID_CITY_ZONE);
mi.addSubMenu(menu, menu_info_types.CITY_MILITIA, SID_CITY_MILITIA);
mi.addSubMenu(menu, menu_info_types.CITY_TAXES, SID_TREASURY_TAXES);
mi.addSubMenu(menu, menu_info_types.CITY_TREASURY_WITHDRAW, SID_TREASURY_WITHDRAW);
mi.addSubMenu(menu, menu_info_types.SERVER_MENU1, SID_CITY_SPECIALIZATIONS);
/*************************************************************************
**************************UPDATE 8: CITY MOTD*****************************
*************************************************************************/
mi.addSubMenu(menu, menu_info_types.SERVER_MENU11, SID_CITY_VISITOR_MOTD);
mi.addSubMenu(menu, menu_info_types.SERVER_MENU12, SID_CITY_CITIZEN_MOTD);
//if for some reason the mayor is NOT a citizen
if(!city.isCitizenOfCity(player, city_id))
mi.addSubMenu(menu, menu_info_types.SERVER_MENU8, SID_CITY_FIX_MAYOR);
//Remove old Skill Trainers
//if(citySkillTrainersExist(city_id))
//{
// mi.addRootMenu(menu_info_types.SERVER_MENU10, SID_CITY_REMOVE_OLD_TRAINERS);
//}
//Add Citizen Protection Menu
mi.addSubMenu(menu, menu_info_types.SERVER_MENU13, SID_CITY_CITIZEN_PROTECTION);
//Add Factional Alignment Menu
int factionId = cityGetFaction(city_id);
if ((##"imperial" == factionId) || (##"rebel" == factionId))
{
mi.addSubMenu(menu, menu_info_types.SERVER_MENU16, SID_ALIGN_NEUTRAL);
}
else
{
mi.addSubMenu(menu, menu_info_types.SERVER_MENU14, SID_ALIGN_IMPERIAL);
mi.addSubMenu(menu, menu_info_types.SERVER_MENU15, SID_ALIGN_REBEL);
}
//Add GCW Region Defender Menu
const String gcwDefenderRegion = cityGetGcwDefenderRegion(city_id);
if ((gcwDefenderRegion == null) || (gcwDefenderRegion.length() <= 0))
{
mi.addSubMenu(menu, menu_info_types.SERVER_MENU17, SID_BEGIN_GCW_REGION_DEFENDER);
}
else
{
mi.addSubMenu(menu, menu_info_types.SERVER_MENU18, SID_END_GCW_REGION_DEFENDER);
}
}
if(isGod(player))
{
int godMenu = mi.addRootMenu(menu_info_types.ITEM_USE_SELF, SID_CITY_HACKS);
mi.addSubMenu(godMenu, menu_info_types.SERVER_MENU4, SID_CITY_FORCE_UPDATE);
mi.addSubMenu(godMenu, menu_info_types.SERVER_MENU6, SID_CITY_RANK_UP);
mi.addSubMenu(godMenu, menu_info_types.SERVER_MENU7, SID_CITY_RANK_DOWN);
mi.addSubMenu(godMenu, menu_info_types.CITY_NAME, SID_CITY_NAME);
mi.addSubMenu(godMenu, menu_info_types.SERVER_MENU9, SID_CITY_MAKE_MAYOR);
mi.addSubMenu(godMenu, menu_info_types.CITY_ADMIN_1, SID_CITY_RESET_CLONE_DATA);
mi.addSubMenu(godMenu, menu_info_types.CITY_ADMIN_2, SID_CITY_RESET_SHUTTLE_DATA);
mi.addSubMenu(godMenu, menu_info_types.CITY_ADMIN_3, SID_CITY_MODIFY_STRUCTURE_LIST);
mi.addSubMenu(godMenu, menu_info_types.CITY_ADMIN_4, SID_CLEAR_STRUCTURE_VARS);
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// OnObjectMenuSelect
//------------------------------------------------
trigger OnObjectMenuSelect(obj_id player, int item)
{
obj_id structure = getTopMostContainer(self);
if(!isIdValid(structure))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return SCRIPT_CONTINUE;
}
string template = getTemplateName(structure);
if(template.indexOf("cityhall_") < 0)
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return SCRIPT_CONTINUE;
}
int city_id = findCityByCityHall(structure);
if(!cityExists(city_id))
return SCRIPT_CONTINUE;
obj_id mayor = cityGetLeader(city_id);
if(item == menu_info_types.CITY_STATUS)
{
// Display city info window.
showCityInfo(player, self, city_id);
}
else if(item == menu_info_types.CITY_CITIZENS)
{
// Display citizens list.
showCitizensList(player, self, city_id);
}
else if(item == menu_info_types.CITY_STRUCTURES)
{
// Display structures list.
showStructuresList(player, self, city_id);
}
else if(item == menu_info_types.CITY_TREASURY)
{
// Show treasury status.
showTreasuryInfo(player, self, city_id);
}
else if(item == menu_info_types.CITY_RANK)
{
// Show advancement status.
showAdvancementInfo(player, self, city_id);
}
else if(item == menu_info_types.SERVER_MENU3)
{
// Show maintenance report.
showMaintInfo(player, self, city_id);
}
if(item == menu_info_types.CITY_TREASURY_DEPOSIT)
{
// Deposit window.
makeTreasuryDeposit(player, self, city_id);
}
if(player == mayor || isGod(player))
{
// Handle mayor options.
if(item == menu_info_types.CITY_NAME)
{
// Change city name.
changeCityName(player, self, city_id);
}
else if(item == menu_info_types.CITY_TAXES)
{
// Change city taxes.
adjustTaxes(player, self, city_id);
}
else if(item == menu_info_types.CITY_MILITIA)
{
// Modify militia.
modifyMilitia(player, self, city_id);
}
else if(item == menu_info_types.CITY_TREASURY_WITHDRAW)
{
// Withdraw window.
makeTreasuryWithdraw(player, self, city_id);
}
else if(item == menu_info_types.CITY_REGISTER)
{
// Register on planetary map.
if(!city.isCityRegistered(city_id))
sui.msgbox(self, player, "@city/city:register_d", sui.YES_NO, "@city/city:register_t", sui.MSG_QUESTION, "handleRegisterCity");
else
sui.msgbox(self, player, "@city/city:unregister_d", sui.YES_NO, "@city/city:unregister_t", sui.MSG_QUESTION, "handleUnregisterCity");
}
else if(item == menu_info_types.SERVER_MENU1)
{
// Pop up specializations dialog.
changeSpecialization(player, self, city_id);
}
else if(item == menu_info_types.SERVER_MENU2)
{
// Pop up zoning dialog.
changeZoning(player, self, city_id);
}
else if(item == menu_info_types.SERVER_MENU8)
{
// Restore this mayor's citizenship.
if(!city.isCitizenOfCity(mayor, city_id))
{
citySetCitizenInfo(city_id, mayor, getName(mayor), mayor, city.CP_CITIZEN);
sendSystemMessage(self, new string_id(STF, "mayor_citizen_restored")); // Restored citizenship to valid city mayor.
}
}
else if(item == menu_info_types.SERVER_MENU10)
{
// Remove old trainers
boolean trainersDestroyed = destroyCitySkillTrainers(mayor, city_id);
if(trainersDestroyed)
sendSystemMessage(mayor, new string_id(STF, "old_trainers_removed")); // All old profession trainers removed from structure list.
}
else if(item == menu_info_types.SERVER_MENU11)
{
// City Visitor Message
string message = "";
if(hasObjVar(structure, "city_visitor_message"))
message = getStringObjVar(structure, "city_visitor_message");
else
message = "Enter a Message for Visitors";
sui.filteredInputbox(self, player, "@city/city:prompt_city_visitor_message", "@city/city:title_city_visitor_message", "handleCityVisitorMessage", message);
}
else if(item == menu_info_types.SERVER_MENU12)
{
// Citizen Visitor Message
string message = "";
if(hasObjVar(structure, "city_citizen_message"))
message = getStringObjVar(structure, "city_citizen_message");
else
message = "Enter a Message for Citizens";
sui.filteredInputbox(self, player, "@city/city:prompt_city_citizen_message", "@city/city:title_city_citizen_message", "handleCityCitizenMessage", message);
}
else if(item == menu_info_types.SERVER_MENU13)
{
// Safe House Protection System
showSafeHouseCitizenList(player, self, city_id);
}
else if(item == menu_info_types.SERVER_MENU14)
{
// Imperial Alignment
boolean allow = true;
if (hasObjVar(structure, "cityTimeEndRebelAlign"))
{
// Must wait 1 day to switch
int cooldown = (getIntObjVar(structure, "cityTimeEndRebelAlign") + (isGod(player) ? 10 : 86400)) - getCalendarTime();
if (cooldown > 0)
{
string cooldownStr = "" + cooldown + "s";
int[] convertedTime = player_structure.convertSecondsTime(cooldown);
if ((convertedTime != null) && (convertedTime.length == 4))
{
if (convertedTime[0] > 0)
{
cooldownStr = "" + convertedTime[0] + "d:" + convertedTime[1] + "h:" + convertedTime[2] + "m:" + convertedTime[3] + "s";
}
else if (convertedTime[1] > 0)
{
cooldownStr = "" + convertedTime[1] + "h:" + convertedTime[2] + "m:" + convertedTime[3] + "s";
}
else if (convertedTime[2] > 0)
{
cooldownStr = "" + convertedTime[2] + "m:" + convertedTime[3] + "s";
}
else if (convertedTime[3] > 0)
{
cooldownStr = "" + convertedTime[3] + "s";
}
else
{
cooldownStr = "" + cooldown + "s";
}
}
sendSystemMessage(player, "You must wait " + cooldownStr + " before you can change the city's factional alignment to Imperial.", "");
allow = false;
}
}
if (allow)
{
sendSystemMessage(player, "Setting the city's factional alignment to Imperial. This may take a few seconds. You will receive mail confirmation once the change has been completed.", "");
setObjVar(structure, "cityFactionAlign", ##"imperial");
citySetFaction(city_id, ##"imperial", true);
}
}
else if(item == menu_info_types.SERVER_MENU15)
{
// Rebel Alignment
boolean allow = true;
if (hasObjVar(structure, "cityTimeEndImperialAlign"))
{
// Must wait 1 day to switch
int cooldown = (getIntObjVar(structure, "cityTimeEndImperialAlign") + (isGod(player) ? 10 : 86400)) - getCalendarTime();
if (cooldown > 0)
{
string cooldownStr = "" + cooldown + "s";
int[] convertedTime = player_structure.convertSecondsTime(cooldown);
if ((convertedTime != null) && (convertedTime.length == 4))
{
if (convertedTime[0] > 0)
{
cooldownStr = "" + convertedTime[0] + "d:" + convertedTime[1] + "h:" + convertedTime[2] + "m:" + convertedTime[3] + "s";
}
else if (convertedTime[1] > 0)
{
cooldownStr = "" + convertedTime[1] + "h:" + convertedTime[2] + "m:" + convertedTime[3] + "s";
}
else if (convertedTime[2] > 0)
{
cooldownStr = "" + convertedTime[2] + "m:" + convertedTime[3] + "s";
}
else if (convertedTime[3] > 0)
{
cooldownStr = "" + convertedTime[3] + "s";
}
else
{
cooldownStr = "" + cooldown + "s";
}
}
sendSystemMessage(player, "You must wait " + cooldownStr + " before you can change the city's factional alignment to Rebel.", "");
allow = false;
}
}
if (allow)
{
sendSystemMessage(player, "Setting the city's factional alignment to Rebel. This may take a few seconds. You will receive mail confirmation once the change has been completed.", "");
setObjVar(structure, "cityFactionAlign", ##"rebel");
citySetFaction(city_id, ##"rebel", true);
}
}
else if(item == menu_info_types.SERVER_MENU16)
{
// Cannot become neutral if currently defending a GCW region
const String gcwDefenderRegion = cityGetGcwDefenderRegion(city_id);
if ((gcwDefenderRegion != null) && (gcwDefenderRegion.length() > 0))
{
sendSystemMessage(player, "You cannot change the city's factional alignment to Neutral while it is a GCW region defender.", "");
}
else
{
// Neutral Alignment
int factionId = cityGetFaction(city_id);
if (##"imperial" == factionId)
{
// flag when city stopped being Imperial
setObjVar(structure, "cityTimeEndImperialAlign", getCalendarTime());
removeObjVar(structure, "cityTimeEndRebelAlign");
}
else if (##"rebel" == factionId)
{
// flag when city stopped being Rebel
setObjVar(structure, "cityTimeEndRebelAlign", getCalendarTime());
removeObjVar(structure, "cityTimeEndImperialAlign");
}
else if (factionId != 0)
{
// city faction is something other than Imperial or Rebel???
removeObjVar(structure, "cityTimeEndImperialAlign");
removeObjVar(structure, "cityTimeEndRebelAlign");
}
sendSystemMessage(player, "Setting the city's factional alignment to Neutral. This may take a few seconds. You will receive mail confirmation once the change has been completed.", "");
removeObjVar(structure, "cityFactionAlign");
citySetFaction(city_id, 0, true);
}
}
else if(item == menu_info_types.SERVER_MENU17)
{
// Cannot become a GCW region defender if neutral
const int factionId = cityGetFaction(city_id);
if (factionId == 0)
{
sendSystemMessage(player, "The city cannot become a GCW region defender until it is aligned with a faction.", "");
}
else
{
const String gcwDefenderRegion = cityGetGcwDefenderRegion(city_id);
if ((gcwDefenderRegion == null) || (gcwDefenderRegion.length() <= 0))
{
String[] gcwDefenderRegions = getGcwDefenderRegions();
if ((gcwDefenderRegions != null) && (gcwDefenderRegions.length > 0))
{
// has the city previously defended a region?
string previousRegion = null;
int previousRegionTimeStartDefend = 0;
int previousRegionTimeEndDefend = 0;
if (hasObjVar(structure, "cityGcwRegionDefender.region"))
previousRegion = getStringObjVar(structure, "cityGcwRegionDefender.region");
if (hasObjVar(structure, "cityGcwRegionDefender.timeBegin"))
previousRegionTimeStartDefend = getIntObjVar(structure, "cityGcwRegionDefender.timeBegin");
if (hasObjVar(structure, "cityGcwRegionDefender.timeEnd"))
previousRegionTimeEndDefend = getIntObjVar(structure, "cityGcwRegionDefender.timeEnd");
string announcement = "Select a GCW region for your city to defend.";
if ((previousRegion != null) && (previousRegion.length() > 0) && (previousRegionTimeStartDefend > 0) && (previousRegionTimeEndDefend > 0))
{
// Must wait 1 day to switch to defending a different region
const int cooldown = previousRegionTimeEndDefend + (isGod(player) ? 10 : 86400) - getCalendarTime();
if (cooldown > 0)
{
string cooldownStr = "" + cooldown + "s";
int[] convertedTime = player_structure.convertSecondsTime(cooldown);
if ((convertedTime != null) && (convertedTime.length == 4))
{
if (convertedTime[0] > 0)
{
cooldownStr = "" + convertedTime[0] + "d:" + convertedTime[1] + "h:" + convertedTime[2] + "m:" + convertedTime[3] + "s";
}
else if (convertedTime[1] > 0)
{
cooldownStr = "" + convertedTime[1] + "h:" + convertedTime[2] + "m:" + convertedTime[3] + "s";
}
else if (convertedTime[2] > 0)
{
cooldownStr = "" + convertedTime[2] + "m:" + convertedTime[3] + "s";
}
else if (convertedTime[3] > 0)
{
cooldownStr = "" + convertedTime[3] + "s";
}
else
{
cooldownStr = "" + cooldown + "s";
}
}
announcement += "\n";
announcement += "You can immediately defend the GCW region you most recently defended (" + localize(new string_id("gcw_regions", previousRegion)) + ").\n";
announcement += "You must wait " + cooldownStr + " before you can defend a different GCW region.";
}
}
const string[] columnHeader = {"GCW Region"};
const string[] columnHeaderType = {"text"};
const string[][] columnData = new string[1][0];
columnData[0] = gcwDefenderRegions;
sui.tableColumnMajor(player, player, sui.OK_CANCEL, "@gcw:gcw_region_defender_war_terminal_menu", "handleCityGcwRegionDefenderChoice", announcement, columnHeader, columnHeaderType, columnData, false);
}
}
}
}
else if(item == menu_info_types.SERVER_MENU18)
{
const String gcwDefenderRegion = cityGetGcwDefenderRegion(city_id);
if ((gcwDefenderRegion != null) && (gcwDefenderRegion.length() > 0))
{
setObjVar(structure, "cityGcwRegionDefender.timeEnd", getCalendarTime());
citySetGcwDefenderRegion(city_id, "", 0, true);
sendSystemMessage(player, "Setting the city's GCW defender region to (None). This may take a few seconds. You will receive mail confirmation once the change has been completed.", "");
}
}
}
else
{
if(item == menu_info_types.SERVER_MENU5)
{
// Revoke this person's citizenship.
if(city.isCitizenOfCity(player, city_id))
sui.msgbox(self, player, "@city/city:revoke_cit_d", sui.YES_NO, "@city/city:revoke_cit_t", sui.MSG_QUESTION, "handleRevokeCitizenship");
}
}
if(isGod(player))
{
if(item == menu_info_types.SERVER_MENU4)
{
// Force a full city update.
forceUpdate(player, self, city_id);
}
else if(item == menu_info_types.SERVER_MENU6)
{
// Force the city to gain one rank.
forceRank(player, self, city_id, 1);
}
else if(item == menu_info_types.SERVER_MENU7)
{
// Force the city to lose one rank.
forceRank(player, self, city_id, -1);
}
else if(item == menu_info_types.SERVER_MENU9)
{
// Change city name.
makeMayor(player, self, city_id);
}
else if(item == menu_info_types.CITY_ADMIN_1)
{
// Reset clone data.
resetCloneData(player, self, city_id);
}
else if(item == menu_info_types.CITY_ADMIN_2)
{
// Reset shuttle data.
resetShuttleData(player, self, city_id);
}
else if(item == menu_info_types.CITY_ADMIN_3)
{
// Clean up structure list.
modifyStructureList(player, self, city_id);
}
else if(item == menu_info_types.CITY_ADMIN_4)
{
// Clear structure ScriptVars (enables new searches since there is a 6 hour refresh lockout).
clearStructureScriptVars(player, self, city_id);
}
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// forceUpdate
//------------------------------------------------
void forceUpdate(obj_id player, obj_id self, int city_id)
{
sui.msgbox(self, player, "@city/city:force_election_only", sui.YES_NO, "@city/city:force_city_update_t", sui.MSG_QUESTION, "handleForceUpdateElection");
}
//------------------------------------------------
// handleForceUpdateElection
//------------------------------------------------
messageHandler handleForceUpdateElection()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
obj_id player = sui.getPlayerId(params);
obj_id structure = getTopMostContainer(self);
int btn = sui.getIntButtonPressed(params);
if(!isIdValid(player) || !isIdValid(structure))
{
sendSystemMessageTestingOnly(player, "Invalid Object Id - Bailing Out - Please Try Again.");
return SCRIPT_CONTINUE;
}
int city_id = findCityByCityHall(structure);
if(city_id <= 0)
{
sendSystemMessageTestingOnly(player, "Invalid City Id - Bailing Out - Please Try Again.");
return SCRIPT_CONTINUE;
}
if(btn == sui.BP_CANCEL)
sui.msgbox(self, player, "@city/city:confirm_city_update", sui.YES_NO, "@city/city:force_city_update_t", sui.MSG_QUESTION, "handleForceUpdateConfirmed");
else
{
// Force an election only.
CustomerServiceLog("player_city", "!!!!! A CITY ELECTION WAS FORCED !!!!! Player: " + player + " City: " + city_id);
sendSystemMessageProse(self, prose.getPackage(new string_id(STF, "force_city_election"), city_id)); // Forcing a city election for city %TO.
obj_id cityMaster = getMasterCityObject();
dictionary outparams = new dictionary();
outparams.put("city_id", city_id);
messageTo(cityMaster, "forceElection", outparams, 0.f, false);
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleForceUpdateConfirmed
//------------------------------------------------
messageHandler handleForceUpdateConfirmed()
{
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
sui.msgbox(self, player, "@city/city:confirm_disable_cleanup", sui.YES_NO, "@city/city:disable_cleanup_t", sui.MSG_QUESTION, "handleForceUpdateNow");
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleForceUpdateNow
//------------------------------------------------
messageHandler handleForceUpdateNow()
{
obj_id player = sui.getPlayerId(params);
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
dictionary outparams = new dictionary();
outparams.put("city_id", city_id);
int btn = sui.getIntButtonPressed(params);
if(btn != sui.BP_CANCEL)
outparams.put("no_citizen_cleanup", 1);
CustomerServiceLog("player_city", "!!!!! A CITY UPDATE WAS FORCED !!!!! Player: " + player + " City: " + city_id);
sendSystemMessageProse(self, prose.getPackage(new string_id(STF, "force_city_update"), city_id)); // Forcing a city update for city %TO.
obj_id cityMaster = getMasterCityObject();
messageTo(cityMaster, "forceUpdate", outparams, 0.f, false);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// forceRank
//------------------------------------------------
void forceRank(obj_id player, obj_id self, int city_id, int rank)
{
utils.setScriptVar(self, "rank_change", rank);
sui.msgbox(self, player, "@city/city:force_city_rank_d", sui.YES_NO, "@city/city:force_city_rank_t", sui.MSG_QUESTION, "handleForceRankConfirmed");
}
//------------------------------------------------
// handleForceRankConfirmed
//------------------------------------------------
messageHandler handleForceRankConfirmed()
{
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
CustomerServiceLog("player_city", "!!!!! A CITY RANK CHANGE WAS FORCED !!!!! Player: " + player + " City: " + city_id);
sendSystemMessageProse(self, prose.getPackage(new string_id(STF, "force_city_rank"), city_id)); // Forcing a city rank change for city %TO.
obj_id cityMaster = getMasterCityObject();
dictionary outparams = new dictionary();
outparams.put("city_id", city_id);
outparams.put("rank_change", utils.getIntScriptVar(self, "rank_change"));
messageTo(cityMaster, "forceRank", outparams, 0.f, false);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// makeMayor
//------------------------------------------------
void makeMayor(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
return;
if(!cityExists(city_id))
{
sendSystemMessageTestingOnly(player, "Player City not found at this location...please try again.");
return;
}
obj_id[] citizen_list = cityGetCitizenIds(city_id);
string[] citizen_names = new string[citizen_list.length];
if(citizen_list == null || citizen_list.length <=0)
{
sendSystemMessageTestingOnly(player, "Player City not found at this location...please try again.");
return;
}
for(int i = 0; i < citizen_list.length; i++)
{
string citizen = cityGetCitizenName(city_id, citizen_list[i]);
if(citizen == null || citizen.equals(""))
{
citizen_names[i] = "Null Citizen";
}
else
{
citizen_names[i] = citizen;
}
}
utils.setScriptVar(player, "god_command_make_mayor_citizen_ids", citizen_list);
utils.setScriptVar(player, "god_command_make_mayor_citizen_names", citizen_names);
sui.listbox(self, player, "Select the Citizen to Make Mayor. You can only select Online Citizens to become the New Mayor", sui.OK_CANCEL, "God Command: Make Mayor", citizen_names, "handleMakeMayor", true);
}
//------------------------------------------------
// handleMakeMayor
//------------------------------------------------
messageHandler handleMakeMayor()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
int btn = sui.getIntButtonPressed(params);
int idx = sui.getListboxSelectedRow(params);
obj_id player = sui.getPlayerId(params);
if(!isIdValid(player))
return SCRIPT_CONTINUE;
if(!utils.hasScriptVar(player, "god_command_make_mayor_citizen_ids") && !utils.hasScriptVar(player, "god_command_make_mayor_citizen_names"))
{
sendSystemMessageTestingOnly(player, "Invalid Data - Please attempt the City Transfer Again.");
return SCRIPT_CONTINUE;
}
string[] names = utils.getStringArrayScriptVar(player, "god_command_make_mayor_citizen_names");
obj_id[] ids = utils.getObjIdArrayScriptVar(player, "god_command_make_mayor_citizen_ids");
utils.removeScriptVar(player, "god_command_make_mayor_citizen_names");
utils.removeScriptVar(player, "god_command_make_mayor_citizen_ids");
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
if(idx < 0)
return SCRIPT_CONTINUE;
string newMayorName = names[idx];
obj_id newMayorId = ids[idx];
// Make this person a mayor if they have the correct skills.
if(!hasSkill(newMayorId, "social_politician_novice"))
{
sendSystemMessage(player, new string_id(STF, "not_politician")); // That citizen is not a politician.
return SCRIPT_CONTINUE;
}
// Make sure they aren't already a mayor.
if(city.isAMayor(newMayorId))
{
sendSystemMessage(player, new string_id(STF, "already_other_mayor")); // That citizen is already the mayor of some other city.
return SCRIPT_CONTINUE;
}
obj_id structure = getTopMostContainer(self);
location structureLoc = getLocation(structure);
int city_id = getCityAtLocation(structureLoc, 0);
obj_id incumbent_mayor = cityGetLeader(city_id);
string template = getTemplateName(structure);
if(template.indexOf("cityhall_") < 0)
{
sendSystemMessageTestingOnly(player, "City Hall not recognized - Please make sure you are in a City Hall and attempt the Mayor Transfer again.");
return SCRIPT_CONTINUE;
}
CustomerServiceLog("player_city", "CSR changed mayor. CSR(" + player + ") Changed City(" + city_id + ")"+ cityGetName(city_id) +" to New Mayor(" + newMayorId + ")" + newMayorName + ".");
// Make them a mayor.
sendSystemMessage(player, new string_id(STF, "mayor_confirm")); // They are now the mayor.
city.setMayor(city_id, newMayorId);
//God tool was broken - did not transfer structures until the UpdatePulse.
city.doMayoralStructureTransfer(newMayorId, incumbent_mayor, city_id);
sendNewMayorMail(city_id, newMayorId);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// resetCloneData
//------------------------------------------------
void resetCloneData(obj_id player, obj_id self, int city_id)
{
// Make sure they want to do this.
sui.msgbox(self, player, "@city/city:reset_clone_data_d", sui.YES_NO, "@city/city:reset_clone_data_t", sui.MSG_QUESTION, "handleResetCloneData");
}
//------------------------------------------------
// handleResetCloneData
//------------------------------------------------
messageHandler handleResetCloneData()
{
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
city.setCloneInfo(city_id, null, null, null);
sendSystemMessage(player, SID_CLONE_DATA_WIPED);
CustomerServiceLog("player_city", "CSR wiped clone data. Player: " + player + " City: " + city_id);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// resetShuttleData
//------------------------------------------------
void resetShuttleData(obj_id player, obj_id self, int city_id)
{
// Make sure they want to do this.
sui.msgbox(self, player, "@city/city:reset_shuttle_data_d", sui.YES_NO, "@city/city:reset_shuttle_data_t", sui.MSG_QUESTION, "handleResetShuttleData");
}
//------------------------------------------------
// handleResetShuttleData
//------------------------------------------------
messageHandler handleResetShuttleData()
{
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
city.removeStarport(self, city_id);
sendSystemMessage(player, SID_SHUTTLE_DATA_WIPED);
CustomerServiceLog("player_city", "CSR wiped shuttle data. Player: " + player + " City: " + city_id);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// modifyStructureList
//------------------------------------------------
//removes Structure Search results from the City Terminal. This makes it so new searches can be made.
void clearStructureScriptVars(obj_id player, obj_id self, int city_id)
{
if(utils.hasScriptVar(self, "loadedStructuresIds") &&
utils.hasScriptVar(self, "loadedStructuresNames") &&
utils.hasScriptVar(self, "loadedStructuresLocations"))
{
utils.removeScriptVar(self, "loadedStructuresIds");
utils.removeScriptVar(self, "loadedStructuresNames");
utils.removeScriptVar(self, "loadedStructuresLocations");
}
if(utils.hasScriptVarTree(self, city.CITIZEN_LIST_QUERIED))
utils.removeScriptVarTree(self, city.CITIZEN_LIST_QUERIED);
if(utils.hasScriptVarTree(self, city.CITIZEN_LIST_DATA))
utils.removeScriptVarTree(self, city.CITIZEN_LIST_DATA);
}
void modifyStructureList(obj_id player, obj_id self, int city_id)
{
resizeable obj_id[] list_structures = new obj_id[0];
resizeable string[] list_strings = new string[0];
obj_id[] structures = cityGetStructureIds(city_id);
for(int i = 0; i < structures.length; i++)
{
if(city.isMissionTerminal(city_id, structures[i]))
{
string name = localize(getNameStringId(structures[i]));
string str = "Mission Terminal: ";
if(name != null)
str += name;
else
str += "\\#FF0000Unloaded or Bad Entry\\";
str += " (" + structures[i] + ")";
list_structures = utils.addElement(list_structures, structures[i]);
list_strings = utils.addElement(list_strings, str);
}
else if(city.isSkillTrainer(city_id, structures[i]))
{
string name = localize(getNameStringId(structures[i]));
string str = "Skill Trainer: ";
if(name != null)
str += name;
else
str += "\\#FF0000Unloaded or Bad Entry\\";
str += " (" + structures[i] + ")";
list_structures = utils.addElement(list_structures, structures[i]);
list_strings = utils.addElement(list_strings, str);
}
else if(city.isDecoration(city_id, structures[i]))
{
string name = localize(getNameStringId(structures[i]));
string str = "Decoration: ";
if(name != null)
str += name;
else
str += "\\#FF0000Unloaded or Bad Entry\\";
str += " (" + structures[i] + ")";
list_structures = utils.addElement(list_structures, structures[i]);
list_strings = utils.addElement(list_strings, str);
}
}
if(list_strings.length == 0)
{
sendSystemMessage(player, new string_id(STF, "no_special_objects")); // There aren't any special objects to manage.
return;
}
utils.setScriptVar(self, "list_structures", list_structures);
utils.setScriptVar(self, "list_strings", list_strings);
sui.listbox(self, player, "@city/city:city_object_list_d", sui.OK_CANCEL, "@city/city:city_object_list_t", list_strings, "handleCityObjectRemove", true);
}
//------------------------------------------------
// handleCityObjectRemove
//------------------------------------------------
messageHandler handleCityObjectRemove()
{
int idx = sui.getListboxSelectedRow(params);
if(idx < 0)
idx = 0;
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
resizeable string[] list_strings = utils.getResizeableStringArrayScriptVar(self, "list_strings");
utils.setScriptVar(self, "list_idx", idx);
string_id destroy_prefix = new string_id(STF, "destroy_prefix"); // Are you sure you want to destroy
string_id destroy_suffix = new string_id(STF, "destroy_suffix"); // ? The object's city DB entry will be removed and the object (if it exists) will be destroyed.
string prompt = getString(destroy_prefix) + list_strings[idx] + getString(destroy_suffix);
sui.msgbox(self, player, prompt, sui.YES_NO, utils.packStringId(SID_SUI_CONFIRM_REMOVE_TITLE), sui.MSG_QUESTION, "handleConfirmObjectRemove");
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleConfirmObjectRemove
//------------------------------------------------
messageHandler handleConfirmObjectRemove()
{
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
int idx = utils.getIntScriptVar(self, "list_idx");
resizeable string[] list_strings = utils.getResizeableStringArrayScriptVar(self, "list_strings");
resizeable obj_id[] list_structures = utils.getResizeableObjIdArrayScriptVar(self, "list_structures");
string name = list_strings[idx];
messageTo(list_structures[idx], "requestDestroy", null, 0.f, true);
cityRemoveStructure(city_id, list_structures[idx]);
sendSystemMessageProse(self, prose.getPackage(new string_id(STF, "destroy_object"), city_id)); // %TO has been removed from the city db and the object destroy message has been sent.
CustomerServiceLog("player_city", "CSR remove city object via menu. Player: " + player + " City: " + city_id + " Object: " + list_structures[idx]);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleRevokeCitizenship
//------------------------------------------------
messageHandler handleRevokeCitizenship()
{
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
obj_id mayor = cityGetLeader(city_id);
string mayor_name = cityGetCitizenName(city_id, mayor);
prose_package bodypp = prose.getPackage(city.LOST_CITIZEN_BODY, cityGetCitizenName(city_id, player));
utils.sendMail(city.LOST_CITIZEN_SUBJECT, bodypp, mayor_name, "City Hall");
string city_name = cityGetName(city_id);
obj_id city_hall = cityGetCityHall(city_id);
cityRemoveCitizen(city_id, player);
sendSystemMessage(player, SID_REVOKE_CITIZEN_WARNING); //"If you have a house within the city limits you must declare your residency at a different location or pack your house up to avoid being a readded as a city resident."
CustomerServiceLog("player_city", "Removed citizen by their request. City: " + city_name + " (" + city_id + "/" + city_hall + ")" + " Citizen: " + player);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// showCityInfo
//------------------------------------------------
void showCityInfo(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
obj_id cityHall = cityGetCityHall(city_id);
string[] city_info = new string[12];
string_id city_name_text = new string_id(STF, "name_prompt");
const string city_name = cityGetName(city_id);
string city_data = city_name;
// if the city is factionally aligned, display it
const int factionId = cityGetFaction(city_id);
if (##"imperial" == factionId)
{
city_data += " (Imperial aligned)";
}
else if (##"rebel" == factionId)
{
city_data += " (Rebel aligned)";
}
// if the city has the founder and/or creation time, display it
string founder = getStringObjVar(cityHall, "founder.id");
int creationTime = cityGetCreationTime(city_id);
if (((founder != null) && (founder.length() > 0)) || (creationTime > 0))
{
city_data += " (founded";
if ((founder != null) && (founder.length() > 0))
{
city_data += " by ";
city_data += founder;
}
if (creationTime > 0)
{
city_data += " on ";
city_data += getCalendarTimeStringLocal(creationTime);
}
city_data += ")";
}
city_info[0] = getString(city_name_text) + city_data;
obj_id mayor = cityGetLeader(city_id);
string_id city_mayor_text = new string_id(STF, "mayor_prompt");
city_info[1] = getString(city_mayor_text) + cityGetCitizenName(city_id, mayor);
const String gcwDefenderRegion = cityGetGcwDefenderRegion(city_id);
if ((gcwDefenderRegion == null) || (gcwDefenderRegion.length() <= 0))
{
city_info[2] = "GCW Region Defender: (None)";
city_info[3] = "GCW Region Defender Bonus: (None)";
}
else
{
const int timeJoinedGcwDefenderRegion = cityGetTimeJoinedGcwDefenderRegion(city_id);
city_info[2] = "GCW Region Defender: " + localize(new string_id("gcw_regions", gcwDefenderRegion));
if (timeJoinedGcwDefenderRegion > 0)
{
city_info[2] += (" (started defending on " + getCalendarTimeStringLocal(timeJoinedGcwDefenderRegion) + ")");
const int gcwDaysRequiredForGcwRegionDefenderBonus = utils.stringToInt(getConfigSetting("GameServer", "gcwDaysRequiredForGcwRegionDefenderBonus"));
const int age = getCalendarTime() - timeJoinedGcwDefenderRegion;
if (age > (gcwDaysRequiredForGcwRegionDefenderBonus * 86400))
{
if (##"imperial" == factionId)
city_info[3] = "GCW Region Defender Bonus: " + getGcwDefenderRegionImperialBonus(gcwDefenderRegion) + "%";
else if (##"rebel" == factionId)
city_info[3] = "GCW Region Defender Bonus: " + getGcwDefenderRegionRebelBonus(gcwDefenderRegion) + "%";
else
city_info[3] = "GCW Region Defender Bonus: (None - cannot determine factional alignment)";
}
else
{
city_info[3] = ("GCW Region Defender Bonus: (None - hasn't defended for " + gcwDaysRequiredForGcwRegionDefenderBonus + " days)\n");
}
}
else
{
city_info[3] = "GCW Region Defender Bonus: (None - cannot determine time started defending)";
}
}
location city_loc = cityGetLocation(city_id);
string_id city_location_text = new string_id(STF, "location_prompt");
string_id city_radius_text = new string_id(STF, "radius_prompt");
city_info[4] = getString(city_location_text) + (int) city_loc.x + ", " + (int) city_loc.z + getString(city_radius_text) + cityGetRadius(city_id) + "m";
string_id citizens_text = new string_id(STF, "citizen_prompt");
string_id structures_text = new string_id(STF, "structures_prompt");
city_info[5] = getString(citizens_text) + cityGetCitizenIds(city_id).length + getString(structures_text) + cityGetStructureIds(city_id).length;
string_id city_specialization_text = new string_id(STF, "specialization_prompt");
city_info[6] = getString(city_specialization_text) + localize(new string_id(STF, city.cityGetSpecString(city_id)));
city_info[7] = "@city/city:income_tax" + " -- " + cityGetIncomeTax(city_id) + " cr";
city_info[8] = "@city/city:property_tax" + " -- " + cityGetPropertyTax(city_id) + "%";
city_info[9] = "@city/city:sales_tax" + " -- " + cityGetSalesTax(city_id) + "%";
city_info[10] = "@city/city:travel_tax" + " -- " + cityGetTravelCost(city_id) + " cr";
string garage = city_name + ".garageFee";
if(!hasObjVar(cityHall, garage))
setObjVar(cityHall, garage, 0);
city_info[11] = "@city/city:garage_tax" + " -- " + getIntObjVar(cityHall, garage) + "%";
sui.listbox(self, player, "@city/city:city_info_d", sui.OK_CANCEL, "@city/city:city_info_t", city_info, "handleCityInfoSelect", true);
}
//------------------------------------------------
// showCitizensList
//------------------------------------------------
void showCitizensList(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
obj_id[] structures = cityGetStructureIds(city_id);
if(structures == null || structures.length <= 0)
{
sendSystemMessage(player, new string_id(STF, "no_city_citizen_data"));
return;
}
int now = getGameTime();
if(utils.hasScriptVar(self, "citizen_list_refresh_time"))
{
int time = utils.getIntScriptVar(self, "citizen_list_refresh_time");
if((time + 3600) < now) //1 hours has passed.
{
//sendSystemMessageTestingOnly(player, "removing 2-hour scriptVar");
utils.removeScriptVar(self, city.CITIZEN_LIST_QUERIED);
}
}
//see if owner of each structure is a self
boolean hasAsked = utils.hasScriptVar(self, city.CITIZEN_LIST_QUERIED);
if (!hasAsked)
{
utils.setScriptVar(self, "citizen_list_refresh_time", now);
utils.setScriptVar(self, city.CITIZEN_LIST_QUERIED, true);
}
dictionary residentInfo = new dictionary();
for(int j = 0; j < structures.length; ++j)
{
if(!exists(structures[j]) && !hasAsked)
{
dictionary dict = new dictionary();
dict.put("terminal_id", self);
dict.put("city_id", city_id);
if(!messageTo(structures[j], "getStructureCitizenInformation", dict, 0.0f, false))
{
CustomerServiceLog("player_city", "Citizen List: City("+ city_id +")"+ cityGetName(city_id) +
" MessageTo failed! Attempted to message Object("+ structures[j] +").");
}
CustomerServiceLog("player_city", "Citizen List: City("+ city_id +")"+ cityGetName(city_id) +
" Structure("+ structures[j] +") does not exist on this Server - Messaging to object to obtain Data.");
}
//separate the structures so only houses show.
if(city.isNormalStructure(city_id, structures[j]) && !player_structure.isCivic(structures[j]))
{
//get houses that have a declared residence
if(exists(structures[j]) && hasObjVar(structures[j], player_structure.VAR_RESIDENCE_BUILDING))
{
obj_id citizenId = getObjIdObjVar(structures[j], player_structure.VAR_RESIDENCE_BUILDING);
dictionary residentDict = new dictionary();
residentDict.put("house_id", structures[j]);
residentDict.put("house_loc", getLocation(structures[j]));
residentInfo.put(citizenId, residentDict);
}
}
}
dictionary newDict = new dictionary();
newDict.put("city_id", city_id);
newDict.put("player", player);
residentInfo.put("city_dict", newDict);
sendSystemMessage(player, new string_id(STF, "accessing_citizen_city_network"));
messageTo(self, "DisplayCitizenList", residentInfo, 3.0f, false);
}
messageHandler DisplayCitizenList()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
dictionary city_info = params.getDictionary("city_dict");
int city_id = city_info.getInt("city_id");
obj_id player = city_info.getObjId("player");
obj_id[] listOfResidents = cityGetCitizenIds(city_id);
if(listOfResidents == null || listOfResidents.length <= 0)
{
sendSystemMessage(player, new string_id(STF, "no_city_citizen_data"));
return SCRIPT_CONTINUE;
}
int columnCount = 6;
string[][] displayData = new string[listOfResidents.length][columnCount];
location[] locationData = new location[listOfResidents.length];
for(int k = 0; k < listOfResidents.length; k++)
{
for(int l = 0; l < columnCount; l++)
{
//Name of Player
string ownerName = cityGetCitizenName(city_id, listOfResidents[k]);
switch(l)
{
case 0:
//Citizen Name
if(ownerName == null || ownerName.length() <= 0)
ownerName = "@city/city:unknown_owner_data"; //"Unknown Owner Data";
if(!isGod(player))
{
if(city.isMilitiaOfCity(listOfResidents[k], city_id))
displayData[k][l] = ownerName + " (Militia)";
else
displayData[k][l] = ownerName;
}
else
{
if(city.isMilitiaOfCity(listOfResidents[k], city_id))
displayData[k][l] = ownerName + " (Militia) : " + listOfResidents[k];
else
displayData[k][l] = ownerName + " : " + listOfResidents[k];
}
break;
case 1:
//Structure Name
if(params.containsKey(listOfResidents[k]))
{
dictionary residentDict = params.getDictionary(listOfResidents[k]);
obj_id house = residentDict.getObjId("house_id");
string houseName = getEncodedName(house);
if(houseName == null || houseName.length() <= 0)
houseName = "@city/city:unknown_structure_data"; //"Unknown Structure Name";
if(!isGod(player))
displayData[k][l] = houseName;
else
displayData[k][l] = houseName + " : " + house;
}
else if(utils.hasScriptVarTree(self, city.CITIZEN_LIST_DATA+"."+listOfResidents[k]))
{
obj_id house = utils.getObjIdScriptVar(self, city.CITIZEN_LIST_DATA+"."+listOfResidents[k]+".house_id");
string houseName = utils.getStringScriptVar(self, city.CITIZEN_LIST_DATA+"."+listOfResidents[k]+".house_name");
if(houseName == null || houseName.length() <= 0)
houseName = "@city/city:unknown_structure_data"; //"Unknown Structure Name";
if(!isGod(player))
displayData[k][l] = houseName;
else
displayData[k][l] = houseName + " : " + house;
}
else if(cityGetLeader(city_id) == listOfResidents[k])
{
obj_id house = getTopMostContainer(self);
string houseName = getEncodedName(house);
if(houseName == null || houseName.length() <= 0)
houseName = "@city/city:unknown_structure_data"; //"Unknown Structure Name";
if(!isGod(player))
displayData[k][l] = houseName;
else
displayData[k][l] = houseName + " : " + house;
}
else
{
string houseName = "unkown";
if(!isGod(player))
displayData[k][l] = houseName;
else
displayData[k][l] = houseName + " : No Id found";
}
break;
case 2:
//Structure Location
if(params.containsKey(listOfResidents[k]))
{
dictionary residentDict = params.getDictionary(listOfResidents[k]);
obj_id house = residentDict.getObjId("house_id");
string houseLoc = getStructureDisplayLocation(residentDict.getLocation("house_loc"));
if(houseLoc == null || houseLoc.length() <= 0)
houseLoc = "@city/city:unknown_location_data"; //"Unknown Location";
displayData[k][l] = houseLoc;
locationData[k] = residentDict.getLocation("house_loc");
}
else if(utils.hasScriptVarTree(self, city.CITIZEN_LIST_DATA+"."+listOfResidents[k]))
{
obj_id house = utils.getObjIdScriptVar(self, city.CITIZEN_LIST_DATA+"."+listOfResidents[k]+".house_id");
string houseLoc = getStructureDisplayLocation(utils.getLocationScriptVar(self, city.CITIZEN_LIST_DATA+"."+listOfResidents[k]+".house_loc"));
if(houseLoc == null || houseLoc.length() <= 0)
houseLoc = "@city/city:unknown_location_data"; //"Unknown Location";
displayData[k][l] = houseLoc;
locationData[k] = utils.getLocationScriptVar(self, city.CITIZEN_LIST_DATA+"."+listOfResidents[k]+".house_loc");
}
else if(cityGetLeader(city_id) == listOfResidents[k])
{
obj_id house = getTopMostContainer(self);
string houseLoc = getStructureDisplayLocation(getLocation(house));
if(houseLoc == null || houseLoc.length() <= 0)
houseLoc = "@city/city:unknown_location_data"; //"Unknown Location";
displayData[k][l] = houseLoc;
locationData[k] = getLocation(house);
}
else
{
string houseLoc = "@city/city:unknown_location_data"; //"Unknown Location"
displayData[k][l] = houseLoc;
locationData[k] = null;
}
break;
case 3:
//player's combat level
int ownerLevel = cityGetCitizenLevel(city_id, listOfResidents[k]);
if(ownerLevel != 0)
displayData[k][l] = "" + ownerLevel;
else
displayData[k][l] = "@city/city:unknown_level";
break;
case 4:
//player's profession
string ownerProfession = cityGetCitizenProfession(city_id, listOfResidents[k]);
if(ownerProfession != null && ownerProfession.length() > 0)
displayData[k][l] = "@ui_roadmap:" + ownerProfession;
else
displayData[k][l] = "@city/city:unknown_profession";
break;
case 5:
//last login - current location
string onlineOfflineStatus = utils.getOnlineOfflineStatus(listOfResidents[k]);
displayData[k][l] = onlineOfflineStatus;
break;
}
}
}
//set scriptvars on the player - multiple players may use the terminal at the same time.
utils.setScriptVar(player, "citizenLocationData", locationData);
utils.setScriptVar(player, "citizenDisplayData", displayData);
/*
string[] colTitles = {
"@city/city:column_citizen_name",
"@city/city:column_structure_name",
"@city/city:column_structure_location",
"@city/city:column_citizen_level",
"@city/city:column_citizen_profession",
"@city/city:column_location_or_last_login"
};
string[] colTypes = {
"text",
"text",
"text",
"integer",
"text",
"text"
};
string_id prompt = new string_id(STF, "citizen_list_prompt");
string stringPrompt = getString(prompt);
sui.tableRowMajor(self, player, sui.OK_CANCEL, "@city/city:citizen_list_t", "handleCitizenSelect", stringPrompt, colTitles, colTypes, displayData, true);
*/
showCitizenshipListSui(self, player, displayData);
return SCRIPT_CONTINUE;
}
//allows for the creation of waypoints to the selected Citizen's Structure.
messageHandler handleCitizenSelect()
{
obj_id player = sui.getPlayerId(params);
//debugConsoleMsg(player, "handler hit. Params = " + params);
int btn = sui.getIntButtonPressed(params);
string eventType = sui.getEventType(params);
if(btn == sui.BP_CANCEL)
{
if(utils.hasScriptVar(player, "citizenDisplayData"))
{
utils.removeScriptVar(player, "citizenDisplayData");
}
if(utils.hasScriptVar(player, "citizenLocationData"))
{
utils.removeScriptVar(player, "citizenLocationData");
}
return SCRIPT_CONTINUE;
}
if(!utils.hasScriptVar(player, "citizenDisplayData") && !utils.hasScriptVar(player, "citizenLocationData"))
{
sendSystemMessage(player, new string_id(STF, "no_available_waypoint"));
return SCRIPT_CONTINUE;
}
location[] locationData = utils.getLocationArrayScriptVar(player, "citizenLocationData");
string[][] displayData = utils.getStringArrayArrayScriptVar(player, "citizenDisplayData");
//utils.removeScriptVar(player, "citizenLocationData");
//utils.removeScriptVar(player, "citizenDisplayData");
if(locationData == null || locationData.length <= 0)
{
sendSystemMessage(player, new string_id(STF, "no_available_waypoint"));
return SCRIPT_CONTINUE;
}
if(displayData == null || displayData.length <= 0)
{
sendSystemMessage(player, new string_id(STF, "no_available_waypoint"));
return SCRIPT_CONTINUE;
}
int idx = sui.getTableLogicalIndex(params);
if(idx < 0)
return SCRIPT_CONTINUE;
else
{
//create waypoint
location chosenLoc = locationData[idx]; //location data
obj_id structureWaypoint = createWaypointInDatapad(player, chosenLoc);
setWaypointName(structureWaypoint, displayData[idx][0]);
setWaypointActive(structureWaypoint, true);
sendSystemMessage(player, new string_id(STF, "creating_waypoint"));
}
showCitizenshipListSui(self, player, displayData);
return SCRIPT_CONTINUE;
}
void showCitizenshipListSui(obj_id self, obj_id player, string[][] displayData)
{
string[] colTitles = {
"@city/city:column_citizen_name",
"@city/city:column_structure_name",
"@city/city:column_structure_location",
"@city/city:column_citizen_level",
"@city/city:column_citizen_profession",
"@city/city:column_location_or_last_login"
};
string[] colTypes = {
"text",
"text",
"text",
"integer",
"text",
"text"
};
string_id prompt = new string_id(STF, "citizen_list_prompt");
string stringPrompt = getString(prompt);
sui.tableRowMajor(self, player, sui.OK_CANCEL, "@city/city:citizen_list_t", "handleCitizenSelect", stringPrompt, colTitles, colTypes, displayData, true);
}
//------------------------------------------------
// showStructuresList
//------------------------------------------------
void showStructuresList(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
/***************SELF is the City Management Terminal**************/
if(utils.hasScriptVar(self, "lastUpdateTime") &&
utils.hasScriptVar(self, "loadedStructuresIds") &&
utils.hasScriptVar(self, "loadedStructuresNames") &&
utils.hasScriptVar(self, "loadedStructuresLocations"))
{
int currentGameTime = getGameTime();
int refreshTime = utils.getIntScriptVar(self, "lastUpdateTime");
if(currentGameTime > refreshTime)
{
//it's time to refresh -
sendSystemMessage(player, new string_id(STF, "accessing_city_network"));
getCityStructuresInfo(player, self, city_id);
}
else
{
showCityStructuresSuiFromScriptVars(self, player);
}
}
else
{
sendSystemMessage(player, new string_id(STF, "accessing_city_network"));
getCityStructuresInfo(player, self, city_id);
}
}
void getCityStructuresInfo(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
//get all structures in the city
obj_id[] structures = cityGetStructureIds(city_id);
//loaded structures
resizeable obj_id[] loadedStructures = new obj_id[0];
//unloaded structures
resizeable obj_id[] unloadedStructures = new obj_id[0];
//loop through all structures and separate loaded from unloaded.
for(int i = 0; i < structures.length; i++)
{
if(structures[i].isLoaded())
{
utils.addElement(loadedStructures, structures[i]);
}
else
{
utils.addElement(unloadedStructures, structures[i]);
}
}
obj_id[] loadedStructuresStaticArray = utils.toStaticObjIdArray(loadedStructures);
obj_id[] unloadedStructuresStaticArray = utils.toStaticObjIdArray(unloadedStructures);
//for loaded structures, call function that gets their information and stores it.
if(loadedStructuresStaticArray != null)
LoadedCityStructuresInfo(self, player, city_id, loadedStructuresStaticArray);
//for unloaded structures, call function that messages those OBJ IDs to get info about them.
if(unloadedStructuresStaticArray != null)
messageUnloadedCityStructures(self, player, city_id, unloadedStructuresStaticArray);
}
void LoadedCityStructuresInfo(obj_id self, obj_id player, int city_id, obj_id[] loadedStructures)
{
location[] structuresLocation = new location[loadedStructures.length];
string[] structuresName = new string[loadedStructures.length];
for(int i = 0; i < loadedStructures.length; i++)
{
if(!city.isNormalStructure(city_id, loadedStructures[i]))
{
structuresLocation[i] = getLocation(loadedStructures[i]);
structuresName[i] = localize(getNameStringId(loadedStructures[i]));
}
else if(player_structure.isCivic(loadedStructures[i]))
{
structuresLocation[i] = getLocation(loadedStructures[i]);
float cond = ((float) player_structure.getStructureCondition(loadedStructures[i])) / ((float) player_structure.getMaxCondition(loadedStructures[i]));
int outcond = (int) (cond * 100);
structuresName[i] = getEncodedName(loadedStructures[i]) + " (Condition : " + outcond + "%)";
}
else
{
//player house - we don't want any info - set it all to null.
loadedStructures[i] = null;
}
}
//structures array now contains nulls - get them out of there.
resizeable obj_id[] loadedStructuresFinal = new obj_id[0];
resizeable location[] structuresLocationFinal = new location[0];
resizeable string[] structuresNameFinal = new string[0];
for(int j = 0; j < loadedStructures.length; j++)
{
if(loadedStructures[j] != null)
{
//
utils.addElement(loadedStructuresFinal, loadedStructures[j]);
utils.addElement(structuresLocationFinal, structuresLocation[j]);
utils.addElement(structuresNameFinal, structuresName[j]);
}
}
obj_id[] structuresIdStaticArray = utils.toStaticObjIdArray(loadedStructuresFinal);
string[] structuresNameStaticArray = utils.toStaticStringArray(structuresNameFinal);
location[] structuresLocationStaticArray = utils.toStaticLocationArray(structuresLocationFinal);
//Set the info on the city terminal so we can display it later
utils.setScriptVar(self, "loadedStructuresIds", structuresIdStaticArray);
utils.setScriptVar(self, "loadedStructuresNames", structuresNameStaticArray);
utils.setScriptVar(self, "loadedStructuresLocations", structuresLocationStaticArray);
//Set the Update Time
int currentGameTime = getGameTime();
utils.setScriptVar(self, "lastUpdateTime", currentGameTime + 3600);
//now we have populated the city hall - let's Message to Show the List.
dictionary dict = new dictionary();
dict.put("player", player);
dict.put("city_id", city_id);
dict.put("city_terminal", self);
messageTo(self, "DisplayCityStructuresList", dict, 3.0f, false);
}
void messageUnloadedCityStructures(obj_id self, obj_id player, int city_id, obj_id[] unloadedStructures)
{
for(int k = 0; k < unloadedStructures.length; k++)
{
dictionary d = new dictionary();
d.put("player", player);
d.put("city_id", city_id);
d.put("city_terminal", self);
//the object is not located on this game server - we need to MessageTo to retrieve it's info.
if(!messageTo(unloadedStructures[k], "handleUnloadedCityStructureReportData", d, 0.0f, false))
{
CustomerServiceLog("player_city", "Structure List: City("+ city_id +")"+ cityGetName(city_id) +
" MessageTo Structure("+ unloadedStructures[k] +") Failed!");
}
CustomerServiceLog("player_city", "Structure List: City("+ city_id +")"+ cityGetName(city_id) +
" Requesting Structure Info from Object("+ unloadedStructures[k] +") - Sent Data: (requesting)Player("+ player +
"), CityID("+ city_id +"), City Terminal("+ self +")."); }
}
messageHandler DisplayCityStructuresList()
{
obj_id player = params.getObjId("player");
obj_id city_terminal = params.getObjId("city_terminal");
int city_id = params.getInt("city_id");
if(!isIdValid(player) || !isIdValid(city_terminal))
{
//tell player something bad happened
sendSystemMessage(player, new string_id(STF, "no_available_waypoint"));
return SCRIPT_CONTINUE;
}
if(!utils.hasScriptVar(city_terminal, "loadedStructuresIds") &&
!utils.hasScriptVar(city_terminal, "loadedStructuresNames") &&
!utils.hasScriptVar(city_terminal, "loadedStructuresLocations"))
{
//tell player something bad happened
sendSystemMessage(player, new string_id(STF, "no_available_waypoint"));
return SCRIPT_CONTINUE;
}
obj_id[] structureIds = utils.getObjIdArrayScriptVar(city_terminal, "loadedStructuresIds");
string[] structureNames = utils.getStringArrayScriptVar(city_terminal, "loadedStructuresNames");
location[] structureLocs = utils.getLocationArrayScriptVar(city_terminal, "loadedStructuresLocations");
const int columnCount = 3;
string[][] displayData = new string[structureIds.length][columnCount];
for(int i = 0; i < structureIds.length; i++)
{
for(int k = 0; k < columnCount; k++)
{
switch(k)
{
case 0:
if(structureNames[i] == null || structureNames[i] == "")
structureNames[i] = "Unknown Structure"; //localize
displayData[i][k] = structureNames[i];
break;
case 1:
displayData[i][k] = getStructureDisplayLocation(structureLocs[i]);
break;
case 2:
string template = getTemplateName(structureIds[i]);
if(template.indexOf("garden_") > -1)
{
displayData[i][k] = "Garden";
break;
}
if(city.isMissionTerminal(city_id, structureIds[i]))
{
displayData[i][k] = "Terminal";
break;
}
if(city.isDecoration(city_id, structureIds[i]))
{
displayData[i][k] = "Decoration";
break;
}
//otherwise - it's a structure.
displayData[i][k] = "Structure";
break;
default:
LOG("sissynoid", "Horrible Failure");
break;
}
}
}
showCityStructuresSui(self, player, displayData);
return SCRIPT_CONTINUE;
}
void showCityStructuresSuiFromScriptVars(obj_id self, obj_id player)
{
if(!utils.hasScriptVar(self, "loadedStructuresIds") &&
!utils.hasScriptVar(self, "loadedStructuresNames") &&
!utils.hasScriptVar(self, "loadedStructuresLocations"))
{
//tell player something bad happened
sendSystemMessage(player, new string_id(STF, "no_available_waypoint"));
}
int city_id = city.checkCity(self, false);
obj_id[] structureIds = utils.getObjIdArrayScriptVar(self, "loadedStructuresIds");
string[] structureNames = utils.getStringArrayScriptVar(self, "loadedStructuresNames");
location[] structureLocs = utils.getLocationArrayScriptVar(self, "loadedStructuresLocations");
const int columnCount = 3;
string[][] displayData = new string[structureIds.length][columnCount];
for(int i = 0; i < structureIds.length; i++)
{
for(int k = 0; k < columnCount; k++)
{
switch(k)
{
case 0:
if(structureNames[i] == null || structureNames[i] == "")
structureNames[i] = "Unknown Structure"; //localize
displayData[i][k] = structureNames[i];
break;
case 1:
displayData[i][k] = getStructureDisplayLocation(structureLocs[i]);
break;
case 2:
string template = getTemplateName(structureIds[i]);
if(template.indexOf("garden_") > -1)
{
displayData[i][k] = "Garden";
break;
}
if(city.isMissionTerminal(city_id, structureIds[i]))
{
displayData[i][k] = "Terminal";
break;
}
if(city.isDecoration(city_id, structureIds[i]))
{
displayData[i][k] = "Decoration";
break;
}
//otherwise - it's a structure.
displayData[i][k] = "Structure";
break;
default:
LOG("sissynoid", "Horrible Failure");
break;
}
}
}
showCityStructuresSui(self, player, displayData);
}
void showCityStructuresSui(obj_id self, obj_id player, string[][] displayData)
{
string[] colTitles = {"Structure Name", "Structure Location", "Structure Type"};
string[] colTypes = {"text", "text", "text"};
string_id prompt = new string_id(STF, "structure_list_prompt");
string stringPrompt = getString(prompt);
sui.tableRowMajor(self, player, sui.OK_CANCEL, "@city/city:structure_list_t", "handleStructureWaypointSelect", stringPrompt, colTitles, colTypes, displayData, true);
}
string getStructureDisplayLocation(location loc)
{
string returnString = "" + Math.round(loc.x) + ", " + Math.round(loc.y) + ", " + Math.round(loc.z);
return returnString;
}
//This fires when an unloaded object (object on another game server) responds to the message sent
//to it. Here, we will grab the info off of the city hall, update it, and stamp it back on it.
messageHandler RecievedUnloadedStructureResponse()
{
int city_id_for_log = getCityAtLocation(getLocation(self), 0);
if(params == null || params.isEmpty())
{
CustomerServiceLog("player_city", "Structure List: City("+ city_id_for_log +")"+ cityGetName(city_id_for_log) +
" Data was returned, but Null or Empty");
return SCRIPT_CONTINUE;
}
obj_id player = params.getObjId("player");
obj_id city_terminal = params.getObjId("city_terminal");
int city_id = params.getInt("city_id");
obj_id newObjectId = params.getObjId("unloadedStructureId");
string newObjectName = params.getString("unloadedStructureName");
location newObjectLocation = params.getLocation("unloadedStructureLocation");
if(!isIdValid(player) || !isIdValid(city_terminal) || !isIdValid(newObjectId))
{
//tell player something bad happened
sendSystemMessage(player, new string_id(STF, "no_available_waypoint"));
return SCRIPT_CONTINUE;
}
//grab data from City Hall
if(!utils.hasScriptVar(city_terminal, "loadedStructuresIds") &&
!utils.hasScriptVar(city_terminal, "loadedStructuresNames") &&
!utils.hasScriptVar(city_terminal, "loadedStructuresLocations"))
{
//tell player something bad happened
sendSystemMessage(player, new string_id(STF, "no_available_waypoint"));
return SCRIPT_CONTINUE;
}
obj_id[] structureIds = utils.getObjIdArrayScriptVar(city_terminal, "loadedStructuresIds");
string[] structureNames = utils.getStringArrayScriptVar(city_terminal, "loadedStructuresNames");
location[] structureLocs = utils.getLocationArrayScriptVar(city_terminal, "loadedStructuresLocations");
resizeable obj_id[] resizeableloadedStructuresIds = structureIds;
resizeable string[] resizeableloadedStructuresNames = structureNames;
resizeable location[] resizeableloadedStructuresLocations = structureLocs;
utils.addElement(resizeableloadedStructuresIds, newObjectId);
utils.addElement(resizeableloadedStructuresNames, newObjectName);
utils.addElement(resizeableloadedStructuresLocations, newObjectLocation);
obj_id[] loadedStructuresIds = utils.toStaticObjIdArray(resizeableloadedStructuresIds);
string[] loadedStructuresNames = utils.toStaticStringArray(resizeableloadedStructuresNames);
location[] loadedStructuresLocations = utils.toStaticLocationArray(resizeableloadedStructuresLocations);
//Set info back on City Hall
utils.setScriptVar(self, "loadedStructuresIds", loadedStructuresIds);
utils.setScriptVar(self, "loadedStructuresNames", loadedStructuresNames);
utils.setScriptVar(self, "loadedStructuresLocations", loadedStructuresLocations);
return SCRIPT_CONTINUE;
}
//This gives players the ability to create a waypoint to the City Structure when selected via the listbox.
messageHandler handleStructureWaypointSelect()
{
obj_id player = sui.getPlayerId(params);
//debugConsoleMsg(player, "handler hit. Params = " + params);
int btn = sui.getIntButtonPressed(params);
string eventType = sui.getEventType(params);
if(btn == sui.BP_CANCEL)
{
if(utils.hasScriptVar(player, "city_structure_report_logical"))
utils.removeScriptVar(player, "city_structure_report_logical");
return SCRIPT_CONTINUE;
}
//grab data from City Hall
if(!utils.hasScriptVar(self, "loadedStructuresIds") &&
!utils.hasScriptVar(self, "loadedStructuresNames") &&
!utils.hasScriptVar(self, "loadedStructuresLocations"))
{
sendSystemMessage(player, new string_id(STF, "no_available_waypoint"));
return SCRIPT_CONTINUE;
}
obj_id[] structureIds = utils.getObjIdArrayScriptVar(self, "loadedStructuresIds");
string[] structureNames = utils.getStringArrayScriptVar(self, "loadedStructuresNames");
location[] structureLocs = utils.getLocationArrayScriptVar(self, "loadedStructuresLocations");
int idx = sui.getTableLogicalIndex(params);
if(idx < 0)
{
return SCRIPT_CONTINUE;
}
else
{
//create waypoint
obj_id structureWaypoint = createWaypointInDatapad(player, structureLocs[idx]);
setWaypointName(structureWaypoint, structureNames[idx]);
setWaypointActive(structureWaypoint, true);
sendSystemMessage(player, new string_id(STF, "creating_waypoint"));
}
showCityStructuresSuiFromScriptVars(self, player);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// showAdvancementInfo
//------------------------------------------------
void showAdvancementInfo(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
obj_id city_hall = getTopMostContainer(self);
string template = getTemplateName(city_hall);
if(template.indexOf("cityhall_") < 0)
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
int city_rank = city.getCityRank(city_id);
string_id rank_name = new string_id(STF, "rank" + city_rank);
string rank_string = localize(rank_name);
obj_id[] citizens = cityGetCitizenIds(city_id);
int next_pop_req = -1;
if(city_rank < 5)
next_pop_req = dataTableGetInt(city.RANK_TABLE, city_rank, city.RANK_POPULATION);
int cur_pop_req = dataTableGetInt(city.RANK_TABLE, city_rank - 1, city.RANK_POPULATION);
resizeable string[] rankInfo = new string[0];
string_id city_rank_prompt = new string_id(STF, "city_rank_prompt");
string_id city_pop_prompt = new string_id(STF, "city_pop_prompt");
string_id total_citizens = new string_id(STF, "citizens");
rankInfo = utils.addElement(rankInfo, getString(city_rank_prompt) + rank_string + " (" + city_rank + ")");
rankInfo = utils.addElement(rankInfo, getString(city_pop_prompt) + citizens.length + getString(total_citizens));
if(citizens.length < cur_pop_req)
{
string_id pop_req_rank_current_green = new string_id(STF, "pop_req_current_rank");
string_id prev_rank_citizens = new string_id(STF, "citizens");
rankInfo = utils.addElement(rankInfo, "\\#FF0000" + getString(pop_req_rank_current_green) + cur_pop_req + getString(prev_rank_citizens) + "\\");
}
else
{
string_id pop_req_rank_current = new string_id(STF, "pop_req_current_rank");
string_id prev_rank_citizens = new string_id(STF, "citizens");
rankInfo = utils.addElement(rankInfo, getString(pop_req_rank_current) + cur_pop_req + getString(prev_rank_citizens));
}
if(next_pop_req == -1)
{
string_id max_rank_achieved = new string_id(STF, "max_rank_achieved");
rankInfo = utils.addElement(rankInfo, getString(max_rank_achieved));
}
else
{
string_id pop_req_rank_next = new string_id(STF, "pop_req_next_rank");
string_id next_rank_citizens = new string_id(STF, "citizens");
rankInfo = utils.addElement(rankInfo, getString(pop_req_rank_next) + next_pop_req + getString(next_rank_citizens));
}
string_id max_structures = new string_id(STF, "max_structures");
rankInfo = utils.addElement(rankInfo, getString(max_structures) + city.getMaxCivicCount(city_id));
string_id max_decorations = new string_id(STF, "max_decorations");
rankInfo = utils.addElement(rankInfo, getString(max_decorations) + city.getMaxDecorationCount(city_id));
string_id max_terminals = new string_id(STF, "max_terminals");
rankInfo = utils.addElement(rankInfo, getString(max_terminals) + city.getMaxMTCount(city_id));
string_id max_trainers = new string_id(STF, "max_trainers");
rankInfo = utils.addElement(rankInfo, getString(max_trainers) + city.getMaxTrainerCount(city_id));
string_id enabled_structures = new string_id(STF, "rank_enabled_structures");
rankInfo = utils.addElement(rankInfo, "\\#00FF00" + getString(enabled_structures) + "\\");
int i = 7;
if(city_rank >= 1)
{
string_id sm_garden = new string_id(STF, "small_garden");
rankInfo = utils.addElement(rankInfo, getString(sm_garden));
}
if(city_rank >= 2)
{
string_id bank = new string_id(STF, "bank");
rankInfo = utils.addElement(rankInfo, getString(bank));
string_id cantina = new string_id(STF, "cantina");
rankInfo = utils.addElement(rankInfo, getString(cantina));
string_id med_garden = new string_id(STF, "medium_garden");
rankInfo = utils.addElement(rankInfo, getString(med_garden));
string_id garage = new string_id(STF, "garage");
rankInfo = utils.addElement(rankInfo, getString(garage));
}
if(city_rank >= 3)
{
string_id cloning = new string_id(STF, "cloning_facility");
rankInfo = utils.addElement(rankInfo, getString(cloning));
string_id hospital = new string_id(STF, "hospital");
rankInfo = utils.addElement(rankInfo, getString(hospital));
string_id lg_garden = new string_id(STF, "large_garden");
rankInfo = utils.addElement(rankInfo, getString(lg_garden));
}
if(city_rank >= 4)
{
string_id theater = new string_id(STF, "theater");
rankInfo = utils.addElement(rankInfo, getString(theater));
string_id shuttleport = new string_id(STF, "shuttleport");
rankInfo = utils.addElement(rankInfo, getString(shuttleport));
}
sui.listbox(self, player, "@city/city:rank_info_d", sui.OK_CANCEL, "@city/city:rank_info_t", rankInfo, "handleRankInfo", true);
// Tell the player the time to update.
obj_id city_master = getMasterCityObject();
dictionary outparams = new dictionary();
outparams.put("player", player);
outparams.put("city_id", city_id);
messageTo(city_master, "reportUpdateEstimate", outparams, 0.f, false);
}
//------------------------------------------------
// showMaintInfo
//------------------------------------------------
void showMaintInfo(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
obj_id city_hall = getTopMostContainer(self);
string template = getTemplateName(city_hall);
if(template.indexOf("cityhall_") < 0)
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
int city_hall_cost = city.getStructureCost(city_id, city_hall);
int spec_cost = city.cityGetSpecCost(city_id);
int over_cap = 0;
int total_cost = 0;
string[] maintInfo;
int civic_count = city.getCivicCount(city_id);
int max_civic = city.getMaxCivicCount(city_id);
if(civic_count > max_civic)
{
over_cap = civic_count - max_civic;
total_cost += 75000 * over_cap;
maintInfo = new string[9];
}
else
maintInfo = new string[7];
int structures_cost = 0;
int deco_cost = 0;
int other_cost = 0;
obj_id[] structures = cityGetStructureIds(city_id);
for(int i = 0; i < structures.length; i++)
{
if(structures[i] == city_hall)
continue;
if(city.isNormalStructure(city_id, structures[i]))
structures_cost += city.getStructureCost(city_id, structures[i]);
else if(city.isDecoration(city_id, structures[i]))
deco_cost += city.getStructureCost(city_id, structures[i]);
else
other_cost += city.getStructureCost(city_id, structures[i]);
}
total_cost = city_hall_cost + spec_cost + structures_cost + deco_cost + other_cost;
if(city.isCityRegistered(city_id))
city_hall_cost -= 5000;
int i = 0;
string_id total_maint = new string_id(STF, "tot_maint");
string_id credits_suffix = new string_id(STF, "credits");
string_id city_hall_prompt = new string_id(STF, "city_hall");
maintInfo[i++] = "\\#FF0000" + getString(total_maint) + "\\" + total_cost + getString(credits_suffix);
maintInfo[i++] = getString(city_hall_prompt) + city_hall_cost + getString(credits_suffix);
if(civic_count > max_civic)
{
string_id civ_struc_pen = new string_id(STF, "civic_structure_panalty");
maintInfo[i++] = "\\#FF0000" + getString(civ_struc_pen) + "\\ " + (75000 * over_cap);
string_id you_have = new string_id(STF, "you_have");
string_id more_than_cap = new string_id(STF, "more_than_cap");
maintInfo[i++] = " (" + getString(you_have) + over_cap + getString(more_than_cap) + max_civic + ".)";
}
if(city.isCityRegistered(city_id))
{
string_id map_reg_cost = new string_id(STF, "map_reg_cost");
maintInfo[i++] = getString(map_reg_cost);
}
else
{
string_id map_unreg = new string_id(STF, "map_unreg");
maintInfo[i++] = getString(map_unreg);
}
string_id spec_text = new string_id(STF, "specialization");
maintInfo[i++] = getString(spec_text) + spec_cost + getString(credits_suffix);
string_id struc_text = new string_id(STF, "structures");
maintInfo[i++] = getString(struc_text) + structures_cost + getString(credits_suffix);
string_id deco_text = new string_id(STF, "decorations");
maintInfo[i++] = getString(deco_text) + deco_cost + getString(credits_suffix);
string_id tnt_text = new string_id(STF, "train_and_term");
maintInfo[i++] = getString(tnt_text) + other_cost + getString(credits_suffix);
sui.listbox(self, player, "@city/city:maint_info_d", sui.OK_CANCEL, "@city/city:maint_info_t", maintInfo, "handleMaintInfo", true);
// Tell the player the time to update.
obj_id city_master = getMasterCityObject();
dictionary outparams = new dictionary();
outparams.put("player", player);
outparams.put("city_id", city_id);
messageTo(city_master, "reportUpdateEstimate", outparams, 0.f, false);
}
//------------------------------------------------
// changeCityName
//------------------------------------------------
void changeCityName(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
// Query about city name.
sui.inputbox(self, player, "@city/city:city_name_new_d", sui.OK_CANCEL, "@city/city:city_name_new_t", sui.INPUT_NORMAL, null, "handleSetCityName", null);
}
//------------------------------------------------
// handleSetCityName
//------------------------------------------------
messageHandler handleSetCityName()
{
// Store the city name.
obj_id player = sui.getPlayerId(params);
string cityName = sui.getInputBoxText(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
// No zero length or obscene names.
if((cityName == "") || isNameReserved(cityName))
{
// Ask them about the name.
sendSystemMessage(player, SID_OBSCENE);
sui.inputbox(self, player, "@city/city:city_name_new_d", sui.OK_CANCEL, "@city/city:city_name_new_t", sui.INPUT_NORMAL, null, "handleSetCityName", null);
return SCRIPT_CONTINUE;
}
if(cityName.length() > 24)
cityName = cityName.substring(0, 23);
// Only unique names.
if(!city.isUniqueCityName(cityName))
{
// Ask them about the name.
sendSystemMessage(player, SID_NOT_UNIQUE);
sui.inputbox(self, player, "@city/city:city_name_new_d", sui.OK_CANCEL, "@city/city:city_name_new_t", sui.INPUT_NORMAL, null, "handleSetCityName", null);
return SCRIPT_CONTINUE;
}
// Store the new name.
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
if(!cityExists(city_id))
return SCRIPT_CONTINUE;
city.setName(city_id, cityName);
// Notify the citizens.
// Notify the mayor.
obj_id mayor = cityGetLeader(city_id);
sendSystemMessage(mayor, SID_NAME_CHANGED);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// modifyMilita
//------------------------------------------------
void modifyMilitia(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
// Check to see if we can do this.
if(!hasCommand(player, "manage_militia"))
{
sendSystemMessage(player, SID_CANT_MILITIA);
return;
}
// Display a list of current militia members.
obj_id[] citizens = cityGetCitizenIds(city_id);
resizeable string[] militiaMembers = new string[0];
militiaMembers = utils.addElement(militiaMembers, "Add Militia Member");
for(int i = 0; i < citizens.length; i++)
{
if(city.hasMilitiaFlag(citizens[i], city_id))
{
string name = cityGetCitizenName(city_id, citizens[i]);
militiaMembers = utils.addElement(militiaMembers, name);
}
}
sui.listbox(self, player, "@city/city:militia_d", sui.OK_CANCEL, "@city/city:militia_t", militiaMembers, "handleRemoveMilitia", true);
}
//------------------------------------------------
// handleRemoveMilitia
//------------------------------------------------
messageHandler handleRemoveMilitia()
{
int idx = sui.getListboxSelectedRow(params);
if(idx < 0)
idx = 0;
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
if(!cityExists(city_id))
return SCRIPT_CONTINUE;
if(idx == 0)
{
// Add a new militia member.
sui.inputbox(self, player, "@city/city:militia_new_d", sui.OK_CANCEL, "@city/city:militia_new_t", sui.INPUT_NORMAL, null, "handleAddMilitia", null);
}
else
{
// Rebuild the militia list.
int j = 0;
string removeName = null;
obj_id[] citizens = cityGetCitizenIds(city_id);
resizeable string[] militiaMembers = new string[0];
militiaMembers = utils.addElement(militiaMembers, "Add Militia Member");
for(int i = 0; i < citizens.length; i++)
{
if(city.hasMilitiaFlag(citizens[i], city_id))
{
j++;
string name = cityGetCitizenName(city_id, citizens[i]);
militiaMembers = utils.addElement(militiaMembers, name);
if(j == idx)
{
utils.setScriptVar(self, "removal.temp", citizens[i]);
removeName = name;
break;
}
}
}
if(removeName == null)
return SCRIPT_CONTINUE;
// Remove someone from the militia.
string_id rem_militia_prefix = new string_id(STF, "remove_militia_prefix");
string_id rem_militia_suffix = new string_id(STF, "remove_militia_suffix");
string prompt = getString(rem_militia_prefix) + removeName + getString(rem_militia_suffix);
sui.msgbox(self, player, prompt, sui.YES_NO, "@city/city:remove_militia_confirm", sui.MSG_QUESTION, "handleRemoveMilitiaConfirmed");
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleAddMilitia
//------------------------------------------------
messageHandler handleAddMilitia()
{
obj_id player = sui.getPlayerId(params);
string playerName = sui.getInputBoxText(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
if(!cityExists(city_id))
return SCRIPT_CONTINUE;
// See if that person is nearby.
string s2 = playerName.toLowerCase();
obj_id[] players = getPlayerCreaturesInRange(getLocation(self), 10);
for(int i = 0; i < players.length; i++)
{
// Convert the city stored player name to a lower case first name.
string s1 = getName(players[i]).toLowerCase();
int indexOf = s1.indexOf(' ');
if(indexOf > -1)
s1 = s1.substring(0, indexOf);
if(s1.compareTo(s2) == 0)
{
// We found him. Make sure he's a member of the city.
if(city.isCitizenOfCity(players[i], city_id))
{
city.addMilitia(city_id, players[i]);
sendSystemMessage(player, SID_ADDED_MILITIA);
sendSystemMessage(players[i], SID_ADDED_MILITIA_TARGET);
}
else
sendSystemMessage(player, SID_NOT_CITIZEN);
return SCRIPT_CONTINUE;
}
}
// We couldn't find them.
sendSystemMessage(player, SID_CANT_FIND_PLAYER);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleRemoveMilitiaConfirmed
//------------------------------------------------
messageHandler handleRemoveMilitiaConfirmed()
{
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
if(!cityExists(city_id))
return SCRIPT_CONTINUE;
obj_id removeTarget = utils.getObjIdScriptVar(self, "removal.temp");
if(city.isCitizenOfCity(removeTarget, city_id))
{
city.removeMilitia(city_id, removeTarget);
sendSystemMessage(player, SID_REMOVED_MILITIA);
sendSystemMessage(removeTarget, SID_REMOVED_MILITIA_TARGET);
}
else
sendSystemMessage(player, SID_NOT_CITIZEN);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// showTreasuryInfo
//------------------------------------------------
void showTreasuryInfo(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
obj_id structure = getTopMostContainer(self);
string template = getTemplateName(structure);
if(template.indexOf("cityhall_") < 0)
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
string[] treasury_info = new string[6];
treasury_info[0] = "Balance: " + getBankBalance(structure);
obj_id city = cityGetCityHall(city_id);
string city_name = cityGetName(city_id);
string garage = city_name + ".garageFee";
if(!hasObjVar(city, garage))
setObjVar(city, garage, 0);
int income_tax = cityGetIncomeTax(city_id);
int property_tax = cityGetPropertyTax(city_id);
int sales_tax = cityGetSalesTax(city_id);
int travel_fee = cityGetTravelCost(city_id);
int garage_fee = getIntObjVar(city, garage);
treasury_info[1] = "@city/city:income_tax" + " -- " + income_tax + " cr";
treasury_info[2] = "@city/city:property_tax" + " -- " + property_tax + "%";
treasury_info[3] = "@city/city:sales_tax" + " -- " + sales_tax + "%";
treasury_info[4] = "@city/city:travel_tax" + " -- " + travel_fee + " cr";
treasury_info[5] = "@city/city:garage_tax" + " -- " + garage_fee + "%";
sui.listbox(self, player, "@city/city:treasury_balance_d", sui.OK_CANCEL, "@city/city:treasury_balance_t", treasury_info, "handleTreasuryInfoSelect", true);
}
//------------------------------------------------
// makeTreasuryDeposit
//------------------------------------------------
void makeTreasuryDeposit(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
obj_id structure = getTopMostContainer(self);
string template = getTemplateName(structure);
if(template.indexOf("cityhall_") < 0)
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
int total = getTotalMoney(player);
if(total > 0)
{
int maint_pool = getBankBalance(structure);
int pid = sui.transfer(self, player, "@city/city:treasury_deposit_d", "@city/city:treasury_deposit", "@city/city:total_funds", total, "@city/city:treasury", 0, "depositTreasury");
}
else
{
// No money to deposit.
sendSystemMessage(player, SID_NO_MONEY);
}
}
//------------------------------------------------
// depositTreasury
//------------------------------------------------
messageHandler depositTreasury()
{
obj_id structure = getTopMostContainer(self);
obj_id player = sui.getPlayerId(params);
int bp = sui.getIntButtonPressed(params);
if(bp == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
int total = getTotalMoney(player);
int end_bal = sui.getTransferInputFrom(params);
int amt = total - end_bal;
if(amt < 0)
{
sendSystemMessage(player, new string_id(STF, "positive_deposit")); // You must select a positive amount to transfer to the treasury.
}
else if(amt == 0)
{
return SCRIPT_CONTINUE;
}
else
{
money.requestPayment(player, structure, amt, "handlePayment", null);
//send a Mail to the Mayor of the City - from the City Hall (Treasury)
int city_id = findCityByCityHall(structure);
obj_id mayor = cityGetLeader(city_id);
string citizen_name = cityGetCitizenName(city_id, player);
prose_package bodypp = prose.getPackage(TREASURY_DEPOSIT_BODY, citizen_name, amt);
//from structure_maintenance_empty_subject that Michael Horn received while offline
//utils.sendMail(strSubject, pp, strName , "@player_structure:management");
//trying it his way - Title/Body/StringTo/StringFrom
string strName = getPlayerName(mayor);
utils.sendMail(TREASURY_DEPOSIT_SUBJECT, bodypp, strName, "City Hall");
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// makeTreasuryWithdraw
//------------------------------------------------
void makeTreasuryWithdraw(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
sui.inputbox(self, player, "@city/city:withdraw_reason_d", sui.OK_CANCEL, "@city/city:withdraw_reason_t", sui.INPUT_NORMAL, null, "handleWithdrawReason", null);
}
//------------------------------------------------
// handleWithdrawReason
//------------------------------------------------
messageHandler handleWithdrawReason()
{
// Store the city name.
obj_id player = sui.getPlayerId(params);
string withdraw_reason = sui.getInputBoxText(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
utils.setScriptVar(self, "withdrawReason", withdraw_reason);
obj_id structure = getTopMostContainer(self);
int total = getBankBalance(structure);
if(total > 0)
{
int player_cash = getCashBalance(player);
int pid = sui.transfer(self, player, "@city/city:treasury_withdraw_prompt", "@city/city:treasury_withdraw", "@city/city:treasury", total, "@city/city:funds", 0, "withdrawTreasury");
}
else
{
// No money to deposit.
sendSystemMessage(player, SID_NO_MONEY);
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// withdrawTreasury
//------------------------------------------------
messageHandler withdrawTreasury()
{
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
obj_id player = sui.getPlayerId(params);
int bp = sui.getIntButtonPressed(params);
if(bp == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
int total = getBankBalance(structure);
int end_bal = sui.getTransferInputFrom(params);
if(hasObjVar(self, "lastWithdrawTime"))
{
int lastWithdrawTime = getIntObjVar(self, "lastWithdrawTime");
if(getGameTime() - lastWithdrawTime < 86400)
{
sendSystemMessage(player, SID_WITHDRAW_DAILY);
return SCRIPT_CONTINUE;
}
}
int amt = total - end_bal;
if(amt < 0)
{
sendSystemMessage(player, new string_id(STF, "withdraw_treasury")); // You must select a positive amount to withdraw from the treasury.
}
else if(amt == 0)
return SCRIPT_CONTINUE;
else
{
if((amt < 5000) || (amt > 150000))
{
sendSystemMessage(player, SID_WITHDRAW_LIMITS);
return SCRIPT_CONTINUE;
}
dictionary payparams = new dictionary();
payparams.put("city_id", city_id);
payparams.put("amt", amt);
payparams.put("player", player);
transferBankCreditsTo(structure, player, amt, "handleWithdrawSuccess", "handleWithdrawFail", payparams);
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleWithdrawSuccess
//------------------------------------------------
messageHandler handleWithdrawSuccess()
{
int city_id = params.getInt("city_id");
int amt = params.getInt("amt");
obj_id player = params.getObjId("player");
setObjVar(self, "lastWithdrawTime", getGameTime());
prose_package ppWithdraw = prose.getPackage(SID_YOU_WITHDRAW_FROM_TREASURY);
prose.setDI(ppWithdraw, amt);
sendSystemMessageProse(player, ppWithdraw);
CustomerServiceLog("player_city", "Mayor withdrew from treasury. City: " + city_id + " Amt: " + amt + " Player: " + player);
// Notify the citizenship.
obj_id mayor = cityGetLeader(city_id);
string mayor_name = cityGetCitizenName(city_id, mayor);
string citizen_name = "";
string withdraw_reason = utils.getStringScriptVar(self, "withdrawReason");
obj_id[] citizens = cityGetCitizenIds(city_id);
for(int i = 0; i < citizens.length; i++)
{
citizen_name = cityGetCitizenName(city_id, citizens[i]);
prose_package bodypp = prose.getPackage(TREASURY_WITHDRAW_BODY, withdraw_reason, mayor_name, amt);
utils.sendMail(TREASURY_WITHDRAW_SUBJECT, bodypp, citizen_name, "City Hall");
}
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleWithdrawFail
//------------------------------------------------
messageHandler handleWithdrawFail()
{
// FIXME: Localize for next publish.
// Non-localized due to time constraints for upcoming publish.
obj_id player = params.getObjId("player");
sendSystemMessage(player, new string_id(STF, "withdraw_treasury_error")); // Unable to complete withdraw. Please try again.
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// adjustTaxes
//------------------------------------------------
void adjustTaxes(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
if(city.getCityRank(city_id) < 2)
{
sendSystemMessage(player, SID_NO_RANK_TAXES);
return;
}
obj_id city = cityGetCityHall(city_id);
string city_name = cityGetName(city_id);
string garage = city_name + ".garageFee";
if(!hasObjVar(city, garage))
setObjVar(city, garage, 0);
int income_tax = cityGetIncomeTax(city_id);
int property_tax = cityGetPropertyTax(city_id);
int sales_tax = cityGetSalesTax(city_id);
int travel_fee = cityGetTravelCost(city_id);
int garage_fee = getIntObjVar(city, garage);
string[] tax_info = new string[5];
tax_info[0] = "@city/city:income_tax" + " -- " + income_tax + " cr";
tax_info[1] = "@city/city:property_tax" + " -- " + property_tax + "%";
tax_info[2] = "@city/city:sales_tax" + " -- " + sales_tax + "%";
tax_info[3] = "@city/city:travel_tax" + " -- " + travel_fee + " cr";
tax_info[4] = "@city/city:garage_tax" + " -- " + garage_fee + " %";
sui.listbox(self, player, "@city/city:adjust_taxes_d", sui.OK_CANCEL, "@city/city:adjust_taxes_t", tax_info, "handleTaxInfoSelect", true);
}
//------------------------------------------------
// handleTaxInfoSelect
//------------------------------------------------
messageHandler handleTaxInfoSelect()
{
int idx = sui.getListboxSelectedRow(params);
if(idx < 0)
idx = 0;
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
if(!hasCommand(player, "manage_taxes"))
{
sendSystemMessage(player, SID_CANT_TAX);
return SCRIPT_CONTINUE;
}
utils.setScriptVar(self, "tax.set", idx);
sui.inputbox(self, player, "@city/city:set_tax_d_" + TAX_STRING[idx], sui.OK_CANCEL, "@city/city:set_tax_t_" + TAX_STRING[idx], sui.INPUT_NORMAL, null, "handleSetTax", null);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleSetTax
//------------------------------------------------
messageHandler handleSetTax()
{
// Store the city name.
obj_id player = sui.getPlayerId(params);
string tax_string = sui.getInputBoxText(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
if(!cityExists(city_id))
return SCRIPT_CONTINUE;
int set_tax = utils.getIntScriptVar(self, "tax.set");
int desired_tax = 0;
try
{
desired_tax = Integer.valueOf(tax_string).intValue();
}
catch(NumberFormatException err)
{
sendSystemMessage(player, SID_TAX_OUT_OF_RANGE);
return SCRIPT_CONTINUE;
}
if(desired_tax < TAX_MIN[set_tax] || desired_tax > TAX_MAX[set_tax])
{
sendSystemMessage(player, SID_TAX_OUT_OF_RANGE);
return SCRIPT_CONTINUE;
}
obj_id mayor = cityGetLeader(city_id);
string mayor_name = cityGetCitizenName(city_id, mayor);
string city_name = cityGetName(city_id);
obj_id[] citizens = cityGetCitizenIds(city_id);
prose_package pp = null;
switch (set_tax)
{
case 0:
// Income tax.
city.setIncomeTax(city_id, desired_tax);
pp = prose.getPackage(SID_INCOME_TAX, desired_tax);
// Notify the public.
for(int i = 0; i < citizens.length; i++)
{
string citizen_name = cityGetCitizenName(city_id, citizens[i]);
prose_package bodypp = prose.getPackage(TAX_INCOME_BODY, city_name, desired_tax);
utils.sendMail(TAX_INCOME_SUBJECT, bodypp, citizen_name, "City Hall");
}
break;
case 1:
// Property tax.
city.setPropertyTax(city_id, desired_tax);
pp = prose.getPackage(SID_PROPERTY_TAX, desired_tax);
// Notify the public.
for(int i = 0; i < citizens.length; i++)
{
string citizen_name = cityGetCitizenName(city_id, citizens[i]);
prose_package bodypp = prose.getPackage(TAX_PROPERTY_BODY, city_name, desired_tax);
utils.sendMail(TAX_PROPERTY_SUBJECT, bodypp, citizen_name, "City Hall");
}
break;
case 2:
// Sales tax.
city.setSalesTax(city_id, desired_tax);
pp = prose.getPackage(SID_SALES_TAX, desired_tax);
// Notify the public.
for(int i = 0; i < citizens.length; i++)
{
string citizen_name = cityGetCitizenName(city_id, citizens[i]);
prose_package bodypp = prose.getPackage(TAX_SALES_BODY, city_name, desired_tax);
utils.sendMail(TAX_SALES_SUBJECT, bodypp, citizen_name, "City Hall");
}
break;
case 3:
location cityTravelLoc = cityGetTravelLocation(city_id);
if((cityTravelLoc == null) || ((cityTravelLoc.x == 0) && (cityTravelLoc.y == 0) && (cityTravelLoc.z == 0)))
{
sendSystemMessage(player, SID_NO_SHUTTLEPORT);
return SCRIPT_CONTINUE;
}
// Travel fee.
city.setTravelFee(city_id, desired_tax);
pp = prose.getPackage(SID_TRAVEL_FEE, desired_tax);
// Notify the public.
for(int i = 0; i < citizens.length; i++)
{
string citizen_name = cityGetCitizenName(city_id, citizens[i]);
prose_package bodypp = prose.getPackage(TAX_TRAVEL_BODY, city_name, desired_tax);
utils.sendMail(TAX_TRAVEL_SUBJECT, bodypp, citizen_name, "City Hall");
}
break;
case 4:
string garageFee = city_name + ".garageFee";
setObjVar(structure, garageFee, desired_tax);
pp = prose.getPackage(SID_GARAGE_TAX, desired_tax);
for(int i = 0; i < citizens.length; i++)
{
string citizen_name = cityGetCitizenName(city_id, citizens[i]);
prose_package bodypp = prose.getPackage(GARAGE_FEE_BODY, city_name, desired_tax);
utils.sendMail(GARAGE_FEE_SUBJECT, bodypp, citizen_name, "City Hall");
}
break;
}
sendSystemMessageProse(player, pp);
// Notify the citizens that the tax rate has changed.
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleRegisterCity
//------------------------------------------------
messageHandler handleRegisterCity()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
if(!cityExists(city_id))
return SCRIPT_CONTINUE;
if(!hasCommand(player, "city_map"))
{
sendSystemMessage(player, SID_CANT_REGISTER);
return SCRIPT_CONTINUE;
}
if(city.getCityRank(city_id) < 3)
{
sendSystemMessage(player, SID_CANT_REGISTER_RANK);
return SCRIPT_CONTINUE;
}
city.registerCity(city_id);
sendSystemMessage(player, SID_REGISTERED);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleUnregisterCity
//------------------------------------------------
messageHandler handleUnregisterCity()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
if(!cityExists(city_id))
return SCRIPT_CONTINUE;
city.unregisterCity(city_id);
sendSystemMessage(player, SID_UNREGISTERED);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// changeSpecialization
//------------------------------------------------
void changeSpecialization(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
int city_rank = city.getCityRank(city_id);
if(city_rank < 3)
{
sendSystemMessage(player, SID_NO_RANK_SPEC);
return;
}
string[] listSpecs = dataTableGetStringColumn(CITY_SPECS, "SPECIALIZATION");
int[] specCosts = dataTableGetIntColumn(CITY_SPECS, "COST");
resizeable string[] knownSpecs = new string[0];
for(int i = 0; i < listSpecs.length; i++)
{
if((i == 0) || hasCommand(player, listSpecs[i]))
utils.addElement(knownSpecs, /*"@city/city:"+listSpecs[i] */ localize(new string_id(STF, listSpecs[i])) + " (Cost: " + specCosts[i] + ")");
}
if(knownSpecs.length == 0)
{
// Player doesn't know any specs.
sendSystemMessage(player, SID_NO_SPECS);
return;
}
sui.listbox(self, player, "@city/city:city_specs_d", sui.OK_CANCEL, "@city/city:city_specs_t", knownSpecs, "handleCitySpecInfo", true);
}
//------------------------------------------------
// handleCitySpecInfo
//------------------------------------------------
messageHandler handleCitySpecInfo()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
int idx = sui.getListboxSelectedRow(params);
if(idx < 0)
idx = 0;
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
string[] listSpecs = dataTableGetStringColumn(CITY_SPECS, "SPECIALIZATION");
resizeable string[] knownSpecs = new string[0];
for(int i = 0; i < listSpecs.length; i++)
{
if((i == 0) || hasCommand(player, listSpecs[i]))
utils.addElement(knownSpecs, listSpecs[i]);
}
utils.setScriptVar(self, "spec", idx);
sui.msgbox(self, player, "@city/city:" + knownSpecs[idx] + "_d", sui.YES_NO, "@city/city:" + knownSpecs[idx], sui.MSG_QUESTION, "handleSetCitySpec");
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// handleSetCitySpec
//------------------------------------------------
messageHandler handleSetCitySpec()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
int spec = utils.getIntScriptVar(self, "spec");
string[] listSpecs = dataTableGetStringColumn(CITY_SPECS, "SPECIALIZATION");
resizeable string[] knownSpecs = new string[0];
for(int i = 0; i < listSpecs.length; i++)
{
if((i == 0) || hasCommand(player, listSpecs[i]))
utils.addElement(knownSpecs, listSpecs[i]);
}
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
if(!cityExists(city_id))
return SCRIPT_CONTINUE;
// Check our last spec change timestamp.
if(spec != 0)
{
if(hasObjVar(structure, "spec_stamp"))
{
int curt = getGameTime();
int stmp = getIntObjVar(structure, "spec_stamp");
if(curt - stmp < (7 * 24 * 60 * 60)) // 1 week
{
prose_package pp = prose.getPackage(SID_SPEC_TIME, player_structure.assembleTimeRemaining(player_structure.convertSecondsTime((7 * 24 * 60 * 60) - (curt - stmp))));
sendSystemMessageProse(player, pp);
return SCRIPT_CONTINUE;
}
}
}
setObjVar(structure, "spec_stamp", getGameTime());
city.setSpecialization(city_id, knownSpecs[spec]);
prose_package pp = prose.getPackage(SID_SPEC_SET, "@city/city:" + knownSpecs[spec]);
sendSystemMessageProse(player, pp);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// changeZoning
//------------------------------------------------
void changeZoning(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
if(city.isCityZoned(city_id))
{
// Remove zoning.
city.setCityZoned(city_id, false);
sendSystemMessage(player, SID_ZONING_DISABLED);
}
else
{
if(!hasSkill(player, "social_politician_novice"))
sendSystemMessage(player, SID_ZONING_SKILL);
else
sui.msgbox(self, player, "@city/city:zoning_d", sui.YES_NO, "@city/city:zoning_t", sui.MSG_QUESTION, "handleSetCityZoning");
}
}
//------------------------------------------------
// handleSetCityZoning
//------------------------------------------------
messageHandler handleSetCityZoning()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
obj_id structure = getTopMostContainer(self);
int city_id = findCityByCityHall(structure);
if(!cityExists(city_id))
return SCRIPT_CONTINUE;
city.setCityZoned(city_id, true);
sendSystemMessage(player, SID_ZONING_ENABLED);
return SCRIPT_CONTINUE;
}
void sendNewMayorMail(int city_id, obj_id mayor)
{
string nmayor_name = cityGetCitizenName(city_id, mayor);
obj_id[] citizens = cityGetCitizenIds(city_id);
string city_name = cityGetName(city_id);
for(int i = 0; i < citizens.length; i++)
{
city.setCitizenAllegiance(city_id, citizens[i], mayor);
string citizen_name = cityGetCitizenName(city_id, citizens[i]);
prose_package bodypp = prose.getPackage(PUBLIC_ELECTION_BODY, city_name, nmayor_name);
utils.sendMail(PUBLIC_ELECTION_SUBJECT, bodypp, citizen_name, "City Hall");
}
return;
}
boolean destroyCitySkillTrainers(obj_id mayor, int city_id)
{
if(!isValidId(mayor) || !exists(mayor))
return false;
if(!cityExists(city_id))
return false;
if(!citySkillTrainersExist(city_id))
return false;
obj_id[] structures = cityGetStructureIds(city_id);
for(int i = 0; i < structures.length; i++)
{
if(structures[i].isLoaded())
{
if(!city.isNormalStructure(city_id, structures[i]))
{
if(hasScript(structures[i], PROFESSION_TRAINER_SCRIPT))
{
CustomerServiceLog("player_city", "Player: " + mayor + " - " + getName(mayor) + " deleted " + structures[i] + " - " + getName(structures[i]) + " at City: " + city_id + " - " + cityGetName(city_id));
destroyObject(structures[i]);
}
}
}
}
return true;
}
boolean citySkillTrainersExist(int city_id)
{
if(!cityExists(city_id))
return false;
obj_id[] structures = cityGetStructureIds(city_id);
for(int i = 0; i < structures.length; i++)
{
if(structures[i].isLoaded())
{
if(!city.isNormalStructure(city_id, structures[i]))
{
return true;
}
}
}
return false;
}
messageHandler handleCityVisitorMessage()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
obj_id player = sui.getPlayerId(params);
int bp = sui.getIntButtonPressed(params);
if(bp == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
string message = sui.getInputBoxText(params);
if(message == null)
{
sendSystemMessage(self, new string_id(STF, "not_valid_message")); // That is not a valid name.
return SCRIPT_CONTINUE;
}
obj_id city_hall = getTopMostContainer(self);
//If there's no message - remove the objvar from the City Hall
if(message.length() == 0)
{
//sendSystemMessageTestingOnly(player, "message removed");
removeObjVar(city_hall, "city_visitor_message");
return SCRIPT_CONTINUE;
}
//let's do a range check - must be within 5m of the City Terminal.
if (utils.outOfRange(self, player, 5.0f, true))
{
sendSystemMessage(self, new string_id(STF, "out_of_message_range"));
return SCRIPT_CONTINUE;
}
setObjVar(city_hall, "city_visitor_message", message);
return SCRIPT_CONTINUE;
}
messageHandler handleCityCitizenMessage()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
obj_id player = sui.getPlayerId(params);
int bp = sui.getIntButtonPressed(params);
if(bp == sui.BP_CANCEL)
return SCRIPT_CONTINUE;
string message = sui.getInputBoxText(params);
if(message == null)
{
sendSystemMessage(self, new string_id(STF, "not_valid_message")); // That is not a valid name.
return SCRIPT_CONTINUE;
}
obj_id city_hall = getTopMostContainer(self);
//If there's no message - remove the objvar from the City Hall
if(message.length() == 0)
{
//sendSystemMessageTestingOnly(player, "message removed");
removeObjVar(city_hall, "city_visitor_message");
return SCRIPT_CONTINUE;
}
//let's do a range check - must be within 5m of the City Terminal.
if (utils.outOfRange(self, player, 5.0f, true))
{
sendSystemMessage(self, new string_id(STF, "out_of_message_range"));
return SCRIPT_CONTINUE;
}
setObjVar(city_hall, "city_citizen_message", message);
return SCRIPT_CONTINUE;
}
messageHandler getStructureCitizenInformationReturn()
{
int city_id = getCityAtLocation(getLocation(self), 0);
if(params == null || params.isEmpty())
{
CustomerServiceLog("player_city", "Citizen List: City("+ city_id +")"+ cityGetName(city_id) +
"Return Data for Citizenship List was 'null' or 'empty'.");
return SCRIPT_CONTINUE;
}
obj_id citizen = params.getObjId("citizen_id");
obj_id house = params.getObjId("house_id");
string houseName = params.getString("house_name");
location houseLoc = params.getLocation("house_loc");
CustomerServiceLog("player_city", "Citizen List: City("+ city_id +")"+ cityGetName(city_id) +
" Saving Return Data on City Terminal: Citizen("+ citizen +
"), House("+ house +") House Name("+ houseName +") House Loc("+ houseLoc +")");
utils.setScriptVar(self, city.CITIZEN_LIST_DATA+"."+citizen+".house_id", house);
utils.setScriptVar(self, city.CITIZEN_LIST_DATA+"."+citizen+".house_name", houseName);
utils.setScriptVar(self, city.CITIZEN_LIST_DATA+"."+citizen+".house_loc", houseLoc);
return SCRIPT_CONTINUE;
}
//------------------------------------------------
// Mayor Safe House System
//------------------------------------------------
void showSafeHouseCitizenList(obj_id player, obj_id self, int city_id)
{
if(!isIdValid(player) || !isIdValid(self))
{
sendSystemMessage(player, new string_id(STF, "city_network_error"));
return;
}
if(!cityExists(city_id))
return;
obj_id[] citizens = cityGetCitizenIds(city_id);
if(citizens == null || citizens.length <= 0)
{
sendSystemMessage(player, new string_id(STF, "no_city_citizen_data"));
return;
}
//create a display table - show: | Citizen Name | Last Login | Safe Status |
int columnCount = 3;
string[][] displayData = new string[citizens.length][columnCount];
for(int k = 0; k < citizens.length; k++)
{
for(int l = 0; l < columnCount; l++)
{
//Name of Player
string ownerName = cityGetCitizenName(city_id, citizens[k]);
switch(l)
{
case 0:
//Citizen Name
if(ownerName == null || ownerName.length() <= 0)
ownerName = "@city/city:unknown_owner_data"; //"Unknown Owner Data";
if(!isGod(player))
displayData[k][l] = ownerName;
else
displayData[k][l] = ownerName + " : " + citizens[k];
break;
case 1:
//last login - current location
string onlineOfflineStatus = utils.getOnlineOfflineStatus(citizens[k]);
displayData[k][l] = onlineOfflineStatus;
break;
case 2:
//Safe Status Column
if(city.hasMayorProtectionFlag(citizens[k], city_id))
displayData[k][l] = "Protected Citizen";
else
displayData[k][l] = "";
break;
default:
break;
}
}
}
//set scriptvars on the player for indexes
utils.setScriptVar(player, "safeHouseCitizenList", citizens);
utils.setScriptVar(player, "city_id", city_id);
string[] colTitles = {
"@city/city:column_citizen_name",
"@city/city:column_location_or_last_login",
"@city/city:column_safe_house_status"
};
string[] colTypes = {
"text",
"text",
"text"
};
//Get Safe House Level
int currentSafeCount = city.getCurrentSafeHouseCount(city_id);
int maxSafeCount = city.getMaxSafeHouseCount(city_id);
/*
prose_package pp = new prose_package();
pp = prose.setDI(pp, maxSafeCount);
pp = prose.setDF(pp, (float)currentSafeCount);
pp = prose.setStringId(pp, SID_SAFE_HOUSE_PROMPT);
//string stringPrompt = getString(pp);
*/
string prompt = "Mayor Safe House System: \nThis system allows for the Mayor of a city to protect a Citizen's Structures by flagging them as a 'Safe House'. This should only be used in extreme circumstances where a Citizen can not log in during a 90 day time period.\n\n" + "Maximum Number of Safe Houses available: " + maxSafeCount + "\nCurrent Number of Safe Houses Used: " + currentSafeCount;
sui.tableRowMajor(self, player, sui.OK_CANCEL, "@city/city:safe_house_list_t", "handleSafeHouseCitizenSelect", prompt, colTitles, colTypes, displayData, false);
}
messageHandler handleSafeHouseCitizenSelect()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
int idx = sui.getTableLogicalIndex(params);
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
{
utils.removeScriptVar(player, "safeHouseCitizenList");
utils.removeScriptVar(player, "city_id");
return SCRIPT_CONTINUE;
}
if(!utils.hasScriptVar(player, "safeHouseCitizenList") && !utils.hasScriptVar(player, "city_id"))
return SCRIPT_CONTINUE;
obj_id[] citizenList = utils.getObjIdArrayScriptVar(player, "safeHouseCitizenList");
int city_id = utils.getIntScriptVar(player, "city_id");
dictionary dict = new dictionary();
dict.put("player", player);
dict.put("city_id", city_id);
if(idx < 0)
return SCRIPT_CONTINUE;
else
{
//Mayor can not protect himself -
obj_id mayor = cityGetLeader(city_id);
if(citizenList[idx] == mayor)
{
//just in case a Mayor has himself protected already...remove his/her protection.
//they can not protect themselves!
if(city.hasMayorProtectionFlag(mayor, city_id))
city.removeSafeHouseCitizen(city_id, mayor);
sendSystemMessage(player, new string_id(STF, "can_not_protect_self"));
messageTo(self, "updateSafeHouseCitizenList", dict, 1.0f, false);
return SCRIPT_CONTINUE;
}
if(city.hasMayorProtectionFlag(citizenList[idx], city_id))
{
//remove the Safe Citizen Flag
city.removeSafeHouseCitizen(city_id, citizenList[idx]);
//Mail the Mayor
prose_package bodypp = prose.getPackage(SID_REMOVE_SAFE_HOUSE_CITIZEN_BODY);
prose.setTT(bodypp, cityGetCitizenName(city_id, citizenList[idx]));
utils.sendMail(SID_REMOVE_SAFE_HOUSE_CITIZEN_SUBJECT, bodypp, player, "City Hall");
}
else
{
int currentSafeCount = city.getCurrentSafeHouseCount(city_id);
int maxSafeCount = city.getMaxSafeHouseCount(city_id);
if(currentSafeCount > maxSafeCount)
{
//you are above your max!
sendSystemMessage(player, new string_id(STF, "safe_house_count_overload"));
messageTo(self, "updateSafeHouseCitizenList", dict, 1.0f, false);
return SCRIPT_CONTINUE;
}
if(currentSafeCount == maxSafeCount)
{
//you have reached your max!
sendSystemMessage(player, new string_id(STF, "safe_house_count_full"));
messageTo(self, "updateSafeHouseCitizenList", dict, 1.0f, false);
return SCRIPT_CONTINUE;
}
//add the Safe Citizen Flag
city.addSafeHouseCitizen(city_id, citizenList[idx]);
//Mail the Mayor
prose_package bodypp = prose.getPackage(SID_ADD_SAFE_HOUSE_CITIZEN_BODY);
prose.setTT(bodypp, cityGetCitizenName(city_id, citizenList[idx]));
utils.sendMail(SID_ADD_SAFE_HOUSE_CITIZEN_SUBJECT, bodypp, player, "City Hall");
}
}
messageTo(self, "updateSafeHouseCitizenList", dict, 1.0f, false);
sendSystemMessage(player, new string_id(STF, "updating_citizen_protection"));
return SCRIPT_CONTINUE;
}
messageHandler updateSafeHouseCitizenList()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
int city_id = params.getInt("city_id");
obj_id player = params.getObjId("player");
if(!isIdValid(player) || !isIdValid(self) || !cityExists(city_id))
return SCRIPT_CONTINUE;
showSafeHouseCitizenList(player, self, city_id);
return SCRIPT_CONTINUE;
}