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, 6 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

# User Rev Content
1 elmex 1.1 /*
2 root 1.17 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 root 1.29 *
4 root 1.32 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
5 root 1.30 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
6 root 1.24 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
7     * Copyright (©) 1992 Frank Tore Johansen
8 root 1.29 *
9 root 1.20 * 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 root 1.29 *
14 root 1.16 * 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 root 1.29 *
19 root 1.20 * 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 root 1.29 *
23 root 1.17 * The authors can be reached via e-mail to <support@deliantra.net>
24 pippijn 1.10 */
25 elmex 1.1
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 root 1.5 void
33     add_friendly_object (object *op)
34     {
35 root 1.9 op->flag [FLAG_FRIENDLY] = 1;
36    
37 root 1.5 objectlink *ol;
38 elmex 1.1
39 root 1.5 /* 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 root 1.31 * the debugger here and see where the problem is happening.
43 root 1.5 */
44 root 1.9 for (ol = first_friendly_object; ol; ol = ol->next)
45 root 1.5 {
46     if (ol->ob == op)
47     {
48 root 1.15 LOG (llevError | logBacktrace, "add_friendly_object: Trying to add object already on list (%s)\n", &op->name);
49 root 1.5 return;
50 root 1.2 }
51 elmex 1.1 }
52    
53 root 1.5 ol = first_friendly_object;
54     first_friendly_object = get_objectlink ();
55     first_friendly_object->ob = op;
56     first_friendly_object->next = ol;
57 elmex 1.1 }
58    
59     /*
60     * Removes the specified object from the linked list of friendly objects.
61     */
62 root 1.5 void
63     remove_friendly_object (object *op)
64     {
65     objectlink *obj;
66 elmex 1.1
67 root 1.26 op->clr_flag (FLAG_FRIENDLY);
68 elmex 1.1
69 root 1.11 if (op->type == GOLEM
70     && op->owner
71     && op->owner->contr
72 root 1.12 && op->owner->contr->golem == op)
73     op->owner->contr->golem = 0;
74 root 1.11
75 root 1.5 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 root 1.9
81 root 1.5 /* 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 root 1.7 delete obj;
89 elmex 1.1 }
90 root 1.5 else
91     {
92     objectlink *prev = first_friendly_object;
93    
94 root 1.9 for (obj = first_friendly_object->next; obj; obj = obj->next)
95 root 1.5 {
96     if (obj->ob == op)
97     break;
98 root 1.11
99 root 1.5 prev = obj;
100 root 1.2 }
101 root 1.7
102 root 1.5 if (obj)
103     {
104     prev->next = obj->next;
105 root 1.7 delete obj;
106 root 1.2 }
107 elmex 1.1 }
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 root 1.5 void
115 root 1.23 clean_friendly_list ()
116 root 1.5 {
117     objectlink *obj, *prev = NULL, *next;
118     int count = 0;
119    
120 root 1.7 for (obj = first_friendly_object; obj; obj = next)
121 root 1.5 {
122     next = obj->next;
123 root 1.26 if (obj->ob->flag [FLAG_FREED] || !obj->ob->flag [FLAG_FRIENDLY])
124 root 1.5 {
125     if (prev)
126 root 1.7 prev->next = obj->next;
127 root 1.5 else
128 root 1.7 first_friendly_object = obj->next;
129    
130 root 1.5 count++;
131 root 1.7 delete obj;
132 root 1.2 }
133 root 1.5 else
134 root 1.7 /* If we removed the object, then prev is still valid. */
135 root 1.5 prev = obj;
136 elmex 1.1 }
137 root 1.7
138 root 1.5 if (count)
139     LOG (llevDebug, "clean_friendly_list: Removed %d bogus links\n", count);
140 elmex 1.1 }
141