--- deliantra/server/common/utils.C 2007/04/23 18:09:57 1.51 +++ deliantra/server/common/utils.C 2007/06/04 12:19:08 1.58 @@ -1,25 +1,25 @@ /* - * CrossFire, A Multiplayer game for X-windows + * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2002 Mark Wedel & Crossfire Development Team - * Copyright (C) 1992 Frank Tore Johansen + * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992,2007 Frank Tore Johansen * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * Crossfire TRT is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * The authors can be reached via e-mail at + * You should have received a copy of the GNU General Public License along + * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * The authors can be reached via e-mail to */ /* @@ -97,9 +97,9 @@ { int base = r_max - r_min > 1 ? 20 : 50; /* d2 and d3 are corner cases */ - if (r_max < 1 || r_max < r_min) + if (r_max < r_min) { - LOG (llevError, "Calling random_roll with min=%d max=%d\n", r_min, r_max); + LOG (llevError | logBacktrace, "Calling random_roll with min=%d max=%d\n", r_min, r_max); return r_min; } @@ -123,16 +123,13 @@ sint64 random_roll64 (sint64 min, sint64 max, const object *op, int goodbad) { - sint64 omin, diff, luck, ran; - int base; - - omin = min; - diff = max - min + 1; - ((diff > 2) ? (base = 20) : (base = 50)); /* d2 and d3 are corner cases */ + sint64 omin = min; + sint64 diff = max - min + 1; + int base = diff > 2 ? 20 : 50; /* d2 and d3 are corner cases */ - if (max < 1 || diff < 1) + if (diff < 0) { - LOG (llevError, "Calling random_roll with min=%" PRId64 " max=%" PRId64 "\n", min, max); + LOG (llevError | logBacktrace, "Calling random_roll64 with min=%" PRId64 " max=%" PRId64 "\n", min, max); return (min); /* avoids a float exception */ } @@ -140,12 +137,13 @@ * Make a call to get two 32 bit unsigned random numbers, and just to * a little bitshifting. */ - ran = (sint64) rndm.next () ^ ((sint64) rndm.next () << 31); + sint64 ran = (sint64) rndm.next () ^ ((sint64) rndm.next () << 31); if (op->type != PLAYER) return ((ran % diff) + min); - luck = op->stats.luck; + int luck = op->stats.luck; + if (rndm (base) < MIN (10, abs (luck))) { /* we have a winner */ @@ -153,12 +151,13 @@ diff -= luck; if (diff < 1) return (omin); /*check again */ + ((goodbad) ? (min += luck) : (diff)); return (MAX (omin, MIN (max, (ran % diff) + min))); } - return ((ran % diff) + min); + return ran % diff + min; } /* @@ -168,20 +167,20 @@ * not the recipient (ie, the poor slob getting hit). * The args are num D size (ie 4d6) [garbled 20010916] */ - int die_roll (int num, int size, const object *op, int goodbad) { - int min, diff, luck, total, i, gotlucky, base; + int min, luck, total, i, gotlucky; - diff = size; + int diff = size; min = 1; luck = total = gotlucky = 0; - ((diff > 2) ? (base = 20) : (base = 50)); /* d2 and d3 are corner cases */ + int base = diff > 2 ? 20 : 50; /* d2 and d3 are corner cases */ + if (size < 2 || diff < 1) { LOG (llevError, "Calling die_roll with num=%d size=%d\n", num, size); - return (num); /* avoids a float exception */ + return num; /* avoids a float exception */ } if (op->type == PLAYER) @@ -309,7 +308,7 @@ mt = name_to_material (op->materialname); if (!mt) { - LOG (llevError, "archetype '%s>%s' uses nonexistent material '%s'\n", &op->arch->name, &op->name, &op->materialname); + LOG (llevError, "archetype '%s>%s' uses nonexistent material '%s'\n", &op->arch->archname, &op->name, &op->materialname); return; } @@ -555,6 +554,9 @@ if (!fork ()) { signal (SIGABRT, SIG_DFL); + // try to put corefiles into a subdirectory, if existing, to allow + // an administrator to reduce the I/O load. + chdir ("cores"); abort (); }