Skip to content
Browse files

Merge pull request #968 from dorkster/effects

Support all effects for adding visual effects
  • Loading branch information...
2 parents 07e7cb1 + a3a6073 commit 56dbd661064c16408996a9fc2ad57af16d998654 @clintbellanger committed Sep 13, 2012
View
38 mods/fantasycore/engine/effects.txt
@@ -5,8 +5,46 @@ frame_offset=32,32
# status effects
id=1
type=shield
+icon=11
gfx=shield.png
size=0,0,128,128
offset=64,96
frame_total=12
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
+
View
38 mods/minicore/engine/effects.txt
@@ -5,8 +5,46 @@ frame_offset=16,16
# status effects
id=1
type=shield
+icon=11
gfx=shield.png
size=0,0,64,64
offset=32,48
frame_total=12
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
+
View
22 src/Avatar.cpp
@@ -595,6 +595,8 @@ void Avatar::logic(int actionbar_power, bool restrictPowerUse) {
setAnimation("block");
+ stats.addEffect("block",powers->getEffectIcon("block"));
+
if (powers->powers[actionbar_power].new_state != POWSTATE_BLOCK) {
stats.cur_state = AVATAR_STANCE;
stats.blocking = false;
@@ -760,10 +762,22 @@ bool Avatar::takeHit(Hazard h) {
// after effects
if (stats.hp > 0 && stats.immunity_duration == 0 && dmg > 0) {
- if (h.stun_duration > stats.stun_duration) stats.stun_duration_total = stats.stun_duration = h.stun_duration;
- if (h.slow_duration > stats.slow_duration) stats.slow_duration_total = stats.slow_duration = h.slow_duration;
- if (h.bleed_duration > stats.bleed_duration) stats.bleed_duration_total = stats.bleed_duration = h.bleed_duration;
- if (h.immobilize_duration > stats.immobilize_duration) stats.immobilize_duration_total = stats.immobilize_duration = h.immobilize_duration;
+ if (h.stun_duration > stats.stun_duration) {
+ stats.stun_duration_total = stats.stun_duration = h.stun_duration;
+ stats.addEffect("stun",powers->getEffectIcon("stun"));
+ }
+ if (h.slow_duration > stats.slow_duration) {
+ stats.slow_duration_total = stats.slow_duration = h.slow_duration;
+ stats.addEffect("slow",powers->getEffectIcon("slow"));
+ }
+ if (h.bleed_duration > stats.bleed_duration) {
+ stats.bleed_duration_total = stats.bleed_duration = h.bleed_duration;
+ stats.addEffect("bleed",powers->getEffectIcon("bleed"));
+ }
+ if (h.immobilize_duration > stats.immobilize_duration) {
+ stats.immobilize_duration_total = stats.immobilize_duration = h.immobilize_duration;
+ 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_speed != 0) {
float theta = powers->calcTheta(h.src_stats->pos.x, h.src_stats->pos.y, stats.pos.x, stats.pos.y);
View
20 src/Enemy.cpp
@@ -214,10 +214,22 @@ bool Enemy::takeHit(Hazard h) {
// after effects
if (stats.hp > 0) {
- if (h.stun_duration > stats.stun_duration) stats.stun_duration_total = stats.stun_duration = h.stun_duration;
- if (h.slow_duration > stats.slow_duration) stats.slow_duration_total = stats.slow_duration = h.slow_duration;
- if (h.bleed_duration > stats.bleed_duration) stats.bleed_duration_total = stats.bleed_duration = h.bleed_duration;
- if (h.immobilize_duration > stats.immobilize_duration) stats.immobilize_duration_total = stats.immobilize_duration = h.immobilize_duration;
+ if (h.stun_duration > stats.stun_duration) {
+ stats.stun_duration_total = stats.stun_duration = h.stun_duration;
+ stats.addEffect("stun",powers->getEffectIcon("stun"));
+ }
+ if (h.slow_duration > stats.slow_duration) {
+ stats.slow_duration_total = stats.slow_duration = h.slow_duration;
+ stats.addEffect("slow",powers->getEffectIcon("slow"));
+ }
+ if (h.bleed_duration > stats.bleed_duration) {
+ stats.bleed_duration_total = stats.bleed_duration = h.bleed_duration;
+ stats.addEffect("bleed",powers->getEffectIcon("bleed"));
+ }
+ if (h.immobilize_duration > stats.immobilize_duration) {
+ stats.immobilize_duration_total = stats.immobilize_duration = h.immobilize_duration;
+ 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_speed != 0) {
float theta = powers->calcTheta(stats.hero_pos.x, stats.hero_pos.y, stats.pos.x, stats.pos.y);
View
5 src/EnemyManager.cpp
@@ -298,9 +298,8 @@ void EnemyManager::addRenders(vector<Renderable> &r, vector<Renderable> &r_dead)
// draw corpses below objects so that floor loot is more visible
bool dead = (*it)->stats.corpse;
(dead ? r_dead : r).push_back(re);
- if ((*it)->stats.shield_hp == 0) {
- (*it)->stats.removeEffect("shield");
- }
+
+ (*it)->stats.updateEffects();
re = powers->renderEffects(&(*it)->stats);
(dead ? r_dead : r).push_back(re);
}
View
4 src/GameStatePlay.cpp
@@ -634,9 +634,7 @@ void GameStatePlay::render() {
rens.push_back(pc_hero); // Avatar
// get additional hero overlays
- if (pc->stats.shield_hp == 0) {
- pc->stats.removeEffect("shield");
- }
+ pc->stats.updateEffects();
Renderable re = powers->renderEffects(&pc->stats);
rens.push_back(re);
View
105 src/MenuActiveEffects.cpp
@@ -43,16 +43,6 @@ MenuActiveEffects::MenuActiveEffects(SDL_Surface *_icons) {
icons = _icons;
orientation = 0; // horizontal
- limits.slow = 0;
- limits.bleed = 0;
- limits.stun = 0;
- limits.immobilize = 0;
- limits.immunity = 0;
- limits.transform = 0;
- limits.haste = 0;
- limits.hot = 0;
- limits.shield = 0;
-
// Load config settings
FileParser infile;
if(infile.open(mods->locate("menus/activeeffects.txt"))) {
@@ -85,28 +75,30 @@ void MenuActiveEffects::loadGraphics() {
}
void MenuActiveEffects::renderIcon(int icon_id, int index, int current, int max){
- SDL_Rect pos,src,overlay;
- if (orientation == 0) {
- pos.x = window_area.x + (index * ICON_SIZE_SMALL);
- pos.y = window_area.y;
- } else if (orientation == 1) {
- pos.x = window_area.x;
- pos.y = window_area.y + (index * ICON_SIZE_SMALL);;
- }
+ if (icon_id > -1) {
+ SDL_Rect pos,src,overlay;
+ if (orientation == 0) {
+ pos.x = window_area.x + (index * ICON_SIZE_SMALL);
+ pos.y = window_area.y;
+ } else if (orientation == 1) {
+ pos.x = window_area.x;
+ pos.y = window_area.y + (index * ICON_SIZE_SMALL);;
+ }
- src.x = (icon_id % 16) * ICON_SIZE_SMALL;
- src.y = (icon_id / 16) * ICON_SIZE_SMALL;
- src.w = src.h = ICON_SIZE_SMALL;
+ src.x = (icon_id % 16) * ICON_SIZE_SMALL;
+ src.y = (icon_id / 16) * 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) {
- overlay.x = 0;
- overlay.y = (ICON_SIZE_SMALL * current) / max;
- overlay.w = ICON_SIZE_SMALL;
- overlay.h = ICON_SIZE_SMALL - overlay.y;
+ if (max > 0) {
+ overlay.x = 0;
+ overlay.y = (ICON_SIZE_SMALL * current) / max;
+ overlay.w = ICON_SIZE_SMALL;
+ overlay.h = ICON_SIZE_SMALL - overlay.y;
- SDL_BlitSurface(timer,&overlay,screen,&pos);
+ SDL_BlitSurface(timer,&overlay,screen,&pos);
+ }
}
}
@@ -115,43 +107,28 @@ void MenuActiveEffects::update(StatBlock *_stats) {
}
void MenuActiveEffects::render() {
- // Make sure the list of effects is empty
- if (effects.size() > 0) effects.clear();
-
- // Append active effects to the effects list
- if (stats->slow_duration > 0) effects.push_back("slow");
- if (stats->bleed_duration > 0) effects.push_back("bleed");
- if (stats->stun_duration > 0) effects.push_back("stun");
- if (stats->immobilize_duration > 0) effects.push_back("immobilize");
- if (stats->immunity_duration > 0) effects.push_back("immunity");
- if (stats->transform_duration > 0) effects.push_back("transform");
- if (stats->haste_duration > 0) effects.push_back("haste");
- if (stats->hot_duration > 0) effects.push_back("hot");
- if (stats->shield_hp > 0) effects.push_back("shield");
- if (stats->blocking) effects.push_back("block");
-
// Step through the list of effects and render those that are active
- for (unsigned int i=0; i<effects.size(); i++) {
- if (effects[i] == "slow")
- renderIcon(14,i,stats->slow_duration,stats->slow_duration_total);
- if (effects[i] == "bleed")
- renderIcon(5,i,stats->bleed_duration,stats->bleed_duration_total);
- if (effects[i] == "stun")
- renderIcon(10,i,stats->stun_duration,stats->stun_duration_total);
- if (effects[i] == "immobilize")
- renderIcon(4,i,stats->immobilize_duration,stats->immobilize_duration_total);
- if (effects[i] == "immunity")
- renderIcon(9,i,stats->immunity_duration,stats->immunity_duration_total);
- if (effects[i] == "transform")
- renderIcon(21,i,stats->transform_duration,stats->transform_duration_total);
- if (effects[i] == "haste")
- renderIcon(12,i,stats->haste_duration,stats->haste_duration_total);
- if (effects[i] == "hot")
- renderIcon(7,i,stats->hot_duration,stats->hot_duration_total);
- if (effects[i] == "shield")
- renderIcon(11,i,stats->shield_hp,stats->shield_hp_total);
- if (effects[i] == "block")
- renderIcon(3,i,0,0);
+ for (unsigned int i=0; i<stats->effects.size(); i++) {
+ if (stats->effects[i].type == "slow")
+ renderIcon(stats->effects[i].icon,i,stats->slow_duration,stats->slow_duration_total);
+ if (stats->effects[i].type == "bleed")
+ renderIcon(stats->effects[i].icon,i,stats->bleed_duration,stats->bleed_duration_total);
+ if (stats->effects[i].type == "stun")
+ renderIcon(stats->effects[i].icon,i,stats->stun_duration,stats->stun_duration_total);
+ if (stats->effects[i].type == "immobilize")
+ renderIcon(stats->effects[i].icon,i,stats->immobilize_duration,stats->immobilize_duration_total);
+ if (stats->effects[i].type == "immunity")
+ renderIcon(stats->effects[i].icon,i,stats->immunity_duration,stats->immunity_duration_total);
+ if (stats->effects[i].type == "transform")
+ renderIcon(stats->effects[i].icon,i,stats->transform_duration,stats->transform_duration_total);
+ if (stats->effects[i].type == "haste")
+ renderIcon(stats->effects[i].icon,i,stats->haste_duration,stats->haste_duration_total);
+ if (stats->effects[i].type == "hot")
+ renderIcon(stats->effects[i].icon,i,stats->hot_duration,stats->hot_duration_total);
+ if (stats->effects[i].type == "shield")
+ renderIcon(stats->effects[i].icon,i,stats->shield_hp,stats->shield_hp_total);
+ if (stats->effects[i].type == "block")
+ renderIcon(stats->effects[i].icon,i,0,0);
}
}
View
13 src/MenuActiveEffects.h
@@ -37,22 +37,9 @@ class MenuActiveEffects : public Menu {
private:
SDL_Surface *icons;
SDL_Surface *timer;
- std::vector<std::string> effects;
StatBlock *stats;
bool orientation;
- struct limits {
- int slow;
- int bleed;
- int stun;
- int immobilize;
- int immunity;
- int transform;
- int haste;
- int hot;
- int shield;
- }limits;
-
void renderIcon(int icon_id, int index, int current, int max);
public:
View
16 src/PowerManager.cpp
@@ -333,6 +333,8 @@ void PowerManager::loadEffects(const std::string& filename) {
if (infile.key == "type") {
effects[input_id].type = eatFirstString(infile.val,',');
+ } else if (infile.key == "icon") {
+ effects[input_id].icon = eatFirstInt(infile.val,',');
} else if (infile.key == "gfx") {
SDL_Surface *surface = IMG_Load(mods->locate("images/powers/" + eatFirstString(infile.val,',')).c_str());
if(!surface)
@@ -792,7 +794,7 @@ void PowerManager::buff(int power_index, StatBlock *src_stats, Point target) {
else
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->addEffect("shield");
+ src_stats->addEffect("shield",getEffectIcon("shield"));
}
// teleport to the target location
@@ -824,22 +826,26 @@ void PowerManager::buff(int power_index, StatBlock *src_stats, Point target) {
// immunity_duration makes one immune to new debuffs
if (src_stats->immunity_duration < powers[power_index].immunity_duration) {
+ src_stats->addEffect("immunity",getEffectIcon("immunity"));
src_stats->immunity_duration = src_stats->immunity_duration_total = powers[power_index].immunity_duration;
}
// transform_duration causes hero to be transformed
if (src_stats->transform_duration < powers[power_index].transform_duration &&
src_stats->transform_duration !=-1) {
+ src_stats->addEffect("transform",getEffectIcon("transform"));
src_stats->transform_duration = src_stats->transform_duration_total = powers[power_index].transform_duration;
}
// haste doubles run speed and removes power cooldowns
if (src_stats->haste_duration < powers[power_index].haste_duration) {
+ src_stats->addEffect("haste",getEffectIcon("haste"));
src_stats->haste_duration = src_stats->haste_duration_total = powers[power_index].haste_duration;
}
// hot is healing over time
if (src_stats->hot_duration < powers[power_index].hot_duration) {
+ src_stats->addEffect("hot",getEffectIcon("hot"));
src_stats->hot_duration = src_stats->hot_duration_total = powers[power_index].hot_duration;
src_stats->hot_value = powers[power_index].hot_value;
}
@@ -1196,6 +1202,14 @@ Renderable PowerManager::renderEffects(StatBlock *src_stats) {
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() {
for (unsigned i=0; i<gfx.size(); i++) {
View
2 src/PowerManager.h
@@ -266,6 +266,7 @@ class PowerManager {
struct Effect {
std::string type;
+ int icon;
SDL_Surface *gfx;
SDL_Rect frame_size;
Point frame_offset;
@@ -316,6 +317,7 @@ class PowerManager {
bool hasValidTarget(int power_index, StatBlock *src_stats, Point target);
bool spawn(const std::string& enemy_type, Point target);
Renderable renderEffects(StatBlock *src_stats);
+ int getEffectIcon(std::string type);
std::vector<Power> powers;
std::queue<Hazard *> hazards; // output; read by HazardManager
View
16 src/StatBlock.cpp
@@ -515,7 +515,7 @@ void StatBlock::clearEffects() {
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++) {
if (effects[i].type == effect) {
return; // already have this one
@@ -524,6 +524,7 @@ void StatBlock::addEffect(std::string effect) {
Effect e;
e.type = effect;
e.frame = 0;
+ e.icon = icon;
effects.push_back(e);
}
@@ -536,6 +537,19 @@ void StatBlock::removeEffect(std::string effect) {
}
}
+void StatBlock::updateEffects() {
+ if (slow_duration == 0) removeEffect("slow");
+ if (bleed_duration == 0) removeEffect("bleed");
+ if (stun_duration == 0) removeEffect("stun");
+ if (immobilize_duration == 0) removeEffect("immobilize");
+ if (immunity_duration == 0) removeEffect("immunity");
+ if (transform_duration == 0) removeEffect("transform");
+ if (haste_duration == 0) removeEffect("haste");
+ if (hot_duration == 0) removeEffect("hot");
+ if (shield_hp == 0) removeEffect("shield");
+ if (!blocking) removeEffect("block");
+}
+
StatBlock::~StatBlock() {
}
View
4 src/StatBlock.h
@@ -79,15 +79,17 @@ class StatBlock {
struct Effect {
std::string type;
int frame;
+ int icon;
};
void load(const std::string& filename);
void takeDamage(int dmg);
void recalc();
void logic();
void clearEffects();
- void addEffect(std::string effect);
+ void addEffect(std::string effect, int icon);
void removeEffect(std::string effect);
+ void updateEffects();
bool alive;
bool corpse; // creature is dead and done animating

0 comments on commit 56dbd66

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