[Freeciv-Dev] (PR#12706) Events framework
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12706 >
> [vasc - Tue May 03 15:07:43 2005]:
>
> > [jdorje - Mon May 02 15:35:34 2005]:
> >
> > And, the random-number function needs to check it's parameters or it can
> > crash.
>
> Thanks! I will make a patch fix for this post-commit of actions.diff.gz.
Here is the patch. To be committed ASAP.
Index: server/scripting/api.pkg
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api.pkg,v
retrieving revision 1.2
diff -u -u -r1.2 api.pkg
--- server/scripting/api.pkg 3 May 2005 15:09:05 -0000 1.2
+++ server/scripting/api.pkg 3 May 2005 23:26:40 -0000
@@ -318,20 +318,16 @@
$]
/* Utilities module. */
-module utilities {
- unsigned api_utilities_random @ random (unsigned min, unsigned max);
-}
+int api_utilities_random @ random (int min, int max);
/* Actions module. */
-module actions {
- Unit *api_actions_create_unit @ create_unit (Player *pplayer, Tile *ptile,
- Unit_Type *ptype,
- int veteran_level,
- City *homecity, int moves_left);
- void api_actions_create_city @ create_city (Player *pplayer, Tile *ptile,
- const char *name);
- void api_actions_change_gold @ change_gold (Player *pplayer, int amount);
- bool api_actions_give_technology @ give_technology (Player *pplayer,
- Tech_Type *ptech);
-}
+Unit *api_actions_create_unit @ create_unit (Player *pplayer, Tile *ptile,
+ Unit_Type *ptype,
+ int veteran_level,
+ City *homecity, int moves_left);
+void api_actions_create_city @ create_city (Player *pplayer, Tile *ptile,
+ const char *name);
+void api_actions_change_gold @ change_gold (Player *pplayer, int amount);
+bool api_actions_give_technology @ give_technology (Player *pplayer,
+ Tech_Type *ptech);
Index: server/scripting/api_utilities.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api_utilities.c,v
retrieving revision 1.1
diff -u -u -r1.1 api_utilities.c
--- server/scripting/api_utilities.c 3 May 2005 15:09:05 -0000 1.1
+++ server/scripting/api_utilities.c 3 May 2005 23:26:40 -0000
@@ -15,12 +15,16 @@
#include <config.h>
#endif
+#include <math.h>
+
#include "rand.h"
#include "api_utilities.h"
-unsigned api_utilities_random(unsigned min, unsigned max)
+int api_utilities_random(int min, int max)
{
- return (min + myrand(max - min));
+ double roll = (double)(myrand(MAX_UINT32) % MAX_UINT32) / (double)MAX_UINT32;
+
+ return (min + floor(roll * (max - min + 1)));
}
Index: server/scripting/api_utilities.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/scripting/api_utilities.h,v
retrieving revision 1.1
diff -u -u -r1.1 api_utilities.h
--- server/scripting/api_utilities.h 3 May 2005 15:09:05 -0000 1.1
+++ server/scripting/api_utilities.h 3 May 2005 23:26:40 -0000
@@ -14,7 +14,7 @@
#ifndef FC__API_UTILITIES_H
#define FC__API_UTILITIES_H
-unsigned api_utilities_random(unsigned min, unsigned max);
+int api_utilities_random(int min, int max);
#endif
- [Freeciv-Dev] Re: (PR#12706) Events framework, Vasco Alexandre da Silva Costa, 2005/05/02
- [Freeciv-Dev] (PR#12706) Events framework, Vasco Alexandre da Silva Costa, 2005/05/03
- [Freeciv-Dev] (PR#12706) Events framework, Vasco Alexandre da Silva Costa, 2005/05/03
- [Freeciv-Dev] Re: (PR#12706) Events framework, Jason Short, 2005/05/03
- [Freeciv-Dev] (PR#12706) Events framework,
Vasco Alexandre da Silva Costa <=
- [Freeciv-Dev] (PR#12706) Events framework, Vasco Alexandre da Silva Costa, 2005/05/06
- [Freeciv-Dev] (PR#12706) Events framework, Guest, 2005/05/23
- [Freeciv-Dev] Re: (PR#12706) Events framework, Per I. Mathisen, 2005/05/24
- [Freeciv-Dev] Re: (PR#12706) Events framework, Jason Short, 2005/05/24
- [Freeciv-Dev] (PR#12706) Events framework, Guest, 2005/05/24
- [Freeciv-Dev] (PR#12706) Events framework, Guest, 2005/05/24
- [Freeciv-Dev] Re: (PR#12706) Events framework, Jason Short, 2005/05/24
- [Freeciv-Dev] Re: (PR#12706) Events framework, Vasco Alexandre da Silva Costa, 2005/05/24
- [Freeciv-Dev] Re: (PR#12706) Events framework, Vasco Alexandre da Silva Costa, 2005/05/24
- [Freeciv-Dev] Re: (PR#12706) Events framework, Peter Schaefer, 2005/05/25
|
|