Skip to content

Commit

Permalink
Small refactor of pc_setpos
Browse files Browse the repository at this point in the history
pc_setpos now delivers an enum for the error that happened.
Additionallly it now returns a different return value when the targeted player is in autotrade state.
Added usage of this new return value to all recall commands.
  • Loading branch information
Lemongrass3110 committed Apr 24, 2016
1 parent e5af113 commit 6ab9fd0
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 40 deletions.
3 changes: 2 additions & 1 deletion conf/msg_conf/map_msg.conf
Expand Up @@ -949,7 +949,8 @@
// @rates
1024: MVP Drop Rates: Common %.2fx / Healing %.2fx / Usable %.2fx / Equipment %.2fx / Card %.2fx

//1025: free
// @recall
1025: The player cannot be recalled, because he is in autotrading state.

// @kick
1026: Please enter a player name (usage: @kick <char name/ID>).
Expand Down
3 changes: 0 additions & 3 deletions conf/msg_conf/map_msg_chn.conf
Expand Up @@ -827,9 +827,6 @@
// @charunblock
1024: 請輸入角色名稱 (用法: @charunblock <char name>).

// @charunban
1025: 請輸入角色名稱 (用法: @charunban <char name>).

// @kick
1026: 請輸入角色名稱 (用法: @kick <char name/ID>).

Expand Down
3 changes: 0 additions & 3 deletions conf/msg_conf/map_msg_frn.conf
Expand Up @@ -839,9 +839,6 @@
// @charunblock
1024: Entrez un nom de Joueur (usage: @charunblock <nom du joueur>).

// @charunban
1025: Entrez un nom de Joueur (usage: @charunban <nom du joueur>).

// @kick
1026: Entrez un nom de Joueur (usage: @kick <nom du joueur/ID>).

Expand Down
3 changes: 0 additions & 3 deletions conf/msg_conf/map_msg_por.conf
Expand Up @@ -819,9 +819,6 @@
// @charunblock
1024: Digite o nome de um jogador (uso: @charunblock <nome do personagem>).

// @charunban
1025: Digite o nome de um jogador (uso: @charunban <nome do personagem>).

// @kick
1026: Digite o nome de um jogador (uso: @kick <nome do personagem/ID>).

Expand Down
3 changes: 0 additions & 3 deletions conf/msg_conf/map_msg_rus.conf
Expand Up @@ -840,9 +840,6 @@
// @charunblock
1024: ������� ��� ��������� (�������������: @charunblock <��� ���������>).

// @charunban
1025: ������� ��� ��������� (�������������: @charunban <��� ���������>).

// @kick
1026: ������� ��� ��������� (�������������: @kick <ID/��� ���������>).

Expand Down
3 changes: 0 additions & 3 deletions conf/msg_conf/map_msg_spn.conf
Expand Up @@ -826,9 +826,6 @@
// @charunblock
1024: Introduce el nombre de un jugador bloqueado (Instrucciones: @charunblock <nombre del personaje>).

// @charunban
1025: Introduce el nombre de un�jugador bloqueado temporalmente�(Instrucciones: @charunban <nombre del personaje>).

// @kick
1026: Introduce el nombre de un personaje (Instrucciones: @kick <nombre del personaje/ID>).

Expand Down
3 changes: 0 additions & 3 deletions conf/msg_conf/map_msg_tha.conf
Expand Up @@ -833,9 +833,6 @@
// @charunblock
1024: �ô�кت��͵���Ф� (�Ը���: @charunblock <���͵���Ф�>).

// @charunban
1025: �ô�кت��͵���Ф� (�Ը���: @charunban <���͵���Ф�>).

// @kick
1026: �ô�кت��͵���Ф� (�Ը���: @kick <����/ID ����Ф�>).

Expand Down
29 changes: 20 additions & 9 deletions src/map/atcommand.c
Expand Up @@ -483,7 +483,7 @@ ACMD_FUNC(mapmove)
clif_displaymessage(fd, msg_txt(sd,248));
return -1;
}
if (pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) != 0) {
if (pc_setpos(sd, mapindex, x, y, CLR_TELEPORT) != SETPOS_OK) {
clif_displaymessage(fd, msg_txt(sd,1)); // Map not found.
return -1;
}
Expand Down Expand Up @@ -2032,7 +2032,7 @@ ACMD_FUNC(go)
clif_displaymessage(fd, msg_txt(sd,248));
return -1;
}
if (pc_setpos(sd, mapindex_name2id(data[town].map), data[town].x, data[town].y, CLR_TELEPORT) == 0) {
if (pc_setpos(sd, mapindex_name2id(data[town].map), data[town].x, data[town].y, CLR_TELEPORT) == SETPOS_OK) {
clif_displaymessage(fd, msg_txt(sd,0)); // Warped.
} else {
clif_displaymessage(fd, msg_txt(sd,1)); // Map not found.
Expand Down Expand Up @@ -2901,7 +2901,11 @@ ACMD_FUNC(recall) {
if (pl_sd->bl.m == sd->bl.m && pl_sd->bl.x == sd->bl.x && pl_sd->bl.y == sd->bl.y) {
return -1;
}
pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
if( pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN) == SETPOS_AUTOTRADE ){
clif_displaymessage(fd, msg_txt(sd,1025)); // The player cannot be recalled, because he is in autotrading state.
return -1;
}

sprintf(atcmd_output, msg_txt(sd,46), pl_sd->status.name); // %s recalled!
clif_displaymessage(fd, atcmd_output);

Expand Down Expand Up @@ -3605,7 +3609,9 @@ ACMD_FUNC(recallall)
if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
count++;
else {
pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
if( pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN) == SETPOS_AUTOTRADE ){
count++;
}
}
}
}
Expand Down Expand Up @@ -3663,8 +3669,10 @@ ACMD_FUNC(guildrecall)
continue; // Skip GMs greater than you... or chars already on the cell
if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
count++;
else
pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
else{
if( pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN) == SETPOS_AUTOTRADE ){
count++;
}
}
}
mapit_free(iter);
Expand Down Expand Up @@ -3722,8 +3730,11 @@ ACMD_FUNC(partyrecall)
continue; // Skip GMs greater than you... or chars already on the cell
if (pl_sd->bl.m >= 0 && map[pl_sd->bl.m].flag.nowarp && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE))
count++;
else
pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN);
else{
if( pc_setpos(pl_sd, sd->mapindex, sd->bl.x, sd->bl.y, CLR_RESPAWN) == SETPOS_AUTOTRADE ){
count++;
}
}
}
}
mapit_free(iter);
Expand Down Expand Up @@ -4442,7 +4453,7 @@ ACMD_FUNC(tonpc)
}

if ((nd = npc_name2id(npcname)) != NULL) {
if (pc_setpos(sd, map_id2index(nd->bl.m), nd->bl.x, nd->bl.y, CLR_TELEPORT) == 0)
if (pc_setpos(sd, map_id2index(nd->bl.m), nd->bl.x, nd->bl.y, CLR_TELEPORT) == SETPOS_OK)
clif_displaymessage(fd, msg_txt(sd,0)); // Warped.
else
return -1;
Expand Down
25 changes: 14 additions & 11 deletions src/map/pc.c
Expand Up @@ -1195,11 +1195,11 @@ bool pc_authok(struct map_session_data *sd, uint32 login_id2, time_t expiration_
sd->qi_count = 0;

//warp player
if ((i=pc_setpos(sd,sd->status.last_point.map, sd->status.last_point.x, sd->status.last_point.y, CLR_OUTSIGHT)) != 0) {
if ((i=pc_setpos(sd,sd->status.last_point.map, sd->status.last_point.x, sd->status.last_point.y, CLR_OUTSIGHT)) != SETPOS_OK) {
ShowError ("Last_point_map %s - id %d not found (error code %d)\n", mapindex_id2name(sd->status.last_point.map), sd->status.last_point.map, i);

// try warping to a default map instead (church graveyard)
if (pc_setpos(sd, mapindex_name2id(MAP_PRONTERA), 273, 354, CLR_OUTSIGHT) != 0) {
if (pc_setpos(sd, mapindex_name2id(MAP_PRONTERA), 273, 354, CLR_OUTSIGHT) != SETPOS_OK) {
// if we fail again
clif_authfail_fd(sd->fd, 0);
return false;
Expand Down Expand Up @@ -5238,21 +5238,24 @@ int pc_steal_coin(struct map_session_data *sd,struct block_list *target)
* @param x
* @param y
* @param clrtype
* @return 0 - Success; 1 - Invalid map index; 2 - Map not in this map-server, and failed to locate alternate map-server.
* @return SETPOS_OK Success
* SETPOS_MAPINDEX Invalid map index
* SETPOS_NO_MAPSERVER Map not in this map-server, and failed to locate alternate map-server.
* SETPOS_AUTOTRADE Player is in autotrade state
*------------------------------------------*/
char pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype)
enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype)
{
int16 m;

nullpo_ret(sd);
nullpo_retr(SETPOS_OK,sd);

if( !mapindex || !mapindex_id2name(mapindex) ) {
ShowDebug("pc_setpos: Passed mapindex(%d) is invalid!\n", mapindex);
return 1;
return SETPOS_MAPINDEX;
}

if ( sd->state.autotrade && (sd->vender_id || sd->buyer_id) ) // Player with autotrade just causes clif glitch! @ FIXME
return 1;
return SETPOS_AUTOTRADE;

if( battle_config.revive_onwarp && pc_isdead(sd) ) { //Revive dead people before warping them
pc_setstand(sd, true);
Expand Down Expand Up @@ -5318,7 +5321,7 @@ char pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int
uint16 port;
//if can't find any map-servers, just abort setting position.
if(!sd->mapindex || map_mapname2ipport(mapindex,&ip,&port))
return 2;
return SETPOS_NO_MAPSERVER;

if (sd->npc_id)
npc_event_dequeue(sd);
Expand All @@ -5335,7 +5338,7 @@ char pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int
//Free session data from this map server [Kevin]
unit_free_pc(sd);

return 0;
return SETPOS_OK;
}

if( x < 0 || x >= map[m].xs || y < 0 || y >= map[m].ys )
Expand Down Expand Up @@ -5422,7 +5425,7 @@ char pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int
else
sd->count_rewarp = 0;

return 0;
return SETPOS_OK;
}

/*==========================================
Expand Down Expand Up @@ -7305,7 +7308,7 @@ void pc_respawn(struct map_session_data* sd, clr_type clrtype)

pc_setstand(sd, true);
pc_setrestartvalue(sd,3);
if( pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, clrtype) )
if( pc_setpos(sd, sd->status.save_point.map, sd->status.save_point.x, sd->status.save_point.y, clrtype) != SETPOS_OK )
clif_resurrection(&sd->bl, 1); //If warping fails, send a normal stand up packet.
}

Expand Down
9 changes: 8 additions & 1 deletion src/map/pc.h
Expand Up @@ -951,7 +951,14 @@ void pc_clean_skilltree(struct map_session_data *sd);
#define pc_checkoverhp(sd) ((sd)->battle_status.hp == (sd)->battle_status.max_hp)
#define pc_checkoversp(sd) ((sd)->battle_status.sp == (sd)->battle_status.max_sp)

char pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype);
enum e_setpos{
SETPOS_OK = 0,
SETPOS_MAPINDEX = 1,
SETPOS_NO_MAPSERVER = 2,
SETPOS_AUTOTRADE = 3
};

enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, int x, int y, clr_type clrtype);
void pc_setsavepoint(struct map_session_data *sd, short mapindex,int x,int y);
char pc_randomwarp(struct map_session_data *sd,clr_type type);
bool pc_memo(struct map_session_data* sd, int pos);
Expand Down

0 comments on commit 6ab9fd0

Please sign in to comment.