/* A item orderable via cargo */ /datum/cargo_item var/path = null //Path of the item var/name = "Cargo Item" //Name of the item var/description = "You should not see this" //Description of the item var/list/categories = list() //List of categories this item appears in var/list/suppliers = list() //List of supliers and their prices var/amount = 1 //Amount of items in the crate var/access = null //What access requirement should be added to the container var/container_type = "crate" //crate or box var/groupable = 1 //If the item can be thrown into the same container as other items //Gets a list of the cargo item - To be json encoded /datum/cargo_item/proc/get_list() var/list/data = list() data["name"] = name data["path"] = path data["description"] = description data["categories"] = categories data["amount"] = amount var/suppliers_list = list() for(var/supplier in suppliers) var/list/sd = list() var/datum/cargo_supplier/cs = suppliers[supplier]["supplier_datum"] if(!cs) log_debug("Cargo - Invalid supplier [supplier] encountered when loading item [name] with path [path]") continue sd["short_name"] = cs.short_name sd["name"] = cs.name sd["available"] = cs.available sd["price_modifier"] = cs.price_modifier sd["base_purchase_price"] = suppliers[supplier]["base_purchase_price"] sd["vars"] = suppliers[supplier]["vars"] sd["adjusted_price"] = sd["base_purchase_price"] * sd["price_modifier"] //Add category adjustments for(var/category in categories) var/datum/cargo_category/cc = SScargo.get_category_by_name(category) if(cc) sd["adjusted_price"] *= cc.price_modifier suppliers_list[supplier] = sd data["suppliers"] = suppliers_list return data /* A supplier of items */ /datum/cargo_supplier var/short_name = "" //Short name of the cargo supplier var/name = "" //Long name of the cargo supplier var/description = "" //Description of the supplier var/tag_line = "" //Tag line of the supplier var/shuttle_time = 0 //Time the shuttle takes to get to the supplier var/shuttle_price = 0 //Price to call the shuttle var/available = 1 //If the supplier is available var/price_modifier = 1 //Price modifier for the supplier //Gets a list of supplier - to be json encoded /datum/cargo_supplier/proc/get_list() var/list/data = list() data["short_name"] = short_name data["name"] = name data["description"] = description data["tag_line"] = tag_line data["shuttle_time"] = shuttle_time data["shuttle_price"] = shuttle_price data["available"] = available data["price_modifier"] = price_modifier return data /* A category displayed in the cargo order app */ /datum/cargo_category var/name = "cargo_category" //Name of the category var/display_name = "Cargo Category" var/description = "You should not see this" //Description of the Category var/icon = "gear" //NanoUI Icon for the category var/price_modifier = 1 //Price Modifier for the category var/list/items = list() //List of items in the category // Gets a list of the cargo category - to be json encoded /datum/cargo_category/proc/get_list() var/list/data = list() data["name"] = name data["display_name"] = display_name data["description"] = description data["icon"] = icon data["price_modifier"] = price_modifier return data // Gets a list of the items in the cargo category - to be json encoded /datum/cargo_category/proc/get_item_list() var/list/item_list = list() for(var/datum/cargo_item/ci in items) item_list.Add(list(ci.get_list())) return item_list /* A order placed in the cargo order app. Contains multiple order items */ /datum/cargo_order var/list/items = list() //List of cargo_order_items in the order var/order_id = 0 //ID of the order var/price = 0 //Total price of the order var/payment_status = 0 //0-Not paid //1-Paid var/item_id = 1 //Current id of the item in the order var/item_num = 0 //Numer of items in the container - Used to limit the items in the crate var/status = "basket" //Status of the order: basket - Adding items, submitted - Submitted to cargo, approved - Order sent to suppliers, rejected - Order has been denied, shipped - Has been shipped to the station, delivered - Order has been delivered var/container_type = "" //Type of the container for the order - cate, box var/list/required_access = list() //Access required to unlock the crate var/can_add_items = 1 //If new items can be added to the order var/customer = null //Person that ordered the items var/authorized_by = null //Person that authorized the order var/received_by = null //Person the order has been delivered to by cargo / paid for the order var/time_submitted = null //Time the order has been sent to cargo var/time_approved = null //Time the order has been approved by cargo var/time_shipped = null //Time the order has been shipped to the station var/time_delivered = null //Time the order has been delivered var/tracking_code = null //Use this code with the order ID to get details about the order var/partial_shipment_fee = 0 //Partial Shipment Fee for the order var/reason = null //Reason for the order //Gets the tracking code for the order. Generates one if it does not exist already /datum/cargo_order/proc/get_tracking_code() if(!tracking_code) tracking_code = rand(1000,9999) return tracking_code // Returns a list of the items in the order - Formated as list to be json_encoded /datum/cargo_order/proc/get_item_list() var/list/item_list = list() for (var/datum/cargo_order_item/coi in items) item_list.Add(list(coi.get_list())) return item_list // Gets a list of the order data - Formated as list to be json_encoded /datum/cargo_order/proc/get_list() var/list/data = list() data["order_id"] = order_id data["tracking_code"] = get_tracking_code() data["price"] = get_value(2) data["price_customer"] = get_value(0) data["price_cargo"] = get_value(1) data["payment_status"] = payment_status data["status"] = get_order_status(0) data["status_pretty"] = get_order_status(1) data["customer"] = customer data["authorized_by"] = authorized_by data["received_by"] = received_by data["time_submitted"] = time_submitted data["time_approved"] = time_approved data["time_shipped"] = time_shipped data["time_delivered"] = time_delivered data["items"] = get_item_list() data["shipment_cost"] = partial_shipment_fee data["shipment_cost_max"] = get_max_shipment_cost() return data //Adds a item to a order. Returns a status message /datum/cargo_order/proc/add_item(var/datum/cargo_order_item/coi) if(!coi) return "Unable to add item - Internal Error" //Check if the container type of the added item matches the one of the current order if(container_type == "") container_type = coi.ci.container_type else if (container_type != coi.ci.container_type) return "Unable to add item - Different container required" //You can only add items with the same container type to the order //Check if more items can be added to the order if(!can_add_items) return "Unable to add item - Order can not contain more items" if(!coi.ci.groupable) //The item is not groupable with other items and needs to be ordered on its own if(get_item_count() > 0) // There are already other items in the order. -> Reject it return "Unable to add item - Item can not be grouped and must be ordered separately" else //No item in the order. Add it and set can_add_items to 0 can_add_items = 0 //Check if there is space in the container if(item_num + coi.ci.amount > get_container_storage()) return "Unable to add item - Container full" //Set item id of coi and increment item_id of co coi.item_id = item_id item_id += 1 //Increment the item number item_num += coi.ci.amount //Add coi to ordered item items.Add(coi) price += coi.price //Update the access requirement of the order if(coi.ci.access) required_access.Add(coi.ci.access) return "Item successfully added" //Removes a item from a order - Returns a status message /datum/cargo_order/proc/remove_item(var/remove_item_id) //Find the item with the specified id in the items list for (var/datum/cargo_order_item/coi in items) if(coi) if(coi.item_id == remove_item_id) items.Remove(coi) price -= coi.price item_num -= coi.ci.amount qdel(coi) return "Item removed successfully" return "Unable to remove item - Internal Error 608" // Returns the value of the order /datum/cargo_order/proc/get_value(var/type=0) //Type specifies if the price cargo has to pay or the price the customer has to be should be returned // 0 - Price the customer has to pay // 1 - Price cargo has to pay // 2 - Just the value of the items in the crate switch(type) if(0) //The price of the contents of the crate + the price for the crate + the handling fee + the partial shipment fee return price + SScargo.get_cratefee() + SScargo.get_handlingfee() + partial_shipment_fee if(1) //The price of the contents of the crate + the price of the crate return price + SScargo.get_cratefee() if(2) //Just the value of the items in the crate return price else //As a fallback, return the value of the items return price // Returns the number of items in the order /datum/cargo_order/proc/get_item_count() return items.len // Returns the type of the required container for the order /datum/cargo_order/proc/get_container_type() switch(container_type) if(CARGO_CONTAINER_CRATE) if(required_access.len > 0) return /obj/structure/closet/crate/secure else return /obj/structure/closet/crate if(CARGO_CONTAINER_BOX) if(required_access.len > 0) return /obj/structure/closet/crate/secure/large else return /obj/structure/largecrate if(CARGO_CONTAINER_FREEZER) return /obj/structure/closet/crate/freezer else log_debug("Cargo: Tried to get container type for invalid container [container_type]") return /obj/structure/largecrate // Returns the numer of items that can be stored in the container /datum/cargo_order/proc/get_container_storage() switch(container_type) if(CARGO_CONTAINER_CRATE) return 40 //Thats the default storage capacity of a crate if(CARGO_CONTAINER_FREEZER) return 40 if(CARGO_CONTAINER_BOX) return 5 //You can fit 5 larger items into a box else log_debug("Cargo: Tried to get storage size for invalid container [container_type]") return 0 //Something went wrong // Gets the list of the suppliers involved in the order /datum/cargo_order/proc/get_supplier_list() var/list/supplier_list = list() for(var/datum/cargo_order_item/coi in items) supplier_list[coi.supplier] = coi.supplier return supplier_list // Gets the maximal shipment cost for the item /datum/cargo_order/proc/get_max_shipment_cost() var/list/supplier_list = get_supplier_list() var/cost = 0 for(var/supplier in supplier_list) var/datum/cargo_supplier/cs = SScargo.cargo_suppliers[supplier] if(cs) cost += cs.shuttle_price return cost // Gets the order status /datum/cargo_order/proc/get_order_status(var/pretty=1) if(pretty) switch(status) if("submitted") return "Submitted to Cargo" if("approved") return "Approved" if("rejected") return "Rejected" if("shipped") return "Shipped to the Station" if("delivered") return "Delivered" else return "Unknown Status" else return status // Returns a HTML to be printed for the order /datum/cargo_order/proc/get_report() var/list/order_data = list() order_data += "