Changed all the various unnecessarily specifically defined types to "int".
Most of these were defining various integers as char types, probably in the naive belief that this is necessarily good because it uses less RAM. There were also several unnecessary unsigned ints, though. These have all been changed to just "int", so the compiler can decide exactly what type to use.
This commit is contained in:
parent
75374cfbc4
commit
1567595def
|
@ -26,6 +26,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#define LIMIT_ADD(x, y, a, b) x = (((x) + (y)) < (b) ? \
|
#define LIMIT_ADD(x, y, a, b) x = (((x) + (y)) < (b) ? \
|
||||||
(((x) + (y)) > (a) ? \
|
(((x) + (y)) > (a) ? \
|
||||||
((x) + (y)) : (a)) : (b))
|
((x) + (y)) : (a)) : (b))
|
||||||
|
#define WRAP_ADD(x, y, a, b) x = (((x) + (y)) + \
|
||||||
|
((x) + (y) < (a) ? ((b) - (a)) : 0) + \
|
||||||
|
((x) + (y) > (b) ? ((a) - (b)) : 0))
|
||||||
|
|
||||||
// ALL
|
// ALL
|
||||||
#define NONE 0
|
#define NONE 0
|
||||||
|
|
|
@ -892,7 +892,7 @@ int mainGameLoop()
|
||||||
doExplosions();
|
doExplosions();
|
||||||
doInfo();
|
doInfo();
|
||||||
|
|
||||||
wrapChar(&(--engine.eventTimer), 0, 60);
|
WRAP_ADD(engine.eventTimer, -1, 0, 60);
|
||||||
|
|
||||||
if (engine.paused)
|
if (engine.paused)
|
||||||
{
|
{
|
||||||
|
@ -916,7 +916,7 @@ int mainGameLoop()
|
||||||
|
|
||||||
if (engine.addAliens > -1)
|
if (engine.addAliens > -1)
|
||||||
{
|
{
|
||||||
wrapInt(&(--engine.addAliens), 0, currentMission.addAliens);
|
WRAP_ADD(engine.addAliens, -1, 0, currentMission.addAliens);
|
||||||
if ((engine.addAliens == 0) && (allowableAliens > 0))
|
if ((engine.addAliens == 0) && (allowableAliens > 0))
|
||||||
{
|
{
|
||||||
allowableAliens -= alien_add();
|
allowableAliens -= alien_add();
|
||||||
|
|
|
@ -698,8 +698,7 @@ SDL_Surface *loadImage(const char *filename)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Simply draws the stars in their positions on screen and moves
|
Simply draws the stars in their positions on screen and moves
|
||||||
them around. They are wrapped around using the wrapFloat()
|
them around.
|
||||||
function, as defined above, and putpixel as defined in cpp
|
|
||||||
*/
|
*/
|
||||||
void doStarfield()
|
void doStarfield()
|
||||||
{
|
{
|
||||||
|
@ -723,9 +722,9 @@ void doStarfield()
|
||||||
else if (star[i].speed == 1)
|
else if (star[i].speed == 1)
|
||||||
color = darkGrey;
|
color = darkGrey;
|
||||||
|
|
||||||
wrapFloat(&(star[i].x += ((engine.ssx + engine.smx) * star[i].speed)), 0,
|
WRAP_ADD(star[i].x, (engine.ssx + engine.smx) * star[i].speed, 0,
|
||||||
screen->w - 1);
|
screen->w - 1);
|
||||||
wrapFloat(&(star[i].y += ((engine.ssy + engine.smy) * star[i].speed)), 0,
|
WRAP_ADD(star[i].y, (engine.ssy + engine.smy) * star[i].speed, 0,
|
||||||
screen->h - 1);
|
screen->h - 1);
|
||||||
|
|
||||||
putpixel(screen, (int)star[i].x, (int)star[i].y, color);
|
putpixel(screen, (int)star[i].x, (int)star[i].y, color);
|
||||||
|
|
|
@ -141,7 +141,7 @@ void saveGame(int slot)
|
||||||
sprintf(fileName, "%ssave%.2d.dat", engine.userHomeDirectory, slot);
|
sprintf(fileName, "%ssave%.2d.dat", engine.userHomeDirectory, slot);
|
||||||
fp = fopen(fileName, "wb");
|
fp = fopen(fileName, "wb");
|
||||||
|
|
||||||
currentGame.saveFormat = 2;
|
currentGame.saveFormat = 3;
|
||||||
currentGame.playerWeapon = weapon[W_PLAYER_WEAPON];
|
currentGame.playerWeapon = weapon[W_PLAYER_WEAPON];
|
||||||
currentGame.thePlayer = player;
|
currentGame.thePlayer = player;
|
||||||
for (int i = 0 ; i < 10 ; i++)
|
for (int i = 0 ; i < 10 ; i++)
|
||||||
|
|
24
src/math.h
24
src/math.h
|
@ -20,30 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#ifndef MATH_H
|
#ifndef MATH_H
|
||||||
#define MATH_H
|
#define MATH_H
|
||||||
|
|
||||||
static inline void wrapChar(signed char *in, signed char low, signed char high)
|
|
||||||
{
|
|
||||||
if (*in < low)
|
|
||||||
*in += high - low;
|
|
||||||
if (*in > high)
|
|
||||||
*in -= high - low;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void wrapInt(int *in, int low, int high)
|
|
||||||
{
|
|
||||||
if (*in < low)
|
|
||||||
*in += high - low;
|
|
||||||
if (*in > high)
|
|
||||||
*in -= high - low;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void wrapFloat(float *in, float low, float high)
|
|
||||||
{
|
|
||||||
if (*in < low)
|
|
||||||
*in += high - low;
|
|
||||||
if (*in > high)
|
|
||||||
*in -= high - low;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int rrand(int min, int max)
|
static inline int rrand(int min, int max)
|
||||||
{
|
{
|
||||||
int r = min;
|
int r = min;
|
||||||
|
|
177
src/structs.h
177
src/structs.h
|
@ -23,22 +23,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
struct object {
|
struct object {
|
||||||
|
|
||||||
bool active;
|
bool active;
|
||||||
signed char classDef; // Used by aliens to determine what they are
|
int classDef; // Used by aliens to determine what they are
|
||||||
signed char AIType; // Type of articifial intelligence
|
int AIType; // Type of articifial intelligence
|
||||||
|
|
||||||
signed char id; // The "job" of the object
|
int id; // The "job" of the object
|
||||||
object *target; // index target in aliens array
|
object *target; // index target in aliens array
|
||||||
|
|
||||||
signed char reload[2];
|
int reload[2];
|
||||||
|
|
||||||
int systemPower; // computer systems for craft
|
int systemPower; // computer systems for craft
|
||||||
int shield; // current shield
|
int shield; // current shield
|
||||||
int maxShield; // max shield (for recharging)
|
int maxShield; // max shield (for recharging)
|
||||||
int deathCounter; // how long to explode for
|
int deathCounter; // how long to explode for
|
||||||
|
|
||||||
signed char speed;
|
int speed;
|
||||||
int damage; // Contact damage for bullets
|
int damage; // Contact damage for bullets
|
||||||
unsigned char ammo[2]; // Ammo for 2nd weapon.
|
int ammo[2]; // Ammo for 2nd weapon.
|
||||||
|
|
||||||
int face; // Either 0 or 1
|
int face; // Either 0 or 1
|
||||||
|
|
||||||
|
@ -47,18 +47,18 @@ struct object {
|
||||||
int chance[2]; // Chance of using the weapons (out of 1000)
|
int chance[2]; // Chance of using the weapons (out of 1000)
|
||||||
|
|
||||||
SDL_Surface *image[2]; // For facing left and right
|
SDL_Surface *image[2]; // For facing left and right
|
||||||
unsigned char imageIndex[2]; // used for loading
|
int imageIndex[2]; // used for loading
|
||||||
signed char hit; // used to make a craft "flash" if it is struck by a shot
|
int hit; // used to make a craft "flash" if it is struck by a shot
|
||||||
|
|
||||||
int engineX; // The place for the engine on the other side of the craft
|
int engineX; // The place for the engine on the other side of the craft
|
||||||
int engineY; // The middle of the engine on the craft
|
int engineY; // The middle of the engine on the craft
|
||||||
|
|
||||||
int thinktime; // When the object will next react
|
int thinktime; // When the object will next react
|
||||||
signed char weaponType[2]; // Weapon types
|
int weaponType[2]; // Weapon types
|
||||||
|
|
||||||
signed char collectChance; // Chance of dropping the object
|
int collectChance; // Chance of dropping the object
|
||||||
signed char collectType; // What the object is carrying
|
int collectType; // What the object is carrying
|
||||||
unsigned int collectValue; // What it is worth
|
int collectValue; // What it is worth
|
||||||
|
|
||||||
int flags; // Various flags for an object
|
int flags; // Various flags for an object
|
||||||
|
|
||||||
|
@ -71,21 +71,21 @@ struct object {
|
||||||
struct mission {
|
struct mission {
|
||||||
|
|
||||||
char primaryObjective[3][50]; // Description
|
char primaryObjective[3][50]; // Description
|
||||||
signed char primaryType[3]; // The type of mission this is
|
int primaryType[3]; // The type of mission this is
|
||||||
signed char target1[3]; // index of target in aliens array
|
int target1[3]; // index of target in aliens array
|
||||||
int targetValue1[3]; // Number of things to collect (slaves, cash, etc)
|
int targetValue1[3]; // Number of things to collect (slaves, cash, etc)
|
||||||
signed char timeLimit1[3]; // In minutes
|
int timeLimit1[3]; // In minutes
|
||||||
int completed1[3];
|
int completed1[3];
|
||||||
|
|
||||||
char secondaryObjective[3][50]; // Description
|
char secondaryObjective[3][50]; // Description
|
||||||
signed char secondaryType[3]; // The type of mission this is
|
int secondaryType[3]; // The type of mission this is
|
||||||
signed char target2[3]; // index of target in aliens array
|
int target2[3]; // index of target in aliens array
|
||||||
int targetValue2[3]; // Number of things to collect (slaves, cash, etc)
|
int targetValue2[3]; // Number of things to collect (slaves, cash, etc)
|
||||||
signed char timeLimit2[3]; // In minutes
|
int timeLimit2[3]; // In minutes
|
||||||
int completed2[3];
|
int completed2[3];
|
||||||
|
|
||||||
signed char remainingObjectives1;
|
int remainingObjectives1;
|
||||||
signed char remainingObjectives2;
|
int remainingObjectives2;
|
||||||
int addAliens; // How often to add new enemies
|
int addAliens; // How often to add new enemies
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -93,7 +93,7 @@ struct mission {
|
||||||
struct Star {
|
struct Star {
|
||||||
|
|
||||||
float x, y, dx, dy;
|
float x, y, dx, dy;
|
||||||
signed char speed; // How fast the star moves
|
int speed; // How fast the star moves
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -102,8 +102,8 @@ struct collectables {
|
||||||
bool active;
|
bool active;
|
||||||
float x, y, dx, dy;
|
float x, y, dx, dy;
|
||||||
SDL_Surface *image;
|
SDL_Surface *image;
|
||||||
signed char type; // What kind of collectable is it?
|
int type; // What kind of collectable is it?
|
||||||
unsigned char value; // How much is it worth?
|
int value; // How much is it worth?
|
||||||
int life; // How long it will stay around for
|
int life; // How long it will stay around for
|
||||||
|
|
||||||
collectables *next;
|
collectables *next;
|
||||||
|
@ -113,9 +113,9 @@ struct collectables {
|
||||||
struct textObject {
|
struct textObject {
|
||||||
|
|
||||||
SDL_Surface *image;
|
SDL_Surface *image;
|
||||||
unsigned char life;
|
int life;
|
||||||
float x, y;
|
float x, y;
|
||||||
signed char fontColor;
|
int fontColor;
|
||||||
char text[255];
|
char text[255];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -124,70 +124,71 @@ struct Game {
|
||||||
object thePlayer;
|
object thePlayer;
|
||||||
object playerWeapon;
|
object playerWeapon;
|
||||||
|
|
||||||
unsigned char system;
|
int system;
|
||||||
unsigned char area;
|
int area;
|
||||||
unsigned char musicVolume;
|
int musicVolume;
|
||||||
unsigned char sfxVolume;
|
int sfxVolume;
|
||||||
|
|
||||||
signed char saveFormat;
|
int saveFormat;
|
||||||
signed char difficulty;
|
int difficulty;
|
||||||
|
|
||||||
unsigned int cash;
|
int cash;
|
||||||
unsigned int cashEarned;
|
int cashEarned;
|
||||||
unsigned int shots;
|
|
||||||
unsigned int hits;
|
int shots;
|
||||||
unsigned char accuracy;
|
int hits;
|
||||||
unsigned char hasWingMate1, hasWingMate2;
|
int accuracy;
|
||||||
unsigned int totalKills, wingMate1Kills, wingMate2Kills;
|
int hasWingMate1, hasWingMate2;
|
||||||
unsigned char wingMate1Ejects, wingMate2Ejects;
|
int totalKills, wingMate1Kills, wingMate2Kills;
|
||||||
unsigned int totalOtherKills;
|
int wingMate1Ejects, wingMate2Ejects;
|
||||||
unsigned char secondaryMissions, secondaryMissionsCompleted;
|
int totalOtherKills;
|
||||||
unsigned int shieldPickups, rocketPickups, cellPickups, powerups, minesKilled, cargoPickups;
|
int secondaryMissions, secondaryMissionsCompleted;
|
||||||
|
int shieldPickups, rocketPickups, cellPickups, powerups, minesKilled, cargoPickups;
|
||||||
|
|
||||||
// slaves for Eyananth
|
// slaves for Eyananth
|
||||||
unsigned int slavesRescued;
|
int slavesRescued;
|
||||||
|
|
||||||
// remaining shield for experimental fighter
|
// remaining shield for experimental fighter
|
||||||
unsigned int experimentalShield;
|
int experimentalShield;
|
||||||
|
|
||||||
unsigned int timeTaken; // In seconds
|
int timeTaken; // In seconds
|
||||||
unsigned char missionCompleted[10];
|
int missionCompleted[10];
|
||||||
|
|
||||||
signed char stationedPlanet;
|
int stationedPlanet;
|
||||||
signed char destinationPlanet;
|
int destinationPlanet;
|
||||||
|
|
||||||
char stationedName[20];
|
char stationedName[20];
|
||||||
char destinationName[20];
|
char destinationName[20];
|
||||||
int distanceCovered;
|
int distanceCovered;
|
||||||
|
|
||||||
unsigned char minPlasmaRate;
|
int minPlasmaRate;
|
||||||
unsigned char minPlasmaDamage;
|
int minPlasmaDamage;
|
||||||
unsigned char minPlasmaOutput;
|
int minPlasmaOutput;
|
||||||
unsigned char maxPlasmaRate;
|
int maxPlasmaRate;
|
||||||
unsigned char maxPlasmaDamage;
|
int maxPlasmaDamage;
|
||||||
unsigned char maxPlasmaOutput;
|
int maxPlasmaOutput;
|
||||||
unsigned char maxPlasmaAmmo;
|
int maxPlasmaAmmo;
|
||||||
unsigned char maxRocketAmmo;
|
int maxRocketAmmo;
|
||||||
|
|
||||||
// Limits on shop upgrades
|
// Limits on shop upgrades
|
||||||
unsigned char minPlasmaRateLimit;
|
int minPlasmaRateLimit;
|
||||||
unsigned char minPlasmaDamageLimit;
|
int minPlasmaDamageLimit;
|
||||||
unsigned char minPlasmaOutputLimit;
|
int minPlasmaOutputLimit;
|
||||||
unsigned char maxPlasmaRateLimit;
|
int maxPlasmaRateLimit;
|
||||||
unsigned char maxPlasmaDamageLimit;
|
int maxPlasmaDamageLimit;
|
||||||
unsigned char maxPlasmaOutputLimit;
|
int maxPlasmaOutputLimit;
|
||||||
unsigned char maxPlasmaAmmoLimit;
|
int maxPlasmaAmmoLimit;
|
||||||
unsigned char maxRocketAmmoLimit;
|
int maxRocketAmmoLimit;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ShopItem {
|
struct ShopItem {
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
unsigned int price;
|
int price;
|
||||||
char name[50];
|
char name[50];
|
||||||
char description[255];
|
char description[255];
|
||||||
unsigned char image;
|
int image;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bRect {
|
struct bRect {
|
||||||
|
@ -203,12 +204,12 @@ struct Planet {
|
||||||
char name[50];
|
char name[50];
|
||||||
SDL_Surface *image;
|
SDL_Surface *image;
|
||||||
|
|
||||||
signed char missionNumber; // associated mission number
|
int missionNumber; // associated mission number
|
||||||
signed char missionCompleted; // whether it has been completed
|
int missionCompleted; // whether it has been completed
|
||||||
|
|
||||||
signed char messageMission;
|
int messageMission;
|
||||||
signed char messageSlot;
|
int messageSlot;
|
||||||
signed char faceImage;
|
int faceImage;
|
||||||
char from[50];
|
char from[50];
|
||||||
char subject[100];
|
char subject[100];
|
||||||
};
|
};
|
||||||
|
@ -231,13 +232,13 @@ enum keys {
|
||||||
struct globalEngineVariables {
|
struct globalEngineVariables {
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
signed char done;
|
int done;
|
||||||
|
|
||||||
SDL_RWops *sdlrw;
|
SDL_RWops *sdlrw;
|
||||||
|
|
||||||
float musicVolume;
|
float musicVolume;
|
||||||
|
|
||||||
signed char maxAliens;
|
int maxAliens;
|
||||||
|
|
||||||
float ssx;
|
float ssx;
|
||||||
float ssy;
|
float ssy;
|
||||||
|
@ -255,35 +256,35 @@ struct globalEngineVariables {
|
||||||
|
|
||||||
int cursor_x, cursor_y;
|
int cursor_x, cursor_y;
|
||||||
|
|
||||||
signed char commsSection;
|
int commsSection;
|
||||||
|
|
||||||
signed char eventTimer;
|
int eventTimer;
|
||||||
|
|
||||||
signed char lowShield;
|
int lowShield;
|
||||||
signed char averageShield;
|
int averageShield;
|
||||||
|
|
||||||
float targetShield;
|
float targetShield;
|
||||||
signed char targetIndex;
|
int targetIndex;
|
||||||
|
|
||||||
// Mission completion timer (allows for 4 seconds before leaving sector)
|
// Mission completion timer (allows for 4 seconds before leaving sector)
|
||||||
unsigned long missionCompleteTimer;
|
long missionCompleteTimer;
|
||||||
|
|
||||||
// Times the mission normally
|
// Times the mission normally
|
||||||
unsigned int counter2;
|
unsigned int counter2;
|
||||||
int timeTaken; // In seconds
|
int timeTaken; // In seconds
|
||||||
|
|
||||||
// For missions with a time limit
|
// For missions with a time limit
|
||||||
signed char timeMission;
|
int timeMission;
|
||||||
unsigned int counter;
|
unsigned int counter;
|
||||||
signed char seconds;
|
int seconds;
|
||||||
signed char minutes;
|
int minutes;
|
||||||
|
|
||||||
// Mission Related stuff
|
// Mission Related stuff
|
||||||
signed char allAliensDead;
|
int allAliensDead;
|
||||||
int addAliens;
|
int addAliens;
|
||||||
|
|
||||||
bool paused;
|
bool paused;
|
||||||
signed char gameSection;
|
int gameSection;
|
||||||
|
|
||||||
bool useAudio;
|
bool useAudio;
|
||||||
bool useSound;
|
bool useSound;
|
||||||
|
@ -306,8 +307,8 @@ struct event {
|
||||||
|
|
||||||
int time;
|
int time;
|
||||||
char message[255];
|
char message[255];
|
||||||
signed char face;
|
int face;
|
||||||
signed char entity;
|
int entity;
|
||||||
int flag;
|
int flag;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -320,8 +321,8 @@ struct cutMsg {
|
||||||
|
|
||||||
struct devVariables {
|
struct devVariables {
|
||||||
|
|
||||||
signed char moveAliens;
|
int moveAliens;
|
||||||
signed char fireAliens;
|
int fireAliens;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -337,7 +337,7 @@ int doTitle()
|
||||||
if (engine.keyState[KEY_UP])
|
if (engine.keyState[KEY_UP])
|
||||||
{
|
{
|
||||||
engine.keyState[KEY_UP] = 0;
|
engine.keyState[KEY_UP] = 0;
|
||||||
wrapChar(&(--selectedOption), 1, listLength + 1);
|
WRAP_ADD(selectedOption, -1, 1, listLength + 1);
|
||||||
if (menuType == MENU_MAIN)
|
if (menuType == MENU_MAIN)
|
||||||
if ((selectedOption == 2) || (selectedOption == 3))
|
if ((selectedOption == 2) || (selectedOption == 3))
|
||||||
if (continueSaveSlot == -1)
|
if (continueSaveSlot == -1)
|
||||||
|
@ -346,7 +346,7 @@ int doTitle()
|
||||||
if (engine.keyState[KEY_DOWN])
|
if (engine.keyState[KEY_DOWN])
|
||||||
{
|
{
|
||||||
engine.keyState[KEY_DOWN] = 0;
|
engine.keyState[KEY_DOWN] = 0;
|
||||||
wrapChar(&(++selectedOption), 0, listLength);
|
WRAP_ADD(selectedOption, 1, 0, listLength);
|
||||||
if (menuType == MENU_MAIN)
|
if (menuType == MENU_MAIN)
|
||||||
if ((selectedOption == 2) || (selectedOption == 3))
|
if ((selectedOption == 2) || (selectedOption == 3))
|
||||||
if (continueSaveSlot == -1)
|
if (continueSaveSlot == -1)
|
||||||
|
|
Loading…
Reference in New Issue