diff --git a/src/battle/ai.c b/src/battle/ai.c index 76feb9c..23b798d 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -20,8 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "ai.h" -static void faceTarget(Entity *f); -static int isInFOV(Entity *f, int fov); +static void faceTarget(Entity *e); +static int isInFOV(Entity *e, int fov); static void preAttack(void); static void huntTarget(void); static void huntAndAttackTarget(void); @@ -31,7 +31,7 @@ static void findTarget(void); static int hasClearShot(void); static void fallback(void); static void moveToPlayer(void); -static int canAttack(Entity *f); +static int canAttack(Entity *e); static int selectWeapon(int type); static int nearExtractionPoint(void); static void moveToExtractionPoint(void); @@ -295,13 +295,13 @@ static void findTarget(void) } } -static int canAttack(Entity *f) +static int canAttack(Entity *e) { self->selectedGunType = self->guns[0].type; - if (f->flags & EF_MUST_DISABLE) + if (e->flags & EF_MUST_DISABLE) { - if (f->systemPower > 0) + if (e->systemPower > 0) { return selectWeapon(BT_MAG); } @@ -309,12 +309,12 @@ static int canAttack(Entity *f) return 0; } - if (f->flags & EF_NO_KILL) + if (e->flags & EF_NO_KILL) { return selectWeapon(BT_LASER) || selectWeapon(BT_MAG); } - if (f->shield > 0) + if (e->shield > 0) { selectWeapon(BT_LASER); } @@ -338,10 +338,10 @@ static int selectWeapon(int type) return 0; } -static void faceTarget(Entity *f) +static void faceTarget(Entity *e) { int dir; - int wantedAngle = getAngle(self->x, self->y, f->x, f->y); + int wantedAngle = getAngle(self->x, self->y, e->x, e->y); wantedAngle %= 360; @@ -357,13 +357,13 @@ static void faceTarget(Entity *f) } } -static int isInFOV(Entity *f, int fov) +static int isInFOV(Entity *e, int fov) { int angle, a, b; a = mod(self->angle - fov, 360); b = mod(self->angle + fov, 360); - angle = getAngle(self->x, self->y, f->x, f->y); + angle = getAngle(self->x, self->y, e->x, e->y); return (a < b) ? (a <= angle && angle <= b) : (a <= angle || angle <= b); } diff --git a/src/battle/bullets.c b/src/battle/bullets.c index e0982f6..be197c1 100644 --- a/src/battle/bullets.c +++ b/src/battle/bullets.c @@ -100,7 +100,6 @@ void doBullets(void) if (--b->life <= 0) { - if (player != NULL && player->alive == ALIVE_ALIVE && b->type == BT_MISSILE && b->damage > 0 && b->target == player) { battle.stats[STAT_MISSILES_EVADED]++; @@ -117,7 +116,7 @@ void doBullets(void) } else { - if (collision(b->x - b->w - battle.camera.x, b->y - b->h - battle.camera.y, b->w * 2, b->h * 2, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)) + if (collision(b->x - (b->w / 2) - battle.camera.x, b->y - (b->h / 2) - battle.camera.y, b->w * 2, b->h * 2, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)) { bulletsToDraw[i++] = b; if (i >= MAX_BULLETS_TO_DRAW) diff --git a/src/battle/bullets.h b/src/battle/bullets.h index f42cf9e..f0ecaf8 100644 --- a/src/battle/bullets.h +++ b/src/battle/bullets.h @@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern SDL_Texture *getTexture(char *filename); extern void blitRotated(SDL_Texture *texture, int x, int y, int angle); extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); -extern void damageFighter(Entity *f, int damage, long flags); +extern void damageFighter(Entity *e, int damage, long flags); extern void playBattleSound(int id, int x, int y); extern long flagsToLong(char *flags, int *add); extern long lookup(char *name); diff --git a/src/battle/fighters.c b/src/battle/fighters.c index 3f7fa30..8de0961 100644 --- a/src/battle/fighters.c +++ b/src/battle/fighters.c @@ -34,68 +34,68 @@ static Entity defHead, *defTail; Entity *spawnFighter(char *name, int x, int y, int side) { - Entity *f, *def; + Entity *e, *def; - f = spawnEntity(); + e = spawnEntity(); def = getFighterDef(name); - memcpy(f, def, sizeof(Entity)); + memcpy(e, def, sizeof(Entity)); - f->id = battle.entId; - f->next = NULL; + e->id = battle.entId; + e->next = NULL; - f->x = x; - f->y = y; - f->side = side; + e->x = x; + e->y = y; + e->side = side; switch (side) { case SIDE_ALLIES: - f->aiAggression = 2 + rand() % 2; - if (!(f->aiFlags & AIF_FOLLOWS_PLAYER)) + e->aiAggression = 2 + rand() % 2; + if (!(e->aiFlags & AIF_FOLLOWS_PLAYER)) { - f->aiFlags |= AIF_MOVES_TO_PLAYER; + e->aiFlags |= AIF_MOVES_TO_PLAYER; } break; case SIDE_PIRATE: - f->aiAggression = rand() % 3; + e->aiAggression = rand() % 3; break; case SIDE_PANDORAN: - f->aiAggression = 3 + rand() % 2; + e->aiAggression = 3 + rand() % 2; break; case SIDE_REBEL: - f->aiAggression = 1 + rand() % 3; + e->aiAggression = 1 + rand() % 3; break; } if (strcmp(name, "ATAF") == 0) { - f->aiAggression = 4; + e->aiAggression = 4; } if (strcmp(name, "Dart") == 0) { - randomizeDart(f); + randomizeDart(e); } if (strcmp(name, "Civilian") == 0 && rand() % 2 == 0) { - f->texture = getTexture("gfx/craft/civilian02.png"); + e->texture = getTexture("gfx/craft/civilian02.png"); } - if (f->aiFlags & AIF_AGGRESSIVE) + if (e->aiFlags & AIF_AGGRESSIVE) { - f->aiAggression = 4; + e->aiAggression = 4; } - f->action = doAI; - f->die = die; + e->action = doAI; + e->die = die; - return f; + return e; } static void randomizeDart(Entity *dart) @@ -385,58 +385,58 @@ void applyFighterBrakes(void) self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy)); } -void damageFighter(Entity *f, int amount, long flags) +void damageFighter(Entity *e, int amount, long flags) { - int prevShield = f->shield; + int prevShield = e->shield; if (flags & BF_SYSTEM_DAMAGE) { - f->systemPower = MAX(0, f->systemPower - amount); + e->systemPower = MAX(0, e->systemPower - amount); - f->systemHit = 255; + e->systemHit = 255; - if (f->systemPower == 0) + if (e->systemPower == 0) { - f->shield = f->maxShield = 0; - f->action = NULL; + e->shield = e->maxShield = 0; + e->action = NULL; } } else if (flags & BF_SHIELD_DAMAGE) { - f->shield = MAX(-(FPS * 10), f->shield - amount); + e->shield = MAX(-(FPS * 10), e->shield - amount); - if (f->shield <= 0 && prevShield > 0) + if (e->shield <= 0 && prevShield > 0) { - playBattleSound(SND_SHIELD_BREAK, f->x, f->y); - addShieldSplinterEffect(f); + playBattleSound(SND_SHIELD_BREAK, e->x, e->y); + addShieldSplinterEffect(e); } } else { - if (f->shield > 0) + if (e->shield > 0) { - f->shield -= amount; + e->shield -= amount; - if (f->shield < 0) + if (e->shield < 0) { - f->health += f->shield; - f->shield = 0; + e->health += e->shield; + e->shield = 0; } } else { - f->health -= amount; - f->armourHit = 255; + e->health -= amount; + e->armourHit = 255; - playBattleSound(SND_ARMOUR_HIT, f->x, f->y); + playBattleSound(SND_ARMOUR_HIT, e->x, e->y); } } - if (f->shield > 0) + if (e->shield > 0) { - f->shieldHit = 255; + e->shieldHit = 255; - playBattleSound(SND_SHIELD_HIT, f->x, f->y); + playBattleSound(SND_SHIELD_HIT, e->x, e->y); } } @@ -556,13 +556,13 @@ void retreatAllies(void) static Entity *getFighterDef(char *name) { - Entity *f; + Entity *e; - for (f = defHead.next ; f != NULL ; f = f->next) + for (e = defHead.next ; e != NULL ; e = e->next) { - if (strcmp(f->name, name) == 0) + if (strcmp(e->name, name) == 0) { - return f; + return e; } } @@ -594,33 +594,33 @@ static void loadFighterDef(char *filename) { cJSON *root, *node; char *text; - Entity *f; + Entity *e; int i; SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename); text = readFile(getFileLocation(filename)); - f = malloc(sizeof(Entity)); - memset(f, 0, sizeof(Entity)); - defTail->next = f; - defTail = f; + e = malloc(sizeof(Entity)); + memset(e, 0, sizeof(Entity)); + defTail->next = e; + defTail = e; - f->type = ET_FIGHTER; - f->active = 1; + e->type = ET_FIGHTER; + e->active = 1; root = cJSON_Parse(text); - STRNCPY(f->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH); - STRNCPY(f->defName, f->name, MAX_NAME_LENGTH); - f->health = f->maxHealth = cJSON_GetObjectItem(root, "health")->valueint; - f->shield = f->maxShield = cJSON_GetObjectItem(root, "shield")->valueint; - f->speed = cJSON_GetObjectItem(root, "speed")->valuedouble; - f->reloadTime = cJSON_GetObjectItem(root, "reloadTime")->valueint; - f->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint; - f->texture = getTexture(cJSON_GetObjectItem(root, "textureName")->valuestring); + STRNCPY(e->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH); + STRNCPY(e->defName, e->name, MAX_NAME_LENGTH); + e->health = e->maxHealth = cJSON_GetObjectItem(root, "health")->valueint; + e->shield = e->maxShield = cJSON_GetObjectItem(root, "shield")->valueint; + e->speed = cJSON_GetObjectItem(root, "speed")->valuedouble; + e->reloadTime = cJSON_GetObjectItem(root, "reloadTime")->valueint; + e->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint; + e->texture = getTexture(cJSON_GetObjectItem(root, "textureName")->valuestring); - SDL_QueryTexture(f->texture, NULL, NULL, &f->w, &f->h); + SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h); if (cJSON_GetObjectItem(root, "guns")) { @@ -628,9 +628,9 @@ static void loadFighterDef(char *filename) for (node = cJSON_GetObjectItem(root, "guns")->child ; node != NULL ; node = node->next) { - f->guns[i].type = lookup(cJSON_GetObjectItem(node, "type")->valuestring); - f->guns[i].x = cJSON_GetObjectItem(node, "x")->valueint; - f->guns[i].y = cJSON_GetObjectItem(node, "y")->valueint; + e->guns[i].type = lookup(cJSON_GetObjectItem(node, "type")->valuestring); + e->guns[i].x = cJSON_GetObjectItem(node, "x")->valueint; + e->guns[i].y = cJSON_GetObjectItem(node, "y")->valueint; i++; @@ -643,32 +643,32 @@ static void loadFighterDef(char *filename) if (cJSON_GetObjectItem(root, "combinedGuns")) { - f->combinedGuns = cJSON_GetObjectItem(root, "combinedGuns")->valueint; + e->combinedGuns = cJSON_GetObjectItem(root, "combinedGuns")->valueint; } } - f->selectedGunType = f->guns[0].type; + e->selectedGunType = e->guns[0].type; if (cJSON_GetObjectItem(root, "missiles")) { - f->missiles = cJSON_GetObjectItem(root, "missiles")->valueint; + e->missiles = cJSON_GetObjectItem(root, "missiles")->valueint; } if (cJSON_GetObjectItem(root, "flags")) { - f->flags = flagsToLong(cJSON_GetObjectItem(root, "flags")->valuestring, NULL); + e->flags = flagsToLong(cJSON_GetObjectItem(root, "flags")->valuestring, NULL); } if (cJSON_GetObjectItem(root, "aiFlags")) { - f->aiFlags = flagsToLong(cJSON_GetObjectItem(root, "aiFlags")->valuestring, NULL); + e->aiFlags = flagsToLong(cJSON_GetObjectItem(root, "aiFlags")->valuestring, NULL); } - f->separationRadius = MAX(f->w, f->h); - f->separationRadius *= 3; + e->separationRadius = MAX(e->w, e->h); + e->separationRadius *= 3; /* all craft default to 100 system power */ - f->systemPower = 100; + e->systemPower = 100; cJSON_Delete(root); free(text); @@ -676,12 +676,12 @@ static void loadFighterDef(char *filename) void destroyFighterDefs(void) { - Entity *f; + Entity *e; while (defHead.next) { - f = defHead.next; - defHead.next = f->next; - free(f); + e = defHead.next; + defHead.next = e->next; + free(e); } } diff --git a/src/battle/items.c b/src/battle/items.c index fcb8fd9..82c4b87 100644 --- a/src/battle/items.c +++ b/src/battle/items.c @@ -124,12 +124,12 @@ static void action(void) void destroyItemDefs(void) { - Entity *f; + Entity *e; while (defHead.next) { - f = defHead.next; - defHead.next = f->next; - free(f); + e = defHead.next; + defHead.next = e->next; + free(e); } } diff --git a/src/battle/radar.c b/src/battle/radar.c index af75bbd..eed564a 100644 --- a/src/battle/radar.c +++ b/src/battle/radar.c @@ -33,7 +33,7 @@ void initRadar(void) void drawRadar(void) { SDL_Rect r; - Entity *f; + Entity *e; blit(radarTexture, SCREEN_WIDTH - 85, SCREEN_HEIGHT - 85, 1); @@ -41,20 +41,20 @@ void drawRadar(void) r.w = r.h = 3; - for (f = battle.entityHead.next ; f != NULL ; f = f->next) + for (e = battle.entityHead.next ; e != NULL ; e = e->next) { - if (f->active && getDistance(f->x, f->y, player->x, player->y) / radarRanges[battle.radarRange] < 70) + if (e->active && getDistance(e->x, e->y, player->x, player->y) / radarRanges[battle.radarRange] < 70) { r.x = SCREEN_WIDTH - 85; r.y = SCREEN_HEIGHT - 85; - r.x -= (player->x - f->x) / radarRanges[battle.radarRange]; - r.y -= (player->y - f->y) / radarRanges[battle.radarRange]; + r.x -= (player->x - e->x) / radarRanges[battle.radarRange]; + r.y -= (player->y - e->y) / radarRanges[battle.radarRange]; r.x--; r.y--; - switch (f->side) + switch (e->side) { case SIDE_ALLIES: SDL_SetRenderDrawColor(app.renderer, 0, 255, 0, 255); @@ -71,12 +71,12 @@ void drawRadar(void) break; } - if (f == player->target) + if (e == player->target) { SDL_SetRenderDrawColor(app.renderer, 255, 255, 0, 255); } - if (f == battle.missionTarget) + if (e == battle.missionTarget) { SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255); } diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 787d145..908407e 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -198,7 +198,7 @@ static void loadPlayer(cJSON *node) static void loadFighters(cJSON *node) { - Entity *f; + Entity *e; char **types, *name, *groupName, *type; int side, scatter, number, active; int i, numTypes, addFlags, addAIFlags; @@ -263,27 +263,27 @@ static void loadFighters(cJSON *node) { type = types[rand() % numTypes]; - f = spawnFighter(type, x, y, side); + e = spawnFighter(type, x, y, side); if (scatter > 1) { - f->x += (rand() % scatter) - (rand() % scatter); - f->y += (rand() % scatter) - (rand() % scatter); + e->x += (rand() % scatter) - (rand() % scatter); + e->y += (rand() % scatter) - (rand() % scatter); } - f->active = active; + e->active = active; if (flags != -1) { if (addFlags) { - f->flags |= flags; + e->flags |= flags; } else { - f->flags = flags; + e->flags = flags; - SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", f->name, f->defName); + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Flags for '%s' (%s) replaced", e->name, e->defName); } } @@ -291,24 +291,24 @@ static void loadFighters(cJSON *node) { if (addAIFlags) { - f->aiFlags |= aiFlags; + e->aiFlags |= aiFlags; } else { - f->aiFlags = aiFlags; + e->aiFlags = aiFlags; - SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "AI Flags for '%s' (%s) replaced", f->name, f->defName); + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "AI Flags for '%s' (%s) replaced", e->name, e->defName); } } if (name) { - STRNCPY(f->name, name, MAX_NAME_LENGTH); + STRNCPY(e->name, name, MAX_NAME_LENGTH); } if (groupName) { - STRNCPY(f->groupName, groupName, MAX_NAME_LENGTH); + STRNCPY(e->groupName, groupName, MAX_NAME_LENGTH); } }