Also allows checking remaining engine charge by examining, and removes
the verb.
This commit is contained in:
mwerezak
2014-08-08 20:31:14 -04:00
parent 6e4c42766e
commit 30c96bc7cc
3 changed files with 54 additions and 53 deletions

View File

@@ -48,7 +48,7 @@
turn_off() //so engine verbs are correctly set
/obj/vehicle/train/cargo/engine/Move()
if(on && cell.charge < power_use)
if(on && cell.charge < charge_use)
turn_off()
update_stats()
if(load && is_train_head())
@@ -183,20 +183,7 @@
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)]%"
usr << "The charge meter reads [cell? round(cell.percent(), 0.01) : 0]%"
/obj/vehicle/train/cargo/engine/verb/start_engine()
set name = "Start engine"
@@ -214,7 +201,7 @@
if (on)
usr << "You start [src]'s engine."
else
if(cell.charge < power_use)
if(cell.charge < charge_use)
usr << "[src] is out of power."
else
usr << "[src]'s engine won't start."
@@ -288,13 +275,22 @@
// more engines increases this limit by car_limit per
// engine.
//-------------------------------------------------------
/obj/vehicle/train/cargo/engine/update_train_stats()
..()
/obj/vehicle/train/cargo/engine/update_car(var/train_length, var/active_engines)
src.train_length = train_length
src.active_engines = active_engines
update_move_delay()
//Update move delay
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
move_delay *= (1 / max(1, active_engines)) * 2 //overweight penalty (scaled by the number of engines)
move_delay += config.run_speed //base reference speed
move_delay *= 1.1 //makes cargo trains 10% slower than running when not overweight
/obj/vehicle/train/cargo/trolley/update_train_stats()
..()
/obj/vehicle/train/cargo/trolley/update_car(var/train_length, var/active_engines)
src.train_length = train_length
src.active_engines = active_engines
if(!lead && !tow)
anchored = 0
@@ -305,12 +301,3 @@
else
anchored = 1
verbs -= /atom/movable/verb/pull
/obj/vehicle/train/cargo/engine/proc/update_move_delay()
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
move_delay *= (1 / max(1, active_engines)) * 2 //overweight penalty (scaled by the number of engines)
move_delay += config.run_speed //base reference speed
move_delay *= 1.1 //makes cargo trains 10% slower than running when not overweight

View File

@@ -142,6 +142,15 @@
if (T.tow)
user << "\red [T] is already towing something."
return
//check for cycles.
var/obj/vehicle/train/next_car = T
while (next_car)
if (next_car == src)
user << "\red That seems very silly."
return
next_car = next_car.lead
//latch with src as the follower
lead = T
T.tow = src
@@ -192,23 +201,28 @@
// size of the train, to limit super long trains.
//-------------------------------------------------------
/obj/vehicle/train/update_stats()
if(tow)
return tow.update_stats() //take us to the very end
else
update_train_stats() //we're at the end
//first, seek to the end of the train
var/obj/vehicle/train/T = src
while(T.tow)
//check for cyclic train.
if (T.tow == src)
lead.tow = null
lead.update_stats()
lead = null
update_stats()
return
T = T.tow
/obj/vehicle/train/proc/update_train_stats()
if(powered && on)
active_engines = 1 //increment active engine count if this is a running engine
else
active_engines = 0
//now walk back to the front.
var/active_engines = 0
var/train_length = 0
while(T)
train_length++
if (powered && on)
active_engines++
T.update_car(train_length, active_engines)
T = T.lead
train_length = 1
if(istype(tow))
active_engines += tow.active_engines
train_length += tow.train_length
//update the next section of train ahead of us
if(istype(lead))
lead.update_train_stats()
/obj/vehicle/train/proc/update_car(var/train_length, var/active_engines)
return

View File

@@ -22,7 +22,7 @@
var/movable = 1
var/obj/item/weapon/cell/cell
var/power_use = 5 //set this to adjust the amount of power the vehicle uses per move
var/charge_use = 5 //set this to adjust the amount of power the vehicle uses per move
var/atom/movable/load //all vehicles can take a load, since they should all be a least drivable
var/load_item_visible = 1 //set if the loaded item should be overlayed on the vehicle sprite
@@ -39,7 +39,7 @@
/obj/vehicle/Move()
if(world.time > l_move_time + move_delay)
if(on && powered && cell.charge < power_use)
if(on && powered && cell.charge < charge_use)
turn_off()
var/init_anc = anchored
@@ -51,7 +51,7 @@
anchored = init_anc
if(on && powered)
cell.use(power_use)
cell.use(charge_use)
if(load)
load.forceMove(loc)// = loc
@@ -172,7 +172,7 @@
/obj/vehicle/proc/turn_on()
if(stat)
return 0
if(powered && cell.charge < power_use)
if(powered && cell.charge < charge_use)
return 0
on = 1
luminosity = initial(luminosity)
@@ -228,7 +228,7 @@
turn_off()
return
if(cell.charge < power_use)
if(cell.charge < charge_use)
turn_off()
return