Atrinik Server  4.0
links.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
30 #include <global.h>
31 #include <toolkit/string.h>
32 #include <object.h>
33 
37 mempool_struct *pool_objectlink;
38 
40 static void objectlink_debugger(objectlink *ol, char *buf, size_t size)
41 {
42  snprintf(buf, size, "ID: %d", ol->id);
43  snprintfcat(buf, size, " value: %ld", ol->value);
44 
45  if (OBJECT_VALID(ol->objlink.ob, ol->id)) {
46  snprintfcat(buf, size, " object: %s", object_get_str(ol->objlink.ob));
47  }
48 }
49 
53 void objectlink_init(void)
54 {
55  pool_objectlink = mempool_create("object links", 500, sizeof(objectlink),
56  MEMPOOL_ALLOW_FREEING, NULL, NULL, NULL, NULL);
57  mempool_set_debugger(pool_objectlink, (chunk_debugger) objectlink_debugger);
58 }
59 
64 {
65 }
66 
73 {
74  objectlink *ol = mempool_get(pool_objectlink);
75 
76  return ol;
77 }
78 
85 {
86  if (OBJECT_VALID(ol->objlink.ob, ol->id)) {
88  }
89 
90  free_objectlink_simple(ol);
91 }
92 
99 {
100  if (ol->next) {
102  }
103 
104  if (OBJECT_VALID(ol->objlink.ob, ol->id)) {
106  }
107 
108  free_objectlink_simple(ol);
109 }
110 
119 {
120  if (obp->next) {
121  free_objectlinkpt(obp->next);
122  }
123 
124  if (obp->objlink.link) {
126  }
127 
128  free_objectlink_simple(obp);
129 }
130 
134 objectlink *objectlink_link(objectlink **startptr, objectlink **endptr, objectlink *afterptr, objectlink *beforeptr, objectlink *objptr)
135 {
136  /* Link it behind afterptr */
137  if (!beforeptr) {
138  /* If not, we just have to update startptr and endptr */
139  if (afterptr) {
140  /* Link between something? */
141  if (afterptr->next) {
142  objptr->next = afterptr->next;
143  afterptr->next->prev = objptr;
144  }
145 
146  afterptr->next = objptr;
147  objptr->prev = afterptr;
148  }
149 
150  if (startptr && !*startptr) {
151  *startptr = objptr;
152  }
153 
154  if (endptr && (!*endptr || *endptr == afterptr)) {
155  *endptr = objptr;
156  }
157  } else if (!afterptr) {
158  /* Link it before beforeptr */
159 
160  if (beforeptr->prev) {
161  objptr->prev = beforeptr->prev;
162  beforeptr->prev->next = objptr;
163  }
164 
165  beforeptr->prev = objptr;
166  objptr->next = beforeptr;
167 
168  /* We can't be endptr but perhaps start */
169  if (startptr && (!*startptr || *startptr == beforeptr)) {
170  *startptr = objptr;
171  }
172  } else {
173  /* Special: link together two lists/objects */
174 
175  beforeptr->prev = objptr;
176  afterptr->next = objptr;
177  objptr->next = beforeptr;
178  objptr->prev = afterptr;
179  }
180 
181  return objptr;
182 }
183 
188 {
189  if (startptr && *startptr == objptr) {
190  *startptr = objptr->next;
191  }
192 
193  if (endptr && *endptr == objptr) {
194  *endptr = objptr->prev;
195  }
196 
197  if (objptr->prev) {
198  objptr->prev->next = objptr->next;
199  }
200 
201  if (objptr->next) {
202  objptr->next->prev = objptr->prev;
203  }
204 
205  return objptr;
206 }
Definition: object.h:488
#define FLAG_IS_LINKED
Definition: define.h:1150
long value
Definition: object.h:509
tag_t id
Definition: object.h:506
object * ob
Definition: object.h:496
const char * object_get_str(const object *op)
Definition: object.c:3151
union oblnk::@3 objlink
struct oblnk * prev
Definition: object.h:503
struct oblnk * link
Definition: object.h:493
struct oblnk * next
Definition: object.h:500
#define CLEAR_FLAG(xyz, p)
Definition: define.h:751
#define OBJECT_VALID(_ob_, _count_)
Definition: object.h:548