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.30 by root, Mon Dec 25 14:43:23 2006 UTC vs.
Revision 1.35 by root, Mon Jan 1 13:31:46 2007 UTC

195 return (min); 195 return (min);
196 196
197 return (RANDOM () % diff + min); 197 return (RANDOM () % diff + min);
198} 198}
199 199
200/* decay and destroy persihable items in a map */ 200/* decay and destroy perishable items in a map */
201
202void 201void
203decay_objects (maptile *m) 202maptile::decay_objects ()
204{ 203{
205 int x, y, destroy; 204 if (!spaces)
206 object *op, *otmp;
207
208 if (m->unique)
209 return; 205 return;
210 206
211 for (x = 0; x < m->width; x++) 207 for (mapspace *ms = spaces + size (); ms-- > spaces; )
212 for (y = 0; y < m->height; y++) 208 for (object *above, *op = ms->bot; op; op = above)
213 for (op = GET_MAP_OB (m, x, y); op; op = otmp)
214 { 209 {
210 above = op->above;
211
215 destroy = 0; 212 bool destroy = 0;
216 otmp = op->above; 213
214 // do not decay anything above unique floor tiles (yet :)
217 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) 215 if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE))
218 break; 216 break;
217
219 if (QUERY_FLAG (op, FLAG_IS_FLOOR) 218 if (QUERY_FLAG (op, FLAG_IS_FLOOR)
220 || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL) 219 || QUERY_FLAG (op, FLAG_OBJ_ORIGINAL)
221 || QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL) 220 || QUERY_FLAG (op, FLAG_OBJ_SAVE_ON_OVL)
222 || QUERY_FLAG (op, FLAG_UNIQUE) 221 || QUERY_FLAG (op, FLAG_UNIQUE)
223 || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR) 222 || QUERY_FLAG (op, FLAG_OVERLAY_FLOOR)
224 || QUERY_FLAG (op, FLAG_UNPAID) 223 || QUERY_FLAG (op, FLAG_UNPAID)
225 || op->is_alive ()) 224 || op->is_alive ())
226 continue; 225 ; // do not decay
227
228 /* otherwise, we decay and destroy */
229 if (op->is_weapon ()) 226 else if (op->is_weapon ())
230 { 227 {
231 op->stats.dam--; 228 op->stats.dam--;
232 if (op->stats.dam < 0) 229 if (op->stats.dam < 0)
233 destroy = 1; 230 destroy = 1;
234 } 231 }
235 else if (op->is_armor ()) 232 else if (op->is_armor ())
236 { 233 {
237 op->stats.ac--; 234 op->stats.ac--;
238 if (op->stats.ac < 0) 235 if (op->stats.ac < 0)
239 destroy = 1; 236 destroy = 1;
240 } 237 }
241 else if (op->type == FOOD) 238 else if (op->type == FOOD)
242 { 239 {
243 op->stats.food -= rndm (5, 20); 240 op->stats.food -= rndm (5, 20);
244 if (op->stats.food < 0) 241 if (op->stats.food < 0)
245 destroy = 1; 242 destroy = 1;
246 } 243 }
247 else 244 else
248 { 245 {
249 if (op->material & M_PAPER || op->material & M_LEATHER || 246 int mat = op->material;
250 op->material & M_WOOD || op->material & M_ORGANIC || op->material & M_CLOTH || op->material & M_LIQUID) 247
248 if (mat & M_PAPER
249 || mat & M_LEATHER
250 || mat & M_WOOD
251 || mat & M_ORGANIC
252 || mat & M_CLOTH
253 || mat & M_LIQUID
254 || (mat & M_IRON && rndm (1, 5) == 1)
255 || (mat & M_GLASS && rndm (1, 2) == 1)
256 || ((mat & M_STONE || mat & M_ADAMANT) && rndm (1, 10) == 1)
257 || ((mat & M_SOFT_METAL || mat & M_BONE) && rndm (1, 3) == 1)
258 || (mat & M_ICE && temp > 32))
251 destroy = 1; 259 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 } 260 }
261
263 /* adjust overall chance below */ 262 /* adjust overall chance below */
264 if (destroy && rndm (0, 1)) 263 if (destroy && rndm (0, 1))
265 op->destroy (); 264 op->destroy ();
266 } 265 }
267} 266}
268 267
269/* convert materialname to materialtype_t */ 268/* convert materialname to materialtype_t */
270 269
271materialtype_t * 270materialtype_t *
598 597
599 gettimeofday (&tv, 0); 598 gettimeofday (&tv, 0);
600 return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6); 599 return tstamp (tv.tv_sec) + tstamp (tv.tv_usec) * tstamp (1e-6);
601} 600}
602 601
602int
603similar_direction (int a, int b)
604{
605 if (!a || !b)
606 return 0;
607
608 int diff = (b - a) & 7;
609 return diff <= 1 || diff >= 7;
610}
611

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines