Skip to content

Commit

Permalink
Changed all integers to ints
Browse files Browse the repository at this point in the history
All integers in function parameters and return types are now either int
or uint.  In fact most of the numeric values in the code are now either
int or uint, with the exception being coordinate values, which are
ubytes.  This has been done to reduce the amount of conversion necessary
to expand the codebase.
  • Loading branch information
Philip Pavlick committed Sep 3, 2018
1 parent 2a1773b commit fd09384
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/color.d
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import global;
+/
struct Color
{
ubyte fg;
uint fg;
// `reverse' determines if the foreground and background colors are
// reversed.
bool reverse;
Expand Down
24 changes: 12 additions & 12 deletions src/dice.d
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ struct Dicebag
{
// `dice' is the number of d6es, `modifier' gets added to the result of the
// roll
ubyte dice;
short modifier;
uint dice;
int modifier;
// `floor' and `ceiling' represent an absolute maximum and absolute minimum.
// these are enforced after the modifier is added. If `floor' < `ceiling',
// use the global limits. Note that there is absolutely nothing stopping
Expand All @@ -52,7 +52,7 @@ struct Dicebag
+ This function is a holdover from the C days. Use D's generic struct
+ constructor instead.
+/
Dicebag Dice( ubyte d, short m, int f, int c )
Dicebag Dice( uint d, int m, int f, int c )
{
Dicebag r = { dice:d, modifier:m, floor:f, ceiling:c };
return r;
Expand Down Expand Up @@ -111,7 +111,7 @@ bool flip()
+ Returns:
+ A random value between 1 and 6 as a `uint`.
+/
uint d()
int d()
{ return uniform( 1, 7, Lucky );
}

Expand All @@ -127,7 +127,7 @@ uint d()
+ Returns:
+ A random number between 1 + `mod` and 6 + `mod`
+/
int dm( byte mod )
int dm( int mod )
{ return (d() + mod);
}

Expand Down Expand Up @@ -169,9 +169,9 @@ int td10()
+ Returns:
+ A random number from 1 to 10
+/
uint d10()
int d10()
{
uint result = td10();
int result = td10();
return result == 0 ? 10 : result;
}

Expand All @@ -194,9 +194,9 @@ uint d10()
+ Returns:
+ A random number between 1 and 100
+/
uint d100()
int d100()
{
uint t = td10(), u = td10();
int t = td10(), u = td10();
if( t == 0 && u == 0 )
{ return 100;
}
Expand All @@ -216,7 +216,7 @@ uint d100()
+ Returns:
+ Either a 1 or a 2, randomly selected.
+/
uint d2()
int d2()
{ return uniform( 1, 3 );
}

Expand Down Expand Up @@ -244,7 +244,7 @@ uint d2()
+ 1, if s == 1; $(LF)
+ A random number between 1 and s, if s &gt; 1
+/
uint dn( int s )
int dn( int s )
{
/* if sides == 1, just return 1. if sides == 0, return 0.
* if sides < 0, force that result (e.g. -4 always produces 4) */
Expand Down Expand Up @@ -416,6 +416,6 @@ bool quick_check( uint num, int mod, uint difficulty )
+ `false` otherwise.
+/
bool quick_check_x( uint num, int mod, uint difficulty,
uint floor, uint ceiling )
int floor, int ceiling )
{ return roll_x( num, mod, floor, ceiling ) <= difficulty;
}
2 changes: 1 addition & 1 deletion src/fov.d
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void TCOD_map_compute_fov_recursive_shadowcasting(
+ viewer_y = The y coordinate of the start point for field-of-vision
+ calculation
+/
void calc_visible( Map* to_display, ushort viewer_x, ushort viewer_y )
void calc_visible( Map* to_display, uint viewer_x, uint viewer_y )
{
TCOD_map_compute_fov_recursive_shadowcasting(
to_display, viewer_x, viewer_y, 0, true );
Expand Down
6 changes: 3 additions & 3 deletions src/inven.d
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ struct Inven
// all `Items' carried in this inventory; 14 "inventory slots" for the
// various body parts, plus 26 for the "bag" (to be implemented)
Item[40] items;
ubyte quiver_count;
ubyte coins;
uint quiver_count;
uint coins;
}

// Special array indeces in the `items' array which correspond to the
Expand Down Expand Up @@ -74,7 +74,7 @@ enum INVENT_LAST_SLOT = INVENT_TAIL;
+ Returns:
+ `true` if i can be equipped in equipment slot s, `false` otherwise
+/
bool check_equip( Item i, ubyte s )
bool check_equip( Item i, uint s )
{
// an empty item can go in any slot (obviously)
if( i.sym.ch == '\0' )
Expand Down
4 changes: 2 additions & 2 deletions src/iocurses.d
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CursesIO : SwashIO
+
+ If `COLOR` is turned on, curses color pairs will be defined here.
+/
this( ushort screen_size_vertical = 24, ushort screen_size_horizontal = 80 )
this( ubyte screen_size_vertical = 24, ubyte screen_size_horizontal = 80 )
{
// Initializing curses
initscr();
Expand Down Expand Up @@ -187,7 +187,7 @@ static if( COLOR )
+ An `attr_t` which can be used to activate colors in the curses
+ interface
+/
attr_t get_color( ubyte color )
attr_t get_color( uint color )
{
switch( color )
{
Expand Down
4 changes: 2 additions & 2 deletions src/ioterm.d
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class SDLTerminalIO : SwashIO
+ Returns:
+ `true` if successful, `false` otherwise.
+/
private bool loadfont( string fpath, ushort height,
private bool loadfont( string fpath, uint height,
ref SDL_Texture*[] target )
{
import std.string : toStringz;
Expand Down Expand Up @@ -336,7 +336,7 @@ class SDLTerminalIO : SwashIO
+ Returns:
+ An `SDL_Color` which can be used by SDL to color textures
+/
SDL_Color to_SDL_Color( ubyte color )
SDL_Color to_SDL_Color( uint color )
{

// Unfortunately this is one of those cases where we just have to use a
Expand Down
4 changes: 2 additions & 2 deletions src/item.d
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ struct Item
{
Symbol sym;
string name;
ushort type, equip;
uint type, equip;
/* modifiers to the player's dice rolls */
byte addd, addm;
int addd, addm;
}

/// A generic Item used to signal an empty equipment slot or a floor tile
Expand Down
4 changes: 2 additions & 2 deletions src/map.d
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void add_mon( Map* mp, Monst mn )
+ be a pointer.
+ index = The index in `mp.m` which is to be removed.
+/
void remove_mon( Map* mp, ushort index )
void remove_mon( Map* mp, uint index )
{
// To remove a Monster in a Map's mon array, move all Monsters that are
// past it in the array up, thus overwriting it.
Expand Down Expand Up @@ -132,7 +132,7 @@ void remove_mon( Map* mp, ushort index )
+ Returns:
+ `true` if the corridor was added to m successfully, `false` otherwise
+/
bool add_corridor_y( uint x, uint y1, int y2, Map* m )
bool add_corridor_y( uint x, uint y1, uint y2, Map* m )
{
// Check if the corridor will be within the bounds of the Map.
if( x < 1 || x > MAP_x )
Expand Down
26 changes: 13 additions & 13 deletions src/monst.d
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ struct Mon
{
Symbol sym;
string name;
ubyte fly;
ubyte swim;
uint fly;
uint swim;
Dicebag hit_dice;
Dicebag attack_roll;
}
Expand Down Expand Up @@ -90,9 +90,9 @@ struct Mon
+ Returns:
+ A `mon`
+/
Mon mondat( char isym, string iname, ubyte ifly, ubyte iswim,
ubyte hit_dice, short hit_modifier, int hit_min, int hit_max,
ubyte at_dice, short at_modifier, int at_min, int at_max )
Mon mondat( char isym, string iname, uint ifly, uint iswim,
uint hit_dice, int hit_modifier, int hit_min, int hit_max,
uint at_dice, int at_modifier, int at_min, int at_max )
{
Mon mn = { sym:symdata( isym, CLR_DEFAULT ), name:iname, fly:ifly,
swim:iswim,
Expand Down Expand Up @@ -129,8 +129,8 @@ struct Monst
Symbol sym;
string name;
int hp;
ubyte fly;
ubyte swim;
uint fly;
uint swim;
Dicebag attack_roll;
ubyte x, y;
Inven inventory;
Expand Down Expand Up @@ -236,9 +236,9 @@ Monst monster( Mon mn )
+ Returns:
+ A `Monst` generated from the function parameters at coordinates (x, y)
+/
Monst new_monst_at( char isym, string iname, ubyte ifly, ubyte iswim,
ubyte hit_dice, short hit_mod, int hit_min, int hit_max,
ubyte at_dice, short at_mod, int at_min, int at_max,
Monst new_monst_at( char isym, string iname, uint ifly, uint iswim,
uint hit_dice, int hit_mod, int hit_min, int hit_max,
uint at_dice, int at_mod, int at_min, int at_max,
ubyte x, ubyte y )
{
Monst mon = { sym:symdata( isym, CLR_DEFAULT ), name:iname,
Expand Down Expand Up @@ -292,9 +292,9 @@ Monst new_monst_at( char isym, string iname, ubyte ifly, ubyte iswim,
+ Returns:
+ A `Monst` generated from the function parameters
+/
Monst new_monst( char isym, string iname, ubyte ifly, ubyte iswim,
ubyte hit_dice, short hit_mod, int hit_min, int hit_max,
ubyte at_dice, short at_mod, int at_min, int at_max )
Monst new_monst( char isym, string iname, uint ifly, uint iswim,
uint hit_dice, int hit_mod, int hit_min, int hit_max,
uint at_dice, int at_mod, int at_min, int at_max )
{ return new_monst_at( isym, iname, ifly, iswim, hit_dice, hit_mod, hit_min,
hit_max, at_dice, at_mod, at_min, at_max,
0, 0
Expand Down
18 changes: 9 additions & 9 deletions src/mov.d
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import global;
+ coordinate, which will be changed to either -1, 0, or 1 depending
+ on what `dir`ection the monster is moving in
+/
void get_dydx( ubyte dir, byte* dy, byte* dx )
void get_dydx( uint dir, byte* dy, byte* dx )
{
switch( dir )
{
Expand Down Expand Up @@ -208,7 +208,7 @@ void mmove( Monst* mn, Map* m, byte idy, byte idx, Player* u )
{
uint dy = idy, dx = idx;

ubyte terrain = 0, monster = 0;
uint terrain = 0, monster = 0;

dx = dx + mn.x; dy = dy + mn.y;
bool cardinal = dx == 0 || dy == 0;
Expand Down Expand Up @@ -299,8 +299,8 @@ void mmove( Monst* mn, Map* m, byte idy, byte idx, Player* u )
void monst_ai( Map* m, uint index, Player* u )
{
Monst* mn = &m.m[index];
int mnx = mn.x, mny = mn.y, ux = u.x, uy = u.y,
dx = 0, dy = 0;
ubyte mnx = mn.x, mny = mn.y, ux = u.x, uy = u.y;
byte dx = 0, dy = 0;
if( mnx > ux )
dx = -1;
if( mnx < ux )
Expand All @@ -309,7 +309,7 @@ void monst_ai( Map* m, uint index, Player* u )
dy = -1;
if( mny < uy )
dy = 1;
mmove( mn, m, cast(byte)dy, cast(byte)dx, u );
mmove( mn, m, dy, dx, u );
}

/++
Expand Down Expand Up @@ -344,7 +344,7 @@ void monst_ai( Map* m, uint index, Player* u )
+ A `ubyte` representing the number of turns expended by the player while
+ moving (usually 1 or 0)
+/
ubyte umove( Player* u, Map* m, ubyte dir )
uint umove( Player* u, Map* m, uint dir )
{
if( dir == MOVE_GET )
{
Expand All @@ -359,7 +359,7 @@ ubyte umove( Player* u, Map* m, ubyte dir )
get_dydx( dir, &dy, &dx );
bool cardinal = dy == 0 || dx == 0;

ubyte terrain = 0, monster = 0;
uint terrain = 0, monster = 0;

dx += u.x; dy += u.y;

Expand Down Expand Up @@ -529,10 +529,10 @@ void map_move_all_monsters( Map* m, Player* u )
foreach( mn; 0 .. m.m.length )
{
if( m.m[mn].hp > 0 )
{ monst_ai( m, cast(uint)mn, u );
{ monst_ai( m, mn, u );
}
else
{ remove_mon( m, cast(ushort)mn );
{ remove_mon( m, mn );
}
}
}
Loading

0 comments on commit fd09384

Please sign in to comment.