Fixed turn order issues. Use a queue instead of a stack

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 3 years ago
parent cf75aa36d0
commit 6edddf45d2
  1. 48
      SeasonsOfLoneliness.cpp
  2. BIN
      Seasons_of_Loneliness

@ -3,7 +3,7 @@
#include "data.h"
#define OLC_PGEX_SPLASHSCREEN
#include "splash.h"
#include <stack>
#include <queue>
using namespace olc;
@ -278,7 +278,7 @@ public:
std::vector<Encounter> ENCOUNTERS;
Encounter ENCOUNTER_SPIDEY_1;
Encounter CURRENT_ENCOUNTER;
std::stack<int> turnOrder;
std::queue<int> turnOrder;
bool OnUserCreate() override
{
@ -445,19 +445,21 @@ public:
}
switch (BATTLE_STATE) {
case battle::PLAYER_SELECTION:{
if (WEATHER_POWERS[BATTLE_CARD_SELECTION_IND]->playerOwnCount>0) {
if (BATTLE_CARD_SELECTION->playerOwnCount>0) {
BATTLE_STATE=battle::PLAYER_TARGET_SELECTION;
if (WEATHER_POWERS[BATTLE_CARD_SELECTION_IND]->name.compare("MEAL")==0||WEATHER_POWERS[BATTLE_CARD_SELECTION_IND]->name.compare("SNACK")==0) {
setupBattleTurns();
} else
if (PLAYER_SELECTED_TARGET==-1||CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->hp<=0) {
for (int i=0;i<CURRENT_ENCOUNTER.entities.size();i++) {
Entity*ent = CURRENT_ENCOUNTER.entities[i];
if (!ent->ally&&ent->hp>0) {
PLAYER_SELECTED_TARGET=i;
break;
if (!(BATTLE_CARD_SELECTION->name.compare("Meal")==0||BATTLE_CARD_SELECTION->name.compare("Snack")==0)) {
if (PLAYER_SELECTED_TARGET==-1||CURRENT_ENCOUNTER.entities[PLAYER_SELECTED_TARGET]->hp<=0) {
for (int i=0;i<CURRENT_ENCOUNTER.entities.size();i++) {
Entity*ent = CURRENT_ENCOUNTER.entities[i];
if (!ent->ally&&ent->hp>0) {
PLAYER_SELECTED_TARGET=i;
break;
}
}
}
} else {
PLAYER_SELECTED_TARGET=-2;
setupBattleTurns();
}
}
}break;
@ -733,7 +735,6 @@ public:
for (int i=0;i<WEATHER_POWER_COUNT;i++) {
if (WEATHER_POWERS[i]->playerOwnCount>0) {
availablePowers.push_back(WEATHER_POWERS[i]);
//cout<<"There are x"<<WEATHER_POWERS[i]->playerOwnCount<<" of "<<WEATHER_POWERS[i]->name<<"\n";
}
}
BATTLE_CARD_SELECTION_IND=0;
@ -853,7 +854,7 @@ public:
PLAYER_SELECTED_TARGET=-1;
}
} else {
BATTLE_CURRENT_TURN_ENTITY=turnOrder.top();
BATTLE_CURRENT_TURN_ENTITY=turnOrder.front();
turnOrder.pop();
if (BATTLE_CURRENT_TURN_ENTITY==-1) {
if (PLAYER_HP<=0) {
@ -1381,13 +1382,13 @@ public:
if (power->damage==-1002) {
//Instead heal for their max health.
PLAYER_MAXHP+=5;
int finalDamage=-PLAYER_MAXHP;
finalDamage=-PLAYER_MAXHP;
foodCount--;
} else
if (power->damage==-1001) {
//Instead heal for their max health.
FOOD_REGEN_TURNS=4;
int finalDamage=-PLAYER_MAXHP*0.33;
finalDamage=-PLAYER_MAXHP*0.33;
foodCount--;
}
PLAYER_HP=std::clamp(PLAYER_HP-finalDamage,0,PLAYER_MAXHP);
@ -1448,6 +1449,9 @@ public:
if (CURRENT_ENCOUNTER.entities[i]->hp>0) {
CURRENT_ENCOUNTER.entities[i]->selectedMove=CURRENT_ENCOUNTER.entities[i]->moveSet[rand()%CURRENT_ENCOUNTER.entities[i]->moveSet.size()];
CURRENT_ENCOUNTER.entities[i]->turnComplete=false;
if (CURRENT_ENCOUNTER.entities[i]->selectedMove->name.compare("Seed Storm")==0) {
std::cout<<" Entity "<<i<<" selected Seed Storm.\n";
}
}
}
PLAYER_TURN_COMPLETE=false;
@ -1462,11 +1466,21 @@ public:
CURRENT_ENCOUNTER.entities[i]->selectedMove->name.compare("Seed Storm")==0) {
turnOrder.push(i);
CURRENT_ENCOUNTER.entities[i]->turnComplete=true;
std::cout<<" Entity "<<i<<" added prio for Seed Storm.\n";
}
}
//Healing has half prio for the player.
if (rand()%2==0&&!PLAYER_TURN_COMPLETE&&(BATTLE_CARD_SELECTION->name.compare("Meal")==0||BATTLE_CARD_SELECTION->name.compare("Snack")==0)) {
turnOrder.push(-1);
PLAYER_TURN_COMPLETE=true;
}
//Otherwise, every enemy has a chance to go before the player unless they are slowed, then they always go after.
for (int i=0;i<CURRENT_ENCOUNTER.entities.size();i++) {
Entity*ent = CURRENT_ENCOUNTER.entities[i];
if (rand()%2==0&&!PLAYER_TURN_COMPLETE&&(BATTLE_CARD_SELECTION->name.compare("Meal")==0||BATTLE_CARD_SELECTION->name.compare("Snack")==0)) {
turnOrder.push(-1);
PLAYER_TURN_COMPLETE=true;
}
if (ent->hp>0&&!ent->turnComplete&&
!ent->slowed&&rand()%2==0) {
turnOrder.push(i);
@ -1486,7 +1500,7 @@ public:
}
}
BATTLE_STATE=battle::PERFORM_TURN;
BATTLE_CURRENT_TURN_ENTITY=turnOrder.top();
BATTLE_CURRENT_TURN_ENTITY=turnOrder.front();
turnOrder.pop();
BATTLE_STATE=battle::WAIT_TURN_ANIMATION;
EFFECT_TIMER=0;

Binary file not shown.
Loading…
Cancel
Save