summaryrefslogtreecommitdiff
path: root/src/char/int_mercenary.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-02-22 01:09:54 +0100
committerHaru <haru@dotalux.com>2016-02-24 19:40:31 +0100
commit1a0ad427708a010992321efbcdca90150b9e3f8b (patch)
treec10b29e4ee666bc391949f081add7ad659560b1b /src/char/int_mercenary.c
parent95e6e3e2437dafcaa270a3891821d13a54107c94 (diff)
downloadhercules-1a0ad427708a010992321efbcdca90150b9e3f8b.tar.gz
hercules-1a0ad427708a010992321efbcdca90150b9e3f8b.tar.bz2
hercules-1a0ad427708a010992321efbcdca90150b9e3f8b.tar.xz
hercules-1a0ad427708a010992321efbcdca90150b9e3f8b.zip
Split mapif->mercenary_save() into two functions (save and create)
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/char/int_mercenary.c')
-rw-r--r--src/char/int_mercenary.c59
1 files changed, 39 insertions, 20 deletions
diff --git a/src/char/int_mercenary.c b/src/char/int_mercenary.c
index 2ed45305c..133dcf565 100644
--- a/src/char/int_mercenary.c
+++ b/src/char/int_mercenary.c
@@ -94,32 +94,51 @@ bool inter_mercenary_owner_delete(int char_id)
return true;
}
-bool mapif_mercenary_save(struct s_mercenary* merc)
+/**
+ * Creates a new mercenary with the given data.
+ *
+ * @remark
+ * The mercenary ID is expected to be 0, and will be filled with the newly
+ * assigned ID.
+ *
+ * @param[in,out] merc The new mercenary's data.
+ * @retval false in case of errors.
+ */
+bool mapif_mercenary_create(struct s_mercenary *merc)
{
- bool flag = true;
+ nullpo_retr(false, merc);
+ Assert_retr(false, merc->mercenary_id == 0);
- nullpo_ret(merc);
- if( merc->mercenary_id == 0 )
- { // Create new DB entry
- if( SQL_ERROR == SQL->Query(inter->sql_handle,
+ if (SQL_ERROR == SQL->Query(inter->sql_handle,
"INSERT INTO `%s` (`char_id`,`class`,`hp`,`sp`,`kill_counter`,`life_time`) VALUES ('%d','%d','%d','%d','%u','%u')",
- mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time) )
- {
- Sql_ShowDebug(inter->sql_handle);
- flag = false;
- }
- else
- merc->mercenary_id = (int)SQL->LastInsertId(inter->sql_handle);
+ mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time)) {
+ Sql_ShowDebug(inter->sql_handle);
+ return false;
}
- else if( SQL_ERROR == SQL->Query(inter->sql_handle,
- "UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'",
- mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id) )
- { // Update DB entry
+ merc->mercenary_id = (int)SQL->LastInsertId(inter->sql_handle);
+
+ return true;
+}
+
+/**
+ * Saves an existing mercenary.
+ *
+ * @param merc The mercenary's data.
+ * @retval false in case of errors.
+ */
+bool mapif_mercenary_save(const struct s_mercenary *merc)
+{
+ nullpo_retr(false, merc);
+ Assert_retr(false, merc->mercenary_id > 0);
+
+ if (SQL_ERROR == SQL->Query(inter->sql_handle,
+ "UPDATE `%s` SET `char_id` = '%d', `class` = '%d', `hp` = '%d', `sp` = '%d', `kill_counter` = '%u', `life_time` = '%u' WHERE `mer_id` = '%d'",
+ mercenary_db, merc->char_id, merc->class_, merc->hp, merc->sp, merc->kill_count, merc->life_time, merc->mercenary_id)) {
Sql_ShowDebug(inter->sql_handle);
- flag = false;
+ return false;
}
- return flag;
+ return true;
}
bool mapif_mercenary_load(int merc_id, int char_id, struct s_mercenary *merc)
@@ -181,7 +200,7 @@ void mapif_mercenary_send(int fd, struct s_mercenary *merc, unsigned char flag)
void mapif_parse_mercenary_create(int fd, struct s_mercenary* merc)
{
- bool result = mapif->mercenary_save(merc);
+ bool result = mapif->mercenary_create(merc);
mapif->mercenary_send(fd, merc, result);
}