ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/friend.C
(Generate patch)

Comparing deliantra/server/common/friend.C (file contents):
Revision 1.1 by elmex, Sun Aug 13 17:16:00 2006 UTC vs.
Revision 1.2 by root, Tue Aug 29 08:01:35 2006 UTC

1/* 1/*
2 * static char *rcsid_friend_c = 2 * static char *rcsid_friend_c =
3 * "$Id: friend.C,v 1.1 2006/08/13 17:16:00 elmex Exp $"; 3 * "$Id: friend.C,v 1.2 2006/08/29 08:01:35 root Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
40 * object list usually isn't very long, and remove_friendly_object 40 * object list usually isn't very long, and remove_friendly_object
41 * won't remove it either. Plus, it is easier to put a breakpoint in 41 * won't remove it either. Plus, it is easier to put a breakpoint in
42 * the debugger here and see where the problem is happening. 42 * the debugger here and see where the problem is happening.
43 */ 43 */
44 for (ol=first_friendly_object; ol!=NULL; ol=ol->next) { 44 for (ol=first_friendly_object; ol!=NULL; ol=ol->next) {
45 if (ol->ob == op) { 45 if (ol->ob == op) {
46 LOG(llevError, "add_friendly_object: Trying to add object already on list (%s)\n", 46 LOG(llevError, "add_friendly_object: Trying to add object already on list (%s)\n",
47 op->name); 47 op->name);
48 return; 48 return;
49 } 49 }
50 } 50 }
51 51
52 ol=first_friendly_object; 52 ol=first_friendly_object;
53 first_friendly_object=get_objectlink(); 53 first_friendly_object=get_objectlink();
54 first_friendly_object->ob = op; 54 first_friendly_object->ob = op;
64 objectlink *obj; 64 objectlink *obj;
65 65
66 CLEAR_FLAG(op,FLAG_FRIENDLY); 66 CLEAR_FLAG(op,FLAG_FRIENDLY);
67 67
68 if (!first_friendly_object) { 68 if (!first_friendly_object) {
69 LOG(llevError,"remove_friendly_object called with empty friendly list, remove ob=%s\n", op->name); 69 LOG(llevError,"remove_friendly_object called with empty friendly list, remove ob=%s\n", op->name);
70 return; 70 return;
71 } 71 }
72 /* if the first object happens to be the one, processing is pretty 72 /* if the first object happens to be the one, processing is pretty
73 * easy. 73 * easy.
74 */ 74 */
75 if(first_friendly_object->ob==op) { 75 if(first_friendly_object->ob==op) {
76 obj=first_friendly_object; 76 obj=first_friendly_object;
77 first_friendly_object=obj->next; 77 first_friendly_object=obj->next;
78 free(obj); 78 free(obj);
79 } else { 79 } else {
80 objectlink *prev=first_friendly_object; 80 objectlink *prev=first_friendly_object;
81 81
82 for (obj=first_friendly_object->next; obj!=NULL; obj=obj->next) { 82 for (obj=first_friendly_object->next; obj!=NULL; obj=obj->next) {
83 if (obj->ob == op) break; 83 if (obj->ob == op) break;
84 prev=obj; 84 prev=obj;
85 } 85 }
86 if (obj) { 86 if (obj) {
87 /* This should not happen. But if it does, presumably the 87 /* This should not happen. But if it does, presumably the
88 * call to remove it is still valid. 88 * call to remove it is still valid.
89 */ 89 */
90 if (obj->id != op->count) { 90 if (obj->id != op->count) {
91 LOG(llevError,"remove_friendly_object, tags do no match, %s, %d != %d\n", 91 LOG(llevError,"remove_friendly_object, tags do no match, %s, %d != %d\n",
92 op->name?op->name:"none", op->count, obj->id); 92 op->name?op->name:"none", op->count, obj->id);
93 } 93 }
94 prev->next = obj->next; 94 prev->next = obj->next;
95 free(obj); 95 free(obj);
96 } 96 }
97 } 97 }
98} 98}
99 99
100/* 100/*
101 * Dumps all friendly objects. Invoked in DM-mode with the G key. 101 * Dumps all friendly objects. Invoked in DM-mode with the G key.
103 103
104void dump_friendly_objects(void) { 104void dump_friendly_objects(void) {
105 objectlink *ol; 105 objectlink *ol;
106 106
107 for(ol=first_friendly_object;ol!=NULL;ol=ol->next) 107 for(ol=first_friendly_object;ol!=NULL;ol=ol->next)
108 LOG(llevError, "%s (%d)\n",ol->ob->name,ol->ob->count); 108 LOG(llevError, "%s (%d)\n",ol->ob->name,ol->ob->count);
109} 109}
110 110
111/* New function, MSW 2000-1-14 111/* New function, MSW 2000-1-14
112 * It traverses the friendly list removing objects that should not be here 112 * It traverses the friendly list removing objects that should not be here
113 * (ie, do not have friendly flag set, freed, etc) 113 * (ie, do not have friendly flag set, freed, etc)
115void clean_friendly_list(void) { 115void clean_friendly_list(void) {
116 objectlink *obj, *prev=NULL, *next; 116 objectlink *obj, *prev=NULL, *next;
117 int count=0; 117 int count=0;
118 118
119 for (obj=first_friendly_object; obj!=NULL; obj=next) { 119 for (obj=first_friendly_object; obj!=NULL; obj=next) {
120 next=obj->next; 120 next=obj->next;
121 if (QUERY_FLAG(obj->ob, FLAG_FREED) || 121 if (QUERY_FLAG(obj->ob, FLAG_FREED) ||
122 !QUERY_FLAG(obj->ob, FLAG_FRIENDLY) || 122 !QUERY_FLAG(obj->ob, FLAG_FRIENDLY) ||
123 (obj->id != obj->ob->count)) { 123 (obj->id != obj->ob->count)) {
124 if (prev) { 124 if (prev) {
125 prev->next = obj->next; 125 prev->next = obj->next;
126 } 126 }
127 else { 127 else {
128 first_friendly_object = obj->next; 128 first_friendly_object = obj->next;
129 } 129 }
130 count++; 130 count++;
131 free(obj); 131 free(obj);
132 } 132 }
133 /* If we removed the object, then prev is still valid. */ 133 /* If we removed the object, then prev is still valid. */
134 else prev=obj; 134 else prev=obj;
135 } 135 }
136 if (count) 136 if (count)
137 LOG(llevDebug,"clean_friendly_list: Removed %d bogus links\n", count); 137 LOG(llevDebug,"clean_friendly_list: Removed %d bogus links\n", count);
138} 138}
139 139
140/* Checks if the given object is already in the friendly list or not 140/* Checks if the given object is already in the friendly list or not
141 * Lauwenmark - 31/07/05 141 * Lauwenmark - 31/07/05
142 */ 142 */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines