Files
wagic/projects/mtg/src/DuelLayers.cpp
T
omegablast2002@yahoo.com c54de679d4 couple bug fixes, a slight refactor,
ok here goes, first, fixed a crash that would happen when ever a player would gain more then 2000 life or take more then 2000 damage...the buffer was becoming corrupted i imagine because it was too small, increasing it to 10 slots allowed players to successfully take massive amounts of damage, highest i bothered checking was about 35k gained/lost, no crash...

2nd, removed the and refactored cantcaster rule, moved it to stateEffects() and renamed stateeffects to better reflect what it will be handling,

removed sneak attack rule and moved it into stateeffects

the following ints have been converted into bool, 
all the cantcasters, canputlandsintoplay is becoming a bool, the amount of lands you can play is now handled by a new varible int landsPlayerCanStillPlay (this is for my ability additional lands increase in support on perminents coming after the release)

the changes to bools were for an obvious reason, they were all ints pretending to be bools, my varibles were confusing as you would often see code like this if(cantblahblah > 0)
which to another coder might not make any sense.

these varible ints were returning 0 as false and 1 as true...changed them all to bools, same goes for putlandsinplay int, in half the places it was being used as a bool, AND it was tracking the amount, when i was coding additional land ability, this made it impossible to maintain correct amounts without damaging the rest of the code.
as a bool, controlled by stateeffects, it can now be used correctly as a bool in all cases, and the stateEffects manages the switch on it to false if you no longer have any landsPlayerCanStillPlay left.

the refactor on cantcaster was also a bug fix, it was reported to me that cantcasters were not correctly working, sometimes ai or player would still be allowed to play a card with one in play, because of the old way i had it setup somecases of bothcantcaster were reseting the cantcast to 0, basically making the check do nothing.

it is now handled in stateeffects if you have one in play, then its true, if not then false...this returns very accurate tracking of the cards instantly instead of checking as cards enter or left play.

the "both" versions now have their own bools to avoid future conflicts with the single player cantcast...

added a case for the fancy moving text, some move to library effects were incorrectly returing fetch.
2010-12-10 20:51:50 +00:00

232 lines
5.8 KiB
C++

#include "PrecompiledHeader.h"
#include "MTGRules.h"
#include "CardSelectorSingleton.h"
#include "GuiCombat.h"
#include "GuiBackground.h"
#include "GuiFrame.h"
#include "GuiPhaseBar.h"
#include "GuiAvatars.h"
#include "GuiHand.h"
#include "GuiPlay.h"
#include "GuiMana.h"
#include "Trash.h"
#include "DuelLayers.h"
void DuelLayers::init()
{
GameObserver* go = GameObserver::GetInstance();
mCardSelector = CardSelectorSingleton::Create(this);
//1 Action Layer
action = NEW ActionLayer();
action->Add(NEW MTGGamePhase(action->getMaxId()));
//Add Magic Specific Rules
action->Add(NEW MTGPutInPlayRule(-1));
action->Add(NEW MTGAlternativeCostRule(-1));
action->Add(NEW MTGBuyBackRule(-1));
action->Add(NEW MTGFlashBackRule(-1));
action->Add(NEW MTGRetraceRule(-1));
action->Add(NEW MTGAttackRule(-1));
action->Add(NEW MTGBlockRule(-1));
action->Add(NEW MTGCombatTriggersRule(-1));
action->Add(NEW MTGLegendRule(-1));
action->Add(NEW MTGTokensCleanup(-1)); // needs to be before persist
action->Add(NEW MTGPersistRule(-1));
action->Add(NEW MTGAffinityRule(-1));
action->Add(NEW MTGUnearthRule(-1));
action->Add(NEW MTGLifelinkRule(-1));
action->Add(NEW MTGDeathtouchRule(-1));
action->Add(NEW OtherAbilitiesEventReceiver(-1));
//Other display elements
action->Add(NEW HUDDisplay(-1));
Add(NEW GuiMana(20, 20, go->players[1]));
Add(NEW GuiMana(440, 20, go->players[0]));
Add(stack = NEW ActionStack(go));
Add(combat = NEW GuiCombat(go));
Add(action);
Add(mCardSelector);
Add(hand = NEW GuiHandSelf(go->players[0]->game->hand));
Add(avatars = NEW GuiAvatars());
Add(NEW GuiHandOpponent(go->players[1]->game->hand));
Add(NEW GuiPlay(go));
Add(NEW GuiPhaseBar());
Add(NEW GuiFrame());
Add(NEW GuiBackground());
}
void DuelLayers::CheckUserInput(int isAI)
{
JButton key;
int x, y;
while ((key = JGE::GetInstance()->ReadButton()))
{
if ((!isAI) && (0 != key))
{
if (stack->CheckUserInput(key))
break;
if (combat->CheckUserInput(key))
break;
if (avatars->CheckUserInput(key))
break; //avatars need to check their input before action (CTRL_CROSS)
if (action->CheckUserInput(key))
break;
if (hand->CheckUserInput(key))
break;
if (CardSelectorSingleton::Instance()->CheckUserInput(key))
break;
}
}
if (JGE::GetInstance()->GetLeftClickCoordinates(x, y))
{
if (avatars->CheckUserInput(x, y))
{
JGE::GetInstance()->LeftClickedProcessed();
}
else if (CardSelectorSingleton::Instance()->CheckUserInput(x, y))
{
JGE::GetInstance()->LeftClickedProcessed();
}
}
}
void DuelLayers::Update(float dt, Player * currentPlayer)
{
for (int i = 0; i < nbitems; ++i)
objects[i]->Update(dt);
int isAI = currentPlayer->isAI();
if (isAI)
currentPlayer->Act(dt);
CheckUserInput(isAI);
}
ActionStack * DuelLayers::stackLayer()
{
return stack;
}
GuiCombat * DuelLayers::combatLayer()
{
return combat;
}
ActionLayer * DuelLayers::actionLayer()
{
return action;
}
GuiAvatars * DuelLayers::GetAvatars()
{
return avatars;
}
DuelLayers::DuelLayers() :
nbitems(0)
{
}
DuelLayers::~DuelLayers()
{
int _nbitems = nbitems;
nbitems = 0;
for (int i = 0; i < _nbitems; ++i)
{
if (objects[i] != mCardSelector)
{
delete objects[i];
objects[i] = NULL;
}
}
for (size_t i = 0; i < waiters.size(); ++i)
delete (waiters[i]);
Trash::cleanup();
CardSelectorSingleton::Terminate();
mCardSelector = NULL;
}
void DuelLayers::Add(GuiLayer * layer)
{
objects.push_back(layer);
nbitems++;
}
void DuelLayers::Remove()
{
--nbitems;
}
void DuelLayers::Render()
{
bool focusMakesItThrough = true;
for (int i = 0; i < nbitems; ++i)
{
objects[i]->hasFocus = focusMakesItThrough;
if (objects[i]->modal)
focusMakesItThrough = false;
}
for (int i = nbitems - 1; i >= 0; --i)
objects[i]->Render();
}
int DuelLayers::receiveEvent(WEvent * e)
{
#if 0
#define PRINT_IF(type) { type *foo = dynamic_cast<type*>(e); if (foo) cout << "Is a " #type " " << *foo << endl; }
cout << "Received event " << e << " ";
PRINT_IF(WEventZoneChange);
PRINT_IF(WEventDamage);
PRINT_IF(WEventPhaseChange);
PRINT_IF(WEventCardUpdate);
PRINT_IF(WEventCardTap);
PRINT_IF(WEventCreatureAttacker);
PRINT_IF(WEventCreatureBlocker);
PRINT_IF(WEventCreatureBlockerRank);
PRINT_IF(WEventCombatStepChange);
PRINT_IF(WEventEngageMana);
PRINT_IF(WEventConsumeMana);
PRINT_IF(WEventEmptyManaPool);
#endif
int used = 0;
for (int i = 0; i < nbitems; ++i)
used |= objects[i]->receiveEventPlus(e);
if (!used)
{
Pos* p;
if (WEventZoneChange *event = dynamic_cast<WEventZoneChange*>(e))
{
MTGCardInstance* card = event->card;
if (card->view)
waiters.push_back(p = NEW Pos(*(card->view)));
else
waiters.push_back(p = NEW Pos(0, 0, 0, 0, 255));
const Pos* ref = card->view;
while (card)
{
if (ref == card->view)
card->view = p;
card = card->next;
}
}
}
for (int i = 0; i < nbitems; ++i)
objects[i]->receiveEventMinus(e);
if (WEventPhaseChange *event = dynamic_cast<WEventPhaseChange*>(e))
if (Constants::MTG_PHASE_BEFORE_BEGIN == event->to->id)
Trash::cleanup();
return 1;
}
float DuelLayers::RightBoundary()
{
return MIN (hand->LeftBoundary(), avatars->LeftBoundarySelf());
}