From 19ef482d877dda816756ae65080d53aecda00551 Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Sun, 19 Jul 2015 01:46:27 -0700 Subject: [PATCH 1/4] 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)) From 7f58d930bbabbdac7efad1952886884d6f42b3af Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Sun, 19 Jul 2015 10:58:33 -0700 Subject: [PATCH 2/4] Shuttle Rotation Tweaks This should fix shuttle walls not rotating back to their old state correctly when the shuttle docks elsewhere. Also uses built in procs and caches the calculated rotation angle to improve shuttle docking speed by not calculating it again for every object. This should also ensure that diagonal objects rotate correctly, rather then snapping back to a cardinal direction. --- code/__HELPERS/game.dm | 35 ------------------------- code/game/turfs/simulated/walls_misc.dm | 7 ++++- code/modules/mob/mob.dm | 2 +- code/modules/shuttle/shuttle.dm | 17 ++++++++---- 4 files changed, 19 insertions(+), 42 deletions(-) diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index 230a77ba1ae..21626590306 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -380,38 +380,3 @@ 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 7b3e20a43ea..e2a05273664 100644 --- a/code/game/turfs/simulated/walls_misc.dm +++ b/code/game/turfs/simulated/walls_misc.dm @@ -62,10 +62,15 @@ T.color = color if(T.dir != dir) T.dir = dir + T.transform = transform return T +/turf/simulated/wall/shuttle/copyTurf(turf/T) + . = ..() + T.transform = transform + //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) + var/matrix/M = transform M.Turn(rotation) transform = M \ No newline at end of file diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 59b83064827..b76f3056cc0 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -967,4 +967,4 @@ var/list/slot_equipment_priority = list( \ //override to avoid rotating pixel_xy on mobs /mob/shuttleRotate(rotation) - dir = getDirFromRotation(rotation, dir) \ No newline at end of file + dir = angle2dir(rotation+dir2angle(dir)) \ No newline at end of file diff --git a/code/modules/shuttle/shuttle.dm b/code/modules/shuttle/shuttle.dm index eeaad37ead2..600795a4f5a 100644 --- a/code/modules/shuttle/shuttle.dm +++ b/code/modules/shuttle/shuttle.dm @@ -270,7 +270,7 @@ //default shuttleRotate /atom/proc/shuttleRotate(rotation) - dir = getDirFromRotation(rotation, dir) + dir = angle2dir(rotation+dir2angle(dir)) //we need to rotate the pixel offsets too. if (pixel_x || pixel_y) @@ -313,6 +313,13 @@ var/list/L0 = return_ordered_turfs(x, y, z, dir, areaInstance) var/list/L1 = return_ordered_turfs(S1.x, S1.y, S1.z, S1.dir) + var/rotation = dir2angle(S1.dir)-dir2angle(dir) + if ((rotation % 90) != 0) + rotation += (rotation % 90) //diagonal rotations not allowed, round up + rotation = SimplifyDegrees(rotation) + + + //remove area surrounding docking port if(areaInstance.contents.len) var/area/A0 = locate("[area_type]") @@ -357,8 +364,8 @@ for(var/atom/movable/AM in T0) - if (dir != S1.dir) - AM.shuttleRotate(getRotationFromDirs(dir,S1.dir)) + if (rotation) + AM.shuttleRotate(rotation) if (istype(AM,/obj)) var/obj/O = AM @@ -392,8 +399,8 @@ M.Weaken(3) T0.ChangeTurf(turf_type) - if (dir != S1.dir) - T1.shuttleRotate(getRotationFromDirs(dir,S1.dir)) + if (rotation) + T1.shuttleRotate(rotation) loc = S1.loc dir = S1.dir From 9108dbba42ae3faf943296e91f84e4976e04b5d8 Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Mon, 20 Jul 2015 10:41:04 -0700 Subject: [PATCH 3/4] Makes shuttle rotate Re-Smooth's atoms if need be. --- code/modules/shuttle/shuttle.dm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/code/modules/shuttle/shuttle.dm b/code/modules/shuttle/shuttle.dm index 600795a4f5a..17c57e80413 100644 --- a/code/modules/shuttle/shuttle.dm +++ b/code/modules/shuttle/shuttle.dm @@ -270,9 +270,14 @@ //default shuttleRotate /atom/proc/shuttleRotate(rotation) + //rotate our direction dir = angle2dir(rotation+dir2angle(dir)) - //we need to rotate the pixel offsets too. + //resmooth if need be. + if(A.smooth) + smooth_icon(A) + + //rotate the pixel offsets too. if (pixel_x || pixel_y) if (rotation < 0) rotation += 360 From 8418ea6d0220d3f5be3338497db8e68bcbd2562e Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Mon, 20 Jul 2015 10:58:19 -0700 Subject: [PATCH 4/4] fixes shuttle rotate compile error --- code/modules/shuttle/shuttle.dm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/modules/shuttle/shuttle.dm b/code/modules/shuttle/shuttle.dm index 17c57e80413..cbb37c661d3 100644 --- a/code/modules/shuttle/shuttle.dm +++ b/code/modules/shuttle/shuttle.dm @@ -274,8 +274,8 @@ dir = angle2dir(rotation+dir2angle(dir)) //resmooth if need be. - if(A.smooth) - smooth_icon(A) + if(smooth) + smooth_icon(src) //rotate the pixel offsets too. if (pixel_x || pixel_y)