From f0fb58027eaaab3572aac3c89227aeab05423819 Mon Sep 17 00:00:00 2001
From: Jared Adams <jaxad0127@gmail.com>
Date: Thu, 23 Oct 2008 00:08:26 +0000
Subject: Commit Mantis tasks 486 and 460

---
 src/map/chrif.c |  8 +-----
 src/map/clif.c  | 84 ++++++++++++++++++++++++++++++++++++++++++++-------------
 src/map/clif.h  |  2 ++
 src/map/map.h   | 17 +++++++++++-
 src/map/pc.c    | 68 +++++++++++++++++++++++-----------------------
 5 files changed, 119 insertions(+), 60 deletions(-)

(limited to 'src/map')

diff --git a/src/map/chrif.c b/src/map/chrif.c
index dc401b6..ceeac26 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -689,13 +689,7 @@ int chrif_divorce(int char_id, int partner_id)
 	nullpo_retr(0, sd = map_nick2sd(map_charid2nick(partner_id)));
 	if (sd->status.partner_id == char_id) {
 		int i;
-		//����(�����͊��ɃL�����������Ă��锤�Ȃ̂�)
 		sd->status.partner_id = 0;
-
-		//�����̌����w�ւ𔍒D
-		for(i = 0; i < MAX_INVENTORY; i++)
-			if (sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F)
-				pc_delitem(sd, i, 1, 0);
 	}
 
 	return 0;
@@ -717,7 +711,7 @@ int chrif_accountdeletion(int fd)
 	if (acc > 0) {
 		if (sd != NULL) {
 			sd->login_id1++; // change identify, because if player come back in char within the 5 seconds, he can change its characters
-			clif_displaymessage(sd->fd, "Your account has been deleted (disconnexion)...");
+			clif_displaymessage(sd->fd, "Your account has been deleted (disconnection)...");
 			clif_setwaitclose(sd->fd); // forced to disconnect for the change
 		}
 	} else {
diff --git a/src/map/clif.c b/src/map/clif.c
index ad750d4..4feaa15 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -1209,6 +1209,23 @@ static int clif_set0192(int fd, int m, int x, int y, int type) {
 	return 0;
 }
 
+/* These indices are derived from equip_pos in pc.c and some guesswork */
+static int equip_points[LOOK_LAST + 1] = {
+        -1, /* 0: base */
+        -1, /* 1: hair */
+        9, /* 2: weapon */
+        4, /* 3: head botom -- leg armour */
+        6, /* 4: head top -- hat */
+        5, /* 5: head mid -- torso armour */
+        -1, /* 6: hair colour */
+        -1, /* 6: clothes colour */
+        8, /* 6: shield */
+        2, /* 9: shoes */
+        3, /* gloves */
+        1, /* cape */
+        7, /* misc1 */
+        0, /* misc2 */};
+
 /*==========================================
  *
  *------------------------------------------
@@ -1286,6 +1303,8 @@ int clif_spawnpc(struct map_session_data *sd) {
 	if (map[sd->bl.m].flag.rain)
 		clif_specialeffect(&sd->bl, 161, 1);
 
+        clif_changelook_accessories(&sd->bl, NULL);
+
 	return 0;
 }
 
@@ -1316,6 +1335,7 @@ int clif_spawnnpc(struct npc_data *nd)
 	len = clif_npc0078(nd,buf);
 	clif_send(buf,len,&nd->bl,AREA);
 
+
 	return 0;
 }
 
@@ -2563,8 +2583,13 @@ int clif_changestatus(struct block_list *bl,int type,int val)
  */
 int clif_changelook(struct block_list *bl,int type,int val)
 {
+        clif_changelook_towards(bl, type, val, NULL);
+}
 
-	unsigned char buf[32];
+int clif_changelook_towards(struct block_list *bl,int type,int val, struct map_session_data *dstsd)
+{
+	unsigned char rbuf[32];
+        unsigned char *buf = dstsd ? WFIFOP(dstsd->fd, 0) : rbuf; // pick target buffer or general-purpose one
 	struct map_session_data *sd = NULL;
 
 	nullpo_retr(0, bl);
@@ -2582,18 +2607,24 @@ int clif_changelook(struct block_list *bl,int type,int val)
 	WBUFL(buf,2)=bl->id;
 	WBUFB(buf,6)=type;
 	WBUFB(buf,7)=val;
-	clif_send(buf,packet_len_table[0xc3],bl,AREA);
+
+        if (dstsd)
+                WFIFOSET(dstsd->fd, packet_len_table[0xc3]);
+        else
+                clif_send(buf,packet_len_table[0xc3],bl,AREA);
 #else
-	if(sd && (type == LOOK_WEAPON || type == LOOK_SHIELD || type == LOOK_SHOES)) {
+	if(sd && (type == LOOK_WEAPON || type == LOOK_SHIELD || type >= LOOK_SHOES)) {
 		WBUFW(buf,0)=0x1d7;
 		WBUFL(buf,2)=bl->id;
-		if(type == LOOK_SHOES) {
-			WBUFB(buf,6)=9;
-			if(sd->equip_index[2] >= 0 && sd->inventory_data[sd->equip_index[2]]) {
-				if(sd->inventory_data[sd->equip_index[2]]->view_id > 0)
-					WBUFW(buf,7)=sd->inventory_data[sd->equip_index[2]]->view_id;
+		if(type >= LOOK_SHOES) {
+                        int equip_point = equip_points[type];
+
+			WBUFB(buf,6) = type;
+			if(sd->equip_index[equip_point] >= 0 && sd->inventory_data[sd->equip_index[2]]) {
+				if(sd->inventory_data[sd->equip_index[equip_point]]->view_id > 0)
+					WBUFW(buf,7)=sd->inventory_data[sd->equip_index[equip_point]]->view_id;
 				else
-					WBUFW(buf,7)=sd->status.inventory[sd->equip_index[2]].nameid;
+					WBUFW(buf,7)=sd->status.inventory[sd->equip_index[equip_point]].nameid;
 			} else
 				WBUFW(buf,7)=0;
 			WBUFW(buf,9)=0;
@@ -2620,22 +2651,21 @@ int clif_changelook(struct block_list *bl,int type,int val)
 			} else
 				WBUFW(buf,9)=0;
 		}
-		clif_send(buf,packet_len_table[0x1d7],bl,AREA);
+                if (dstsd)
+                        WFIFOSET(dstsd->fd, packet_len_table[0x1d7]);
+                else
+                        clif_send(buf, packet_len_table[0x1d7], bl, AREA);
 	}
-	else if(sd && (type == LOOK_BASE) && (val > 255))
-		{
+	else {
 		WBUFW(buf,0)=0x1d7;
 		WBUFL(buf,2)=bl->id;
 		WBUFB(buf,6)=type;
 		WBUFW(buf,7)=val;
 		WBUFW(buf,9)=0;
-		clif_send(buf,packet_len_table[0x1d7],bl,AREA);
-	} else {
-		WBUFW(buf,0)=0xc3;
-		WBUFL(buf,2)=bl->id;
-		WBUFB(buf,6)=type;
-		WBUFB(buf,7)=val;
-		clif_send(buf,packet_len_table[0xc3],bl,AREA);
+                if (dstsd)
+                        WFIFOSET(dstsd->fd, packet_len_table[0x1d7]);
+                else
+                        clif_send(buf, packet_len_table[0x1d7], bl, AREA);
 	}
 #endif
 	return 0;
@@ -3514,6 +3544,17 @@ int clif_storageclose(struct map_session_data *sd)
 	return 0;
 }
 
+void
+clif_changelook_accessories(struct block_list *bl, struct map_session_data *dest)
+{
+        int i;
+
+         for (i = LOOK_SHOES; i <= LOOK_LAST; i++)
+                 clif_changelook_towards(bl, i, 0, dest);
+}
+
+
+
 //
 // callback�n ?
 //
@@ -3555,6 +3596,8 @@ void clif_getareachar_pc(struct map_session_data* sd,struct map_session_data* ds
 	if(sd->status.manner < 0)
 		clif_changestatus(&sd->bl,SP_MANNER,sd->status.manner);
 
+        clif_changelook_accessories(sd, dstsd);
+        clif_changelook_accessories(dstsd, sd);
 }
 
 /*==========================================
@@ -3640,6 +3683,7 @@ int clif_fixpcpos(struct map_session_data *sd)
 		len = clif_set0078(sd,buf);
 		clif_send(buf,len,&sd->bl,AREA);
 	}
+        clif_changelook_accessories(sd, NULL);
 
 	return 0;
 }
@@ -7221,6 +7265,8 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
 			skill_status_change_start(&sd->bl,SC_BROKNARMOR,0,0,0,0,0,0);
 	}
 
+        clif_changelook_accessories(sd, NULL);
+
 	map_foreachinarea(clif_getareachar,sd->bl.m,sd->bl.x-AREA_SIZE,sd->bl.y-AREA_SIZE,sd->bl.x+AREA_SIZE,sd->bl.y+AREA_SIZE,0,sd);
 }
 
diff --git a/src/map/clif.h b/src/map/clif.h
index d04d821..a6f8a3c 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -65,6 +65,8 @@ int clif_changestatus(struct block_list*,int,int);	//area
 int clif_damage(struct block_list *,struct block_list *,unsigned int,int,int,int,int,int,int);	// area
 #define clif_takeitem(src,dst) clif_damage(src,dst,0,0,0,0,0,1,0)
 int clif_changelook(struct block_list *,int,int);	// area
+int clif_changelook_towards(struct block_list *,int,int, struct map_session_data *dst);	// area or target
+void clif_changelook_accessories(struct block_list *bl, struct map_session_data *dst); // area or target; list gloves, boots etc.
 int clif_arrowequip(struct map_session_data *sd,int val); //self
 int clif_arrow_fail(struct map_session_data *sd,int type); //self
 int clif_arrow_create_list(struct map_session_data *sd);	//self
diff --git a/src/map/map.h b/src/map/map.h
index 28d6758..ea240f2 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -610,9 +610,24 @@ enum {
 };
 
 enum {
-	LOOK_BASE,LOOK_HAIR,LOOK_WEAPON,LOOK_HEAD_BOTTOM,LOOK_HEAD_TOP,LOOK_HEAD_MID,LOOK_HAIR_COLOR,LOOK_CLOTHES_COLOR,LOOK_SHIELD,LOOK_SHOES
+        LOOK_BASE,
+        LOOK_HAIR,
+        LOOK_WEAPON,
+        LOOK_HEAD_BOTTOM,
+        LOOK_HEAD_TOP,
+        LOOK_HEAD_MID,
+        LOOK_HAIR_COLOR,
+        LOOK_CLOTHES_COLOR,
+        LOOK_SHIELD,
+        LOOK_SHOES, /* 9 */
+        LOOK_GLOVES,
+        LOOK_CAPE,
+        LOOK_MISC1,
+        LOOK_MISC2
 };
 
+#define LOOK_LAST LOOK_MISC2
+
 struct chat_data {
 	struct block_list bl;
 
diff --git a/src/map/pc.c b/src/map/pc.c
index fe8dab4..8bb2ee8 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -5759,12 +5759,14 @@ int pc_equiplookall(struct map_session_data *sd)
 	clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
 #else
 	clif_changelook(&sd->bl,LOOK_WEAPON,0);
-	clif_changelook(&sd->bl,LOOK_SHOES,0);
+//	clif_changelook(&sd->bl,LOOK_SHOES,0);
 #endif
 	clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
 	clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
 	clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
 
+        clif_changelook_accessories(&sd->bl, NULL);
+
 	return 0;
 }
 
@@ -6307,9 +6309,25 @@ int pc_cleareventtimer(struct map_session_data *sd)
  * �A�C�e���𑕔�����
  *------------------------------------------
  */
+static int
+pc_signal_advanced_equipment_change(struct map_session_data *sd,int n)
+{
+        if(sd->status.inventory[n].equip & 0x0040)
+                clif_changelook(&sd->bl,LOOK_SHOES,0);
+        if(sd->status.inventory[n].equip & 0x0004)
+                clif_changelook(&sd->bl, LOOK_GLOVES, 0);
+        if(sd->status.inventory[n].equip & 0x0008)
+                clif_changelook(&sd->bl, LOOK_CAPE, 0);
+        if(sd->status.inventory[n].equip & 0x0010)
+                clif_changelook(&sd->bl, LOOK_MISC1, 0);
+        if(sd->status.inventory[n].equip & 0x0080)
+                clif_changelook(&sd->bl, LOOK_MISC2, 0);
+}
+
+
 int pc_equipitem(struct map_session_data *sd,int n,int pos)
 {
-	int i,nameid, arrow;
+	int i,nameid, arrow, view;
 	struct item_data *id;
 	//�]����{�q�̏ꍇ�̌��̐E�Ƃ��Z�o����
 
@@ -6380,11 +6398,15 @@ int pc_equipitem(struct map_session_data *sd,int n,int pos)
 	}
 	sd->status.inventory[n].equip=pos;
 
+	if(sd->inventory_data[n]) {
+		view = sd->inventory_data[n]->look;
+		if (view == 0) view = sd->inventory_data[n]->nameid;
+	} else {
+		view = 0;
+	}
+
 	if(sd->status.inventory[n].equip & 0x0002) {
-		if(sd->inventory_data[n])
-			sd->weapontype1 = sd->inventory_data[n]->look;
-		else
-			sd->weapontype1 = 0;
+		sd->weapontype1 = view;
 		pc_calcweapontype(sd);
                 pc_set_weapon_look(sd);
 	}
@@ -6393,12 +6415,10 @@ int pc_equipitem(struct map_session_data *sd,int n,int pos)
 			if(sd->inventory_data[n]->type == 4) {
 				sd->status.shield = 0;
 				if(sd->status.inventory[n].equip == 0x0020)
-					sd->weapontype2 = sd->inventory_data[n]->look;
-				else
-					sd->weapontype2 = 0;
+					sd->weapontype2 = view;
 			}
 			else if(sd->inventory_data[n]->type == 5) {
-				sd->status.shield = sd->inventory_data[n]->look;
+				sd->status.shield = view;
 				sd->weapontype2 = 0;
 			}
 		}
@@ -6408,28 +6428,18 @@ int pc_equipitem(struct map_session_data *sd,int n,int pos)
 		clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
 	}
 	if(sd->status.inventory[n].equip & 0x0001) {
-		if(sd->inventory_data[n])
-			sd->status.head_bottom = sd->inventory_data[n]->look;
-		else
-			sd->status.head_bottom = 0;
+		sd->status.head_bottom = view;
 		clif_changelook(&sd->bl,LOOK_HEAD_BOTTOM,sd->status.head_bottom);
 	}
 	if(sd->status.inventory[n].equip & 0x0100) {
-		if(sd->inventory_data[n])
-			sd->status.head_top = sd->inventory_data[n]->look;
-		else
-			sd->status.head_top = 0;
+		sd->status.head_top = view;
 		clif_changelook(&sd->bl,LOOK_HEAD_TOP,sd->status.head_top);
 	}
 	if(sd->status.inventory[n].equip & 0x0200) {
-		if(sd->inventory_data[n])
-			sd->status.head_mid = sd->inventory_data[n]->look;
-		else
-			sd->status.head_mid = 0;
+		sd->status.head_mid = view;
 		clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
 	}
-	if(sd->status.inventory[n].equip & 0x0040)
-		clif_changelook(&sd->bl,LOOK_SHOES,0);
+        pc_signal_advanced_equipment_change(sd, n);
 
 	pc_checkallowskill(sd);	// �����i�ŃX�L������������邩�`�F�b�N
 	if (itemdb_look(sd->status.inventory[n].nameid) == 11 && arrow){	// Added by RoVeRT
@@ -6501,8 +6511,7 @@ int pc_unequipitem(struct map_session_data *sd,int n,int type)
 			sd->status.head_mid = 0;
 			clif_changelook(&sd->bl,LOOK_HEAD_MID,sd->status.head_mid);
 		}
-		if(sd->status.inventory[n].equip & 0x0040)
-			clif_changelook(&sd->bl,LOOK_SHOES,0);
+                pc_signal_advanced_equipment_change(sd, n);
 
 		if(sd->sc_data[SC_BROKNWEAPON].timer != -1 && sd->status.inventory[n].equip & 0x0002 &&
 		sd->status.inventory[i].broken==1)
@@ -6733,19 +6742,12 @@ int pc_divorce(struct map_session_data *sd)
 		return -1;
 
 	if( (p_sd=map_nick2sd(map_charid2nick(sd->status.partner_id))) !=NULL){
-		int i;
 		if(p_sd->status.partner_id != sd->status.char_id || sd->status.partner_id != p_sd->status.char_id){
 			printf("pc_divorce: Illegal partner_id sd=%d p_sd=%d\n",sd->status.partner_id,p_sd->status.partner_id);
 			return -1;
 		}
 		sd->status.partner_id=0;
 		p_sd->status.partner_id=0;
-		for(i=0;i<MAX_INVENTORY;i++)
-			if(sd->status.inventory[i].nameid == WEDDING_RING_M || sd->status.inventory[i].nameid == WEDDING_RING_F)
-				pc_delitem(sd,i,1,0);
-		for(i=0;i<MAX_INVENTORY;i++)
-			if(p_sd->status.inventory[i].nameid == WEDDING_RING_M || p_sd->status.inventory[i].nameid == WEDDING_RING_F)
-				pc_delitem(p_sd,i,1,0);
 
 	}else{
 		printf("pc_divorce: p_sd nullpo\n");
-- 
cgit v1.2.3-70-g09d2