mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 10:12:45 +00:00
Cargo train update
- Cleans up some old code - Fixes some bugs - Adds keys to start the engine
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
/obj/vehicle/train/cargo/engine
|
||||
name = "cargo train tug"
|
||||
desc = "A ridable electric car designed for pulling cargo trolleys."
|
||||
icon = 'icons/obj/aibots.dmi'
|
||||
icon_state = "mulebot1" //mulebot icons until I get some proper icons
|
||||
on = 1
|
||||
on = 0
|
||||
powered = 1
|
||||
locked = 0
|
||||
|
||||
@@ -13,6 +14,14 @@
|
||||
|
||||
var/car_limit = 3 //how many cars an engine can pull before performance degrades
|
||||
active_engines = 1
|
||||
var/obj/item/weapon/key/cargo_train/key
|
||||
|
||||
/obj/item/weapon/key/cargo_train
|
||||
name = "key"
|
||||
desc = "A keyring with a small steel key, and a yellow fob reading \"Choo Choo!\"."
|
||||
icon = 'icons/obj/vehicles.dmi'
|
||||
icon_state = "train_keys"
|
||||
w_class = 1
|
||||
|
||||
/obj/vehicle/train/cargo/trolley
|
||||
name = "cargo train trolley"
|
||||
@@ -34,16 +43,14 @@
|
||||
..()
|
||||
cell = new /obj/item/weapon/cell/high
|
||||
verbs -= /atom/movable/verb/pull
|
||||
|
||||
/obj/vehicle/train/cargo/engine/initialize()
|
||||
..()
|
||||
key = new()
|
||||
|
||||
/obj/vehicle/train/cargo/engine/Move()
|
||||
if(on && cell.charge < power_use)
|
||||
turn_off()
|
||||
update_stats()
|
||||
if(load && is_train_head())
|
||||
load << "The drive motor briefly whines, then crawls to a stop."
|
||||
load << "The drive motor briefly whines, then drones to a stop."
|
||||
|
||||
if(is_train_head() && !on)
|
||||
return 0
|
||||
@@ -57,6 +64,16 @@
|
||||
else
|
||||
..()
|
||||
|
||||
/obj/vehicle/train/cargo/engine/attackby(obj/item/weapon/W as obj, mob/user as mob)
|
||||
if(istype(W, /obj/item/weapon/key/cargo_train))
|
||||
if(!key)
|
||||
user.drop_item()
|
||||
key = W
|
||||
W.loc = src
|
||||
verbs += /obj/vehicle/train/cargo/engine/verb/remove_key
|
||||
return
|
||||
..()
|
||||
|
||||
/obj/vehicle/train/cargo/update_icon()
|
||||
if(open)
|
||||
icon_state = "mulebot-hatch"
|
||||
@@ -94,6 +111,13 @@
|
||||
//-------------------------------------------
|
||||
// Train procs
|
||||
//-------------------------------------------
|
||||
/obj/vehicle/train/cargo/engine/turn_on()
|
||||
if(!key)
|
||||
return
|
||||
else
|
||||
..()
|
||||
update_stats()
|
||||
|
||||
/obj/vehicle/train/cargo/RunOver(var/mob/living/carbon/human/H)
|
||||
var/list/parts = list("head", "chest", "l_leg", "r_leg", "l_arm", "r_arm")
|
||||
|
||||
@@ -121,39 +145,6 @@
|
||||
//-------------------------------------------
|
||||
// Interaction procs
|
||||
//-------------------------------------------
|
||||
/obj/vehicle/train/cargo/trolley/verb/rotate()
|
||||
set name = "Rotate"
|
||||
set category = "Object"
|
||||
set src in view(1)
|
||||
|
||||
if(anchored)
|
||||
usr << "You cannot turn the trolley while it is latched onto a train."
|
||||
return
|
||||
|
||||
var/cur_dir = null
|
||||
switch(dir)
|
||||
if(NORTH)
|
||||
cur_dir = "North"
|
||||
if(SOUTH)
|
||||
cur_dir = "South"
|
||||
if(EAST)
|
||||
cur_dir = "East"
|
||||
if(WEST)
|
||||
cur_dir = "West"
|
||||
|
||||
var/new_dir = input("Select a new direction:", "Rotate", cur_dir) in list("North", "South", "East", "West")
|
||||
|
||||
switch(new_dir)
|
||||
if("North")
|
||||
dir = NORTH
|
||||
if("South")
|
||||
dir = SOUTH
|
||||
if("East")
|
||||
dir = EAST
|
||||
if("West")
|
||||
dir = WEST
|
||||
|
||||
|
||||
/obj/vehicle/train/cargo/engine/relaymove(mob/user, direction)
|
||||
if(user != load)
|
||||
return 0
|
||||
@@ -167,24 +158,37 @@
|
||||
else
|
||||
return ..()
|
||||
|
||||
/obj/vehicle/train/cargo/engine/verb/climb_down(mob/user as mob)
|
||||
set name = "Exit vehicle"
|
||||
set category = "Object"
|
||||
set src in range(0)
|
||||
|
||||
if(!load)
|
||||
return
|
||||
if(user != load)
|
||||
return
|
||||
|
||||
unload(user)
|
||||
/obj/vehicle/train/cargo/engine/examine()
|
||||
..()
|
||||
|
||||
if(!istype(usr, /mob/living/carbon/human))
|
||||
return
|
||||
|
||||
if(get_dist(usr,src) <= 1)
|
||||
usr << "The power light is [on ? "on" : "off"].\nThere are[key ? "" : " no"] keys in the ignition."
|
||||
|
||||
/obj/vehicle/train/cargo/engine/verb/check_power()
|
||||
set name = "Check power level"
|
||||
set category = "Object"
|
||||
set src in view(1)
|
||||
|
||||
if(!istype(usr, /mob/living/carbon/human))
|
||||
return
|
||||
|
||||
if(!cell)
|
||||
usr << "There is no power cell installed in [src]."
|
||||
return
|
||||
|
||||
usr << "The power meter reads [round(cell.percent(), 0.01)]%"
|
||||
|
||||
/obj/vehicle/train/cargo/engine/verb/start_engine()
|
||||
set name = "Start engine"
|
||||
set category = "Object"
|
||||
set src in view(1)
|
||||
|
||||
if(!istype(usr, /mob/living/carbon/human))
|
||||
return
|
||||
|
||||
if(on)
|
||||
usr << "The engine is already running."
|
||||
return
|
||||
@@ -203,6 +207,9 @@
|
||||
set category = "Object"
|
||||
set src in view(1)
|
||||
|
||||
if(!istype(usr, /mob/living/carbon/human))
|
||||
return
|
||||
|
||||
if(!on)
|
||||
usr << "The engine is already stopped."
|
||||
return
|
||||
@@ -211,20 +218,26 @@
|
||||
if (!on)
|
||||
usr << "You stop [src]'s engine."
|
||||
|
||||
//-------------------------------------------
|
||||
// Latching/unlatching procs
|
||||
//-------------------------------------------
|
||||
/obj/vehicle/train/cargo/trolley/attach_to(obj/vehicle/train/T, mob/user)
|
||||
..()
|
||||
if (lead)
|
||||
//This is now part of a train, anchor it so it cant be pushed around
|
||||
anchored = 1
|
||||
/obj/vehicle/train/cargo/engine/verb/remove_key()
|
||||
set name = "Remove key"
|
||||
set category = "Object"
|
||||
set src in view(1)
|
||||
|
||||
/obj/vehicle/train/cargo/trolley/unattach(mob/user)
|
||||
..()
|
||||
if (!lead && !tow)
|
||||
//if this carriage isn't part of a train anymore; unanchor it so it can be pushed around
|
||||
anchored = 0
|
||||
if(!istype(usr, /mob/living/carbon/human))
|
||||
return
|
||||
|
||||
if(!key || (load && load != usr))
|
||||
return
|
||||
|
||||
if(on)
|
||||
turn_off()
|
||||
|
||||
key.loc = usr.loc
|
||||
if(!usr.get_active_hand())
|
||||
usr.put_in_hands(key)
|
||||
key = null
|
||||
|
||||
verbs -= /obj/vehicle/train/cargo/engine/verb/remove_key
|
||||
|
||||
//-------------------------------------------
|
||||
// Loading/unloading procs
|
||||
@@ -260,9 +273,21 @@
|
||||
|
||||
update_move_delay()
|
||||
|
||||
/obj/vehicle/train/cargo/trolley/update_train_stats()
|
||||
..()
|
||||
|
||||
if(!lead && !tow)
|
||||
anchored = 0
|
||||
if(verbs.Find(/atom/movable/verb/pull))
|
||||
return
|
||||
else
|
||||
verbs += /atom/movable/verb/pull
|
||||
else
|
||||
anchored = 1
|
||||
verbs -= /atom/movable/verb/pull
|
||||
|
||||
/obj/vehicle/train/cargo/engine/proc/update_move_delay()
|
||||
if(!is_train_head())
|
||||
if(!is_train_head() || !on)
|
||||
move_delay = initial(move_delay) //so that engines that have been turned off don't lag behind
|
||||
else
|
||||
move_delay = max(0, (-car_limit * active_engines) + train_length - active_engines) //limits base overweight so you cant overspeed trains
|
||||
|
||||
@@ -67,8 +67,9 @@
|
||||
return 0
|
||||
|
||||
if(user != load)
|
||||
if(user in src) //for handling players stuck in src
|
||||
unload(user, direction, 1)
|
||||
if(user in src) //for handling players stuck in src - this shouldn't happen - but just in case it does
|
||||
user.loc = T
|
||||
contents -= user
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -81,19 +82,19 @@
|
||||
/obj/vehicle/train/MouseDrop_T(var/atom/movable/C, mob/user as mob)
|
||||
if(!usr.canmove || usr.stat || usr.restrained() || !Adjacent(usr) || !user.Adjacent(C))
|
||||
return
|
||||
|
||||
if(istype(C,/obj/vehicle/train))
|
||||
latch(C)
|
||||
latch(C, user)
|
||||
else
|
||||
if(!load(C))
|
||||
user << "\red You were unable to load [C] on [src]."
|
||||
|
||||
/obj/vehicle/train/attack_hand(mob/user as mob)
|
||||
if(!user.canmove || user.stat || user.restrained() || !Adjacent(user))
|
||||
if(user.stat || user.restrained() || !Adjacent(user))
|
||||
return 0
|
||||
|
||||
if(user != load && (user in src))
|
||||
unload(user, null, 1) //for handling players stuck in src
|
||||
user.loc = loc //for handling players stuck in src
|
||||
contents -= user
|
||||
else if(load)
|
||||
unload(user) //unload if loaded
|
||||
else if(!load)
|
||||
@@ -106,6 +107,9 @@
|
||||
set desc = "Unhitches this train from the one in front of it."
|
||||
set category = "Object"
|
||||
set src in view(1)
|
||||
|
||||
if(!istype(usr, /mob/living/carbon/human))
|
||||
return
|
||||
|
||||
if(!usr.canmove || usr.stat || usr.restrained() || !Adjacent(usr))
|
||||
return
|
||||
@@ -130,12 +134,13 @@
|
||||
if (T.tow)
|
||||
user << "\red [T] is already towing something."
|
||||
return
|
||||
|
||||
//latch with src as the follower
|
||||
lead = T
|
||||
T.tow = src
|
||||
dir = lead.dir
|
||||
|
||||
user << "\blue You hitch [src] to [T]."
|
||||
if(user)
|
||||
user << "\blue You hitch [src] to [T]."
|
||||
|
||||
update_stats()
|
||||
|
||||
@@ -152,15 +157,12 @@
|
||||
user << "\blue You unhitch [src] from [lead]."
|
||||
lead = null
|
||||
|
||||
/obj/vehicle/train/proc/latch(mob/user, obj/vehicle/train/T)
|
||||
update_stats()
|
||||
|
||||
/obj/vehicle/train/proc/latch(obj/vehicle/train/T, mob/user)
|
||||
if(!istype(T) || !Adjacent(T))
|
||||
return 0
|
||||
|
||||
/* --- commented out until we get directional sprites ---
|
||||
if(dir != T.dir) //cars need to be inline to latch
|
||||
return 0
|
||||
*/
|
||||
|
||||
var/T_dir = get_dir(src, T) //figure out where T is wrt src
|
||||
|
||||
if(dir == T_dir) //if car is ahead
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/obj/vehicle
|
||||
name = "vehicle"
|
||||
icon = 'icons/obj/vehicles.dmi'
|
||||
layer = OBJ_LAYER - 0.1 //so it sits below objects
|
||||
layer = MOB_LAYER + 0.1 //so it sits above objects including mobs
|
||||
density = 1
|
||||
anchored = 1
|
||||
animate_movement=1
|
||||
@@ -275,6 +275,7 @@
|
||||
if(load_item_visible)
|
||||
C.pixel_x += load_offset_x
|
||||
C.pixel_y += load_offset_y
|
||||
C.layer = layer + 0.1 //so it sits above the vehicle
|
||||
|
||||
if(ismob(C))
|
||||
var/mob/M = C
|
||||
@@ -284,7 +285,10 @@
|
||||
return 1
|
||||
|
||||
|
||||
/obj/vehicle/proc/unload(var/mob/user, var/direction, var/exception = 0)
|
||||
/obj/vehicle/proc/unload(var/mob/user, var/direction)
|
||||
if(!load)
|
||||
return
|
||||
|
||||
var/turf/dest = null
|
||||
|
||||
//find a turf to unload to
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 7.0 KiB |
Reference in New Issue
Block a user