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

Comparing deliantra/server/common/utils.C (file contents):
Revision 1.26 by root, Mon Dec 18 03:00:02 2006 UTC vs.
Revision 1.36 by pippijn, Sat Jan 6 14:42:29 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
3 3
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
6 7
7 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
195 return (min); 196 return (min);
196 197
197 return (RANDOM () % diff + min); 198 return (RANDOM () % diff + min);
198} 199}
199 200
200/* decay and destroy persihable items in a map */ 201/* decay and destroy perishable items in a map */
201
202void 202void
203decay_objects (maptile *m) 203maptile::decay_objects ()
204{ 204{
205 int x, y, destroy; 205 if (!spaces)
206 object *op, *otmp;
207
208 if (m->unique)
209 return; 206 return;
210 207
211 for (x = 0; x < MAP_WIDTH (m); x++) 208 for (mapspace *ms = spaces + size (); ms-- > spaces; )
212 for (y = 0; y < MAP_HEIGHT (m); y++) 209 for (object *above, *op = ms->bot; op; op = above)
213 for (op = get_map_ob (m, x, y); op; op = otmp)
214 { 210 {
211 above = op->above;
212
215 destroy = 0; 213 bool destroy = 0;
216 otmp = op->above; 214
215 // do not decay anything above unique floor tiles (yet :)
217 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 216 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
218 break; 217 break;
218
219 if (QUERY_FLAG (op, FLAG_IS_FLOOR) 219 if (QUERY_FLAG (op, FLAG_IS_FLOOR)
220 || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) 220 || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL)
221 || QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL) 221 || QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL)
222 || QUERY_FLAG (op, FLAG_UNIQUE) 222 || QUERY_FLAG (op, FLAG_UNIQUE)
223 || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) 223 || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)
224 || QUERY_FLAG (op, FLAG_UNPAID) 224 || QUERY_FLAG (op, FLAG_UNPAID)
225 || op->is_alive ()) 225 || op->is_alive ())
226 continue; 226 ; // do not decay
227
228 /* otherwise, we decay and destroy */
229 if (op->is_weapon ()) 227 else if (op->is_weapon ())
230 { 228 {
231 op->stats.dam--; 229 op->stats.dam--;
232 if (op->stats.dam < 0) 230 if (op->stats.dam < 0)
233 destroy = 1; 231 destroy = 1;
234 } 232 }
235 else if (op->is_armor ()) 233 else if (op->is_armor ())
236 { 234 {
237 op->stats.ac--; 235 op->stats.ac--;
238 if (op->stats.ac < 0) 236 if (op->stats.ac < 0)
239 destroy = 1; 237 destroy = 1;
240 } 238 }
241 else if (op->type == FOOD) 239 else if (op->type == FOOD)
242 { 240 {
243 op->stats.food -= rndm (5, 20); 241 op->stats.food -= rndm (5, 20);
244 if (op->stats.food < 0) 242 if (op->stats.food < 0)
245 destroy = 1; 243 destroy = 1;
246 } 244 }
247 else 245 else
248 { 246 {
249 if (op->material & M_PAPER || op->material & M_LEATHER || 247 int mat = op->material;
250 op->material & M_WOOD || op->material & M_ORGANIC || op->material & M_CLOTH || op->material & M_LIQUID) 248
249 if (mat & M_PAPER
250 || mat & M_LEATHER
251 || mat & M_WOOD
252 || mat & M_ORGANIC
253 || mat & M_CLOTH
254 || mat & M_LIQUID
255 || (mat & M_IRON && rndm (1, 5) == 1)
256 || (mat & M_GLASS && rndm (1, 2) == 1)
257 || ((mat & M_STONE || mat & M_ADAMANT) && rndm (1, 10) == 1)
258 || ((mat & M_SOFT_METAL || mat & M_BONE) && rndm (1, 3) == 1)
259 || (mat & M_ICE && temp > 32))
251 destroy = 1; 260 destroy = 1;
252 if (op->material & M_IRON && rndm (1, 5) == 1)
253 destroy = 1;
254 if (op->material & M_GLASS && rndm (1, 2) == 1)
255 destroy = 1;
256 if ((op->material & M_STONE || op->material & M_ADAMANT) && rndm (1, 10) == 1)
257 destroy = 1;
258 if ((op->material & M_SOFT_METAL || op->material & M_BONE) && rndm (1, 3) == 1)
259 destroy = 1;
260 if (op->material & M_ICE && MAP_TEMP (m) > 32)
261 destroy = 1;
262 } 261 }
262
263 /* adjust overall chance below */ 263 /* adjust overall chance below */
264 if (destroy && rndm (0, 1)) 264 if (destroy && rndm (0, 1))
265 op->destroy (); 265 op->destroy ();
266 } 266 }
267} 267}
268 268
269/* convert materialname to materialtype_t */ 269/* convert materialname to materialtype_t */
270 270
271materialtype_t * 271materialtype_t *
544 return; 544 return;
545} 545}
546 546
547///////////////////////////////////////////////////////////////////////////// 547/////////////////////////////////////////////////////////////////////////////
548 548
549#if 0
550refcounted *refcounted::rc_first;
551
552refcounted::refcounted ()
553{
554 refcnt = 0;
555 rc_next = rc_first;
556 rc_first = this;
557}
558
559refcounted::~refcounted ()
560{
561 assert (!rc_next);
562 assert (!refcnt);
563}
564#endif
565
566void *salloc_ (int n) throw (std::bad_alloc) 549void *salloc_ (int n) throw (std::bad_alloc)
567{ 550{
568 void *ptr = g_slice_alloc (n); 551 void *ptr = g_slice_alloc (n);
569 552
570 if (!ptr) 553 if (!ptr)
615 598
616 gettimeofday (&tv, 0); 599 gettimeofday (&tv, 0);
617 return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6); 600 return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6);
618} 601}
619 602
603int
604similar_direction (int a, int b)
605{
606 if (!a || !b)
607 return 0;
608
609 int diff = (b - a) & 7;
610 return diff <= 1 || diff >= 7;
611}
612

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines