Skip to content

Commit

Permalink
Shuttle engines affecting travel time (tgstation#28564)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnturK authored and lzimann committed Jun 26, 2017
1 parent 4e2793e commit 0c3edf1
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 20 deletions.
7 changes: 6 additions & 1 deletion code/__DEFINES/shuttles.dm
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@
#define HYPERSPACE_LAUNCH 2
#define HYPERSPACE_END 3

#define CALL_SHUTTLE_REASON_LENGTH 12
#define CALL_SHUTTLE_REASON_LENGTH 12

//Engine related
#define ENGINE_COEFF_MIN 0.5
#define ENGINE_COEFF_MAX 2
#define ENGINE_DEFAULT_MAXSPEED_ENGINES 5
4 changes: 4 additions & 0 deletions code/controllers/subsystem/shuttle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,7 @@ SUBSYSTEM_DEF(shuttle)
if(M.is_in_shuttle_bounds(A))
return TRUE

/datum/controller/subsystem/shuttle/proc/get_containing_shuttle(atom/A)
for(var/obj/docking_port/mobile/M in mobile)
if(M.is_in_shuttle_bounds(A))
return M
10 changes: 10 additions & 0 deletions code/datums/shuttles.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
mappath = "[prefix][shuttle_id].dmm"
. = ..()

//Whatever special stuff you want
/datum/map_template/shuttle/proc/on_bought()
return

/datum/map_template/shuttle/emergency
port_id = "emergency"
name = "Base Shuttle Template (Emergency)"
Expand Down Expand Up @@ -49,6 +53,12 @@
// first 10 minutes only
return world.time - SSticker.round_start_time < 6000

/datum/map_template/shuttle/emergency/airless/on_bought()
//enable buying engines from cargo
var/datum/supply_pack/P = SSshuttle.supply_packs[/datum/supply_pack/engineering/shuttle_engine]
P.special_enabled = TRUE


/datum/map_template/shuttle/emergency/asteroid
suffix = "asteroid"
name = "Asteroid Station Emergency Shuttle"
Expand Down
86 changes: 82 additions & 4 deletions code/game/shuttle_engines.dm
Original file line number Diff line number Diff line change
@@ -1,21 +1,95 @@
#define ENGINE_UNWRENCHED 0
#define ENGINE_WRENCHED 1
#define ENGINE_WELDED 2
#define ENGINE_WELDTIME 200

/obj/structure/shuttle
name = "shuttle"
icon = 'icons/turf/shuttle.dmi'
resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | ACID_PROOF
resistance_flags = LAVA_PROOF | FIRE_PROOF | ACID_PROOF
obj_integrity = 500
max_integrity = 500
armor = list(melee = 100, bullet = 10, laser = 10, energy = 0, bomb = 0, bio = 0, rad = 0, fire = 50, acid = 70) //default + ignores melee

/obj/structure/shuttle/engine
name = "engine"
density = 1
anchored = 1
density = TRUE
anchored = TRUE
var/engine_power = 1
var/state = ENGINE_WELDED //welding shmelding

//Ugh this is a lot of copypasta from emitters, welding need some boilerplate reduction
/obj/structure/shuttle/engine/can_be_unfasten_wrench(mob/user, silent)
if(state == ENGINE_WELDED)
if(!silent)
to_chat(user, "<span class='warning'>[src] is welded to the floor!</span>")
return FAILED_UNFASTEN
return ..()

/obj/structure/shuttle/engine/default_unfasten_wrench(mob/user, obj/item/weapon/wrench/W, time = 20)
. = ..()
if(. == SUCCESSFUL_UNFASTEN)
if(anchored)
state = ENGINE_WRENCHED
else
state = ENGINE_UNWRENCHED

/obj/structure/shuttle/engine/attackby(obj/item/I, mob/user, params)
add_fingerprint(user)
if(default_unfasten_wrench(user, I))
return
else if(istype(I, /obj/item/weapon/weldingtool))
var/obj/item/weapon/weldingtool/WT = I
switch(state)
if(ENGINE_UNWRENCHED)
to_chat(user, "<span class='warning'>The [src.name] needs to be wrenched to the floor!</span>")
if(EM_SECURED)
if(WT.remove_fuel(0,user))
playsound(loc, WT.usesound, 50, 1)
user.visible_message("[user.name] starts to weld the [name] to the floor.", \
"<span class='notice'>You start to weld \the [src] to the floor...</span>", \
"<span class='italics'>You hear welding.</span>")
if(do_after(user,ENGINE_WELDTIME*WT.toolspeed, target = src) && WT.isOn())
state = ENGINE_WELDED
to_chat(user, "<span class='notice'>You weld \the [src] to the floor.</span>")
alter_engine_power(engine_power)
if(EM_WELDED)
if(WT.remove_fuel(0,user))
playsound(loc, WT.usesound, 50, 1)
user.visible_message("[user.name] starts to cut the [name] free from the floor.", \
"<span class='notice'>You start to cut \the [src] free from the floor...</span>", \
"<span class='italics'>You hear welding.</span>")
if(do_after(user,ENGINE_WELDTIME*WT.toolspeed, target = src) && WT.isOn())
state = ENGINE_WRENCHED
to_chat(user, "<span class='notice'>You cut \the [src] free from the floor.</span>")
alter_engine_power(-engine_power)
return
else
return ..()

/obj/structure/shuttle/engine/Destroy()
if(state == ENGINE_WELDED)
alter_engine_power(-engine_power)
. = ..()

//Propagates the change to the shuttle.
/obj/structure/shuttle/engine/proc/alter_engine_power(mod)
if(mod == 0)
return
if(SSshuttle.is_in_shuttle_bounds(src))
var/obj/docking_port/mobile/M = SSshuttle.get_containing_shuttle(src)
if(M)
M.alter_engines(mod)

/obj/structure/shuttle/engine/heater
name = "heater"
icon_state = "heater"
engine_power = 0 // todo make these into 2x1 parts

/obj/structure/shuttle/engine/platform
name = "platform"
icon_state = "platform"
engine_power = 0

/obj/structure/shuttle/engine/propulsion
name = "propulsion engine"
Expand All @@ -33,6 +107,10 @@
/obj/structure/shuttle/engine/propulsion/burst
name = "burst engine"

/obj/structure/shuttle/engine/propulsion/burst/cargo
state = ENGINE_UNWRENCHED
anchored = FALSE

/obj/structure/shuttle/engine/propulsion/burst/left
name = "left burst engine"
icon_state = "burst_l"
Expand All @@ -54,7 +132,7 @@
bound_height = 64
appearance_flags = 0

obj/structure/shuttle/engine/huge
/obj/structure/shuttle/engine/huge
name = "engine"
opacity = 1
icon = 'icons/obj/3x3.dmi'
Expand Down
9 changes: 9 additions & 0 deletions code/modules/cargo/packs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,15 @@
/obj/item/weapon/am_containment)
crate_name = "antimatter jar crate"

/datum/supply_pack/engineering/shuttle_engine
name = "Shuttle Engine Crate"
cost = 5000
access = GLOB.access_ce
contains = list(/obj/structure/shuttle/engine/propulsion/burst/cargo)
crate_name = "shuttle engine crate"
crate_type = /obj/structure/closet/crate/secure/engineering
special = TRUE

//////////////////////////////////////////////////////////////////////////////
//////////////////////////// Medical /////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions code/modules/shuttle/emergency.dm
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
set_coefficient = 1
else
set_coefficient = 0.5
var/call_time = SSshuttle.emergencyCallTime * set_coefficient
var/call_time = SSshuttle.emergencyCallTime * set_coefficient * engine_coeff
switch(mode)
// The shuttle can not normally be called while "recalling", so
// if this proc is called, it's via admin fiat
Expand Down Expand Up @@ -359,7 +359,7 @@
enterTransit()
mode = SHUTTLE_ESCAPE
launch_status = ENDGAME_LAUNCHED
setTimer(SSshuttle.emergencyEscapeTime)
setTimer(SSshuttle.emergencyEscapeTime * engine_coeff)
priority_announce("The Emergency Shuttle has left the station. Estimate [timeLeft(600)] minutes until the shuttle docks at Central Command.", null, null, "Priority")

if(SHUTTLE_STRANDED)
Expand Down
3 changes: 3 additions & 0 deletions code/modules/shuttle/manipulator.dm
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@

message_admins(msg)
WARNING(msg)
return
//Everything fine
S.on_bought()

/obj/machinery/shuttle_manipulator/proc/unload_preview()
if(preview_shuttle)
Expand Down
86 changes: 73 additions & 13 deletions code/modules/shuttle/shuttle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

resistance_flags = INDESTRUCTIBLE | LAVA_PROOF | FIRE_PROOF | UNACIDABLE | ACID_PROOF
anchored = 1

//
var/id
// this should point -away- from the dockingport door, ie towards the ship
dir = NORTH
Expand Down Expand Up @@ -224,11 +224,9 @@
var/timid = FALSE

var/list/ripples = list()

/obj/docking_port/mobile/Initialize()
. = ..()
if(!timid)
register()
var/engine_coeff = 1 //current engine coeff
var/current_engines = 0 //current engine power
var/initial_engines = 0 //initial engine power

/obj/docking_port/mobile/proc/register()
SSshuttle.mobile += src
Expand All @@ -244,6 +242,8 @@

/obj/docking_port/mobile/Initialize(mapload)
. = ..()
if(!timid)
register()

var/area/A = get_area(src)
if(istype(A, /area/shuttle))
Expand All @@ -259,6 +259,9 @@
areaInstance.name = name
areaInstance.contents += return_ordered_turfs()

initial_engines = count_engines()
current_engines = initial_engines

#ifdef DOCKING_PORT_HIGHLIGHT
highlight("#0f0")
#endif
Expand Down Expand Up @@ -328,17 +331,17 @@
switch(mode)
if(SHUTTLE_CALL)
if(S == destination)
if(timeLeft(1) < callTime)
setTimer(callTime)
if(timeLeft(1) < callTime * engine_coeff)
setTimer(callTime * engine_coeff)
else
destination = S
setTimer(callTime)
setTimer(callTime * engine_coeff)
if(SHUTTLE_RECALL)
if(S == destination)
setTimer(callTime - timeLeft(1))
setTimer(callTime * engine_coeff - timeLeft(1))
else
destination = S
setTimer(callTime)
setTimer(callTime * engine_coeff)
mode = SHUTTLE_CALL
if(SHUTTLE_IDLE, SHUTTLE_IGNITING)
destination = S
Expand Down Expand Up @@ -624,7 +627,7 @@
return
else
mode = SHUTTLE_CALL
setTimer(callTime)
setTimer(callTime * engine_coeff)
enterTransit()
return

Expand Down Expand Up @@ -688,7 +691,7 @@

var/ds_remaining
if(!timer)
ds_remaining = callTime
ds_remaining = callTime * engine_coeff
else
ds_remaining = max(0, timer - world.time)

Expand Down Expand Up @@ -768,5 +771,62 @@
return TRUE
return FALSE

// Losing all initial engines should get you 2
// Adding another set of engines at 0.5 time
/obj/docking_port/mobile/proc/alter_engines(mod)
if(mod == 0)
return
var/old_coeff = engine_coeff
engine_coeff = get_engine_coeff(current_engines,mod)
current_engines = max(0,current_engines + mod)
if(in_flight())
var/delta_coeff = engine_coeff / old_coeff
modTimer(delta_coeff)

/obj/docking_port/mobile/proc/count_engines()
. = 0
for(var/obj/structure/shuttle/engine/E in areaInstance.contents)
if(!QDELETED(E))
. += E.engine_power

// Double initial engines to get to 0.5 minimum
// Lose all initial engines to get to 2
//For 0 engine shuttles like BYOS 5 engines to get to doublespeed
/obj/docking_port/mobile/proc/get_engine_coeff(current,engine_mod)
var/new_value = max(0,current + engine_mod)
if(new_value == initial_engines)
return 1
if(new_value > initial_engines)
var/delta = new_value - initial_engines
var/change_per_engine = (1 - ENGINE_COEFF_MIN) / ENGINE_DEFAULT_MAXSPEED_ENGINES // 5 by default
if(initial_engines > 0)
change_per_engine = (1 - ENGINE_COEFF_MIN) / initial_engines // or however many it had
return Clamp(1 - delta * change_per_engine,ENGINE_COEFF_MIN,ENGINE_COEFF_MAX)
if(new_value < initial_engines)
var/delta = initial_engines - new_value
var/change_per_engine = 1 //doesn't really matter should not be happening for 0 engine shuttles
if(initial_engines > 0)
change_per_engine = (ENGINE_COEFF_MAX - 1) / initial_engines //just linear drop to max delay
return Clamp(1 + delta * change_per_engine,ENGINE_COEFF_MIN,ENGINE_COEFF_MAX)


/obj/docking_port/mobile/proc/in_flight()
switch(mode)
if(SHUTTLE_CALL,SHUTTLE_RECALL)
return TRUE
if(SHUTTLE_IDLE,SHUTTLE_IGNITING)
return FALSE
else
return FALSE // hmm

/obj/docking_port/mobile/emergency/in_flight()
switch(mode)
if(SHUTTLE_ESCAPE)
return TRUE
if(SHUTTLE_STRANDED,SHUTTLE_ENDGAME)
return FALSE
else
return ..()


#undef DOCKING_PORT_HIGHLIGHT

0 comments on commit 0c3edf1

Please sign in to comment.