summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-09-27 18:08:51 -0300
committershennetsind <ind@henn.et>2013-09-27 18:08:51 -0300
commitc728c1f7d1ccff7c1a1bcf4b7a4dd4ef15a0b599 (patch)
treebcb4aa49f0b15538c8fdd80b71eeda3b4fb8a2c2 /src
parent6b00c1c8ef7ebe324c6c02f5a9f1abf9eeb3a581 (diff)
downloadhercules-c728c1f7d1ccff7c1a1bcf4b7a4dd4ef15a0b599.tar.gz
hercules-c728c1f7d1ccff7c1a1bcf4b7a4dd4ef15a0b599.tar.bz2
hercules-c728c1f7d1ccff7c1a1bcf4b7a4dd4ef15a0b599.tar.xz
hercules-c728c1f7d1ccff7c1a1bcf4b7a4dd4ef15a0b599.zip
HPM: Elemental.c Completed
Moved missing vars and declarations of interest into the interface, removed duplicate mentions of elemental within calls to shorten wherever it made sense to. And on a minor thing updated the duel.h header given the file had been previously modified (when the duel interface was implemented) Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src')
-rw-r--r--src/map/atcommand.c2
-rw-r--r--src/map/duel.h8
-rw-r--r--src/map/elemental.c102
-rw-r--r--src/map/elemental.h43
-rw-r--r--src/map/map.c4
5 files changed, 100 insertions, 59 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 4f784ecc5..cec314134 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -3561,7 +3561,7 @@ ACMD(reloadmobdb) {
homun->reload();
mercenary->read_db();
mercenary->read_skilldb();
- elemental->reload_elementaldb();
+ elemental->reload_db();
clif->message(fd, msg_txt(98)); // Monster database has been reloaded.
return true;
diff --git a/src/map/duel.h b/src/map/duel.h
index 7802f6163..d1ec58415 100644
--- a/src/map/duel.h
+++ b/src/map/duel.h
@@ -1,5 +1,7 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
+
#ifndef _DUEL_H_
#define _DUEL_H_
@@ -11,8 +13,6 @@ struct duel {
#define MAX_DUEL 1024
-
-
/*=====================================
* Interface : duel.h
* Generated by HerculesInterfaceMaker
diff --git a/src/map/elemental.c b/src/map/elemental.c
index 12e8f4c4e..5a3630c70 100644
--- a/src/map/elemental.c
+++ b/src/map/elemental.c
@@ -39,22 +39,24 @@
#include <string.h>
#include <math.h>
+struct elemental_interface elemental_s;
+
int elemental_search_index(int class_) {
int i;
- ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, elemental->elemental_db[i].class_ == class_);
+ ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, elemental->db[i].class_ == class_);
return (i == MAX_ELEMENTAL_CLASS)?-1:i;
}
bool elemental_class(int class_) {
- return (bool)(elemental_search_index(class_) > -1);
+ return (bool)(elemental->search_index(class_) > -1);
}
struct view_data * elemental_get_viewdata(int class_) {
- int i = elemental_search_index(class_);
+ int i = elemental->search_index(class_);
if( i < 0 )
return 0;
- return &elemental->elemental_db[i].vd;
+ return &elemental->db[i].vd;
}
int elemental_create(struct map_session_data *sd, int class_, unsigned int lifetime) {
@@ -64,10 +66,10 @@ int elemental_create(struct map_session_data *sd, int class_, unsigned int lifet
nullpo_retr(1,sd);
- if( (i = elemental_search_index(class_)) < 0 )
+ if( (i = elemental->search_index(class_)) < 0 )
return 0;
- db = &elemental->elemental_db[i];
+ db = &elemental->db[i];
memset(&ele,0,sizeof(struct s_elemental));
ele.char_id = sd->status.char_id;
@@ -75,27 +77,27 @@ int elemental_create(struct map_session_data *sd, int class_, unsigned int lifet
ele.mode = EL_MODE_PASSIVE; // Initial mode
i = db->status.size+1; // summon level
- //[(Caster�s Max HP/ 3 ) + (Caster�s INT x 10 )+ (Caster�s Job Level x 20 )] x [(Elemental Summon Level + 2) / 3]
+ //[(Caster's Max HP/ 3 ) + (Caster's INT x 10 )+ (Caster's Job Level x 20 )] x [(Elemental Summon Level + 2) / 3]
ele.hp = ele.max_hp = (sd->battle_status.max_hp/3 + sd->battle_status.int_*10 + sd->status.job_level) * ((i + 2) / 3);
- //Caster�s Max SP /4
+ //Caster's Max SP /4
ele.sp = ele.max_sp = sd->battle_status.max_sp/4;
- //Caster�s [ Max SP / (18 / Elemental Summon Skill Level) 1- 100 ]
+ //Caster's [ Max SP / (18 / Elemental Summon Skill Level) 1- 100 ]
ele.atk = (sd->battle_status.max_sp / (18 / i) * 1 - 100);
- //Caster�s [ Max SP / (18 / Elemental Summon Skill Level) ]
+ //Caster's [ Max SP / (18 / Elemental Summon Skill Level) ]
ele.atk2 = sd->battle_status.max_sp / 18;
- //Caster�s HIT + (Caster�s Base Level )
+ //Caster's HIT + (Caster's Base Level)
ele.hit = sd->battle_status.hit + sd->status.base_level;
- //[Elemental Summon Skill Level x (Caster�s INT / 2 + Caster�s DEX / 4)]
+ //[Elemental Summon Skill Level x (Caster's INT / 2 + Caster's DEX / 4)]
ele.matk = i * (sd->battle_status.int_ / 2 + sd->battle_status.dex / 4);
- //150 + [Caster�s DEX / 10] + [Elemental Summon Skill Level x 3 ]
+ //150 + [Caster's DEX / 10] + [Elemental Summon Skill Level x 3 ]
ele.amotion = 150 + sd->battle_status.dex / 10 + i * 3;
- //Caster�s DEF + (Caster�s Base Level / (5 � Elemental Summon Skill Level)
+ //Caster's DEF + (Caster's Base Level / (5 - Elemental Summon Skill Level)
ele.def = sd->battle_status.def + sd->status.base_level / (5-i);
- //Caster�s MDEF + (Caster�s INT / (5 - Elemental Summon Skill Level)
+ //Caster's MDEF + (Caster's INT / (5 - Elemental Summon Skill Level)
ele.mdef = sd->battle_status.mdef + sd->battle_status.int_ / (5-i);
- //Caster�s FLEE + (Caster�s Base Level / (5 � Elemental Summon Skill Level)
+ //Caster's FLEE + (Caster's Base Level / (5 - Elemental Summon Skill Level)
ele.flee = sd->status.base_level / (5-i);
- //Caster�s HIT + (Caster�s Base Level )
+ //Caster's HIT + (Caster's Base Level)
ele.hit = sd->battle_status.hit + sd->status.base_level;
//per individual bonuses
@@ -167,7 +169,7 @@ int elemental_save(struct elemental_data *ed) {
return 1;
}
-static int elemental_summon_end(int tid, unsigned int tick, int id, intptr_t data) {
+int elemental_summon_end_timer(int tid, unsigned int tick, int id, intptr_t data) {
struct map_session_data *sd;
struct elemental_data *ed;
@@ -177,7 +179,7 @@ static int elemental_summon_end(int tid, unsigned int tick, int id, intptr_t dat
return 1;
if( ed->summon_timer != tid ) {
- ShowError("elemental_summon_end %d != %d.\n", ed->summon_timer, tid);
+ ShowError("elemental_summon_end_timer %d != %d.\n", ed->summon_timer, tid);
return 0;
}
@@ -190,7 +192,7 @@ static int elemental_summon_end(int tid, unsigned int tick, int id, intptr_t dat
void elemental_summon_stop(struct elemental_data *ed) {
nullpo_retv(ed);
if( ed->summon_timer != INVALID_TIMER )
- timer->delete(ed->summon_timer, elemental_summon_end);
+ timer->delete(ed->summon_timer, elemental->summon_end_timer);
ed->summon_timer = INVALID_TIMER;
}
@@ -215,7 +217,7 @@ int elemental_delete(struct elemental_data *ed, int reply) {
void elemental_summon_init(struct elemental_data *ed) {
if( ed->summon_timer == INVALID_TIMER )
- ed->summon_timer = timer->add(timer->gettick() + ed->elemental.life_time, elemental_summon_end, ed->master->bl.id, 0);
+ ed->summon_timer = timer->add(timer->gettick() + ed->elemental.life_time, elemental->summon_end_timer, ed->master->bl.id, 0);
ed->regen.state.block = 0;
}
@@ -224,7 +226,7 @@ int elemental_data_received(struct s_elemental *ele, bool flag) {
struct map_session_data *sd;
struct elemental_data *ed;
struct s_elemental_db *db;
- int i = elemental_search_index(ele->class_);
+ int i = elemental->search_index(ele->class_);
if( (sd = map->charid2sd(ele->char_id)) == NULL )
return 0;
@@ -234,7 +236,7 @@ int elemental_data_received(struct s_elemental *ele, bool flag) {
return 0;
}
- db = &elemental->elemental_db[i];
+ db = &elemental->db[i];
if( !sd->ed ) { // Initialize it after first summon.
sd->ed = ed = (struct elemental_data*)aCalloc(1,sizeof(struct elemental_data));
ed->bl.type = BL_ELEM;
@@ -259,7 +261,7 @@ int elemental_data_received(struct s_elemental *ele, bool flag) {
status_calc_elemental(ed,1);
ed->last_spdrain_time = ed->last_thinktime = timer->gettick();
ed->summon_timer = INVALID_TIMER;
- elemental_summon_init(ed);
+ elemental->summon_init(ed);
} else {
memcpy(&sd->ed->elemental, ele, sizeof(struct s_elemental));
ed = sd->ed;
@@ -598,7 +600,7 @@ int elemental_set_target( struct map_session_data *sd, struct block_list *bl ) {
return 1;
}
-static int elemental_ai_sub_timer_activesearch(struct block_list *bl, va_list ap) {
+int elemental_ai_sub_timer_activesearch(struct block_list *bl, va_list ap) {
struct elemental_data *ed;
struct block_list **target;
int dist;
@@ -634,7 +636,7 @@ static int elemental_ai_sub_timer_activesearch(struct block_list *bl, va_list ap
return 0;
}
-static int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_data *sd, unsigned int tick) {
+int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_data *sd, unsigned int tick) {
struct block_list *target = NULL;
int master_dist, view_range, mode;
@@ -713,7 +715,7 @@ static int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_
target = map->id2bl(ed->ud.target);
if( !target )
- map->foreachinrange(elemental_ai_sub_timer_activesearch, &ed->bl, view_range, BL_CHAR, ed, &target, status_get_mode(&ed->bl));
+ map->foreachinrange(elemental->ai_sub_timer_activesearch, &ed->bl, view_range, BL_CHAR, ed, &target, status_get_mode(&ed->bl));
if( !target ) { //No targets available.
elemental->unlocktarget(ed);
@@ -743,16 +745,16 @@ static int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_
return 0;
}
-static int elemental_ai_sub_foreachclient(struct map_session_data *sd, va_list ap) {
+int elemental_ai_sub_foreachclient(struct map_session_data *sd, va_list ap) {
unsigned int tick = va_arg(ap,unsigned int);
if(sd->status.ele_id && sd->ed)
- elemental_ai_sub_timer(sd->ed,sd,tick);
+ elemental->ai_sub_timer(sd->ed,sd,tick);
return 0;
}
-static int elemental_ai_timer(int tid, unsigned int tick, int id, intptr_t data) {
- map->map_foreachpc(elemental_ai_sub_foreachclient,tick);
+int elemental_ai_timer(int tid, unsigned int tick, int id, intptr_t data) {
+ map->map_foreachpc(elemental->ai_sub_foreachclient,tick);
return 0;
}
@@ -765,7 +767,9 @@ int read_elementaldb(void) {
struct status_data *estatus;
sprintf(line, "%s/%s", map->db_path, "elemental_db.txt");
- memset(elemental->elemental_db,0,sizeof(elemental->elemental_db));
+
+ if( runflag == MAPSERVER_ST_RUNNING ) //only necessary after we're up
+ memset(elemental->db,0,sizeof(elemental->db));
fp = fopen(line, "r");
if( !fp ) {
@@ -792,7 +796,7 @@ int read_elementaldb(void) {
continue;
}
- db = &elemental->elemental_db[j];
+ db = &elemental->db[j];
db->class_ = atoi(str[0]);
safestrncpy(db->sprite, str[1], NAME_LENGTH);
safestrncpy(db->name, str[2], NAME_LENGTH);
@@ -882,7 +886,7 @@ int read_elemental_skilldb(void) {
}
class_ = atoi(str[0]);
- ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, class_ == elemental->elemental_db[i].class_);
+ ARR_FIND(0, MAX_ELEMENTAL_CLASS, i, class_ == elemental->db[i].class_);
if( i == MAX_ELEMENTAL_CLASS ) {
ShowError("read_elemental_skilldb : Class not found in elemental_db for skill entry, line %d.\n", k);
continue;
@@ -894,7 +898,7 @@ int read_elemental_skilldb(void) {
continue;
}
- db = &elemental->elemental_db[i];
+ db = &elemental->db[i];
skill_lv = atoi(str[2]);
skillmode = atoi(str[3]);
@@ -919,7 +923,7 @@ int read_elemental_skilldb(void) {
}
void reload_elementaldb(void) {
- read_elementaldb();
+ elemental->read_db();
elemental->reload_skilldb();
}
@@ -928,11 +932,11 @@ void reload_elemental_skilldb(void) {
}
int do_init_elemental(void) {
- read_elementaldb();
+ elemental->read_db();
elemental->read_skilldb();
- timer->add_func_list(elemental_ai_timer,"elemental_ai_timer");
- timer->add_interval(timer->gettick()+MIN_ELETHINKTIME,elemental_ai_timer,0,0,MIN_ELETHINKTIME);
+ timer->add_func_list(elemental->ai_timer,"elemental_ai_timer");
+ timer->add_interval(timer->gettick()+MIN_ELETHINKTIME,elemental->ai_timer,0,0,MIN_ELETHINKTIME);
return 0;
}
@@ -949,6 +953,13 @@ void do_final_elemental(void) {
void elemental_defaults(void) {
elemental = &elemental_s;
+ /* */
+ elemental->init = do_init_elemental;
+ elemental->final = do_final_elemental;
+
+ /* */
+ memset(elemental->db,0,sizeof(elemental->db));
+
/* funcs */
elemental->class = elemental_class;
@@ -978,8 +989,15 @@ void elemental_defaults(void) {
elemental->skill_get_requirements = elemental_skill_get_requirements;
elemental->read_skilldb = read_elemental_skilldb;
- elemental->reload_elementaldb = reload_elementaldb;
+ elemental->reload_db = reload_elementaldb;
elemental->reload_skilldb = reload_elemental_skilldb;
- elemental->do_init_elemental = do_init_elemental;
- elemental->do_final_elemental = do_final_elemental;
+
+ elemental->search_index = elemental_search_index;
+ elemental->summon_init = elemental_summon_init;
+ elemental->summon_end_timer = elemental_summon_end_timer;
+ elemental->ai_sub_timer_activesearch = elemental_ai_sub_timer_activesearch;
+ elemental->ai_sub_timer = elemental_ai_sub_timer;
+ elemental->ai_sub_foreachclient = elemental_ai_sub_foreachclient;
+ elemental->ai_timer = elemental_ai_timer;
+ elemental->read_db = read_elementaldb;
}
diff --git a/src/map/elemental.h b/src/map/elemental.h
index ccc3bcb5f..b42d5c0b7 100644
--- a/src/map/elemental.h
+++ b/src/map/elemental.h
@@ -1,9 +1,16 @@
-// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
-// For more information, see LICENCE in the main folder
+// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
+
#ifndef _ELEMENTAL_H_
#define _ELEMENTAL_H_
+
#include "status.h" // struct status_data, struct status_change
#include "unit.h" // struct unit_data
+
+/**
+ * Defines
+ **/
#define MIN_ELETHINKTIME 100
#define MIN_ELEDISTANCE 2
#define MAX_ELEDISTANCE 5
@@ -13,10 +20,18 @@
#define EL_SKILLMODE_PASIVE 0x1
#define EL_SKILLMODE_ASSIST 0x2
#define EL_SKILLMODE_AGGRESSIVE 0x4
+
+#define elemental_stop_walking(ed, type) unit->stop_walking(&(ed)->bl, type)
+#define elemental_stop_attack(ed) unit->stop_attack(&(ed)->bl)
+
+/**
+ * Structures
+ **/
struct elemental_skill {
unsigned short id, lv;
short mode;
};
+
struct s_elemental_db {
int class_;
char sprite[NAME_LENGTH], name[NAME_LENGTH];
@@ -26,6 +41,7 @@ struct s_elemental_db {
struct view_data vd;
struct elemental_skill skill[MAX_ELESKILLTREE];
};
+
struct elemental_data {
struct block_list bl;
struct unit_data ud;
@@ -46,9 +62,6 @@ struct elemental_data {
int target_id, attacked_id;
};
-#define elemental_stop_walking(ed, type) unit->stop_walking(&(ed)->bl, type)
-#define elemental_stop_attack(ed) unit->stop_attack(&(ed)->bl)
-
/*=====================================
* Interface : elemental.h
* Generated by HerculesInterfaceMaker
@@ -57,8 +70,11 @@ struct elemental_data {
struct elemental_interface {
/* vars */
- struct s_elemental_db elemental_db[MAX_ELEMENTAL_CLASS]; // Elemental Database
+ struct s_elemental_db db[MAX_ELEMENTAL_CLASS]; // Elemental Database
+ /* */
+ int (*init) (void);
+ void (*final) (void);
/* funcs */
bool (*class) (int class_);
struct view_data * (*get_viewdata) (int class_);
@@ -87,11 +103,18 @@ struct elemental_interface {
struct skill_condition (*skill_get_requirements) (uint16 skill_id, uint16 skill_lv);
int (*read_skilldb) (void);
- void (*reload_elementaldb) (void);
+ void (*reload_db) (void);
void (*reload_skilldb) (void);
- int (*do_init_elemental) (void);
- void (*do_final_elemental) (void);
-} elemental_s;
+
+ int (*search_index) (int class_);
+ void (*summon_init) (struct elemental_data *ed);
+ int (*summon_end_timer) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*ai_sub_timer_activesearch) (struct block_list *bl, va_list ap);
+ int (*ai_sub_timer) (struct elemental_data *ed, struct map_session_data *sd, unsigned int tick);
+ int (*ai_sub_foreachclient) (struct map_session_data *sd, va_list ap);
+ int (*ai_timer) (int tid, unsigned int tick, int id, intptr_t data);
+ int (*read_db) (void);
+};
struct elemental_interface *elemental;
diff --git a/src/map/map.c b/src/map/map.c
index 09defc75a..8641f7011 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -4918,7 +4918,7 @@ void do_final(void)
unit->final();
bg->final();
duel->final();
- elemental->do_final_elemental();
+ elemental->final();
do_final_maps();
vending->final();
@@ -5393,7 +5393,7 @@ int do_init(int argc, char *argv[])
pet->init();
homun->init();
mercenary->init();
- elemental->do_init_elemental();
+ elemental->init();
quest->init();
npc->init();
unit->init();