Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
clintbellanger committed Dec 18, 2012
2 parents 69f5aa9 + d70efd5 commit 0f86bf7
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 154 deletions.
14 changes: 13 additions & 1 deletion src/Avatar.cpp
Expand Up @@ -390,6 +390,14 @@ void Avatar::logic(int actionbar_power, bool restrictPowerUse) {
bool allowed_to_move;
bool allowed_to_use_power;

// check for revive
if (stats.hp <= 0 && stats.effects.revive) {
stats.hp = stats.maxhp;
stats.alive = true;
stats.corpse = false;
stats.cur_state = AVATAR_STANCE;
}

// check level up
if (stats.xp >= stats.xp_table[stats.level] && stats.level < MAX_CHARACTER_LEVEL) {
stats.level_up = true;
Expand Down Expand Up @@ -418,6 +426,7 @@ void Avatar::logic(int actionbar_power, bool restrictPowerUse) {

// check for bleeding to death
if (stats.hp == 0 && !(stats.cur_state == AVATAR_DEAD)) {
stats.effects.triggered_death = true;
stats.cur_state = AVATAR_DEAD;
}

Expand Down Expand Up @@ -602,6 +611,8 @@ void Avatar::logic(int actionbar_power, bool restrictPowerUse) {
break;

case AVATAR_DEAD:
if (stats.effects.triggered_death) break;

if (stats.transformed) {
stats.transform_duration = 0;
untransform();
Expand Down Expand Up @@ -650,7 +661,7 @@ void Avatar::logic(int actionbar_power, bool restrictPowerUse) {
}

// turn on all passive powers
if (stats.hp > 0 && !respawn) powers->activatePassives(&stats);
if ((stats.hp > 0 || stats.effects.triggered_death) && !respawn) powers->activatePassives(&stats);

// calc new cam position from player position
// cam is focused at player position
Expand Down Expand Up @@ -776,6 +787,7 @@ bool Avatar::takeHit(const Hazard &h) {
}

if (stats.hp <= 0) {
stats.effects.triggered_death = true;
stats.cur_state = AVATAR_DEAD;

// raise the death penalty flag. Another module will read this and reset.
Expand Down
14 changes: 12 additions & 2 deletions src/BehaviorStandard.cpp
Expand Up @@ -78,9 +78,18 @@ void BehaviorStandard::doUpkeep() {
if (e->stats.wander_pause_ticks > 0)
e->stats.wander_pause_ticks--;

// check for revive
if (e->stats.hp <= 0 && e->stats.effects.revive) {
e->stats.hp = e->stats.maxhp;
e->stats.alive = true;
e->stats.corpse = false;
e->stats.cur_state = ENEMY_STANCE;
}

// check for bleeding to death
if (e->stats.hp <= 0 && !(e->stats.cur_state == ENEMY_DEAD || e->stats.cur_state == ENEMY_CRITDEAD)) {
e->doRewards();
e->stats.effects.triggered_death = true;
e->stats.cur_state = ENEMY_DEAD;
e->map->collider.unblock(e->stats.pos.x,e->stats.pos.y);
}
Expand Down Expand Up @@ -451,6 +460,7 @@ void BehaviorStandard::updateState() {
break;

case ENEMY_DEAD:
if (e->stats.effects.triggered_death) break;

e->setAnimation("die");
if (e->activeAnimation->isFirstFrame()) {
Expand Down Expand Up @@ -486,8 +496,8 @@ void BehaviorStandard::updateState() {
break;
}

// activated all passive powers
if (e->stats.hp > 0) e->powers->activatePassives(&e->stats);
// activate all passive powers
if (e->stats.hp > 0 || e->stats.effects.triggered_death) e->powers->activatePassives(&e->stats);
}


5 changes: 4 additions & 1 deletion src/EffectManager.cpp
Expand Up @@ -33,6 +33,7 @@ EffectManager::EffectManager()
, triggered_hit(false)
, triggered_halfdeath(false)
, triggered_joincombat(false)
, triggered_death(false)
{
clearStatus();
}
Expand All @@ -52,6 +53,7 @@ void EffectManager::clearStatus() {
stun = false;
forced_speed = 0;
forced_move = false;
revive = false;

bonus_hp = 0;
bonus_hp_regen = 0;
Expand Down Expand Up @@ -93,6 +95,7 @@ void EffectManager::logic() {
forced_move = true;
forced_speed = effect_list[i].magnitude;
}
else if (effect_list[i].type == "revive") revive = true;
else if (effect_list[i].type == "hp") bonus_hp += effect_list[i].magnitude;
else if (effect_list[i].type == "hp_regen") bonus_hp_regen += effect_list[i].magnitude;
else if (effect_list[i].type == "hp_percent") bonus_hp_percent += effect_list[i].magnitude;
Expand Down Expand Up @@ -219,7 +222,7 @@ void EffectManager::clearEffects() {
}

// clear triggers
triggered_others = triggered_block = triggered_hit = triggered_halfdeath = triggered_joincombat = false;
triggered_others = triggered_block = triggered_hit = triggered_halfdeath = triggered_joincombat = triggered_death = false;
}

void EffectManager::clearNegativeEffects() {
Expand Down
2 changes: 2 additions & 0 deletions src/EffectManager.h
Expand Up @@ -102,6 +102,7 @@ class EffectManager {
bool stun;
int forced_speed;
bool forced_move;
bool revive;

int bonus_hp;
int bonus_hp_regen;
Expand All @@ -127,6 +128,7 @@ class EffectManager {
bool triggered_hit;
bool triggered_halfdeath;
bool triggered_joincombat;
bool triggered_death;
};

#endif
2 changes: 2 additions & 0 deletions src/Enemy.cpp
Expand Up @@ -269,12 +269,14 @@ bool Enemy::takeHit(const Hazard &h) {

if (stats.hp <= 0 && crit) {
doRewards();
stats.effects.triggered_death = true;
stats.cur_state = ENEMY_CRITDEAD;
map->collider.unblock(stats.pos.x,stats.pos.y);

}
else if (stats.hp <= 0) {
doRewards();
stats.effects.triggered_death = true;
stats.cur_state = ENEMY_DEAD;
map->collider.unblock(stats.pos.x,stats.pos.y);

Expand Down
12 changes: 8 additions & 4 deletions src/GameStatePlay.cpp
Expand Up @@ -477,12 +477,16 @@ void GameStatePlay::checkLootDrop() {
* When a consumable-based power is used, we need to remove it from the inventory.
*/
void GameStatePlay::checkConsumable() {
if (powers->used_item != -1) {
if (menu->items->items[powers->used_item].type == "consumable") {
menu->inv->remove(powers->used_item);
powers->used_item = -1;
for (unsigned i=0; i<powers->used_items.size(); i++) {
if (menu->items->items[powers->used_items[i]].type == "consumable") {
menu->inv->remove(powers->used_items[i]);
}
}
for (unsigned i=0; i<powers->used_equipped_items.size(); i++) {
menu->inv->removeEquipped(powers->used_equipped_items[i]);
}
powers->used_items.clear();
powers->used_equipped_items.clear();
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/MapRenderer.cpp
Expand Up @@ -930,8 +930,6 @@ void MapRenderer::renderOrthoFrontObjects(std::vector<Renderable> &r) {
while (r_cursor != r_end && (r_cursor->map_pos.y>>TILE_SHIFT) < startj)
++r_cursor;



for (j = startj; j<max_tiles_height; j++) {
for (i = starti; i<max_tiles_width; i++) {

Expand Down
20 changes: 18 additions & 2 deletions src/MenuInventory.cpp
Expand Up @@ -393,9 +393,12 @@ void MenuInventory::activate(InputState * input) {
// if this item requires targeting it can't be used this way
if (!powers->powers[items->items[inventory[CARRIED][slot].item].power].requires_targeting) {

unsigned used_item_count = powers->used_items.size();
unsigned used_equipped_item_count = powers->used_equipped_items.size();
powers->activate(items->items[inventory[CARRIED][slot].item].power, stats, nullpt);
// intercept used_item flag. We will destroy the item here.
powers->used_item = -1;
// Remove any used items from the queue of items to be removed. We will destroy the items here.
if (used_item_count < powers->used_items.size()) powers->used_items.pop_back();
if (used_equipped_item_count < powers->used_equipped_items.size()) powers->used_equipped_items.pop_back();
inventory[CARRIED].substract(slot);
}
else {
Expand Down Expand Up @@ -522,9 +525,18 @@ void MenuInventory::add(ItemStack stack, int area, int slot) {
void MenuInventory::remove(int item) {
if( !inventory[CARRIED].remove(item)) {
inventory[EQUIPMENT].remove(item);
applyEquipment(inventory[EQUIPMENT].storage);
}
}

/**
* Remove an equipped item from the player's inventory.
*/
void MenuInventory::removeEquipped(int item) {
inventory[EQUIPMENT].remove(item);
applyEquipment(inventory[EQUIPMENT].storage);
}

/**
* Add currency to the current total
*/
Expand Down Expand Up @@ -728,6 +740,7 @@ void MenuInventory::applyEquipment(ItemStack *equipped) {

// defaults
stats->recalc_alt();
stats->powers_list_items.clear();

// the default for weapons/absorb are not added to equipped items
// later this function they are applied if the defaults aren't met
Expand Down Expand Up @@ -824,6 +837,9 @@ void MenuInventory::applyItemStats(ItemStack *equipped) {
bonus_counter++;
}

// add item powers
if (item.power > 0) stats->powers_list_items.push_back(item.power);

}
}

Expand Down
1 change: 1 addition & 0 deletions src/MenuInventory.h
Expand Up @@ -83,6 +83,7 @@ class MenuInventory : public Menu {

void add( ItemStack stack, int area = CARRIED, int slot = -1);
void remove(int item);
void removeEquipped(int item);
void addCurrency(int count);
bool buy(ItemStack stack, int tab);
bool sell(ItemStack stack);
Expand Down
43 changes: 39 additions & 4 deletions src/PowerManager.cpp
Expand Up @@ -47,7 +47,8 @@ using namespace std;
PowerManager::PowerManager()
: collider(NULL)
, log_msg("")
, used_item(-1)
, used_items(std::vector<int>())
, used_equipped_items(std::vector<int>())
{
loadAll();
}
Expand Down Expand Up @@ -145,6 +146,7 @@ void PowerManager::loadPowers(const std::string& filename) {
else if (infile.val == "on_hit") powers[input_id].passive_trigger = TRIGGER_HIT;
else if (infile.val == "on_halfdeath") powers[input_id].passive_trigger = TRIGGER_HALFDEATH;
else if (infile.val == "on_joincombat") powers[input_id].passive_trigger = TRIGGER_JOINCOMBAT;
else if (infile.val == "on_death") powers[input_id].passive_trigger = TRIGGER_DEATH;
else fprintf(stderr, "unknown passive trigger %s\n", infile.val.c_str());
}
// power requirements
Expand All @@ -166,6 +168,8 @@ void PowerManager::loadPowers(const std::string& filename) {
powers[input_id].requires_empty_target = toBool(infile.val);
else if (infile.key == "requires_item")
powers[input_id].requires_item = toInt(infile.val);
else if (infile.key == "requires_equipped_item")
powers[input_id].requires_equipped_item = toInt(infile.val);
else if (infile.key == "requires_targeting")
powers[input_id].requires_targeting = toBool(infile.val);
else if (infile.key == "cooldown")
Expand Down Expand Up @@ -983,7 +987,9 @@ void PowerManager::payPowerCost(int power_index, StatBlock *src_stats) {
if (src_stats->hero) {
src_stats->mp -= powers[power_index].requires_mp;
if (powers[power_index].requires_item != -1)
used_item = powers[power_index].requires_item;
used_items.push_back(powers[power_index].requires_item);
if (powers[power_index].requires_equipped_item != -1)
used_equipped_items.push_back(powers[power_index].requires_equipped_item);
}
src_stats->hp -= powers[power_index].requires_hp;
src_stats->hp = (src_stats->hp < 0 ? 0 : src_stats->hp);
Expand All @@ -995,9 +1001,11 @@ void PowerManager::payPowerCost(int power_index, StatBlock *src_stats) {
*/
void PowerManager::activatePassives(StatBlock *src_stats) {
bool triggered_others = false;
int trigger = -1;
// unlocked powers
for (unsigned i=0; i<src_stats->powers_list.size(); i++) {
if (powers[src_stats->powers_list[i]].passive) {
int trigger = powers[src_stats->powers_list[i]].passive_trigger;
trigger = powers[src_stats->powers_list[i]].passive_trigger;

if (trigger == -1) {
if (src_stats->effects.triggered_others) continue;
Expand All @@ -1013,17 +1021,44 @@ void PowerManager::activatePassives(StatBlock *src_stats) {
if (!src_stats->in_combat) continue;
else src_stats->effects.triggered_joincombat = true;
}
else if (trigger == TRIGGER_DEATH && !src_stats->effects.triggered_death) continue;

activate(src_stats->powers_list[i], src_stats, src_stats->pos);
src_stats->refresh_stats = true;
}
}
// item powers
for (unsigned i=0; i<src_stats->powers_list_items.size(); i++) {
if (powers[src_stats->powers_list_items[i]].passive) {
trigger = powers[src_stats->powers_list_items[i]].passive_trigger;

if (trigger == -1) {
if (src_stats->effects.triggered_others) continue;
else triggered_others = true;
}
else if (trigger == TRIGGER_BLOCK && !src_stats->effects.triggered_block) continue;
else if (trigger == TRIGGER_HIT && !src_stats->effects.triggered_hit) continue;
else if (trigger == TRIGGER_HALFDEATH && !src_stats->effects.triggered_halfdeath) {
if (src_stats->hp > src_stats->maxhp/2) continue;
else src_stats->effects.triggered_halfdeath = true;
}
else if (trigger == TRIGGER_JOINCOMBAT && !src_stats->effects.triggered_joincombat) {
if (!src_stats->in_combat) continue;
else src_stats->effects.triggered_joincombat = true;
}
else if (trigger == TRIGGER_DEATH && !src_stats->effects.triggered_death) continue;

activate(src_stats->powers_list_items[i], src_stats, src_stats->pos);
src_stats->refresh_stats = true;
}
}
// Only trigger normal passives once
if (triggered_others) src_stats->effects.triggered_others = true;

// the hit trigger can be triggered more than once, so reset it here
// the hit/death triggers can be triggered more than once, so reset them here
// the block trigger is handled in the Avatar class
src_stats->effects.triggered_hit = false;
src_stats->effects.triggered_death = false;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/PowerManager.h
Expand Up @@ -77,6 +77,7 @@ const int TRIGGER_BLOCK = 0;
const int TRIGGER_HIT = 1;
const int TRIGGER_HALFDEATH = 2;
const int TRIGGER_JOINCOMBAT = 3;
const int TRIGGER_DEATH = 4;

struct PostEffect {
int id;
Expand Down Expand Up @@ -116,6 +117,7 @@ class Power {
bool requires_los; // line of sight
bool requires_empty_target; // target square must be empty
int requires_item;
int requires_equipped_item;
bool consumable;
bool requires_targeting; // power only makes sense when using click-to-target
int cooldown; // milliseconds before you can use the power again
Expand Down Expand Up @@ -311,7 +313,8 @@ class PowerManager {
// shared sounds for power special effects
std::vector<Mix_Chunk*> sfx;

int used_item;
std::vector<int> used_items;
std::vector<int> used_equipped_items;
};

#endif

0 comments on commit 0f86bf7

Please sign in to comment.