summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/chrif.c2
-rw-r--r--src/map/clif.c2
-rw-r--r--src/map/mercenary.c26
-rw-r--r--src/map/mercenary.h1
-rw-r--r--src/map/unit.c5
5 files changed, 19 insertions, 17 deletions
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 2fc1b9dbe..7ff0c12e6 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -286,7 +286,7 @@ int chrif_save(struct map_session_data *sd, int flag)
intif_save_petdata(sd->status.account_id,&sd->pd->pet);
if( sd->hd && merc_is_hom_active(sd->hd) )
merc_save(sd->hd);
- if( sd->md && sd->md->mercenary.remain_life_time > 0 )
+ if( sd->md && mercenary_get_lifetime(sd->md) > 0 )
mercenary_save(sd->md);
return 0;
diff --git a/src/map/clif.c b/src/map/clif.c
index c56fc3f26..67ab85b39 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -12434,7 +12434,7 @@ void clif_mercenary_info(struct map_session_data *sd)
WFIFOL(fd,52) = status->max_hp;
WFIFOL(fd,56) = status->sp;
WFIFOL(fd,60) = status->max_sp;
- WFIFOL(fd,64) = (int)time(NULL) + (md->mercenary.remain_life_time / 1000);
+ WFIFOL(fd,64) = (int)time(NULL) + (mercenary_get_lifetime(md) / 1000);
WFIFOW(fd,68) = 0; // Loyalty
WFIFOL(fd,70) = 0; // Summon Count
WFIFOL(fd,74) = md->mercenary.kill_count;
diff --git a/src/map/mercenary.c b/src/map/mercenary.c
index 08a640275..bcbba3dd1 100644
--- a/src/map/mercenary.c
+++ b/src/map/mercenary.c
@@ -76,7 +76,7 @@ int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime)
merc.class_ = class_;
merc.hp = db->status.max_hp;
merc.sp = db->status.max_sp;
- merc.remain_life_time = lifetime;
+ merc.life_time = lifetime;
// Request Char Server to create this mercenary
intif_mercenary_create(&merc);
@@ -84,19 +84,21 @@ int merc_create(struct map_session_data *sd, int class_, unsigned int lifetime)
return 1;
}
-int mercenary_save(struct mercenary_data *md)
+int mercenary_get_lifetime(struct mercenary_data *md)
{
- const struct TimerData * td = get_timer(md->contract_timer);
+ const struct TimerData * td;
+ if( md == NULL )
+ return 0;
+ td = get_timer(md->contract_timer);
+ return (td != NULL) ? DIFF_TICK(td->tick, gettick()) : 0;
+}
+
+int mercenary_save(struct mercenary_data *md)
+{
md->mercenary.hp = md->battle_status.hp;
md->mercenary.sp = md->battle_status.sp;
- if( td != NULL )
- md->mercenary.remain_life_time = DIFF_TICK(td->tick, gettick());
- else
- {
- md->mercenary.remain_life_time = 0;
- ShowWarning("mercenary_save : mercenary without timer (tid %d)\n", md->contract_timer);
- }
+ md->mercenary.life_time = mercenary_get_lifetime(md);
intif_mercenary_save(&md->mercenary);
return 1;
@@ -127,7 +129,7 @@ static int merc_contract_end(int tid, unsigned int tick, int id, intptr data)
int merc_delete(struct mercenary_data *md, int reply)
{
struct map_session_data *sd = md->master;
- md->mercenary.remain_life_time = 0;
+ md->mercenary.life_time = 0;
merc_contract_stop(md);
@@ -149,7 +151,7 @@ void merc_contract_stop(struct mercenary_data *md)
void merc_contract_init(struct mercenary_data *md)
{
if( md->contract_timer == INVALID_TIMER )
- md->contract_timer = add_timer(gettick() + md->mercenary.remain_life_time, merc_contract_end, md->master->bl.id, 0);
+ md->contract_timer = add_timer(gettick() + md->mercenary.life_time, merc_contract_end, md->master->bl.id, 0);
md->regen.state.block = 0;
}
diff --git a/src/map/mercenary.h b/src/map/mercenary.h
index 0579cc2bf..9c65b19e7 100644
--- a/src/map/mercenary.h
+++ b/src/map/mercenary.h
@@ -47,5 +47,6 @@ int mercenary_dead(struct mercenary_data *md, struct block_list *src);
int do_init_mercenary(void);
int merc_delete(struct mercenary_data *md, int reply);
void merc_contract_stop(struct mercenary_data *md);
+int mercenary_get_lifetime(struct mercenary_data *md);
#endif /* _MERCENARY_H_ */
diff --git a/src/map/unit.c b/src/map/unit.c
index c1fb60031..59924a108 100644
--- a/src/map/unit.c
+++ b/src/map/unit.c
@@ -1850,14 +1850,13 @@ int unit_remove_map_(struct block_list *bl, int clrtype, const char* file, int l
map_freeblock_unlock();
return 0;
}
-
break;
}
case BL_MER:
{
struct mercenary_data *md = (struct mercenary_data *)bl;
ud->canact_tick = ud->canmove_tick;
- if( !md->mercenary.remain_life_time && !(md->master && !md->master->state.active) )
+ if( mercenary_get_lifetime(md) <= 0 && !(md->master && !md->master->state.active) )
{
clif_clearunit_area(bl,clrtype);
map_delblock(bl);
@@ -2097,7 +2096,7 @@ int unit_free(struct block_list *bl, int clrtype)
struct map_session_data *sd = md->master;
if( clrtype >= 0 )
{
- if( md->mercenary.remain_life_time > 0 )
+ if( mercenary_get_lifetime(md) > 0 )
mercenary_save(md);
else
{