[Change] Just some cosmetic changes, and removed of bzero and strdup.

This commit is contained in:
Allanis 2013-02-23 20:30:49 +00:00
parent 13228c39d8
commit 82ed9ac551
2 changed files with 15 additions and 3 deletions

View File

@ -138,14 +138,17 @@ static int ai_broadcast(lua_State* L); // broadcast(string)
static int ai_rng(lua_State* L); // rng(number, number) static int ai_rng(lua_State* L); // rng(number, number)
static const luaL_Reg ai_methods[] = { static const luaL_Reg ai_methods[] = {
// Tasks.
{ "pushtask", ai_pushtask }, { "pushtask", ai_pushtask },
{ "poptask", ai_poptask }, { "poptask", ai_poptask },
{ "taskname", ai_taskname }, { "taskname", ai_taskname },
// Sanity checks.
{ "exists", ai_exists }, { "exists", ai_exists },
{ "ismaxvel", ai_ismaxvel }, { "ismaxvel", ai_ismaxvel },
{ "isstopped", ai_isstopped }, { "isstopped", ai_isstopped },
{ "isenemy", ai_isenemy }, { "isenemy", ai_isenemy },
{ "isally", ai_isally }, { "isally", ai_isally },
// Get's.
{ "incombat", ai_incombat }, { "incombat", ai_incombat },
{ "target", ai_gettarget }, { "target", ai_gettarget },
{ "targetid", ai_gettargetid }, { "targetid", ai_gettargetid },
@ -158,20 +161,24 @@ static const luaL_Reg ai_methods[] = {
{ "minbrakedist", ai_minbrakedist }, { "minbrakedist", ai_minbrakedist },
{ "nearestplanet", ai_getnearestplanet }, { "nearestplanet", ai_getnearestplanet },
{ "rndplanet", ai_getrndplanet }, { "rndplanet", ai_getrndplanet },
// Movement.
{ "accel", ai_accel }, { "accel", ai_accel },
{ "turn", ai_turn }, { "turn", ai_turn },
{ "face", ai_face }, { "face", ai_face },
{ "brake", ai_brake }, { "brake", ai_brake },
{ "stop", ai_stop }, { "stop", ai_stop },
{ "hyperspace", ai_hyperspace }, { "hyperspace", ai_hyperspace },
// Combat.
{ "combat", ai_combat }, { "combat", ai_combat },
{ "settarget", ai_settarget }, { "settarget", ai_settarget },
{ "secondary", ai_secondary }, { "secondary", ai_secondary },
{ "shoot", ai_shoot }, { "shoot", ai_shoot },
{ "getenemy", ai_getenemy }, { "getenemy", ai_getenemy },
{ "hostile", ai_hostile }, { "hostile", ai_hostile },
// Timers.
{ "settime", ai_settimer }, { "settime", ai_settimer },
{ "timeup", ai_timeup }, { "timeup", ai_timeup },
// Messages.
{ "comm", ai_comm }, { "comm", ai_comm },
{ "broadcast", ai_broadcast }, { "broadcast", ai_broadcast },
{ "rnd", ai_rng }, { "rnd", ai_rng },
@ -223,8 +230,13 @@ static int ai_loadProfile(char* filename) {
uint32_t bufsize = 0; uint32_t bufsize = 0;
profiles = realloc(profiles, sizeof(AI_Profile)*(++nprofiles)); profiles = realloc(profiles, sizeof(AI_Profile)*(++nprofiles));
profiles[nprofiles-1].name = strndup(filename+strlen(AI_PREFIX),
strlen(filename)-strlen(AI_PREFIX)-strlen(AI_SUFFIX)); profiles[nprofiles-1].name =
malloc(sizeof(char)*(strlen(filename)-strlen(AI_PREFIX)-strlen(AI_SUFFIX))+1);
snprintf(profiles[nprofiles-1].name,
strlen(filename)-strlen(AI_PREFIX)-strlen(AI_SUFFIX)+1,
"%s", filename+strlen(AI_PREFIX));
profiles[nprofiles-1].L = luaL_newstate(); profiles[nprofiles-1].L = luaL_newstate();

View File

@ -111,7 +111,7 @@ static uint8_t* SDL_MapTrans(SDL_Surface* s) {
// Allocate memory for just enough bits to hold all the data we need. // Allocate memory for just enough bits to hold all the data we need.
int size = s->w*s->h/8 + ((s->w*s->h%8)?1:0); int size = s->w*s->h/8 + ((s->w*s->h%8)?1:0);
uint8_t* t = malloc(size); uint8_t* t = malloc(size);
bzero(t, size); // *must* be set to zero. memset(t, 0, size); // *must* be set to zero.
if(t == NULL) { if(t == NULL) {
WARN("Out of memeory"); WARN("Out of memeory");