From 9134827dd6eb4552e4ecc570de6b572d7c2deb10 Mon Sep 17 00:00:00 2001 From: Kearel Date: Wed, 6 Jan 2016 15:04:04 -0600 Subject: [PATCH] Can now set things directly onto the board There are now checks in place for adjacency and consciousness so unconscious/dead people can't play checkers. --- code/modules/games/boardgame.dm | 116 +++++++++++++++++++++----------- 1 file changed, 78 insertions(+), 38 deletions(-) diff --git a/code/modules/games/boardgame.dm b/code/modules/games/boardgame.dm index 56f8c968a53..62abc1daa49 100644 --- a/code/modules/games/boardgame.dm +++ b/code/modules/games/boardgame.dm @@ -30,28 +30,49 @@ src.examine(M) obj/item/weapon/board/attackby(obj/item/I as obj, mob/user as mob) + if(!addPiece(I,user)) + ..() + +/obj/item/weapon/board/proc/addPiece(obj/item/I as obj, mob/user as mob, var/tile = 0) if(I.w_class != 1) //only small stuff user.show_message("\The [I] is too big to be used as a board piece.") - return + return 0 if(num == 64) user.show_message("\The [src] is already full!") - return + return 0 + if(tile > 0 && board["[tile]"]) + user.show_message("That space is already filled!") + return 0 + if(!user.Adjacent(src)) + return 0 + user.drop_from_inventory(I) I.forceMove(src) num++ + if(!board_icons["[I.icon] [I.icon_state]"]) board_icons["[I.icon] [I.icon_state]"] = new /icon(I.icon,I.icon_state) - var i; - for(i=0;i<64;i++) - if(!board["[i]"]) - board["[i]"] = I - break + if(tile == 0) + var i; + for(i=0;i<64;i++) + if(!board["[i]"]) + board["[i]"] = I + break + else + board["[tile]"] = I src.updateDialog() + return 1 + + /obj/item/weapon/board/interact(mob/user as mob) + if(user.incapacitated(INCAPACITATION_DISABLED) || (!isAI(user) && !user.Adjacent(src))) //can't see if you arent conscious. If you are not an AI you can't see it unless you are next to it, either. + user << browse(null, "window=boardgame") + user.unset_machine() + return var/dat = "" dat += "" @@ -68,7 +89,7 @@ obj/item/weapon/board/attackby(obj/item/I as obj, mob/user as mob) dat += "'#66CCFF'>" else dat += "'#252536'>" - dat += "= 0) - if(I) //cant put items on other items. - return + if(!usr.Adjacent(src)) + usr.unset_machine() + usr << browse(null, "window=boardgame") + return + + if(!usr.incapacitated()) //you can't move pieces if you can't move + if(href_list["select"]) + var/s = href_list["select"] + var/obj/item/I = board["[s]"] + if(selected >= 0) + //check to see if clicked on tile is currently selected one + if(text2num(s) == selected) + selected = 0 //deselect it + return + + if(I) //cant put items on other items. + return //put item in new spot. - I = board["[selected]"] + I = board["[selected]"] + board["[selected]"] = null + board -= "[selected]" + board -= null + board["[s]"] = I + selected = -1 + else + if(I) + selected = text2num(s) + else + var/mob/living/carbon/human/H = locate(href_list["person"]) + if(!istype(H)) + return + var/obj/item/O = H.get_active_hand() + if(!O) + return + addPiece(O,H,text2num(s)) + if(href_list["remove"]) + var/obj/item/I = board["[selected]"] board["[selected]"] = null board -= "[selected]" board -= null - board["[s]"] = I + I.forceMove(src.loc) + num-- selected = -1 - else - if(I) - selected = text2num(s) - if(href_list["remove"]) - var/obj/item/I = board["[selected]"] - board["[selected]"] = null - board -= "[selected]" - board -= null - I.forceMove(src.loc) - num-- - selected = -1 - var j - for(j=0;j<64;j++) - if(board["[j]"]) - var/obj/item/K = board["[j]"] - if(K.icon == I.icon && cmptext(K.icon_state,I.icon_state)) - src.updateDialog() - return - //Didn't find it in use, remove it and allow GC to delete it. - board_icons["[I.icon] [I.icon_state]"] = null - board_icons -= "[I.icon] [I.icon_state]" - board_icons -= null + var j + for(j=0;j<64;j++) + if(board["[j]"]) + var/obj/item/K = board["[j]"] + if(K.icon == I.icon && cmptext(K.icon_state,I.icon_state)) + src.updateDialog() + return + //Didn't find it in use, remove it and allow GC to delete it. + board_icons["[I.icon] [I.icon_state]"] = null + board_icons -= "[I.icon] [I.icon_state]" + board_icons -= null src.updateDialog() /obj/item/weapon/checker/