From 6aa6efb720d12f88a0e0ec335b80b129ea4f2b53 Mon Sep 17 00:00:00 2001 From: Juliano Leal Goncalves Date: Sun, 30 May 2021 19:22:51 -0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Extract=20item=20position?= =?UTF-8?q?=20generation=20logic=20to=20common=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/items.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/Source/items.cpp b/Source/items.cpp index 8b5ff39a5..4f4bf2593 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -438,24 +438,29 @@ bool ItemPlace(int xp, int yp) return true; } +Point GetRandomAvailableItemPosition() +{ + Point position = {}; + do { + position = Point { 16, 16 } + Point { GenerateRnd(80), GenerateRnd(80) }; + } while (!ItemPlace(position.x, position.y)); + + return position; +} + void AddInitItems() { - int x, y, j, rnd; + int j, rnd; int curlv = items_get_currlevel(); rnd = GenerateRnd(3) + 3; for (j = 0; j < rnd; j++) { int ii = AllocateItem(); - x = GenerateRnd(80) + 16; - y = GenerateRnd(80) + 16; - while (!ItemPlace(x, y)) { - x = GenerateRnd(80) + 16; - y = GenerateRnd(80) + 16; - } - items[ii].position = { x, y }; + Point position = GetRandomAvailableItemPosition(); + items[ii].position = position; - dItem[x][y] = ii + 1; + dItem[position.x][position.y] = ii + 1; items[ii]._iSeed = AdvanceRndSeed(); @@ -475,14 +480,8 @@ void AddInitItems() static void items_42390F() { - int x, y, id; - - x = GenerateRnd(80) + 16; - y = GenerateRnd(80) + 16; - while (!ItemPlace(x, y)) { - x = GenerateRnd(80) + 16; - y = GenerateRnd(80) + 16; - } + int id; + switch (currlevel) { case 22: id = IDI_NOTE2; @@ -494,7 +493,9 @@ static void items_42390F() id = IDI_NOTE1; break; } - SpawnQuestItem(id, { x, y }, 0, 1); + + Point position = GetRandomAvailableItemPosition(); + SpawnQuestItem(id, position, 0, 1); } void InitItems()