ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/friend.C
Revision: 1.32
Committed: Sat Nov 17 23:40:00 2018 UTC (5 years, 5 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.31: +1 -0 lines
Log Message:
copyright update 2018

File Contents

# Content
1 /*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 *
4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
7 * Copyright (©) 1992 Frank Tore Johansen
8 *
9 * Deliantra is free software: you can redistribute it and/or modify it under
10 * the terms of the Affero GNU General Public License as published by the
11 * Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the Affero GNU General Public License
20 * and the GNU General Public License along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
22 *
23 * The authors can be reached via e-mail to <support@deliantra.net>
24 */
25
26 #include <global.h>
27
28 /*
29 * Add a new friendly object to the linked list of friendly objects.
30 * No checking to see if the object is already in the linked list is done.
31 */
32 void
33 add_friendly_object (object *op)
34 {
35 op->flag [FLAG_FRIENDLY] = 1;
36
37 objectlink *ol;
38
39 /* Add some error checking. This shouldn't happen, but the friendly
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
42 * the debugger here and see where the problem is happening.
43 */
44 for (ol = first_friendly_object; ol; ol = ol->next)
45 {
46 if (ol->ob == op)
47 {
48 LOG (llevError | logBacktrace, "add_friendly_object: Trying to add object already on list (%s)\n", &op->name);
49 return;
50 }
51 }
52
53 ol = first_friendly_object;
54 first_friendly_object = get_objectlink ();
55 first_friendly_object->ob = op;
56 first_friendly_object->next = ol;
57 }
58
59 /*
60 * Removes the specified object from the linked list of friendly objects.
61 */
62 void
63 remove_friendly_object (object *op)
64 {
65 objectlink *obj;
66
67 op->clr_flag (FLAG_FRIENDLY);
68
69 if (op->type == GOLEM
70 && op->owner
71 && op->owner->contr
72 && op->owner->contr->golem == op)
73 op->owner->contr->golem = 0;
74
75 if (!first_friendly_object)
76 {
77 LOG (llevError, "remove_friendly_object called with empty friendly list, remove ob=%s\n", &op->name);
78 return;
79 }
80
81 /* if the first object happens to be the one, processing is pretty
82 * easy.
83 */
84 if (first_friendly_object->ob == op)
85 {
86 obj = first_friendly_object;
87 first_friendly_object = obj->next;
88 delete obj;
89 }
90 else
91 {
92 objectlink *prev = first_friendly_object;
93
94 for (obj = first_friendly_object->next; obj; obj = obj->next)
95 {
96 if (obj->ob == op)
97 break;
98
99 prev = obj;
100 }
101
102 if (obj)
103 {
104 prev->next = obj->next;
105 delete obj;
106 }
107 }
108 }
109
110 /* New function, MSW 2000-1-14
111 * It traverses the friendly list removing objects that should not be here
112 * (ie, do not have friendly flag set, freed, etc)
113 */
114 void
115 clean_friendly_list ()
116 {
117 objectlink *obj, *prev = NULL, *next;
118 int count = 0;
119
120 for (obj = first_friendly_object; obj; obj = next)
121 {
122 next = obj->next;
123 if (obj->ob->flag [FLAG_FREED] || !obj->ob->flag [FLAG_FRIENDLY])
124 {
125 if (prev)
126 prev->next = obj->next;
127 else
128 first_friendly_object = obj->next;
129
130 count++;
131 delete obj;
132 }
133 else
134 /* If we removed the object, then prev is still valid. */
135 prev = obj;
136 }
137
138 if (count)
139 LOG (llevDebug, "clean_friendly_list: Removed %d bogus links\n", count);
140 }
141