[CF-Devel] Re: Patch: Win32 fixes

crossfire-devel at archives.real-time.com crossfire-devel at archives.real-time.com
Wed Apr 28 10:41:26 CDT 2004


Nicolas Weeger wrote:
>
     
      Just a small patch for 1.6.0 release, I don't think it changes
     
     >
     
      anything to Linux, but just to be on the safe side, i submit it here
     
     >
     
      :)
     
     
It does not work with Linux and gcc 3.3.2 :-(

>
     
      Just need 3 explicit casts from 'float' to 'unsigned float', because
     
     >
     
      messing uint64 & float isn't great apparently (error message). Since
     
     >
     
      the 3 are in shops or money-related, and the value is a uint64, the
     
     >
     
      cast seems harmless.
     
     
The README file states that an "Ansi C compiler" is a requirement to
compile the game. Ansi C (C99) does not define the type "unsigned float"
but allows casts between "float" and "[unsigned] [long] long". Therefore
this *should* work.

I think we should use Ansi C constructs in the common (i.e. all
non-WIN32) parts to remain portable. Therefore we should not introduce
the type "unsigned float" even if we can make it work with gcc.

One solution to keep all compilers happy may be to avoid the casts (see
attached diff):

 - Both casts in "shop.c" (explicit cast from "float" to "long" and
   implicit cast from "long" to "uint64") should cause no problems.
   (Note: I don't know if the accuracy of three digits is sufficient.)

 - The calculation in "spell_effect.c" does no type conversion anymore.

(Note: I have no WIN32 compiler. Therefore I could not check if it
actually works with this compiler.)
-------------- next part --------------
Index: server/shop.c
===================================================================
RCS file: /cvsroot/crossfire/crossfire/server/shop.c,v
retrieving revision 1.28
diff -u -w -r1.28 shop.c
--- server/shop.c	25 Apr 2004 07:17:40 -0000	1.28
+++ server/shop.c	28 Apr 2004 15:11:31 -0000
@@ -189,9 +189,9 @@
 	 * reflect values (potion charisma list for 1250 gold)
 	 */
 	if(flag==F_BUY)
-          val=(4.0*(float)val*(1.0+diff));
+          val=(4*val*(long)(1000*(1+diff)))/1000;
 	else if (flag==F_SELL)
-          val=(4.0*(float)val*(1.0-diff));
+          val=(4*val*(long)(1000*(1-diff)))/1000;
 	else val *=4;
     }
 
Index: server/spell_effect.c
===================================================================
RCS file: /cvsroot/crossfire/crossfire/server/spell_effect.c,v
retrieving revision 1.117
diff -u -w -r1.117 spell_effect.c
--- server/spell_effect.c	25 Apr 2004 07:17:40 -0000	1.117
+++ server/spell_effect.c	28 Apr 2004 15:11:31 -0000
@@ -1648,7 +1648,7 @@
     else if (obj->type==MONEY || obj->type==GEM)
 	value /=3;
     else
-	value *= 0.9;
+	value = (value*9)/10;
 
     if ((obj->value>0) && rndm(0, 29)) {
 	int count;
-------------- next part --------------
_______________________________________________
crossfire-devel mailing list
     
     crossfire-devel at lists.real-time.com
     
     
     https://mailman.real-time.com/mailman/listinfo/crossfire-devel
     
     
    


More information about the crossfire mailing list