summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-07-31 19:44:17 +0300
committerAndrei Karas <akaras@inbox.ru>2016-07-31 19:44:17 +0300
commit48ce547ec3ead9228f81404c7abf4ee99dbe2819 (patch)
tree20d0f2e21b729a7f59cece8b2c1102ca569bb166 /src
parent1a4218d46ecbed547be1a6849448bbfa3ef82bf3 (diff)
downloadplugin-48ce547ec3ead9228f81404c7abf4ee99dbe2819.tar.gz
plugin-48ce547ec3ead9228f81404c7abf4ee99dbe2819.tar.bz2
plugin-48ce547ec3ead9228f81404c7abf4ee99dbe2819.tar.xz
plugin-48ce547ec3ead9228f81404c7abf4ee99dbe2819.zip
Use VECTOR for allowed cards array.
Diffstat (limited to 'src')
-rw-r--r--src/emap/data/itemd.c2
-rw-r--r--src/emap/itemdb.c16
-rw-r--r--src/emap/pc.c14
-rw-r--r--src/emap/struct/itemdext.h2
4 files changed, 23 insertions, 11 deletions
diff --git a/src/emap/data/itemd.c b/src/emap/data/itemd.c
index 2a4ba80..d7817e5 100644
--- a/src/emap/data/itemd.c
+++ b/src/emap/data/itemd.c
@@ -71,7 +71,7 @@ struct ItemdExt *itemd_create(void)
data->dropScript = NULL;
data->takeScript = NULL;
data->insertScript = NULL;
- memset(&data->allowedCards, 0, sizeof(data->allowedCards));
+ VECTOR_INIT(data->allowedCards);
data->subX = 8;
data->subY = 8;
return data;
diff --git a/src/emap/itemdb.c b/src/emap/itemdb.c
index 0c2ca9d..3a90eab 100644
--- a/src/emap/itemdb.c
+++ b/src/emap/itemdb.c
@@ -9,6 +9,7 @@
#include "common/conf.h"
#include "common/HPMi.h"
+#include "common/db.h"
#include "common/memmgr.h"
#include "common/mmo.h"
#include "common/socket.h"
@@ -140,22 +141,27 @@ void eitemdb_readdb_additional_fields_pre(int *itemid,
{
int idx = 0;
struct config_setting_t *it2 = NULL;
- int cnt = 0;
+ int cnt = VECTOR_LENGTH(data->allowedCards);
while ((it2 = libconfig->setting_get_elem(group, idx ++)))
{
const char *name = config_setting_name(it2);
if (name && strncmp(name, "id", 2) && strncmp(name, "Id", 2))
continue;
const int val = libconfig->setting_get_int(it2);
+
+ VECTOR_ENSURE(data->allowedCards, cnt + 1, 1);
+ VECTOR_INSERTZEROED(data->allowedCards, cnt);
+ struct ItemCardExt *allowedCard = &VECTOR_INDEX(data->allowedCards, cnt);
+
if (name)
{
- data->allowedCards[cnt].id = atoi(name + 2);
- data->allowedCards[cnt].amount = val;
+ allowedCard->id = atoi(name + 2);
+ allowedCard->amount = val;
}
else
{
- data->allowedCards[cnt].id = val;
- data->allowedCards[cnt].amount = 1;
+ allowedCard->id = val;
+ allowedCard->amount = 1;
}
cnt ++;
}
diff --git a/src/emap/pc.c b/src/emap/pc.c
index 898ea28..8980662 100644
--- a/src/emap/pc.c
+++ b/src/emap/pc.c
@@ -462,17 +462,23 @@ bool epc_can_insert_card_into_post(bool retVal,
if (!sd)
return retVal;
struct ItemdExt *data = itemd_get(sd->inventory_data[idx_equip]);
- if (!data || !data->allowedCards[0].id) // allow cards if AllowedCards list is empty
+ if (!data)
+ return retVal;
+
+ const int sz = VECTOR_LENGTH(data->allowedCards);
+
+ if (sz == 0) // allow cards if AllowedCards list is empty
return retVal;
const int newCardId = sd->status.inventory[idx_card].nameid;
int cardAmountLimit = 0;
- for (f = 0; f < 100 && data->allowedCards[f].id; f ++)
+ for (f = 0; f < sz; f ++)
{
- if (data->allowedCards[f].id == newCardId)
+ struct ItemCardExt *const card = &VECTOR_INDEX(data->allowedCards, f);
+ if (card->id == newCardId)
{
- cardAmountLimit = data->allowedCards[f].amount;
+ cardAmountLimit = card->amount;
break;
}
}
diff --git a/src/emap/struct/itemdext.h b/src/emap/struct/itemdext.h
index 2ce9e61..6a8d2c0 100644
--- a/src/emap/struct/itemdext.h
+++ b/src/emap/struct/itemdext.h
@@ -34,7 +34,7 @@ struct ItemdExt
int unequipEffect;
int unequipFailEffect;
- struct ItemCardExt allowedCards[100];
+ VECTOR_DECL(struct ItemCardExt) allowedCards;
struct script_code *dropScript;
struct script_code *takeScript;
struct script_code *insertScript;