Skip to content

Commit

Permalink
Remove hardcoded effect icons
Browse files Browse the repository at this point in the history
  • Loading branch information
dorkster committed Sep 13, 2012
1 parent dc04430 commit a3a6073
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 44 deletions.
38 changes: 38 additions & 0 deletions mods/fantasycore/engine/effects.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,8 +5,46 @@ frame_offset=32,32
# status effects # status effects
id=1 id=1
type=shield type=shield
icon=11
gfx=shield.png gfx=shield.png
size=0,0,128,128 size=0,0,128,128
offset=64,96 offset=64,96
frame_total=12 frame_total=12
ticks_per_frame=3 ticks_per_frame=3

id=2
type=slow
icon=14

id=3
type=bleed
icon=5

id=4
type=stun
icon=10

id=5
type=immobilize
icon=4

id=6
type=immunity
icon=9

id=7
type=transform
icon=21

id=8
type=haste
icon=12

id=9
type=hot
icon=7

id=10
type=block
icon=3

38 changes: 38 additions & 0 deletions mods/minicore/engine/effects.txt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,8 +5,46 @@ frame_offset=16,16
# status effects # status effects
id=1 id=1
type=shield type=shield
icon=11
gfx=shield.png gfx=shield.png
size=0,0,64,64 size=0,0,64,64
offset=32,48 offset=32,48
frame_total=12 frame_total=12
ticks_per_frame=3 ticks_per_frame=3

id=2
type=slow
icon=14

id=3
type=bleed
icon=5

id=4
type=stun
icon=10

id=5
type=immobilize
icon=4

id=6
type=immunity
icon=9

id=7
type=transform
icon=21

id=8
type=haste
icon=12

id=9
type=hot
icon=7

id=10
type=block
icon=3

10 changes: 5 additions & 5 deletions src/Avatar.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ void Avatar::logic(int actionbar_power, bool restrictPowerUse) {


setAnimation("block"); setAnimation("block");


stats.addEffect("block"); stats.addEffect("block",powers->getEffectIcon("block"));


if (powers->powers[actionbar_power].new_state != POWSTATE_BLOCK) { if (powers->powers[actionbar_power].new_state != POWSTATE_BLOCK) {
stats.cur_state = AVATAR_STANCE; stats.cur_state = AVATAR_STANCE;
Expand Down Expand Up @@ -764,19 +764,19 @@ bool Avatar::takeHit(Hazard h) {
if (stats.hp > 0 && stats.immunity_duration == 0 && dmg > 0) { if (stats.hp > 0 && stats.immunity_duration == 0 && dmg > 0) {
if (h.stun_duration > stats.stun_duration) { if (h.stun_duration > stats.stun_duration) {
stats.stun_duration_total = stats.stun_duration = h.stun_duration; stats.stun_duration_total = stats.stun_duration = h.stun_duration;
stats.addEffect("stun"); stats.addEffect("stun",powers->getEffectIcon("stun"));
} }
if (h.slow_duration > stats.slow_duration) { if (h.slow_duration > stats.slow_duration) {
stats.slow_duration_total = stats.slow_duration = h.slow_duration; stats.slow_duration_total = stats.slow_duration = h.slow_duration;
stats.addEffect("slow"); stats.addEffect("slow",powers->getEffectIcon("slow"));
} }
if (h.bleed_duration > stats.bleed_duration) { if (h.bleed_duration > stats.bleed_duration) {
stats.bleed_duration_total = stats.bleed_duration = h.bleed_duration; stats.bleed_duration_total = stats.bleed_duration = h.bleed_duration;
stats.addEffect("bleed"); stats.addEffect("bleed",powers->getEffectIcon("bleed"));
} }
if (h.immobilize_duration > stats.immobilize_duration) { if (h.immobilize_duration > stats.immobilize_duration) {
stats.immobilize_duration_total = stats.immobilize_duration = h.immobilize_duration; stats.immobilize_duration_total = stats.immobilize_duration = h.immobilize_duration;
stats.addEffect("immobilize"); stats.addEffect("immobilize",powers->getEffectIcon("immobilize"));
} }
if (h.forced_move_duration > stats.forced_move_duration) stats.forced_move_duration_total = stats.forced_move_duration = h.forced_move_duration; if (h.forced_move_duration > stats.forced_move_duration) stats.forced_move_duration_total = stats.forced_move_duration = h.forced_move_duration;
if (h.forced_move_speed != 0) { if (h.forced_move_speed != 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/Enemy.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -216,19 +216,19 @@ bool Enemy::takeHit(Hazard h) {
if (stats.hp > 0) { if (stats.hp > 0) {
if (h.stun_duration > stats.stun_duration) { if (h.stun_duration > stats.stun_duration) {
stats.stun_duration_total = stats.stun_duration = h.stun_duration; stats.stun_duration_total = stats.stun_duration = h.stun_duration;
stats.addEffect("stun"); stats.addEffect("stun",powers->getEffectIcon("stun"));
} }
if (h.slow_duration > stats.slow_duration) { if (h.slow_duration > stats.slow_duration) {
stats.slow_duration_total = stats.slow_duration = h.slow_duration; stats.slow_duration_total = stats.slow_duration = h.slow_duration;
stats.addEffect("slow"); stats.addEffect("slow",powers->getEffectIcon("slow"));
} }
if (h.bleed_duration > stats.bleed_duration) { if (h.bleed_duration > stats.bleed_duration) {
stats.bleed_duration_total = stats.bleed_duration = h.bleed_duration; stats.bleed_duration_total = stats.bleed_duration = h.bleed_duration;
stats.addEffect("bleed"); stats.addEffect("bleed",powers->getEffectIcon("bleed"));
} }
if (h.immobilize_duration > stats.immobilize_duration) { if (h.immobilize_duration > stats.immobilize_duration) {
stats.immobilize_duration_total = stats.immobilize_duration = h.immobilize_duration; stats.immobilize_duration_total = stats.immobilize_duration = h.immobilize_duration;
stats.addEffect("immobilize"); stats.addEffect("immobilize",powers->getEffectIcon("immobilize"));
} }
if (h.forced_move_duration > stats.forced_move_duration) stats.forced_move_duration_total = stats.forced_move_duration = h.forced_move_duration; if (h.forced_move_duration > stats.forced_move_duration) stats.forced_move_duration_total = stats.forced_move_duration = h.forced_move_duration;
if (h.forced_move_speed != 0) { if (h.forced_move_speed != 0) {
Expand Down
58 changes: 30 additions & 28 deletions src/MenuActiveEffects.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -75,28 +75,30 @@ void MenuActiveEffects::loadGraphics() {
} }


void MenuActiveEffects::renderIcon(int icon_id, int index, int current, int max){ void MenuActiveEffects::renderIcon(int icon_id, int index, int current, int max){
SDL_Rect pos,src,overlay; if (icon_id > -1) {
if (orientation == 0) { SDL_Rect pos,src,overlay;
pos.x = window_area.x + (index * ICON_SIZE_SMALL); if (orientation == 0) {
pos.y = window_area.y; pos.x = window_area.x + (index * ICON_SIZE_SMALL);
} else if (orientation == 1) { pos.y = window_area.y;
pos.x = window_area.x; } else if (orientation == 1) {
pos.y = window_area.y + (index * ICON_SIZE_SMALL);; pos.x = window_area.x;
} pos.y = window_area.y + (index * ICON_SIZE_SMALL);;
}


src.x = (icon_id % 16) * ICON_SIZE_SMALL; src.x = (icon_id % 16) * ICON_SIZE_SMALL;
src.y = (icon_id / 16) * ICON_SIZE_SMALL; src.y = (icon_id / 16) * ICON_SIZE_SMALL;
src.w = src.h = ICON_SIZE_SMALL; src.w = src.h = ICON_SIZE_SMALL;


SDL_BlitSurface(icons,&src,screen,&pos); SDL_BlitSurface(icons,&src,screen,&pos);


if (max > 0) { if (max > 0) {
overlay.x = 0; overlay.x = 0;
overlay.y = (ICON_SIZE_SMALL * current) / max; overlay.y = (ICON_SIZE_SMALL * current) / max;
overlay.w = ICON_SIZE_SMALL; overlay.w = ICON_SIZE_SMALL;
overlay.h = ICON_SIZE_SMALL - overlay.y; overlay.h = ICON_SIZE_SMALL - overlay.y;


SDL_BlitSurface(timer,&overlay,screen,&pos); SDL_BlitSurface(timer,&overlay,screen,&pos);
}
} }
} }


Expand All @@ -108,25 +110,25 @@ void MenuActiveEffects::render() {
// Step through the list of effects and render those that are active // Step through the list of effects and render those that are active
for (unsigned int i=0; i<stats->effects.size(); i++) { for (unsigned int i=0; i<stats->effects.size(); i++) {
if (stats->effects[i].type == "slow") if (stats->effects[i].type == "slow")
renderIcon(14,i,stats->slow_duration,stats->slow_duration_total); renderIcon(stats->effects[i].icon,i,stats->slow_duration,stats->slow_duration_total);
if (stats->effects[i].type == "bleed") if (stats->effects[i].type == "bleed")
renderIcon(5,i,stats->bleed_duration,stats->bleed_duration_total); renderIcon(stats->effects[i].icon,i,stats->bleed_duration,stats->bleed_duration_total);
if (stats->effects[i].type == "stun") if (stats->effects[i].type == "stun")
renderIcon(10,i,stats->stun_duration,stats->stun_duration_total); renderIcon(stats->effects[i].icon,i,stats->stun_duration,stats->stun_duration_total);
if (stats->effects[i].type == "immobilize") if (stats->effects[i].type == "immobilize")
renderIcon(4,i,stats->immobilize_duration,stats->immobilize_duration_total); renderIcon(stats->effects[i].icon,i,stats->immobilize_duration,stats->immobilize_duration_total);
if (stats->effects[i].type == "immunity") if (stats->effects[i].type == "immunity")
renderIcon(9,i,stats->immunity_duration,stats->immunity_duration_total); renderIcon(stats->effects[i].icon,i,stats->immunity_duration,stats->immunity_duration_total);
if (stats->effects[i].type == "transform") if (stats->effects[i].type == "transform")
renderIcon(21,i,stats->transform_duration,stats->transform_duration_total); renderIcon(stats->effects[i].icon,i,stats->transform_duration,stats->transform_duration_total);
if (stats->effects[i].type == "haste") if (stats->effects[i].type == "haste")
renderIcon(12,i,stats->haste_duration,stats->haste_duration_total); renderIcon(stats->effects[i].icon,i,stats->haste_duration,stats->haste_duration_total);
if (stats->effects[i].type == "hot") if (stats->effects[i].type == "hot")
renderIcon(7,i,stats->hot_duration,stats->hot_duration_total); renderIcon(stats->effects[i].icon,i,stats->hot_duration,stats->hot_duration_total);
if (stats->effects[i].type == "shield") if (stats->effects[i].type == "shield")
renderIcon(11,i,stats->shield_hp,stats->shield_hp_total); renderIcon(stats->effects[i].icon,i,stats->shield_hp,stats->shield_hp_total);
if (stats->effects[i].type == "block") if (stats->effects[i].type == "block")
renderIcon(3,i,0,0); renderIcon(stats->effects[i].icon,i,0,0);
} }
} }


Expand Down
20 changes: 15 additions & 5 deletions src/PowerManager.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ void PowerManager::loadEffects(const std::string& filename) {


if (infile.key == "type") { if (infile.key == "type") {
effects[input_id].type = eatFirstString(infile.val,','); effects[input_id].type = eatFirstString(infile.val,',');
} else if (infile.key == "icon") {
effects[input_id].icon = eatFirstInt(infile.val,',');
} else if (infile.key == "gfx") { } else if (infile.key == "gfx") {
SDL_Surface *surface = IMG_Load(mods->locate("images/powers/" + eatFirstString(infile.val,',')).c_str()); SDL_Surface *surface = IMG_Load(mods->locate("images/powers/" + eatFirstString(infile.val,',')).c_str());
if(!surface) if(!surface)
Expand Down Expand Up @@ -792,7 +794,7 @@ void PowerManager::buff(int power_index, StatBlock *src_stats, Point target) {
else else
CombatText::Instance()->addMessage(msg->get("+%d Shield",shield_amt), src_stats->pos, COMBAT_MESSAGE_BUFF, false); CombatText::Instance()->addMessage(msg->get("+%d Shield",shield_amt), src_stats->pos, COMBAT_MESSAGE_BUFF, false);
src_stats->shield_hp = src_stats->shield_hp_total = shield_amt; src_stats->shield_hp = src_stats->shield_hp_total = shield_amt;
src_stats->addEffect("shield"); src_stats->addEffect("shield",getEffectIcon("shield"));
} }


// teleport to the target location // teleport to the target location
Expand Down Expand Up @@ -824,26 +826,26 @@ void PowerManager::buff(int power_index, StatBlock *src_stats, Point target) {


// immunity_duration makes one immune to new debuffs // immunity_duration makes one immune to new debuffs
if (src_stats->immunity_duration < powers[power_index].immunity_duration) { if (src_stats->immunity_duration < powers[power_index].immunity_duration) {
src_stats->addEffect("immunity"); src_stats->addEffect("immunity",getEffectIcon("immunity"));
src_stats->immunity_duration = src_stats->immunity_duration_total = powers[power_index].immunity_duration; src_stats->immunity_duration = src_stats->immunity_duration_total = powers[power_index].immunity_duration;
} }


// transform_duration causes hero to be transformed // transform_duration causes hero to be transformed
if (src_stats->transform_duration < powers[power_index].transform_duration && if (src_stats->transform_duration < powers[power_index].transform_duration &&
src_stats->transform_duration !=-1) { src_stats->transform_duration !=-1) {
src_stats->addEffect("transform"); src_stats->addEffect("transform",getEffectIcon("transform"));
src_stats->transform_duration = src_stats->transform_duration_total = powers[power_index].transform_duration; src_stats->transform_duration = src_stats->transform_duration_total = powers[power_index].transform_duration;
} }


// haste doubles run speed and removes power cooldowns // haste doubles run speed and removes power cooldowns
if (src_stats->haste_duration < powers[power_index].haste_duration) { if (src_stats->haste_duration < powers[power_index].haste_duration) {
src_stats->addEffect("haste"); src_stats->addEffect("haste",getEffectIcon("haste"));
src_stats->haste_duration = src_stats->haste_duration_total = powers[power_index].haste_duration; src_stats->haste_duration = src_stats->haste_duration_total = powers[power_index].haste_duration;
} }


// hot is healing over time // hot is healing over time
if (src_stats->hot_duration < powers[power_index].hot_duration) { if (src_stats->hot_duration < powers[power_index].hot_duration) {
src_stats->addEffect("hot"); src_stats->addEffect("hot",getEffectIcon("hot"));
src_stats->hot_duration = src_stats->hot_duration_total = powers[power_index].hot_duration; src_stats->hot_duration = src_stats->hot_duration_total = powers[power_index].hot_duration;
src_stats->hot_value = powers[power_index].hot_value; src_stats->hot_value = powers[power_index].hot_value;
} }
Expand Down Expand Up @@ -1200,6 +1202,14 @@ Renderable PowerManager::renderEffects(StatBlock *src_stats) {
return r; return r;
} }


int PowerManager::getEffectIcon(std::string type) {
for (unsigned int i=0; i<effects.size(); i++) {
if (effects[i].type == type)
return effects[i].icon;
}
return -1;
}

PowerManager::~PowerManager() { PowerManager::~PowerManager() {


for (unsigned i=0; i<gfx.size(); i++) { for (unsigned i=0; i<gfx.size(); i++) {
Expand Down
2 changes: 2 additions & 0 deletions src/PowerManager.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class PowerManager {


struct Effect { struct Effect {
std::string type; std::string type;
int icon;
SDL_Surface *gfx; SDL_Surface *gfx;
SDL_Rect frame_size; SDL_Rect frame_size;
Point frame_offset; Point frame_offset;
Expand Down Expand Up @@ -316,6 +317,7 @@ class PowerManager {
bool hasValidTarget(int power_index, StatBlock *src_stats, Point target); bool hasValidTarget(int power_index, StatBlock *src_stats, Point target);
bool spawn(const std::string& enemy_type, Point target); bool spawn(const std::string& enemy_type, Point target);
Renderable renderEffects(StatBlock *src_stats); Renderable renderEffects(StatBlock *src_stats);
int getEffectIcon(std::string type);


std::vector<Power> powers; std::vector<Power> powers;
std::queue<Hazard *> hazards; // output; read by HazardManager std::queue<Hazard *> hazards; // output; read by HazardManager
Expand Down
3 changes: 2 additions & 1 deletion src/StatBlock.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ void StatBlock::clearEffects() {
forced_move_duration = 0; forced_move_duration = 0;
} }


void StatBlock::addEffect(std::string effect) { void StatBlock::addEffect(std::string effect, int icon) {
for (unsigned int i=0; i<effects.size(); i++) { for (unsigned int i=0; i<effects.size(); i++) {
if (effects[i].type == effect) { if (effects[i].type == effect) {
return; // already have this one return; // already have this one
Expand All @@ -524,6 +524,7 @@ void StatBlock::addEffect(std::string effect) {
Effect e; Effect e;
e.type = effect; e.type = effect;
e.frame = 0; e.frame = 0;
e.icon = icon;
effects.push_back(e); effects.push_back(e);
} }


Expand Down
3 changes: 2 additions & 1 deletion src/StatBlock.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ class StatBlock {
struct Effect { struct Effect {
std::string type; std::string type;
int frame; int frame;
int icon;
}; };


void load(const std::string& filename); void load(const std::string& filename);
void takeDamage(int dmg); void takeDamage(int dmg);
void recalc(); void recalc();
void logic(); void logic();
void clearEffects(); void clearEffects();
void addEffect(std::string effect); void addEffect(std::string effect, int icon);
void removeEffect(std::string effect); void removeEffect(std::string effect);
void updateEffects(); void updateEffects();


Expand Down

0 comments on commit a3a6073

Please sign in to comment.