Skip to content

Commit

Permalink
Merge branch 'master' into HEAD
Browse files Browse the repository at this point in the history
Conflicts:
	src/MapRenderer.cpp
	src/Utils.cpp
	src/Utils.h
  • Loading branch information
stefanbeller committed Apr 1, 2013
2 parents 545b7e4 + e0bb78b commit 3fc0933
Show file tree
Hide file tree
Showing 75 changed files with 875 additions and 1,376 deletions.
3 changes: 3 additions & 0 deletions .mailmap
@@ -1,5 +1,7 @@
# Proper Name <proper@email.xx> Commit Name <commit@email.xx>
Clint Bellanger <clintbellanger@gmail.com> clintbellanger <clintbellanger@gmail.com>
Clint Bellanger <clintbellanger@gmail.com> unknown <cpb0001@LIB-AU16638.auburn.edu>
Clint Bellanger <clintbellanger@gmail.com> unknown <clintbellanger@gmail.com>
Thane Brimhall <thane.brimhall@gmail.com> Thane Brimhall <thane@lenny.(none)>
Thane Brimhall <thane.brimhall@gmail.com> Thane Brimhall <tbrimhall@turtle.(none)>
Thane Brimhall <thane.brimhall@gmail.com> Thane Brimhall <thane@thane-laptop.(none)>
Expand All @@ -12,4 +14,5 @@ Chris Oelmueller <chris.oelmueller@gmail.com> Chris Oelmueller <eoc.eoc.eoc@gmai
Manuel A. Fernandez Montecelo <manuel.montezelo@gmail.com> Manuel A. Fernandez Montecelo <mafm@mafm-laptop.itsari.org>
Adrián Chaves Fernández (Gallaecio) <adriyetichaves@gmail.com> Adrian Chavez Fernandez (Gallaecio) <adriyetichaves@gmail.com>
Adrián Chaves Fernández (Gallaecio) <adriyetichaves@gmail.com> Adrian Chaves Fernandez <adriyetichaves@gmail.com>
Henrik Andersson <hean01@users.sourceforge.net> Henrik Andersson <henrik.4e@gmail.com>

8 changes: 3 additions & 5 deletions src/Animation.cpp
Expand Up @@ -203,9 +203,6 @@ Renderable Animation::getCurrentFrame(int kind) {
r.offset.y = render_offset[index].y;
r.sprite = sprite;
}
else {
memset(&r, 0, sizeof(Renderable));
}
return r;
}

Expand All @@ -226,9 +223,10 @@ void Animation::syncTo(const Animation *other) {
}

void Animation::setActiveFrames(const std::vector<short> &_active_frames) {
if (_active_frames.size() == 1 && _active_frames[0] == -1)
for (short i=0; i < number_frames; ++i)
if (_active_frames.size() == 1 && _active_frames[0] == -1) {
for (short i = 0; i < number_frames; ++i)
active_frames.push_back(i);
}
else
active_frames = std::vector<short>(_active_frames);
}
4 changes: 1 addition & 3 deletions src/AnimationSet.cpp
Expand Up @@ -66,10 +66,8 @@ void AnimationSet::load() {
FileParser parser;
const string filename = mods->locate(name);

if (!parser.open(filename.c_str())) {
cout << "Error loading animation definition file: " << name << endl;
if (!parser.open(filename, "Error loading animation definition: " + name))
return;
}

string _name = "";
int position = 0;
Expand Down
9 changes: 5 additions & 4 deletions src/Avatar.cpp
Expand Up @@ -35,6 +35,7 @@ FLARE. If not, see http://www.gnu.org/licenses/
#include "MapRenderer.h"
#include "PowerManager.h"
#include "SharedResources.h"
#include "Utils.h"
#include "UtilsParsing.h"
#include "UtilsMath.h"

Expand Down Expand Up @@ -170,7 +171,7 @@ void Avatar::loadLayerDefinitions() {
}
}
infile.close();
} else fprintf(stderr, "Unable to open engine/hero_options.txt!\n");
}

// There are the positions of the items relative to layer_reference_order
// so if layer_reference_order=main,body,head,off
Expand Down Expand Up @@ -276,7 +277,7 @@ void Avatar::set_direction() {
target = path.back();
}
}
stats.direction = face(target.x, target.y);
stats.direction = calcDirection(stats.pos, target);
} else {
if (inpt->pressing[UP] && inpt->pressing[LEFT]) stats.direction = 1;
else if (inpt->pressing[UP] && inpt->pressing[RIGHT]) stats.direction = 3;
Expand Down Expand Up @@ -327,7 +328,7 @@ void Avatar::handlePower(int actionbar_power) {

// is this a power that requires changing direction?
if (power.face) {
stats.direction = face(target.x, target.y);
stats.direction = calcDirection(stats.pos, target);
}

switch (power.new_state) {
Expand Down Expand Up @@ -776,7 +777,7 @@ bool Avatar::takeHit(const Hazard &h) {

if (!stats.effects.immunity) {
if (stats.effects.forced_move) {
float theta = powers->calcTheta(h.src_stats->pos.x, h.src_stats->pos.y, stats.pos.x, stats.pos.y);
float theta = calcTheta(h.src_stats->pos.x, h.src_stats->pos.y, stats.pos.x, stats.pos.y);
stats.forced_speed.x = static_cast<int>(ceil(stats.effects.forced_speed * cos(theta)));
stats.forced_speed.y = static_cast<int>(ceil(stats.effects.forced_speed * sin(theta)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/BehaviorStandard.cpp
Expand Up @@ -315,7 +315,7 @@ void BehaviorStandard::checkMove() {
}
}

e->stats.direction = e->face(pursue_pos.x, pursue_pos.y);
e->stats.direction = calcDirection(e->stats.pos, pursue_pos);
e->stats.turn_ticks = 0;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/CombatText.cpp
Expand Up @@ -54,7 +54,7 @@ CombatText::CombatText() {
}
}
infile.close();
} else fprintf(stderr, "Unable to open engine/combat_text.txt!\n");
}
}

void CombatText::setCam(Point location) {
Expand Down
2 changes: 1 addition & 1 deletion src/Enemy.cpp
Expand Up @@ -240,7 +240,7 @@ bool Enemy::takeHit(const Hazard &h) {
powers->effect(&stats, h.power_index);

if (stats.effects.forced_move) {
float theta = powers->calcTheta(stats.hero_pos.x, stats.hero_pos.y, stats.pos.x, stats.pos.y);
float theta = calcTheta(stats.hero_pos.x, stats.hero_pos.y, stats.pos.x, stats.pos.y);
stats.forced_speed.x = static_cast<int>(ceil(stats.effects.forced_speed * cos(theta)));
stats.forced_speed.y = static_cast<int>(ceil(stats.effects.forced_speed * sin(theta)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/EnemyGroupManager.cpp
Expand Up @@ -77,7 +77,7 @@ void EnemyGroupManager::parseEnemyFileAndStore(const string& filename) {
}
}
infile.close();
} else fprintf(stderr, "Unable to open enemies/%s!\n", filename.c_str());
}
}

Enemy_Level EnemyGroupManager::getRandomEnemy(const std::string& category, int minlevel, int maxlevel) const {
Expand Down
48 changes: 24 additions & 24 deletions src/EnemyManager.cpp
Expand Up @@ -201,45 +201,45 @@ void EnemyManager::logic() {

handleSpawn();

for (unsigned int i=0; i < enemies.size(); i++) {

vector<Enemy*>::iterator it;
for (it = enemies.begin(); it != enemies.end(); ++it) {
// hazards are processed after Avatar and Enemy[]
// so process and clear sound effects from previous frames
// check sound effects
if (AUDIO) {
vector<string>::iterator found = find (sfx_prefixes.begin(), sfx_prefixes.end(), enemies[i]->stats.sfx_prefix);
vector<string>::iterator found = find (sfx_prefixes.begin(), sfx_prefixes.end(), (*it)->stats.sfx_prefix);
unsigned pref_id = distance(sfx_prefixes.begin(), found);

if (pref_id >= sfx_prefixes.size()) {
cerr << "ERROR: enemy sfx_prefix doesn't match registered prefixes (enemy: '"
<< enemies[i]->stats.name << "', sfx_prefix: '"
<< enemies[i]->stats.sfx_prefix << "')" << endl;
<< (*it)->stats.name << "', sfx_prefix: '"
<< (*it)->stats.sfx_prefix << "')" << endl;
} else {
if (enemies[i]->sfx_phys)
snd->play(sound_phys[pref_id], GLOBAL_VIRTUAL_CHANNEL, enemies[i]->stats.pos, false);
if (enemies[i]->sfx_ment)
snd->play(sound_ment[pref_id], GLOBAL_VIRTUAL_CHANNEL, enemies[i]->stats.pos, false);
if (enemies[i]->sfx_hit)
snd->play(sound_hit[pref_id], GLOBAL_VIRTUAL_CHANNEL, enemies[i]->stats.pos, false);
if (enemies[i]->sfx_die)
snd->play(sound_die[pref_id], GLOBAL_VIRTUAL_CHANNEL, enemies[i]->stats.pos, false);
if (enemies[i]->sfx_critdie)
snd->play(sound_critdie[pref_id], GLOBAL_VIRTUAL_CHANNEL, enemies[i]->stats.pos, false);
if ((*it)->sfx_phys)
snd->play(sound_phys[pref_id], GLOBAL_VIRTUAL_CHANNEL, (*it)->stats.pos, false);
if ((*it)->sfx_ment)
snd->play(sound_ment[pref_id], GLOBAL_VIRTUAL_CHANNEL, (*it)->stats.pos, false);
if ((*it)->sfx_hit)
snd->play(sound_hit[pref_id], GLOBAL_VIRTUAL_CHANNEL, (*it)->stats.pos, false);
if ((*it)->sfx_die)
snd->play(sound_die[pref_id], GLOBAL_VIRTUAL_CHANNEL, (*it)->stats.pos, false);
if ((*it)->sfx_critdie)
snd->play(sound_critdie[pref_id], GLOBAL_VIRTUAL_CHANNEL, (*it)->stats.pos, false);
}

// clear sound flags
enemies[i]->sfx_hit = false;
enemies[i]->sfx_phys = false;
enemies[i]->sfx_ment = false;
enemies[i]->sfx_die = false;
enemies[i]->sfx_critdie = false;
(*it)->sfx_hit = false;
(*it)->sfx_phys = false;
(*it)->sfx_ment = false;
(*it)->sfx_die = false;
(*it)->sfx_critdie = false;
}

// new actions this round
enemies[i]->stats.hero_pos = hero_pos;
enemies[i]->stats.hero_alive = hero_alive;
enemies[i]->stats.hero_stealth = hero_stealth;
enemies[i]->logic();
(*it)->stats.hero_pos = hero_pos;
(*it)->stats.hero_alive = hero_alive;
(*it)->stats.hero_stealth = hero_stealth;
(*it)->logic();

}
}
Expand Down
34 changes: 0 additions & 34 deletions src/Entity.cpp
Expand Up @@ -103,40 +103,6 @@ bool Entity::move() {
return full_move;
}

/**
* Change direction to face the target map location
*/
int Entity::face(int mapx, int mapy) {
// inverting Y to convert map coordinates to standard cartesian coordinates
int dx = mapx - stats.pos.x;
int dy = stats.pos.y - mapy;

// avoid div by zero
if (dx == 0) {
if (dy > 0) return 3;
else return 7;
}

float slope = ((float)dy)/((float)dx);
if (0.5 <= slope && slope <= 2.0) {
if (dy > 0) return 4;
else return 0;
}
if (-0.5 <= slope && slope <= 0.5) {
if (dx > 0) return 5;
else return 1;
}
if (-2.0 <= slope && slope <= -0.5) {
if (dx > 0) return 6;
else return 2;
}
if (2.0 <= slope || -2.0 >= slope) {
if (dy > 0) return 3;
else return 7;
}
return stats.direction;
}

/**
* Set the entity's current animation by name
*/
Expand Down
1 change: 0 additions & 1 deletion src/Entity.h
Expand Up @@ -44,7 +44,6 @@ class Entity {
virtual ~Entity();

bool move();
int face(int, int);

// Each child of Entity defines its own rendering method
virtual Renderable getRender() = 0;
Expand Down
15 changes: 12 additions & 3 deletions src/FileParser.cpp
Expand Up @@ -33,9 +33,13 @@ FileParser::FileParser()
, val("")
{}

bool FileParser::open(const string& filename) {
bool FileParser::open(const string& filename, const string &errormessage) {
this->filename = filename;
infile.open(filename.c_str(), ios::in);
return infile.is_open();
bool ret = infile.is_open();
if (!ret && !errormessage.empty())
fprintf(stderr, "%s: %s\n", errormessage.c_str(), filename.c_str());
return ret;
}

void FileParser::close() {
Expand Down Expand Up @@ -105,7 +109,7 @@ string FileParser::nextValue() {
size_t seppos = val.find_first_of(',');
size_t alt_seppos = val.find_first_of(';');
if (alt_seppos != string::npos && alt_seppos < seppos)
seppos = alt_seppos; // return the first ',' or ';'
seppos = alt_seppos; // return the first ',' or ';'

if (seppos == string::npos) {
s = val;
Expand All @@ -118,6 +122,11 @@ string FileParser::nextValue() {
return s;
}

std::string FileParser::getFileName()
{
return filename;
}

FileParser::~FileParser() {
close();
}
13 changes: 12 additions & 1 deletion src/FileParser.h
Expand Up @@ -31,18 +31,29 @@ FLARE. If not, see http://www.gnu.org/licenses/

class FileParser {
private:
std::string filename;
std::ifstream infile;
std::string line;

public:
FileParser();
~FileParser();

bool open(const std::string& filename);
/**
* @brief open
* @param filename The file to be opened
* @param errormessage
* Optional parameter, will be printed to stderr together with the filename
* if an error occurs. If errormessage is empty, there will be no output to
* stderr in any case.
* @return true if file could be opened successfully for reading.
*/
bool open(const std::string& filename, const std::string &errormessage = "Could not open text file");
void close();
bool next();
std::string nextValue(); // next value inside one line.
std::string getRawLine();
std::string getFileName();

bool new_section;
std::string section;
Expand Down
4 changes: 2 additions & 2 deletions src/FontEngine.cpp
Expand Up @@ -77,7 +77,7 @@ FontEngine::FontEngine()
}
}
infile.close();
} else fprintf(stderr, "Unable to open engine/font_settings.txt!\n");
}

// set the font colors
// RGB values, the last value is 'unused'. For info,
Expand All @@ -92,7 +92,7 @@ FontEngine::FontEngine()
color_map[infile.key] = color;
}
infile.close();
} else fprintf(stderr, "Unable to open engine/font_colors.txt!\n");
}

// Attempt to set the default active font
setFont("font_regular");
Expand Down

0 comments on commit 3fc0933

Please sign in to comment.