From d0ebdc80451d554db35986c108b1e2e6e9dffb82 Mon Sep 17 00:00:00 2001 From: Yaroslav Nurkov <78199449+AnywayFarus@users.noreply.github.com> Date: Sat, 4 Sep 2021 19:59:30 +0300 Subject: [PATCH] Feat: add keybinds to AI for saved locs (Shift + num) (#327) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * AI: Создание биндов для локаций камер * Update code/modules/keybindings/bindings_ai.dm * Update code/modules/keybindings/bindings_ai.dm * Update code/modules/keybindings/bindings_ai.dm * Update code/modules/keybindings/bindings_ai.dm * Update code/modules/keybindings/bindings_ai.dm * больше процов богу процов. * Убран лишний дебаг текст, заменен тип сообщения. * Refine code * clean whitespaces * fix var typo and clean up logic Co-authored-by: Aziz Chynaliev Fix AI camera cycle logic for keybinds --- code/modules/keybindings/bindings_ai.dm | 61 +++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/code/modules/keybindings/bindings_ai.dm b/code/modules/keybindings/bindings_ai.dm index 975b5ba81a96..1ad4cdc9d345 100644 --- a/code/modules/keybindings/bindings_ai.dm +++ b/code/modules/keybindings/bindings_ai.dm @@ -1,6 +1,59 @@ +/mob/living/silicon/ai/var/current_camera = 0 + /mob/living/silicon/ai/key_down(_key, client/user) - switch(_key) - if("4") - a_intent_change(INTENT_HOTKEY_LEFT) + if(user.keys_held["Shift"]) + if(text2num(_key) != null) + if(set_camera_by_index(user, text2num(_key))) + update_binded_camera(user) return - return ..() + return ..() + else + switch(_key) + if("4") + a_intent_change(INTENT_HOTKEY_LEFT) + return + if("N") + if(check_for_binded_cameras(user)) + current_camera_next(user) + update_binded_camera(user) + return + if("B") + if(check_for_binded_cameras(user)) + current_camera_back(user) + update_binded_camera(user) + return + return ..() + +/mob/living/silicon/ai/proc/check_for_binded_cameras(client/user) + if(!length(stored_locations)) + to_chat(user, "You have no stored camera positions") + return 0 + return 1 + +/mob/living/silicon/ai/proc/set_camera_by_index(client/user, var/camnum) + var/camnum_length = length(stored_locations) + if(camnum > camnum_length || (camnum == 0 && camnum_length < 10)) + to_chat(user, "You have no stored camera on [camnum] position") + return 0 + if(camnum == 0) + camnum = 10 + current_camera = camnum + return 1 + +/mob/living/silicon/ai/proc/update_binded_camera(client/user) + var/camname + camname = stored_locations[current_camera] + ai_goto_location(camname) + to_chat(user, "Now you on camera position: [camname]") + +/mob/living/silicon/ai/proc/current_camera_next(client/user) + if(current_camera >= length(stored_locations)) + current_camera = 1 + else + current_camera += 1 + +/mob/living/silicon/ai/proc/current_camera_back(client/user) + if(current_camera <= 1) + current_camera = length(stored_locations) + else + current_camera -= 1