Cargo Overhaul (#3221)

Changes cargo to be based on credits instead of items

The following is still ToDo:

 Test SQL Loading + Add flyway migration
 Add changelog
 Restore the PDA Application
This commit is contained in:
Werner
2017-09-14 21:32:06 +03:00
committed by Erki
parent 3803b29661
commit ff853542b1
25 changed files with 2082 additions and 579 deletions
@@ -1,7 +1,7 @@
/datum/modular_computer_app_presets
var/name = "default_preset"
var/display_name = "default preset"
var/description = "Description of the preset"
var/description = "Description of the preset."
var/available = 0
/datum/modular_computer_app_presets/proc/return_install_programs()
return list()
@@ -9,7 +9,7 @@
/datum/modular_computer_app_presets/all
name = "all"
display_name = "All Programs"
description = "Contains all Progams"
description = "Contains all programs."
available = 0
/datum/modular_computer_app_presets/all/return_install_programs()
var/list/_prg_list = list()
@@ -21,7 +21,7 @@
/datum/modular_computer_app_presets/engineering
name = "engineering"
display_name = "Engineering"
description = "Contains the most common engineering Programs"
description = "Contains the most common engineering programs."
available = 1
/datum/modular_computer_app_presets/engineering/return_install_programs()
var/list/_prg_list = list(
@@ -39,7 +39,7 @@
/datum/modular_computer_app_presets/medical
name = "medical"
display_name = "Medical"
description = "Contains the most common medical Programs"
description = "Contains the most common medical programs."
available = 1
/datum/modular_computer_app_presets/medical/return_install_programs()
var/list/_prg_list = list(
@@ -52,7 +52,7 @@
/datum/modular_computer_app_presets/research
name = "research"
display_name = "Research"
description = "Contains the most common research Programs"
description = "Contains the most common research programs."
available = 1
/datum/modular_computer_app_presets/research/return_install_programs()
var/list/_prg_list = list(
@@ -67,7 +67,7 @@
/datum/modular_computer_app_presets/command
name = "command"
display_name = "Command"
description = "Contains the most common command Programs"
description = "Contains the most common command programs."
available = 1
/datum/modular_computer_app_presets/command/return_install_programs()
var/list/_prg_list = list(
@@ -81,7 +81,7 @@
/datum/modular_computer_app_presets/security
name = "security"
display_name = "Security"
description = "Contains the most common security Programs"
description = "Contains the most common security programs."
available = 1
/datum/modular_computer_app_presets/security/return_install_programs()
var/list/_prg_list = list(
@@ -96,21 +96,36 @@
/datum/modular_computer_app_presets/civilian
name = "civilian"
display_name = "Civilian"
description = "Contains the most common civilian Programs"
description = "Contains the most common civilian programs."
available = 1
/datum/modular_computer_app_presets/civilian/return_install_programs()
var/list/_prg_list = list(
new/datum/computer_file/program/filemanager(),
new/datum/computer_file/program/chatclient(),
new/datum/computer_file/program/game/arcade(),
new/datum/computer_file/program/game/sudoku()
new/datum/computer_file/program/game/sudoku(),
new/datum/computer_file/program/civilian/cargoorder()
)
return _prg_list
/datum/modular_computer_app_presets/supply
name = "supply"
display_name = "Supply"
description = "Contains the most common cargo programs."
available = 1
/datum/modular_computer_app_presets/supply/return_install_programs()
var/list/_prg_list = list(
new/datum/computer_file/program/filemanager(),
new/datum/computer_file/program/chatclient(),
new/datum/computer_file/program/civilian/cargocontrol(),
new/datum/computer_file/program/civilian/cargoorder()
)
return _prg_list
/datum/modular_computer_app_presets/wall_generic
name = "wallgeneric"
display_name = "Wall - Generic"
description = "A generic preset for the wall console"
description = "A generic preset for the wall console."
available = 0
/datum/modular_computer_app_presets/wall_generic/return_install_programs()
var/list/_prg_list = list(
@@ -124,7 +139,7 @@
/datum/modular_computer_app_presets/merc
name = "merc"
display_name = "Mercenary"
description = "Preset for the Merc Console"
description = "Preset for the Merc Console."
available = 0
/datum/modular_computer_app_presets/merc/return_install_programs()
var/list/_prg_list = list(
@@ -137,7 +152,7 @@
/datum/modular_computer_app_presets/ert
name = "ert"
display_name = "EmergencyResposeTeam"
description = "Preset for the ERT Console"
description = "Preset for the ERT Console."
available = 0
/datum/modular_computer_app_presets/ert/return_install_programs()
var/list/_prg_list = list(
@@ -155,7 +170,7 @@
/datum/modular_computer_app_presets/trashcompactor
name = "trashcompactor"
display_name = "Trash Compactor"
description = "A preset for the Trash Compactor Wall Console"
description = "A preset for the Trash Compactor Wall Console."
available = 0
/datum/modular_computer_app_presets/trashcompactor/return_install_programs()
var/list/_prg_list = list(
@@ -167,7 +182,7 @@
/datum/modular_computer_app_presets/merchant
name = "merchant"
display_name = "Merchant"
description = "A preset for the merchant console"
description = "A preset for the merchant console."
available = 0
/datum/modular_computer_app_presets/merchant/return_install_programs()
var/list/_prg_list = list(
@@ -0,0 +1,192 @@
/datum/computer_file/program/civilian/cargocontrol
filename = "cargocontrol"
filedesc = "Cargo Control"
extended_desc = "Application to Control Cargo Orders"
size = 12
requires_ntnet = 1
available_on_ntnet = 1
required_access_download = access_hop
required_access_run = access_cargo
nanomodule_path = /datum/nano_module/program/civilian/cargocontrol/
/datum/nano_module/program/civilian/cargocontrol/
name = "Cargo Control"
var/page = "overview_main" //overview_main - Main Menu, overview_submitted - Submitted Order Overview, overview_approved - Approved Order Overview, settings - Settings, details - order details
var/last_user_name = "" //Name of the User that last used the computer
var/status_message = null //A status message that can be displayed
var/list/order_details = list() //Order Details for the order
var/list/shipment_details = list() //Shipment Details for a selected shipment
/datum/nano_module/program/civilian/cargocontrol/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1, var/datum/topic_state/state = default_state)
var/list/data = host.initial_data()
post_signal("supply")
//Send the page to display
data["page"] = page
//Send teh status message
data["status_message"] = status_message
//Pass the ID Data
var/obj/item/weapon/card/id/user_id_card = user.GetIdCard()
last_user_name = GetNameAndAssignmentFromId(user_id_card)
data["username"] = last_user_name
var/list/submitted_orders = SScargo.get_orders_by_status("submitted",1)
data["order_submitted_number"] = submitted_orders.len
data["order_submitted_value"] = SScargo.get_orders_value_by_status("submitted",1)
data["order_submitted_suppliers"] = SScargo.get_order_suppliers_by_status("submitted",1)
data["order_submitted_shuttle_time"] = SScargo.get_pending_shipment_time("submitted")
data["order_submitted_shuttle_price"] = SScargo.get_pending_shipment_cost("submitted")
if(page == "overview_submitted")
data["order_list"] = submitted_orders
var/list/approved_orders = SScargo.get_orders_by_status("approved",1)
data["order_approved_number"] = approved_orders.len
data["order_approved_value"] = SScargo.get_orders_value_by_status("approved",1)
data["order_approved_suppliers"] = SScargo.get_order_suppliers_by_status("approved",1)
data["order_approved_shuttle_time"] = SScargo.get_pending_shipment_time("approved")
data["order_approved_shuttle_price"] = SScargo.get_pending_shipment_cost("approved")
if(page == "overview_approved")
data["order_list"] = approved_orders
var/list/shipped_orders = SScargo.get_orders_by_status("shipped",1)
data["order_shipped_number"] = shipped_orders.len
data["order_shipped_value"] = SScargo.get_orders_value_by_status("shipped",1)
if(page == "overview_shipped")
data["order_list"] = shipped_orders
if(page == "order_details")
data["order_details"] = order_details
if(page == "overview_shipments")
data["shipment_list"] = SScargo.get_shipment_list()
if(page == "shipment_details")
data["shipment_details"] = shipment_details
data["cargo_money"] = SScargo.get_cargo_money()
data["handling_fee"] = SScargo.get_handlingfee()
//Shuttle Stuff
var/datum/shuttle/ferry/supply/shuttle = SScargo.shuttle
if(shuttle)
data["shuttle_available"] = 1
data["shuttle_has_arrive_time"] = shuttle.has_arrive_time()
data["shuttle_eta_minutes"] = shuttle.eta_minutes()
data["shuttle_can_launch"] = shuttle.can_launch()
data["shuttle_can_cancel"] = shuttle.can_cancel()
data["shuttle_can_force"] = shuttle.can_force()
data["shuttle_at_station"] = shuttle.at_station()
if(shuttle.docking_controller)
data["shuttle_docking_status"] = shuttle.docking_controller.get_docking_status()
else
data["shuttle_docking_status"] = "error"
else
data["shuttle_available"] = 0
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
ui = new(user, src, ui_key, "cargo_control.tmpl", name, 850, 600, state = state)
ui.auto_update_layout = 1
ui.set_initial_data(data)
ui.open()
ui.set_auto_update(1)
/datum/nano_module/program/civilian/cargocontrol/Topic(href, href_list)
var/datum/shuttle/ferry/supply/shuttle = SScargo.shuttle
if (!shuttle)
world.log << "## ERROR: Eek. The supply/shuttle datum is missing somehow."
return
if(..())
return 1
//Page switch between main, submitted, approved and settings
if(href_list["page"])
switch(href_list["page"])
if("overview_main")
page = "overview_main" //Main overview page with links to the different sub overview pages - submitted, approved, shipped
if("overview_submitted")
page = "overview_submitted" //Overview page listing the orders that have been submitted with options to view them, approve them and reject them
if("overview_approved")
page = "overview_approved" //Overview page listing the current shuttle price and time as well as orders that have been approved, with options to view the details
if("overview_shipped")
page = "overview_shipped" //Overview page listing the orders that have been shipped to the station but not delivered, with the option to mark them as delivered as well as to specify a person it has been delivered to
if("order_details")
page = "order_details" //Details page for a specific order - Lists the contents of the orde with the suppliers, prices and required access levels
//Fetch the order details and store it for the order. No need to fetch it again every 2 seconds
var/datum/cargo_order/co = SScargo.get_order_by_id(text2num(href_list["order_details"]))
order_details = co.get_list()
if("overview_shipments") //Overview of the shipments to / from the station
page = "overview_shipments"
if("shipment_details") //Details of a Shipment to / from the station
page = "shipment_details"
if("settings")
page = "settings" //Settings page that allows to tweak various settings such as the cargo handling fee
else
page = "overview_main" //fall back to overview_main if a unknown page has been supplied
return 1
//Approve a order
if(href_list["order_approve"])
var/datum/cargo_order/co = SScargo.get_order_by_id(text2num(href_list["order_approve"]))
if(co)
var/message = SScargo.approve_order(co,last_user_name)
if(message)
status_message = message
return 1
//Reject a order
if(href_list["order_reject"])
var/datum/cargo_order/co = SScargo.get_order_by_id(text2num(href_list["order_reject"]))
if(co)
var/message = SScargo.reject_order(co)
if(message)
status_message = message
return 1
//Send shuttle
if(href_list["shuttle_send"])
var/message = SScargo.shuttle_call(last_user_name)
if(message)
status_message = message
return 1
//Cancel shuttle
if(href_list["shuttle_cancel"])
var/message = SScargo.shuttle_cancel()
if(message)
status_message = message
return 1
//Force shuttle
if(href_list["shuttle_force"])
var/message = SScargo.shuttle_force()
if(message)
status_message = message
return 1
//Clear Status Message
if(href_list["clear_message"])
status_message = null
return 1
if(href_list["handling_fee"])
var/handling_fee = sanitize(input(usr,"Handling Fee:","Set the new handling fee?",SScargo.get_handlingfee()) as null|text)
status_message = SScargo.set_handlingfee(text2num(handling_fee))
return 1
//Change Settings
/datum/nano_module/program/civilian/cargocontrol/proc/post_signal(var/command) //Old code right here - Used to send a refresh command to the status screens incargo
var/datum/radio_frequency/frequency = SSradio.return_frequency(1435)
if(!frequency) return
var/datum/signal/status_signal = new
status_signal.source = src
status_signal.transmission_method = 1
status_signal.data["command"] = command
frequency.post_signal(src, status_signal)
@@ -0,0 +1,187 @@
/datum/computer_file/program/civilian/cargoorder
filename = "cargoorder"
filedesc = "Cargo Order"
extended_desc = "Application to Order Items from Cargo"
size = 10
requires_ntnet = 1
available_on_ntnet = 1
nanomodule_path = /datum/nano_module/program/civilian/cargoorder/
/datum/nano_module/program/civilian/cargoorder/
name = "Cargo Order"
var/page = "main" //main - Main Menu, order - Order Page, item_details - Item Details Page, tracking - Tracking Page
var/selected_category = "" // Category that is currently selected
var/selected_item = "" // Path of the currently selected item
var/datum/cargo_order/co
var/last_user_name = "" //Name of the user that used the program
var/status_message = null //Status Message to be displayed to the user
var/user_tracking_id = 0 //Tracking id of the user
var/user_tracking_code = 0 //Tracking Code of the user
/datum/nano_module/program/civilian/cargoorder/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1, var/datum/topic_state/state = default_state)
//Check if a cargo order exists. If not create a new one
if(!co)
var/datum/cargo_order/crord = new
co = crord
var/list/data = host.initial_data()
//Pass the ID Data
var/obj/item/weapon/card/id/user_id_card = user.GetIdCard()
if(!user_id_card)
last_user_name = "Unknown"
else
last_user_name = user_id_card.registered_name
data["username"] = last_user_name
//Pass the list of all ordered items and the order value
data["order_items"] = co.get_item_list()
data["order_value"] = co.get_value(0)
data["order_item_count"] = co.get_item_count()
data["order_shuttle_fee"] = co.get_max_shipment_cost()
//Pass Data for Main page
if(page == "main")
//Pass all available categories and the selected category
data["cargo_categories"] = SScargo.get_category_list()
data["selected_category"] = selected_category
//Pass a list of items in the selected category
data["category_items"] = SScargo.get_items_for_category(selected_category)
//Pass Data for Item Details Page
else if(page == "item_details")
var/datum/cargo_item/ci = SScargo.cargo_items[selected_item]
if(ci)
data["item_details"] = ci.get_list()
else if (page == "tracking")
data["tracking_id"] = user_tracking_id
data["tracking_code"] = user_tracking_code
//If no tracking id / code is entered the page the enter them should be displayed
if(!user_tracking_id || !user_tracking_code)
data["tracking_status"] = "Incomplete Input"
//If we have a tracking id / code, then try to find a order with mathing details
else if(user_tracking_id && user_tracking_code)
//Now, lets try to find a order with a matching id
var/datum/cargo_order/co = SScargo.get_order_by_id(user_tracking_id)
if(co)
if(co.tracking_code == user_tracking_code)
data["tracking_status"] = "Success"
data["tracked_order"] = co.get_list()
data["tracked_order_report"] = co.get_report()
else
data["tracking_status"] = "Invalid Tracking Code"
else
data["tracking_status"] = "Invalid Order"
//Pass the current page
data["page"] = page
//Pass the status message along
data["status_message"] = status_message
data["handling_fee"] = SScargo.get_handlingfee()
data["crate_fee"] = SScargo.get_cratefee()
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
ui = new(user, src, ui_key, "cargo_order.tmpl", name, 500, 600, state = state)
ui.auto_update_layout = 1
ui.set_initial_data(data)
ui.open()
ui.set_auto_update(1)
/datum/nano_module/program/civilian/cargoorder/Topic(href, href_list)
if(..())
return 1
//Send the order to cargo
if(href_list["submit_order"])
if(co.items.len == 0)
return 1 //Only submit the order if there are items in it
if(last_user_name == "Unknown")
status_message = "Unable to submit order. ID could not be located"
return 1
var/reason = sanitize(input(usr,"Reason:","Why do you require this item?","") as null|text)
if(!reason)
status_message = "Unable to submit order. No reason supplied."
return 1
co.customer = last_user_name
co.reason = reason
SScargo.submit_order(co)
status_message = "Order submitted successfully. Order ID: [co.order_id] Tracking code: [co.get_tracking_code()]"
//TODO: Print a list with the order data
co = null
return 1
//Add item to the order list
if(href_list["add_item"])
var/datum/cargo_order_item/coi = new
coi.ci = SScargo.cargo_items[href_list["add_item"]]
coi.supplier = href_list["supplier"]
//Check if the selected supplier exists for the item and get the price for the supplier
var/supplier_details = coi.ci.suppliers[coi.supplier]
if(supplier_details)
coi.cs = SScargo.get_supplier_by_name(coi.supplier)
coi.calculate_price()
if(coi.price > 0)
status_message = co.add_item(coi)
else
status_message = "Unable to add item [coi.ci.name] - Internal Error 602."
log_debug("Cargo Order: Warning - Attempted to order item [coi.ci.name] from supplier [href_list["supplier"]] with invalid purchase price")
qdel(coi)
else
status_message = "Unable to add item [coi.ci.name] - Internal Error 605."
log_debug("Cargo Order: Warning - Attempted to order item [coi.ci.name] from non existant supplier [href_list["supplier"]]")
qdel(coi)
//Reset page to main page - TODO: Maybe add a way to disable jumping back to the main page
page = "main"
selected_item = ""
return 1
//Remove item from the order list
if(href_list["remove_item"])
status_message = co.remove_item(text2num(href_list["remove_item"]))
return 1
//Clear the items in the order list
if(href_list["clear_order"])
status_message = "Order Cleared"
qdel(co)
co = new
return 1
//Change the selected page
if(href_list["item_details"])
page = "item_details"
selected_item = href_list["item_details"]
return 1
if(href_list["page"])
page = href_list["page"]
return 1
//Tracking Stuff
if(href_list["trackingid"])
var/trackingid = text2num(sanitize(input(usr,"Order ID:","ID of the Order that you want to track","") as null|text))
if(trackingid)
user_tracking_id = trackingid
return 1
if(href_list["trackingcode"])
var/trackingcode = text2num(sanitize(input(usr,"Tracking Code:","Tracking Code of the Order that you want to track","") as null|text))
if(trackingcode)
user_tracking_code = trackingcode
return 1
//Change the displayed item category
if(href_list["select_category"])
selected_category = href_list["select_category"]
return 1
if(href_list["clear_message"])
status_message = null
return 1