From 19ef482d877dda816756ae65080d53aecda00551 Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Sun, 19 Jul 2015 01:46:27 -0700 Subject: [PATCH] Finishes carnmc's shuttle rotation feature. Under carn shuttles, When shuttles dock at a docking port that is not the same direction as them, they rotate their bounding box, and they do magic i don't understand to rotate where the turfs get placed. But it doesn't rotate the items or smoothwall or handle pixel_xy or any of that. This fixes that. Shuttle rotation will call /atom/proc/shuttleRotate(degrees) Default behavior handles most cases, and overrides handle edge cases. Shuttle walls don't smooth wall or obey directions, so I just rotate their icon using matrix transform, its dirty but it works. See: https://tgstation13.org/msoshit/powrightinthekisser.png or https://tgstation13.org/msoshit/fuckingshuttles.png --- code/__HELPERS/game.dm | 36 ++++++++ code/game/turfs/simulated/walls_misc.dm | 8 +- code/modules/awaymissions/gateway.dm | 4 +- code/modules/mob/mob.dm | 6 +- code/modules/power/gravitygenerator.dm | 4 + code/modules/shuttle/shuttle.dm | 112 +++++++++++++++--------- 6 files changed, 124 insertions(+), 46 deletions(-) diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index 8a0b055d4b2..230a77ba1ae 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -379,3 +379,39 @@ var/dest_y = src_y + distance*cos(rotation); return new /datum/projectile_data(src_x, src_y, time, distance, power_x, power_y, dest_x, dest_y) + +/proc/getRotationFromDirs(dir1, dir2) + return getDegreesFromDir(dir2)-getDegreesFromDir(dir1) + +/proc/getDirFromRotation(rotation, olddir) + return getDirFromDegrees(rotation+getDegreesFromDir(olddir)) + +/proc/getDirFromDegrees(degrees) + if (degrees < 0) + degrees += 360 + if (degrees >= 360) + degrees %= 360 + if (degrees == 360) + degrees = 0 + switch(degrees) + if (0) + return NORTH + if (90) + return EAST + if (180) + return SOUTH + if (270) + return WEST + + +/proc/getDegreesFromDir(dir) + switch(dir) + if (NORTH) + return 0 + if (EAST) + return 90 + if (SOUTH) + return 180 + if (WEST) + return 270 + return 0 \ No newline at end of file diff --git a/code/game/turfs/simulated/walls_misc.dm b/code/game/turfs/simulated/walls_misc.dm index 4d664e2b4ba..7b3e20a43ea 100644 --- a/code/game/turfs/simulated/walls_misc.dm +++ b/code/game/turfs/simulated/walls_misc.dm @@ -62,4 +62,10 @@ T.color = color if(T.dir != dir) T.dir = dir - return T \ No newline at end of file + return T + +//why don't shuttle walls habe smoothwall? now i gotta do rotation the dirty way +/turf/simulated/wall/shuttle/shuttleRotate(rotation) + var/matrix/M = matrix(transform) + M.Turn(rotation) + transform = M \ No newline at end of file diff --git a/code/modules/awaymissions/gateway.dm b/code/modules/awaymissions/gateway.dm index 4b6c9ff0881..89e24aa3672 100644 --- a/code/modules/awaymissions/gateway.dm +++ b/code/modules/awaymissions/gateway.dm @@ -21,7 +21,9 @@ return icon_state = "off" - +//prevents shuttles attempting to rotate this since it messes up sprites +/obj/machinery/gateway/shuttleRotate() + return //this is da important part wot makes things go /obj/machinery/gateway/centerstation diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 6e9e8ccd996..59b83064827 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -963,4 +963,8 @@ var/list/slot_equipment_priority = list( \ spell.action.background_icon_state = spell.action_background_icon_state if(isliving(src)) spell.action.Grant(src) - return \ No newline at end of file + return + +//override to avoid rotating pixel_xy on mobs +/mob/shuttleRotate(rotation) + dir = getDirFromRotation(rotation, dir) \ No newline at end of file diff --git a/code/modules/power/gravitygenerator.dm b/code/modules/power/gravitygenerator.dm index 5c63a5cc097..be09fdadd38 100644 --- a/code/modules/power/gravitygenerator.dm +++ b/code/modules/power/gravitygenerator.dm @@ -36,6 +36,10 @@ var/const/GRAV_NEEDS_WRENCH = 3 ..() icon_state = "[get_status()]_[sprite_number]" +//prevents shuttles attempting to rotate this since it messes up sprites +/obj/machinery/gravity_generator/shuttleRotate() + return + /obj/machinery/gravity_generator/proc/get_status() return "off" diff --git a/code/modules/shuttle/shuttle.dm b/code/modules/shuttle/shuttle.dm index dfbb6085368..eeaad37ead2 100644 --- a/code/modules/shuttle/shuttle.dm +++ b/code/modules/shuttle/shuttle.dm @@ -22,7 +22,8 @@ /obj/docking_port/Destroy() return QDEL_HINT_LETMELIVE - +/obj/docking_port/shuttleRotate() + return //we don't rotate with shuttles via this code. //returns a list(x0,y0, x1,y1) where points 0 and 1 are bounding corners of the projected rectangle /obj/docking_port/proc/return_coords(_x, _y, _dir) if(!_dir) @@ -267,6 +268,22 @@ else WARNING("shuttle \"[id]\" could not enter transit space. S0=[S0 ? S0.id : "null"] S1=[S1 ? S1.id : "null"]") +//default shuttleRotate +/atom/proc/shuttleRotate(rotation) + dir = getDirFromRotation(rotation, dir) + + //we need to rotate the pixel offsets too. + if (pixel_x || pixel_y) + if (rotation < 0) + rotation += 360 + for (var/turntimes=rotation/90;turntimes>0;turntimes--) + var/oldPX = pixel_x + var/oldPY = pixel_y + pixel_x = oldPY + pixel_y = (oldPX*(-1)) + + + //this is the main proc. It instantly moves our mobile port to stationary port S1 //it handles all the generic behaviour, such as sanity checks, closing doors on the shuttle, stunning mobs, etc /obj/docking_port/mobile/proc/dock(obj/docking_port/stationary/S1) @@ -315,6 +332,18 @@ if(!T1) continue + + //lighting stuff + T1.redraw_lighting() + SSair.remove_from_active(T1) + T1.CalculateAdjacentTurfs() + SSair.add_to_active(T1,1) + + T0.redraw_lighting() + SSair.remove_from_active(T0) + T0.CalculateAdjacentTurfs() + SSair.add_to_active(T0,1) + T0.copyTurf(T1) areaInstance.contents += T1 @@ -324,54 +353,49 @@ Ts1.copy_air_with_tile(T0) //move mobile to new location - loc = S1.loc - dir = S1.dir - //move all objects - for(var/obj/O in T0) - if(O.invisibility >= 101) - continue - if(O == T0.lighting_object) - continue - O.loc = T1 - //close open doors - if(istype(O, /obj/machinery/door)) - var/obj/machinery/door/Door = O - spawn(-1) - if(Door) - Door.close() - for(var/mob/M in T0) - if(!M.move_on_shuttle) - continue - M.loc = T1 + for(var/atom/movable/AM in T0) + if (dir != S1.dir) + AM.shuttleRotate(getRotationFromDirs(dir,S1.dir)) - //docking turbulence - if(M.client) - spawn(0) - if(M.buckled) - shake_camera(M, 2, 1) // turn it down a bit come on - else - shake_camera(M, 7, 1) - if(istype(M, /mob/living/carbon)) - if(!M.buckled) - M.Weaken(3) + if (istype(AM,/obj)) + var/obj/O = AM + if(O.invisibility >= 101) + continue + if(O == T0.lighting_object) + continue + O.loc = T1 + + //close open doors + if(istype(O, /obj/machinery/door)) + var/obj/machinery/door/Door = O + spawn(-1) + if(Door) + Door.close() + else if (istype(AM,/mob)) + var/mob/M = AM + if(!M.move_on_shuttle) + continue + M.loc = T1 + + //docking turbulence + if(M.client) + spawn(0) + if(M.buckled) + shake_camera(M, 2, 1) // turn it down a bit come on + else + shake_camera(M, 7, 1) + if(istype(M, /mob/living/carbon)) + if(!M.buckled) + M.Weaken(3) T0.ChangeTurf(turf_type) - - //air system updates - for(var/turf/T1 in L1) - T1.redraw_lighting() - SSair.remove_from_active(T1) - T1.CalculateAdjacentTurfs() - SSair.add_to_active(T1,1) - - for(var/turf/T0 in L0) - T0.redraw_lighting() - SSair.remove_from_active(T0) - T0.CalculateAdjacentTurfs() - SSair.add_to_active(T0,1) + if (dir != S1.dir) + T1.shuttleRotate(getRotationFromDirs(dir,S1.dir)) + loc = S1.loc + dir = S1.dir /* if(istype(S1, /obj/docking_port/stationary/transit)) @@ -381,6 +405,8 @@ T.update_icon() */ + + /obj/docking_port/mobile/proc/findTransitDock() var/obj/docking_port/stationary/transit/T = SSshuttle.getDock("[id]_transit") if(T && !canDock(T))