From ed5561b7965118fc11ae278e968c3de08eae98a7 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 8 Apr 2016 23:58:35 +0300 Subject: In debugspawn check clones positions and not spawn them outside of map. --- src/actions/commands.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/actions/commands.cpp') diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index 529025481..5fe0f1b08 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -75,6 +75,8 @@ #include "resources/db/itemdb.h" +#include "resources/map/map.h" + #include "utils/chatutils.h" #include "utils/gettext.h" #include "utils/gmfunctions.h" @@ -842,13 +844,25 @@ impHandler(hack) impHandler(debugSpawn) { + if (!localPlayer) + return false; int cnt = atoi(event.args.c_str()); if (cnt < 1) cnt = 1; const int half = cnt / 2; - for (int x = -half; x < cnt - half; x ++) - { - for (int y = -half; y < cnt - half; y ++) + const Map *const map = localPlayer->getMap(); + int x1 = -half; + if (x1 < 0) + x1 = 0; + int y1 = x1; + int x2 = cnt - half; + if (x2 > map->getWidth()) + x2 = map->getWidth(); + int y2 = x2; + + for (int x = x1; x < x2; x ++) + { + for (int y = y1; y < y2; y ++) ActorManager::cloneBeing(localPlayer, x, y, cnt); } return true; -- cgit v1.2.3-60-g2f50