Browse Source

Refactored Monster Mode
* Refactored all monster mode checks to use the enum e_mode.
* Created elemental_skillmode enum to separate usage from monster mode enum.
* Renamed EL_SKILLMODE_PASIVE -> EL_SKILLMODE_PASSIVE.
* elemental_change_mode() will now return the proper value from elemental_change_mode_ack().

aleos89 9 years ago
parent
commit
d512f1588c
7 changed files with 39 additions and 30 deletions
  1. 14 10
      src/map/elemental.c
  2. 9 6
      src/map/elemental.h
  3. 7 6
      src/map/mob.c
  4. 1 1
      src/map/mob.h
  5. 2 1
      src/map/script.c
  6. 1 1
      src/map/skill.c
  7. 5 5
      src/map/status.c

+ 14 - 10
src/map/elemental.c

@@ -461,7 +461,7 @@ int elemental_action(struct elemental_data *ed, struct block_list *bl, unsigned
  * Action that elemental perform after changing mode.
  * Activates one of the skills of the new mode.
  *-------------------------------------------------------------*/
-int elemental_change_mode_ack(struct elemental_data *ed, int mode) {
+int elemental_change_mode_ack(struct elemental_data *ed, enum elemental_skillmode skill_mode) {
 	struct block_list *bl = &ed->master->bl;
 	uint16 skill_id, skill_lv;
 	int i;
@@ -472,7 +472,7 @@ int elemental_change_mode_ack(struct elemental_data *ed, int mode) {
 		return 0;
 
 	// Select a skill.
-	ARR_FIND(0, MAX_ELESKILLTREE, i, ed->db->skill[i].id && (ed->db->skill[i].mode&mode));
+	ARR_FIND(0, MAX_ELESKILLTREE, i, ed->db->skill[i].id && (ed->db->skill[i].mode&skill_mode));
 	if( i == MAX_ELESKILLTREE )
 		return 0;
 
@@ -503,7 +503,9 @@ int elemental_change_mode_ack(struct elemental_data *ed, int mode) {
 /*===============================================================
  * Change elemental mode.
  *-------------------------------------------------------------*/
-int elemental_change_mode(struct elemental_data *ed, int mode) {
+int elemental_change_mode(struct elemental_data *ed, enum e_mode mode) {
+	enum elemental_skillmode skill_mode;
+
 	nullpo_ret(ed);
 
 	// Remove target
@@ -515,13 +517,14 @@ int elemental_change_mode(struct elemental_data *ed, int mode) {
 	ed->battle_status.mode = ed->elemental.mode = mode;
 
 	// Normalize elemental mode to elemental skill mode.
-	if( mode == EL_MODE_AGGRESSIVE ) mode = EL_SKILLMODE_AGGRESSIVE;	// Aggressive spirit mode -> Aggressive spirit skill.
-	else if( mode == EL_MODE_ASSIST ) mode = EL_SKILLMODE_ASSIST;		// Assist spirit mode -> Assist spirit skill.
-	else mode = EL_SKILLMODE_PASIVE;									// Passive spirit mode -> Passive spirit skill.
+	if( mode == EL_MODE_AGGRESSIVE ) skill_mode = EL_SKILLMODE_AGGRESSIVE;	// Aggressive spirit mode -> Aggressive spirit skill.
+	else if( mode == EL_MODE_ASSIST ) skill_mode = EL_SKILLMODE_ASSIST;		// Assist spirit mode -> Assist spirit skill.
+	else skill_mode = EL_SKILLMODE_PASSIVE;									// Passive spirit mode -> Passive spirit skill.
 
 	// Use a skill inmediately after every change mode.
-	if( mode != EL_SKILLMODE_AGGRESSIVE )
-		elemental_change_mode_ack(ed,mode);
+	if( skill_mode != EL_SKILLMODE_AGGRESSIVE )
+		return elemental_change_mode_ack(ed, skill_mode);
+
 	return 1;
 }
 
@@ -627,7 +630,8 @@ static int elemental_ai_sub_timer_activesearch(struct block_list *bl, va_list ap
 
 static 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;
+	int master_dist, view_range;
+	enum e_mode mode;
 
 	nullpo_ret(ed);
 	nullpo_ret(sd);
@@ -848,7 +852,7 @@ static bool read_elemental_skilldb_sub(char* str[], int columns, int current) {
 	skill_lv = atoi(str[2]);
 
 	skillmode = atoi(str[3]);
-	if( skillmode < EL_SKILLMODE_PASIVE || skillmode > EL_SKILLMODE_AGGRESSIVE ) {
+	if( skillmode < EL_SKILLMODE_PASSIVE || skillmode > EL_SKILLMODE_AGGRESSIVE ) {
 		ShowError("read_elemental_skilldb_sub: Skillmode out of range, line %d.\n",current);
 		return false;
 	}

+ 9 - 6
src/map/elemental.h

@@ -15,11 +15,14 @@
 #define EL_MODE_ASSIST (MD_CANMOVE|MD_ASSIST)
 #define EL_MODE_PASSIVE MD_CANMOVE
 
-#define EL_SKILLMODE_PASIVE 0x1
-#define EL_SKILLMODE_ASSIST 0x2
-#define EL_SKILLMODE_AGGRESSIVE 0x4
+///Enum of Elemental Skill Mode
+enum elemental_skillmode {
+	EL_SKILLMODE_PASSIVE    = 0x1,
+	EL_SKILLMODE_ASSIST     = 0x2,
+	EL_SKILLMODE_AGGRESSIVE = 0x4,
+};
 
-///Enum of ELemental ID
+///Enum of Elemental ID
 enum elemental_elementalid {
 	ELEMENTALID_AGNI_S = 2114,
 	ELEMENTALID_AGNI_M,
@@ -80,8 +83,8 @@ int elemental_create(struct map_session_data *sd, int class_, unsigned int lifet
 int elemental_data_received(struct s_elemental *ele, bool flag);
 int elemental_save(struct elemental_data *ed);
 
-int elemental_change_mode_ack(struct elemental_data *ed, int mode);
-int elemental_change_mode(struct elemental_data *ed, int mode);
+int elemental_change_mode_ack(struct elemental_data *ed, enum elemental_skillmode skill_mode);
+int elemental_change_mode(struct elemental_data *ed, enum e_mode mode);
 
 void elemental_heal(struct elemental_data *ed, int hp, int sp);
 int elemental_dead(struct elemental_data *ed);

+ 7 - 6
src/map/mob.c

@@ -884,7 +884,8 @@ int mob_delayspawn(int tid, unsigned int tick, int id, intptr_t data)
  *------------------------------------------*/
 int mob_setdelayspawn(struct mob_data *md)
 {
-	unsigned int spawntime, mode;
+	unsigned int spawntime;
+	enum e_mode mode;
 	struct mob_db *db;
 
 	if (!md->spawn) //Doesn't has respawn data!
@@ -1033,7 +1034,7 @@ int mob_spawn (struct mob_data *md)
 /*==========================================
  * Determines if the mob can change target. [Skotlex]
  *------------------------------------------*/
-static int mob_can_changetarget(struct mob_data* md, struct block_list* target, int mode)
+static int mob_can_changetarget(struct mob_data* md, struct block_list* target, enum e_mode mode)
 {
 	// if the monster was provoked ignore the above rule [celest]
 	if(md->state.provoke_flag)
@@ -1095,13 +1096,13 @@ static int mob_ai_sub_hard_activesearch(struct block_list *bl,va_list ap)
 {
 	struct mob_data *md;
 	struct block_list **target;
-	int mode;
+	enum e_mode mode;
 	int dist;
 
 	nullpo_ret(bl);
 	md=va_arg(ap,struct mob_data *);
 	target= va_arg(ap,struct block_list**);
-	mode= va_arg(ap,int);
+	mode= va_arg(ap,enum e_mode);
 
 	//If can't seek yet, not an enemy, or you can't attack it, skip.
 	if ((*target) == bl || !status_check_skilluse(&md->bl, bl, 0, 0))
@@ -1468,7 +1469,7 @@ int mob_warpchase(struct mob_data *md, struct block_list *target)
 static bool mob_ai_sub_hard(struct mob_data *md, unsigned int tick)
 {
 	struct block_list *tbl = NULL, *abl = NULL;
-	int mode;
+	enum e_mode mode;
 	int view_range, can_move;
 
 	if(md->bl.prev == NULL || md->status.hp == 0)
@@ -3508,7 +3509,7 @@ int mob_is_clone(int mob_id)
 //If mode is not passed, a default aggressive mode is used.
 //If master_id is passed, clone is attached to him.
 //Returns: ID of newly crafted copy.
-int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, int mode, int flag, unsigned int duration)
+int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, enum e_mode mode, int flag, unsigned int duration)
 {
 	int mob_id;
 	int i,j,inf, fd;

+ 1 - 1
src/map/mob.h

@@ -323,7 +323,7 @@ int mob_count_sub(struct block_list *bl, va_list ap);
 
 int mob_is_clone(int mob_id);
 
-int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, int mode, int flag, unsigned int duration);
+int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, enum e_mode mode, int flag, unsigned int duration);
 int mob_clone_delete(struct mob_data *md);
 
 void mob_reload(void);

+ 2 - 1
src/map/script.c

@@ -9956,7 +9956,8 @@ BUILDIN_FUNC(clone)
 {
 	TBL_PC *sd, *msd=NULL;
 	uint32 char_id;
-	int master_id=0,x,y, mode = 0, flag = 0, m;
+	int master_id=0,x,y, flag = 0, m;
+	enum e_mode mode;
 	unsigned int duration = 0;
 	const char *mapname,*event;
 

+ 1 - 1
src/map/skill.c

@@ -10045,7 +10045,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 
 	case SO_EL_CONTROL:
 		if( sd ) {
-			int mode = EL_MODE_PASSIVE;	// Standard mode.
+			enum e_mode mode = EL_MODE_PASSIVE;	// Standard mode.
 
 			if( !sd->ed )	break;
 

+ 5 - 5
src/map/status.c

@@ -80,7 +80,7 @@ static unsigned int status_calc_maxhp(struct block_list *bl, uint64 maxhp);
 static unsigned int status_calc_maxsp(struct block_list *bl, uint64 maxsp);
 static unsigned char status_calc_element(struct block_list *bl, struct status_change *sc, int element);
 static unsigned char status_calc_element_lv(struct block_list *bl, struct status_change *sc, int lv);
-static unsigned short status_calc_mode(struct block_list *bl, struct status_change *sc, int mode);
+static enum e_mode status_calc_mode(struct block_list *bl, struct status_change *sc, enum e_mode mode);
 #ifdef RENEWAL
 static unsigned short status_calc_ematk(struct block_list *,struct status_change *,int);
 #endif
@@ -6759,10 +6759,10 @@ unsigned char status_calc_attack_element(struct block_list *bl, struct status_ch
  * @param mode: Original mode
  * @return mode with cap_value(mode,0,USHRT_MAX)
  */
-static unsigned short status_calc_mode(struct block_list *bl, struct status_change *sc, int mode)
+static enum e_mode status_calc_mode(struct block_list *bl, struct status_change *sc, enum e_mode mode)
 {
 	if(!sc || !sc->count)
-		return cap_value(mode, 0, USHRT_MAX);
+		return cap_value(mode, 0, INT_MAX);
 	if(sc->data[SC_MODECHANGE]) {
 		if (sc->data[SC_MODECHANGE]->val2)
 			mode = sc->data[SC_MODECHANGE]->val2; // Set mode
@@ -6771,7 +6771,7 @@ static unsigned short status_calc_mode(struct block_list *bl, struct status_chan
 		if (sc->data[SC_MODECHANGE]->val4)
 			mode&=~sc->data[SC_MODECHANGE]->val4; // Del mode
 	}
-	return cap_value(mode,0,USHRT_MAX);
+	return cap_value(mode, 0, INT_MAX);
 }
 
 /**
@@ -7964,7 +7964,7 @@ int status_change_start(struct block_list* src, struct block_list* bl,enum sc_ty
 	break;
 	case SC_MODECHANGE:
 	{
-		int mode;
+		enum e_mode mode;
 		struct status_data *bstatus = status_get_base_status(bl);
 		if (!bstatus) return 0;
 		if (sc->data[type]) { // Pile up with previous values.