Skip to content
Browse files

Merge branch 'master' of https://github.com/clintbellanger/flare-engine

  • Loading branch information...
2 parents 16add5c + 4f887cf commit f8bbf0daa8d8c2b97d8dd1090ae91f345b5991e3 @clintbellanger committed Dec 24, 2012
View
2 .travis.yml
@@ -7,7 +7,7 @@ before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev cppcheck gcc-snapshot
script: cmake . && make
-after_script: cppcheck --enable=all -q `git ls-files src/\*.cpp`
+after_script: cppcheck --verbose --enable=all --std=posix --std=c++11 --quiet `git ls-files src/\*.cpp`
notifications:
irc:
channels:
View
7 CMakeLists.txt
@@ -15,7 +15,7 @@ endif (NOT MSVC)
if (CMAKE_CXX_COMPILER MATCHES "clang")
# clang needs lstdc++ linked explicitly:
set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -lstdc++")
-elseif (NOT MSVC)
+elseif ()
# assume gcc:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-enforce-eh-specs")
endif ()
@@ -31,6 +31,11 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-pg")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "-pg")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "-pg")
+else()
+ set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -pg")
+ set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-pg")
+ set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "-pg")
+ set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "-pg")
endif()
set(BINDIR "games" CACHE STRING "Directory from CMAKE_INSTALL_PREFIX where game executable will be installed.")
View
14 src/Avatar.cpp
@@ -207,15 +207,11 @@ void Avatar::loadSounds() {
Mix_FreeChunk(sound_block);
Mix_FreeChunk(level_up);
- sound_melee = Mix_LoadWAV(mods->locate("soundfx/melee_attack.ogg").c_str());
- sound_hit = Mix_LoadWAV(mods->locate("soundfx/" + stats.base + "_hit.ogg").c_str());
- sound_die = Mix_LoadWAV(mods->locate("soundfx/" + stats.base + "_die.ogg").c_str());
- sound_block = Mix_LoadWAV(mods->locate("soundfx/powers/block.ogg").c_str());
- level_up = Mix_LoadWAV(mods->locate("soundfx/level_up.ogg").c_str());
-
- if (!sound_melee || !sound_hit || !sound_die || !level_up) {
- printf("Mix_LoadWAV: %s\n", Mix_GetError());
- }
+ sound_melee = loadSfx(mods->locate("soundfx/melee_attack.ogg"), "Avatar melee attack");
+ sound_hit = loadSfx(mods->locate("soundfx/" + stats.base + "_hit.ogg"), "Avatar was hit");
+ sound_die = loadSfx(mods->locate("soundfx/" + stats.base + "_die.ogg"), "Avatar death");
+ sound_block = loadSfx(mods->locate("soundfx/powers/block.ogg"), "Avatar blocking");
+ level_up = loadSfx(mods->locate("soundfx/level_up.ogg"), "Avatar leveling up");
}
}
View
22 src/EffectManager.cpp
@@ -24,10 +24,8 @@ FLARE. If not, see http://www.gnu.org/licenses/
#include "EffectManager.h"
#include "Settings.h"
-using namespace std;
-
EffectManager::EffectManager()
- : bonus_resist(vector<int>(ELEMENTS.size(), 0))
+ : bonus_resist(std::vector<int>(ELEMENTS.size(), 0))
, triggered_others(false)
, triggered_block(false)
, triggered_hit(false)
@@ -122,16 +120,28 @@ void EffectManager::logic() {
if (effect_list[i].duration > 0) {
if (effect_list[i].ticks > 0) effect_list[i].ticks--;
- if (effect_list[i].ticks == 0) removeEffect(i);
+ if (effect_list[i].ticks == 0) {
+ removeEffect(i);
+ i--;
+ continue;
+ }
}
}
// expire shield effects
if (effect_list[i].magnitude_max > 0 && effect_list[i].magnitude == 0) {
- if (effect_list[i].type == "shield") removeEffect(i);
+ if (effect_list[i].type == "shield") {
+ removeEffect(i);
+ i--;
+ continue;
+ }
}
// expire effects based on animations
if ((effect_list[i].animation && effect_list[i].animation->isLastFrame()) || !effect_list[i].animation) {
- if (effect_list[i].type == "heal") removeEffect(i);
+ if (effect_list[i].type == "heal") {
+ removeEffect(i);
+ i--;
+ continue;
+ }
}
// animate
View
15 src/EnemyManager.cpp
@@ -50,24 +50,19 @@ void EnemyManager::loadSounds(const string& type_id) {
if (audio && SOUND_VOLUME && type_id != "none") {
string path;
path = mods->locate("soundfx/enemies/" + type_id + "_phys.ogg");
- sound_phys.push_back(Mix_LoadWAV(path.c_str()));
- if (!sound_phys.back()) fprintf(stderr, "Could not load %s\n", path.c_str());
+ sound_phys.push_back(loadSfx(path, "EnemyManager physical attack sound"));
path = mods->locate("soundfx/enemies/" + type_id + "_ment.ogg");
- sound_ment.push_back(Mix_LoadWAV(path.c_str()));
- if (!sound_ment.back()) fprintf(stderr, "Could not load %s\n", path.c_str());
+ sound_ment.push_back(loadSfx(path, "EnemyManager mental attack sound"));
path = mods->locate("soundfx/enemies/" + type_id + "_hit.ogg");
- sound_hit.push_back(Mix_LoadWAV(path.c_str()));
- if (!sound_hit.back()) fprintf(stderr, "Could not load %s\n", path.c_str());
+ sound_hit.push_back(loadSfx(path, "EnemyManager physical hit sound"));
path = mods->locate("soundfx/enemies/" + type_id + "_die.ogg");
- sound_die.push_back(Mix_LoadWAV(path.c_str()));
- if (!sound_die.back()) fprintf(stderr, "Could not load %s\n", path.c_str());
+ sound_die.push_back(loadSfx(path, "EnemyManager die sound"));
path = mods->locate("soundfx/enemies/" + type_id + "_critdie.ogg");
- sound_critdie.push_back(Mix_LoadWAV(path.c_str()));
- if (!sound_critdie.back()) fprintf(stderr, "Could not load %s\n", path.c_str());
+ sound_critdie.push_back(loadSfx(path, "EnemyManager critdeath sound"));
} else {
sound_phys.push_back(NULL);
View
26 src/ItemManager.cpp
@@ -349,18 +349,18 @@ void ItemManager::loadSounds() {
memset(sfx, 0, sizeof(sfx));
if (audio && SOUND_VOLUME) {
- sfx[SFX_BOOK] = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_book.ogg").c_str());
- sfx[SFX_CLOTH] = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_cloth.ogg").c_str());
- sfx[SFX_COINS] = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_coins.ogg").c_str());
- sfx[SFX_GEM] = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_gem.ogg").c_str());
- sfx[SFX_LEATHER] = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_leather.ogg").c_str());
- sfx[SFX_METAL] = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_metal.ogg").c_str());
- sfx[SFX_PAGE] = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_page.ogg").c_str());
- sfx[SFX_MAILLE] = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_maille.ogg").c_str());
- sfx[SFX_OBJECT] = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_object.ogg").c_str());
- sfx[SFX_HEAVY] = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_heavy.ogg").c_str());
- sfx[SFX_WOOD] = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_wood.ogg").c_str());
- sfx[SFX_POTION] = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_potion.ogg").c_str());
+ sfx[SFX_BOOK] = loadSfx(mods->locate("soundfx/inventory/inventory_book.ogg"),"ItemManager books");
+ sfx[SFX_CLOTH] = loadSfx(mods->locate("soundfx/inventory/inventory_cloth.ogg"), "ItemManager cloths");
+ sfx[SFX_COINS] = loadSfx(mods->locate("soundfx/inventory/inventory_coins.ogg"), "ItemManager coins");
+ sfx[SFX_GEM] = loadSfx(mods->locate("soundfx/inventory/inventory_gem.ogg"), "ItemManager gems");
+ sfx[SFX_LEATHER] = loadSfx(mods->locate("soundfx/inventory/inventory_leather.ogg"), "ItemManager leather");
+ sfx[SFX_METAL] = loadSfx(mods->locate("soundfx/inventory/inventory_metal.ogg"), "ItemManager metal");
+ sfx[SFX_PAGE] = loadSfx(mods->locate("soundfx/inventory/inventory_page.ogg"), "ItemManager page");
+ sfx[SFX_MAILLE] = loadSfx(mods->locate("soundfx/inventory/inventory_maille.ogg"), "ItemManager maille");
+ sfx[SFX_OBJECT] = loadSfx(mods->locate("soundfx/inventory/inventory_object.ogg"), "ItemManager objects");
+ sfx[SFX_HEAVY] = loadSfx(mods->locate("soundfx/inventory/inventory_heavy.ogg"), "ItemManager heavy");
+ sfx[SFX_WOOD] = loadSfx(mods->locate("soundfx/inventory/inventory_wood.ogg"), "ItemManager wood");
+ sfx[SFX_POTION] = loadSfx(mods->locate("soundfx/inventory/inventory_potion.ogg"), "ItemManager potions");
}
}
@@ -604,7 +604,7 @@ TooltipData ItemManager::getTooltip(int item, StatBlock *stats, int context) {
if (items[item].flavor != "") {
tip.addText(items[item].flavor, color_flavor);
}
-
+
// buy or sell price
if (items[item].price > 0) {
View
3 src/LootManager.cpp
@@ -97,7 +97,8 @@ LootManager::LootManager(ItemManager *_items, MapRenderer *_map, StatBlock *_her
loadGraphics();
if (audio && SOUND_VOLUME)
- loot_flip = Mix_LoadWAV(mods->locate("soundfx/flying_loot.ogg").c_str());
+ loot_flip = loadSfx(mods->locate("soundfx/flying_loot.ogg").c_str(), "LootManager dropping loot");
+
full_msg = false;
if (!lootManager)
View
124 src/MapRenderer.cpp
@@ -40,50 +40,35 @@ MapRenderer::MapRenderer(CampaignManager *_camp)
, show_tooltip(false)
, sfx(NULL)
, sfx_filename("")
+ , events(vector<Map_Event>())
, background(NULL)
, fringe(NULL)
, object(NULL)
, foreground(NULL)
, collision(NULL)
, shakycam(Point())
, new_music(false)
+ , backgroundsurface(NULL)
, backgroundsurfaceoffset(Point(0,0))
, repaint_background(false)
-
, camp(_camp)
, powers(NULL)
, w(0)
, h(0)
+ , cam(Point(0,0))
, hero_tile(Point())
, spawn(Point())
, spawn_dir(0)
, map_change(false)
- , new_enemy(Map_Enemy())
- , new_group(Map_Group())
- , enemy_awaiting_queue(false)
- , group_awaiting_queue(false)
- , new_npc(Map_NPC())
- , npc_awaiting_queue(false)
, teleportation(false)
, teleport_destination(Point())
, respawn_point(Point())
+ , log_msg("")
+ , shaky_cam_ticks(0)
, stash(false)
, stash_pos(Point())
, enemies_cleared(false)
{
- cam.x = 0;
- cam.y = 0;
- //~ new_music = false;
-
- clearEvents();
-
- log_msg = "";
- shaky_cam_ticks = 0;
-
- backgroundsurface = NULL;
- //~ backgroundsurfaceoffset.x = 0;
- //~ backgroundsurfaceoffset.y = 0;
- //~ repaint_background = false;
}
void MapRenderer::clearEvents() {
@@ -96,7 +81,7 @@ void MapRenderer::playSFX(string filename) {
Mix_FreeChunk(sfx);
sfx = NULL;
if (audio) {
- sfx = Mix_LoadWAV(mods->locate(filename).c_str());
+ sfx = loadSfx(mods->locate(filename), "MapRenderer background music");
sfx_filename = filename;
}
}
@@ -110,57 +95,50 @@ void MapRenderer::push_enemy_group(Map_Group g) {
return;
}
- // populate valid_locations
- vector<Point> valid_locations;
- Point pt;
- for (int width = 0; width < g.area.x; width++) {
- for (int height = 0; height < g.area.y; height++) {
- pt.x = (g.pos.x + width) * UNITS_PER_TILE + UNITS_PER_TILE / 2;
- pt.y = (g.pos.y + height) * UNITS_PER_TILE + UNITS_PER_TILE / 2;
- if (collider.is_empty(pt.x, pt.y)) {
- valid_locations.push_back(pt);
- }
- }
- }
- //remove locations that already have an enemy on them
- Map_Enemy test_enemy;
- for (size_t i = 0; i < enemies.size(); i++) {
- test_enemy = enemies.front();
- enemies.pop();
- enemies.push(test_enemy);
- for (size_t j = 0; j < valid_locations.size(); j++) {
- if ( (test_enemy.pos.x == valid_locations.at(j).x) && (test_enemy.pos.y == valid_locations.at(j).y) ) {
- valid_locations.erase(valid_locations.begin() + j);
- }
- }
- }
+ // The algorithm tries to place the enemies at random locations.
+ // However if a location is not possible (unwalkable or there is already an entity),
+ // then try again.
+ // This could result in an infinite loop if there were more enemies than
+ // actual places, so have an upper bound of tries.
- // spawn the appropriate number of enemies
- int number = rand() % (g.numbermax + 1 - g.numbermin) + g.numbermin;
-
- for(int i = 0; i < number; i++) {
- Enemy_Level enemy_lev = EnemyGroupManager::instance().getRandomEnemy(g.category, g.levelmin, g.levelmax);
- Map_Enemy group_member;
- if ((enemy_lev.type != "") && (!valid_locations.empty())){
- group_member.clear();
- group_member.type = enemy_lev.type;
- int index = rand() % valid_locations.size();
- group_member.pos = valid_locations.at(index);
- valid_locations.erase(valid_locations.begin() + index);
- group_member.direction = rand() % 8;
- enemies.push(group_member);
+ // random number of enemies
+ int enemies_to_spawn = g.numbermin + rand() % (g.numbermax + 1 - g.numbermin);
+
+ // pick an upper bound, which is definitely larger than threetimes the enemy number to spawn.
+ int allowed_misses = 3 * g.numbermax;
+
+ while (enemies_to_spawn && allowed_misses) {
+
+ int x = (g.pos.x + (rand() % g.area.x)) * UNITS_PER_TILE + UNITS_PER_TILE / 2;
+ int y = (g.pos.y + (rand() % g.area.y)) * UNITS_PER_TILE + UNITS_PER_TILE / 2;
+ bool success = false;
+
+ if (collider.is_empty(x, y)) {
+ Enemy_Level enemy_lev = EnemyGroupManager::instance().getRandomEnemy(g.category, g.levelmin, g.levelmax);
+ if (enemy_lev.type != ""){
+ Map_Enemy group_member = Map_Enemy(enemy_lev.type, Point(x, y));
+ enemies.push(group_member);
+
+ success = true;
+ }
}
+ if (success)
+ enemies_to_spawn--;
+ else
+ allowed_misses--;
}
}
-/**
- * load
- */
int MapRenderer::load(string filename) {
FileParser infile;
string val;
- string data_format;
maprow *cur_layer;
+ Map_Enemy new_enemy;
+ Map_Group new_group;
+ bool enemy_awaiting_queue = false;
+ bool group_awaiting_queue = false;
+ bool npc_awaiting_queue = false;
+ Map_NPC new_npc;
clearEvents();
clearLayers();
@@ -176,7 +154,6 @@ int MapRenderer::load(string filename) {
while (infile.next()) {
if (infile.new_section) {
- data_format = "dec"; // default
if (enemy_awaiting_queue) {
enemies.push(new_enemy);
@@ -193,7 +170,7 @@ int MapRenderer::load(string filename) {
// for sections that are stored in collections, add a new object here
if (infile.section == "enemy") {
- new_enemy.clear();
+ new_enemy = Map_Enemy();
enemy_awaiting_queue = true;
}
else if (infile.section == "enemygroup") {
@@ -247,15 +224,19 @@ int MapRenderer::load(string filename) {
else if (infile.val == "collision") collision = cur_layer;
}
else if (infile.key == "format") {
- data_format = infile.val;
+ if (infile.val != "dec") {
+ fprintf(stderr, "ERROR: maploading: The format of a layer must be \"dec\"!\n");
+ SDL_Quit();
+ exit(1);
+ }
}
else if (infile.key == "data") {
// layer map data handled as a special case
// The next h lines must contain layer data. TODO: err
for (int j=0; j<h; j++) {
val = infile.getRawLine() + ',';
for (int i=0; i<w; i++)
- cur_layer[i][j] = eatFirstInt(val, ',', (data_format == "hex" ? std::hex : std::dec));
+ cur_layer[i][j] = eatFirstInt(val, ',');
}
if (cur_layer == collision)
collider.setmap(collision, w, h);
@@ -584,12 +565,9 @@ int MapRenderer::load(string filename) {
}
void MapRenderer::clearQueues() {
- while(!enemies.empty())
- enemies.pop();
- while(!npcs.empty())
- npcs.pop();
- while(!loot.empty())
- loot.pop();
+ enemies = queue<Map_Enemy>();
+ npcs = queue<Map_NPC>();
+ loot = queue<Event_Component>();
}
/**
View
22 src/MapRenderer.h
@@ -127,15 +127,13 @@ class Map_Enemy {
bool wander;
SDL_Rect wander_area;
- void clear() {
- pos.x = 0;
- pos.y = 0;
- // enemies face a random direction unless otherwise specified
- direction = rand() % 8;
- type = "";
- std::queue<Point> empty;
- waypoints = empty;
- wander = false;
+ Map_Enemy(std::string _type="", Point _pos=Point())
+ : type(_type)
+ , pos(_pos)
+ , direction(rand() % 8)
+ , waypoints(std::queue<Point>())
+ , wander(false)
+ {
wander_area.x = 0;
wander_area.y = 0;
wander_area.w = 0;
@@ -261,15 +259,9 @@ class MapRenderer {
// enemy load handling
std::queue<Map_Enemy> enemies;
- Map_Enemy new_enemy;
- Map_Group new_group;
- bool enemy_awaiting_queue;
- bool group_awaiting_queue;
// npc load handling
std::queue<Map_NPC> npcs;
- Map_NPC new_npc;
- bool npc_awaiting_queue;
// event-created loot or items
std::queue<Event_Component> loot;
View
22 src/MenuCharacter.cpp
@@ -70,6 +70,9 @@ MenuCharacter::MenuCharacter(StatBlock *_stats) {
// menu title
labelCharacter = new WidgetLabel();
+ // unspent points
+ labelUnspent = new WidgetLabel();
+
// Load config settings
FileParser infile;
if(infile.open(mods->locate("menus/character.txt"))) {
@@ -149,12 +152,7 @@ MenuCharacter::MenuCharacter(StatBlock *_stats) {
value_pos[5].w = eatFirstInt(infile.val,',');
value_pos[5].h = eatFirstInt(infile.val,',');
} else if(infile.key == "unspent") {
- value_pos[6].x = eatFirstInt(infile.val,',');
- value_pos[6].y = eatFirstInt(infile.val,',');
- value_pos[6].w = eatFirstInt(infile.val,',');
- value_pos[6].h = eatFirstInt(infile.val,',');
- } else if (infile.key == "show_unspent"){
- if (eatFirstInt(infile.val,',') == 0) cstat[CSTAT_UNSPENT].visible = false;
+ unspent_pos = eatLabelInfo(infile.val);
} else if (infile.key == "show_upgrade_physical"){
if (eatFirstInt(infile.val,',') == 0) show_upgrade[0] = false;
} else if (infile.key == "show_upgrade_mental"){
@@ -242,8 +240,6 @@ void MenuCharacter::update() {
cstat[CSTAT_MENTAL].setHover(window_area.x+value_pos[3].x, window_area.y+value_pos[3].y, value_pos[3].w, value_pos[3].h);
cstat[CSTAT_OFFENSE].setHover(window_area.x+value_pos[4].x, window_area.y+value_pos[4].y, value_pos[4].w, value_pos[4].h);
cstat[CSTAT_DEFENSE].setHover(window_area.x+value_pos[5].x, window_area.y+value_pos[5].y, value_pos[5].w, value_pos[5].h);
- cstat[CSTAT_UNSPENT].setHover(window_area.x+value_pos[6].x, window_area.y+value_pos[6].y, value_pos[6].w, value_pos[6].h);
-
}
void MenuCharacter::loadGraphics() {
@@ -295,8 +291,7 @@ void MenuCharacter::refreshStats() {
ss.str("");
if (skill_points > 0) ss << skill_points << " " << msg->get("points remaining");
else ss.str("");
- cstat[CSTAT_UNSPENT].value->set(window_area.x+value_pos[6].x+value_pos[6].w/2, window_area.y+value_pos[6].y+value_pos[6].h/2, JUSTIFY_CENTER, VALIGN_CENTER, ss.str(), font->getColor("menu_bonus"));
- ss.str("");
+ labelUnspent->set(window_area.x+unspent_pos.x, window_area.y+unspent_pos.y, unspent_pos.justify, unspent_pos.valign, ss.str(), font->getColor("menu_bonus"), unspent_pos.font_style);
// scrolling stat list
@@ -448,9 +443,6 @@ void MenuCharacter::refreshStats() {
cstat[CSTAT_DEFENSE].tip.clear();
cstat[CSTAT_DEFENSE].tip.addText(msg->get("Defense (D) increases armor proficiency and avoidance."));
cstat[CSTAT_DEFENSE].tip.addText(msg->get("base (%d), bonus (%d)", stats->defense_character, stats->defense_additional));
-
- if (skill_points) cstat[CSTAT_UNSPENT].tip.addText(msg->get("Unspent attribute points"));
-
}
@@ -518,6 +510,9 @@ void MenuCharacter::render() {
// title
labelCharacter->render();
+ // unspent points
+ labelUnspent->render();
+
// labels and values
for (int i=0; i<CSTAT_COUNT; i++) {
if (cstat[i].visible) {
@@ -601,6 +596,7 @@ MenuCharacter::~MenuCharacter() {
delete closeButton;
delete labelCharacter;
+ delete labelUnspent;
for (int i=0; i<CSTAT_COUNT; i++) {
delete cstat[i].label;
delete cstat[i].value;
View
7 src/MenuCharacter.h
@@ -45,8 +45,7 @@ const int CSTAT_PHYSICAL = 2;
const int CSTAT_MENTAL = 3;
const int CSTAT_OFFENSE = 4;
const int CSTAT_DEFENSE = 5;
-const int CSTAT_UNSPENT = 6;
-const int CSTAT_COUNT = 7;
+const int CSTAT_COUNT = 6;
struct CharStat {
WidgetLabel *label;
@@ -70,6 +69,7 @@ class MenuCharacter : public Menu {
WidgetButton *closeButton;
WidgetButton *upgradeButton[4];
WidgetLabel *labelCharacter;
+ WidgetLabel *labelUnspent;
WidgetListBox *statList;
CharStat cstat[CSTAT_COUNT];
@@ -88,7 +88,8 @@ class MenuCharacter : public Menu {
Point statlist_pos;
int statlist_rows;
int statlist_scrollbar_offset;
- LabelInfo label_pos[CSTAT_COUNT-1]; //unspent points doesn't have a separate label
+ LabelInfo unspent_pos;
+ LabelInfo label_pos[CSTAT_COUNT];
SDL_Rect value_pos[CSTAT_COUNT];
bool show_upgrade[4];
bool show_stat[16];
View
7 src/MenuManager.cpp
@@ -207,11 +207,8 @@ void MenuManager::loadIcons() {
void MenuManager::loadSounds() {
if (audio && SOUND_VOLUME) {
- sfx_open = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_page.ogg").c_str());
- sfx_close = Mix_LoadWAV(mods->locate("soundfx/inventory/inventory_book.ogg").c_str());
-
- if (!sfx_open || !sfx_close)
- fprintf(stderr, "Mix_LoadWAV: %s\n", Mix_GetError());
+ sfx_open = loadSfx(mods->locate("soundfx/inventory/inventory_page.ogg"), "MenuManager open tab");
+ sfx_close = loadSfx(mods->locate("soundfx/inventory/inventory_book.ogg"), "MenuManager close tab");
} else {
sfx_open = NULL;
sfx_close = NULL;
View
6 src/NPC.cpp
@@ -195,18 +195,18 @@ int NPC::loadSound(const string& filename, int type) {
if (!SOUND_VOLUME || !audio)
return -1;
- Mix_Chunk *a = Mix_LoadWAV(mods->locate("soundfx/npcs/" + filename).c_str());
+ Mix_Chunk *a = loadSfx(mods->locate("soundfx/npcs/" + filename), "NPC voice");
if (!a)
return -1;
if (type == NPC_VOX_INTRO) {
vox_intro.push_back(a);
- return vox_intro.size()-1;
+ return vox_intro.size() - 1;
}
if (type == NPC_VOX_QUEST) {
vox_quests.push_back(a);
- return vox_quests.size()-1;
+ return vox_quests.size() - 1;
}
return -1;
}
View
6 src/PowerManager.cpp
@@ -305,11 +305,9 @@ int PowerManager::loadSFX(const string& filename) {
// we don't already have this sound loaded, so load it
Mix_Chunk* sound;
if (audio && SOUND_VOLUME) {
- sound = Mix_LoadWAV(mods->locate("soundfx/powers/" + filename).c_str());
- if(!sound) {
- cerr << "Couldn't load power soundfx: " << filename << endl;
+ sound = loadSfx(mods->locate("soundfx/powers/" + filename), "PowerManager sfx");
+ if (!sound)
return -1;
- }
} else {
sound = NULL;
}
View
28 src/StatBlock.cpp
@@ -394,29 +394,35 @@ void StatBlock::recalc() {
void StatBlock::recalc_alt() {
int lev0 = level -1;
- int phys0 = get_physical() -1;
- int ment0 = get_mental() -1;
- int off0 = get_offense() -1;
- int def0 = get_defense() -1;
if (hero) {
- maxhp = hp_base + (hp_per_level * lev0) + (hp_per_physical * phys0) + effects.bonus_hp + (effects.bonus_hp_percent * (hp_base + (hp_per_level * lev0) + (hp_per_physical * phys0)) / 100);
- maxmp = mp_base + (mp_per_level * lev0) + (mp_per_mental * ment0) + effects.bonus_mp + (effects.bonus_mp_percent * (mp_base + (mp_per_level * lev0) + (mp_per_mental * phys0)) / 100);
- hp_per_minute = hp_regen_base + (hp_regen_per_level * lev0) + (hp_regen_per_physical * phys0) + effects.bonus_hp_regen;
- mp_per_minute = mp_regen_base + (mp_regen_per_level * lev0) + (mp_regen_per_mental * ment0) + effects.bonus_mp_regen;
- accuracy = accuracy_base + (accuracy_per_level * lev0) + (accuracy_per_offense * off0) + effects.bonus_accuracy;
- avoidance = avoidance_base + (avoidance_per_level * lev0) + (avoidance_per_defense * def0) + effects.bonus_avoidance;
- crit = crit_base + (crit_per_level * lev0) + effects.bonus_crit;
+ // calculate primary stats
+ offense_additional = defense_additional = physical_additional = mental_additional = 0;
offense_additional = effects.bonus_offense;
defense_additional = effects.bonus_defense;
physical_additional = effects.bonus_physical;
mental_additional = effects.bonus_mental;
+ int phys0 = get_physical() -1;
+ int ment0 = get_mental() -1;
+ int off0 = get_offense() -1;
+ int def0 = get_defense() -1;
+
+ // calculate compound primary stats
physoff = get_physical() + get_offense();
physdef = get_physical() + get_defense();
mentoff = get_mental() + get_offense();
mentdef = get_mental() + get_defense();
physment = get_physical() + get_mental();
offdef = get_offense() + get_defense();
+
+ // calculate other stats
+ maxhp = hp_base + (hp_per_level * lev0) + (hp_per_physical * phys0) + effects.bonus_hp + (effects.bonus_hp_percent * (hp_base + (hp_per_level * lev0) + (hp_per_physical * phys0)) / 100);
+ maxmp = mp_base + (mp_per_level * lev0) + (mp_per_mental * ment0) + effects.bonus_mp + (effects.bonus_mp_percent * (mp_base + (mp_per_level * lev0) + (mp_per_mental * phys0)) / 100);
+ hp_per_minute = hp_regen_base + (hp_regen_per_level * lev0) + (hp_regen_per_physical * phys0) + effects.bonus_hp_regen;
+ mp_per_minute = mp_regen_base + (mp_regen_per_level * lev0) + (mp_regen_per_mental * ment0) + effects.bonus_mp_regen;
+ accuracy = accuracy_base + (accuracy_per_level * lev0) + (accuracy_per_offense * off0) + effects.bonus_accuracy;
+ avoidance = avoidance_base + (avoidance_per_level * lev0) + (avoidance_per_defense * def0) + effects.bonus_avoidance;
+ crit = crit_base + (crit_per_level * lev0) + effects.bonus_crit;
} else {
maxhp = hp_base + effects.bonus_hp;
maxmp = mp_base + effects.bonus_mp;
View
8 src/Utils.cpp
@@ -361,3 +361,11 @@ bool checkPixel(Point px, SDL_Surface *surface) {
return true;
}
+
+Mix_Chunk *loadSfx(const string &filename, const string &errormessage)
+{
+ Mix_Chunk * sound = Mix_LoadWAV(filename.c_str());
+ if (!sound)
+ fprintf(stderr, "%s: Loading sound %s failed: %s \n", errormessage.c_str(), filename.c_str(), Mix_GetError());
+ return sound;
+}
View
4 src/Utils.h
@@ -28,6 +28,8 @@ FLARE. If not, see http://www.gnu.org/licenses/
#include <SDL.h>
#include <SDL_image.h>
+#include <SDL_mixer.h>
+
#include <string>
#include <stdint.h>
@@ -109,4 +111,6 @@ SDL_Surface* createAlphaSurface(int width, int height);
* The bright pink (rgb 0xff00ff) is set as transparent color.
*/
SDL_Surface* createSurface(int width, int height);
+
+Mix_Chunk *loadSfx(const std::string &filename, const std::string &errormessage);
#endif
View
70 src/UtilsParsing.cpp
@@ -46,66 +46,6 @@ bool isInt(const string& s) {
}
/**
- * Convert a single hex character (0123456789abcdef) into the equivalent integer
- */
-unsigned short xtoi(char c) {
- if (c >= 97) return c - 87;
- else if (c >= 65) return c - 55;
- else return c - 48;
-}
-
-/**
- * Convert two-char hex string to int 0-255
- */
-unsigned short xtoi(const string& hex) {
-
- char c0 = hex.at(0);
- char c1 = hex.at(1);
- unsigned short val;
-
- val = xtoi(c0) * 16;
- val = val + xtoi(c1);
-
- return val;
-}
-
-/**
- * Convert four booleans into a single hex character 0-f
- */
-char btox(bool b1, bool b2, bool b3, bool b4) {
- if (b4)
- if (b3)
- if (b2)
- if (b1) return 'f';
- else return 'e';
- else
- if (b1) return 'd';
- else return 'c';
- else
- if (b2)
- if (b1) return 'b';
- else return 'a';
- else
- if (b1) return '9';
- else return '8';
- else
- if (b3)
- if (b2)
- if (b1) return '7';
- else return '6';
- else
- if (b1) return '5';
- else return '4';
- else
- if (b2)
- if (b1) return '3';
- else return '2';
- else
- if (b1) return '1';
- else return '0';
-}
-
-/**
* trim: remove leading and trailing c from s
*/
string trim(const string& s, char c) {
@@ -144,18 +84,18 @@ void parse_key_pair(const string& s, string &key, string &val) {
}
/**
- * Given a string that starts with a number then a comma
+ * Given a string that starts with a decimal number then a comma
* Return that int, and modify the string to remove the num and comma
*
* This is basically a really lazy "split" replacement
*/
-int eatFirstInt(string &s, char separator, std::ios_base& (*f)(std::ios_base&)) {
+int eatFirstInt(string &s, char separator) {
size_t seppos = s.find_first_of(separator);
if (seppos == string::npos) {
s = "";
return 0; // not found
}
- int num = toInt(s.substr(0, seppos), f);
+ int num = toInt(s.substr(0, seppos));
s = s.substr(seppos+1, s.length());
return num;
}
@@ -265,9 +205,9 @@ std::string toString(const type_info & type, void * value) {
return stream.str();
}
-int toInt(const string& s, std::ios_base& (*f)(std::ios_base&), int default_value) {
+int toInt(const string& s, int default_value) {
int result;
- if (!(stringstream(s) >> f >> result))
+ if (!(stringstream(s) >> result))
result = default_value;
return result;
}
View
7 src/UtilsParsing.h
@@ -25,21 +25,18 @@ FLARE. If not, see http://www.gnu.org/licenses/
#include <iostream>
bool isInt(const std::string& s);
-unsigned short xtoi(char c);
-unsigned short xtoi(const std::string& hex);
-char btox(bool b1, bool b2, bool b3, bool b4);
std::string trim(const std::string& s, char c);
std::string parse_section_title(const std::string& s);
void parse_key_pair(const std::string& s, std::string& key, std::string& val);
-int eatFirstInt(std::string& s, char separator, std::ios_base& (*f)(std::ios_base&) = std::dec);
+int eatFirstInt(std::string& s, char separator);
std::string eatFirstString(std::string& s, char separator);
std::string getNextToken(const std::string& s, size_t& cursor, char separator);
std::string stripCarriageReturn(const std::string& line);
std::string getLine(std::ifstream& infile);
bool tryParseValue(const std::type_info & type, const char * value, void * output);
bool tryParseValue(const std::type_info & type, const std::string & value, void * output);
std::string toString(const std::type_info & type, void * value);
-int toInt(const std::string& s, std::ios_base& (*f)(std::ios_base&) = std::dec, int default_value = 0);
+int toInt(const std::string& s, int default_value = 0);
bool toBool(std::string value);
#endif

0 comments on commit f8bbf0d

Please sign in to comment.
Something went wrong with that request. Please try again.