fixed last check in. Test suite passes. Added comments on possible null pointer exceptions.

Updated XCode project file to include AIPlayerBaka classes.
Added test suite to iOS build
This commit is contained in:
techdragon.nguyen@gmail.com
2011-10-09 05:51:45 +00:00
parent 2bfe76e124
commit 6f10ef8425
16 changed files with 75 additions and 60 deletions

View File

@@ -270,11 +270,9 @@ void DestroyGame(void)
NSLog(@"EAGL View - init With Frame: origin(%f %f) size(%f %f)",
frame.origin.x, frame.origin.y, frame.size.width, frame.size.height);
if ((self = [super initWithFrame:frame])) {
self = [self initialize];
}
self = [super initWithFrame:frame];
if (self)
[self initialize];
return self;
}
@@ -283,9 +281,11 @@ void DestroyGame(void)
//The EAGL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
- (id)initWithCoder:(NSCoder*)coder
{
if (( self = [super initWithCoder:coder] ))
self = [super initWithCoder:coder];
if (self)
{
self = [self initialize];
[self initialize];
}
return self;

View File

@@ -798,7 +798,7 @@ class WGuiMenu: public WGuiItem
public:
friend class WGuiFilters;
virtual ~WGuiMenu();
WGuiMenu(JButton next, JButton prev, bool mDPad = false, WSyncable * syncme = NULL);
WGuiMenu(JButton next = JGE_BTN_RIGHT, JButton prev = JGE_BTN_LEFT, bool mDPad = false, WSyncable * syncme = NULL);
virtual bool yieldFocus();
virtual void Render();

View File

@@ -87,7 +87,6 @@ int AIAction::clickMultiAct(vector<Targetable*>& actionTargets)
{
GameObserver * g = owner->getObserver();
TargetChooser * tc = g->getCurrentTargetChooser();
if(!tc) return 0;
for(size_t f = 0;f < actionTargets.size();f++)
{
@@ -198,7 +197,6 @@ int AIPlayer::clickSingleTarget(TargetChooser * tc, vector<Targetable*>& potenti
{
MTGCardInstance * card = ((MTGCardInstance *) potentialTargets[i]);
clickstream.push(NEW AIAction(this, card));
chosenCard = card;
}
break;
}

View File

@@ -51,10 +51,10 @@ int OrderedAIAction::getEfficiency(AADamager * aad)
if(p == target->controller())
return 0;
if (aad->getDamage() >= dTarget->toughness)
if (dTarget && aad && (aad->getDamage() >= dTarget->toughness))
return 100;
if (dTarget->toughness)
if (dTarget && dTarget->toughness)
return (50 * aad->getDamage()) / dTarget->toughness;
return 0;

View File

@@ -3519,18 +3519,25 @@ void APhaseAction::Update(float dt)
if(newPhase == phase && next )
{
MTGCardInstance * _target = NULL;
bool isTargetable = false;
if(target)
_target = (MTGCardInstance *) target;
if(!sAbility.size() || (!target || _target != this->source))
{
_target = static_cast<MTGCardInstance *>(target);
isTargetable = (_target && !_target->currentZone && _target != this->source);
}
if(!sAbility.size() || (!target || isTargetable))
{
this->forceDestroy = 1;
return;
}
else
{
while(_target->next)
while(_target && _target->next)
_target = _target->next;
}
AbilityFactory af(game);
MTGAbility * ability = af.parseMagicLine(sAbility, abilityId, NULL, _target);

View File

@@ -392,7 +392,7 @@ void StatsWrapper::updateStats(DeckDataWrapper *myDeck)
this->totalManaCost = 0;
this->totalCreatureCost = 0;
this->totalSpellCost = 0;
MTGCard * current = myDeck->getCard();
MTGCard * current = NULL;
// Clearing arrays
for (int i = 0; i <= Constants::STATS_MAX_MANA_COST; i++)

View File

@@ -568,9 +568,14 @@ CounterCost * CounterCost::clone() const
CounterCost * ec = NEW CounterCost(*this);
if (tc)
ec->tc = tc->clone();
if (counter)
ec->counter = NEW Counter(counter->target, counter->name.c_str(), counter->power, counter->toughness);
ec->counter->nb = counter->nb;
//TODO: counter can be NULL at this point, what do we set ec->counter->nb to if it is?
if (ec->counter != NULL)
ec->counter->nb = counter->nb;
return ec;
}

View File

@@ -932,6 +932,7 @@ int GameObserver::cardClick(MTGCardInstance * card, Targetable * object)
if (ORDER == combatStep)
{
//TODO it is possible at this point that card is NULL. if so, what do we return since card->defenser would result in a crash?
card->defenser->raiseBlockerRankOrder(card);
return 1;
}

View File

@@ -24,7 +24,7 @@
#include "NetworkPlayer.h"
#endif
#if defined (WIN32) || defined (LINUX)
#if defined (WIN32) || defined (LINUX) || defined(IOS)
#include <time.h>
#endif

View File

@@ -747,7 +747,6 @@ void GameStateMenu::Render()
}
else
{
PIXEL_TYPE colors[] = {
ARGB(255,3,3,0), ARGB(255,8,8,0), ARGB(255,21,21,10), ARGB(255,50,50,30), };

View File

@@ -759,7 +759,7 @@ void MTGLibrary::shuffleTopToBottom(int nbcards)
{
_cards[i] = cards[i - nb_cards];
}
// Logic error here: the final value of cards[i] will always be garbage. possible optimization: use vectors to push and pop
//TODO Logic error here: the final value of cards[i] will always be garbage. possible optimization: use vectors to push and pop
for (int i = 0; i < nb_cards; i++)
{
cards[i] = _cards[i];
@@ -845,6 +845,7 @@ MTGGameZone * MTGGameZone::intToZone(GameObserver *g, int zoneId, MTGCardInstanc
p = source->controller();
if (!target)
{
//TODO source may be NULL, need to handle the case when it is NULL. method declaration has NULL being default value of source and target.
if(source->target)
{
//bug case, this is a patchwork fix for now

View File

@@ -1123,9 +1123,9 @@ int MTGMorphCostRule::reactToClick(MTGCardInstance * card)
}
//------------------------------------------------------------------------
ManaCost * previousManaPool = NEW ManaCost(player->getManaPool());
int payResult = player->getManaPool()->pay(card->getManaCost()->morph);
player->getManaPool()->pay(card->getManaCost()->morph);
card->getManaCost()->morph->doPayExtra();
payResult = ManaCost::MANA_PAID_WITH_MORPH;
int payResult = ManaCost::MANA_PAID_WITH_MORPH;
//if morph has a extra payment thats set, this code pays it.the if statement is 100% needed as it would cause a crash on cards that dont have the morph cost.
if (morph)
{

View File

@@ -15,7 +15,7 @@
vector<Rules *> Rules::RulesList = vector<Rules *>();
//Sorting by dissplayName
//Sorting by displayName
struct RulesMenuCmp{
bool operator()(const Rules * a,const Rules * b) const{
return a->displayName < b->displayName;
@@ -305,6 +305,7 @@ Player * Rules::initPlayer(GameObserver *g, int playerId)
return loadPlayerRandom(g, isAI, GAME_TYPE_RANDOM2);
}
}
//TODO p may still be NULL, what do we do to handle this? Above switch has no default case to handle the case where p is NULL
p->phaseRing = initState.playerData[playerId].player->phaseRing;
p->offerInterruptOnPhase = initState.playerData[playerId].player->offerInterruptOnPhase;
return p;
@@ -345,8 +346,10 @@ void Rules::initPlayers(GameObserver *g)
if(p && g->getPlayersNumber() < 2)
g->players.push_back(p);
MTGDeck * deck = buildDeck(i);
if (deck)
{
// TODO: p may be NULL, initPlayer(g, i) may return NULL, what do we do in this case?
p->game->initDeck(deck);
SAFE_DELETE(deck);
p->game->setOwner(p);

View File

@@ -727,11 +727,17 @@ bool TargetChooser::canTarget(Targetable * target,bool withoutProtections)
tempcard = tempcard->previous;
}
}
if(source && ((source->hasSubtype(Subtypes::TYPE_AURA) || source->hasSubtype(Subtypes::TYPE_EQUIPMENT)) && source->target && source->target == card && source->target->isPhased && targetter->target == card))
return true;
{
return true;
}
//this is kinda cheating but by default we let auras and equipments always continue to target a phased creature.
else if(card->isPhased)
return false;
else if (card && card->isPhased)
{
return false;
}
if (source && targetter && card->isInPlay(observer) && !withoutProtections)
{
if (card->has(Constants::SHROUD)) return false;

View File

@@ -899,13 +899,12 @@ bool WGuiSplit::yieldFocus()
}
//WGuiMenu
WGuiMenu::WGuiMenu(JButton next = JGE_BTN_RIGHT, JButton prev = JGE_BTN_LEFT, bool m, WSyncable * syncme) :
WGuiItem("")
WGuiMenu::WGuiMenu(JButton next, JButton prev, bool dPad, WSyncable * syncme) : WGuiItem("")
{
buttonNext = next;
buttonPrev = prev;
currentItem = -1;
mDPad = m;
mDPad = dPad;
sync = syncme;
held = JGE_BTN_NONE;
}
@@ -1100,7 +1099,6 @@ bool WGuiMenu::nextItem()
while (potential < nbitems - 1 && items[potential]->Selectable() == false)
potential++;
if (potential != currentItem && (!now || now->Leaving(buttonNext)))
{
currentItem = potential;
@@ -1130,9 +1128,9 @@ bool WGuiMenu::prevItem()
while (potential > 0 && items[potential]->Selectable() == false)
potential--;
if (potential < 0 || !items[potential]->Selectable())
potential = -1;
else if (potential != currentItem && (!now || now->Leaving(buttonNext)))
if ( (!(potential < 0 || !items[potential]->Selectable()))
&& (potential != currentItem && (!now || now->Leaving(buttonNext))))
{
currentItem = potential;
items[currentItem]->Entering(buttonPrev);

View File

@@ -3,12 +3,13 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 45;
objects = {
/* Begin PBXBuildFile section */
122F4B501438D553003A9129 /* AIPlayerBaka.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 122F4B4E1438D553003A9129 /* AIPlayerBaka.cpp */; };
122F4B511438D553003A9129 /* AIPlayerBakaB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 122F4B4F1438D553003A9129 /* AIPlayerBakaB.cpp */; };
12769486144127380088F6D3 /* AIPlayerBaka.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12769483144127380088F6D3 /* AIPlayerBaka.cpp */; };
12769487144127380088F6D3 /* AIPlayerBakaB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12769484144127380088F6D3 /* AIPlayerBakaB.cpp */; };
12769488144127380088F6D3 /* TestSuiteAI.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 12769485144127380088F6D3 /* TestSuiteAI.cpp */; };
127D4C6F1376B33200109AB4 /* mtg.txt in Resources */ = {isa = PBXBuildFile; fileRef = 127D4C6E1376B33200109AB4 /* mtg.txt */; };
12B812341404B9E20092E303 /* !Pak0.cpk in Resources */ = {isa = PBXBuildFile; fileRef = 12B8121F1404B9E10092E303 /* !Pak0.cpk */; };
12B812351404B9E20092E303 /* !Pak1.cpk in Resources */ = {isa = PBXBuildFile; fileRef = 12B812201404B9E10092E303 /* !Pak1.cpk */; };
@@ -182,8 +183,11 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
122F4B4E1438D553003A9129 /* AIPlayerBaka.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AIPlayerBaka.cpp; sourceTree = "<group>"; };
122F4B4F1438D553003A9129 /* AIPlayerBakaB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AIPlayerBakaB.cpp; sourceTree = "<group>"; };
12769483144127380088F6D3 /* AIPlayerBaka.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AIPlayerBaka.cpp; sourceTree = "<group>"; };
12769484144127380088F6D3 /* AIPlayerBakaB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AIPlayerBakaB.cpp; sourceTree = "<group>"; };
12769485144127380088F6D3 /* TestSuiteAI.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestSuiteAI.cpp; sourceTree = "<group>"; };
127694891441274D0088F6D3 /* AIPlayerBaka.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIPlayerBaka.h; sourceTree = "<group>"; };
1276948A1441274D0088F6D3 /* AIPlayerBakaB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIPlayerBakaB.h; sourceTree = "<group>"; };
127D4C6E1376B33200109AB4 /* mtg.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = mtg.txt; path = bin/Res/sets/primitives/mtg.txt; sourceTree = "<group>"; };
12B8121F1404B9E10092E303 /* !Pak0.cpk */ = {isa = PBXFileReference; lastKnownFileType = file; path = "!Pak0.cpk"; sourceTree = "<group>"; };
12B812201404B9E10092E303 /* !Pak1.cpk */ = {isa = PBXFileReference; lastKnownFileType = file; path = "!Pak1.cpk"; sourceTree = "<group>"; };
@@ -671,6 +675,8 @@
CEA376851291C60500B9016A /* include */ = {
isa = PBXGroup;
children = (
127694891441274D0088F6D3 /* AIPlayerBaka.h */,
1276948A1441274D0088F6D3 /* AIPlayerBakaB.h */,
12B812411404BCE30092E303 /* AIHints.h */,
12B812421404BCE30092E303 /* CacheEngine.h */,
12B812431404BCE30092E303 /* IconButton.h */,
@@ -789,8 +795,9 @@
CEA376ED1291C60500B9016A /* src */ = {
isa = PBXGroup;
children = (
122F4B4E1438D553003A9129 /* AIPlayerBaka.cpp */,
122F4B4F1438D553003A9129 /* AIPlayerBakaB.cpp */,
12769483144127380088F6D3 /* AIPlayerBaka.cpp */,
12769484144127380088F6D3 /* AIPlayerBakaB.cpp */,
12769485144127380088F6D3 /* TestSuiteAI.cpp */,
12B8124A1404BD0D0092E303 /* IconButton.cpp */,
12B8124C1404BD0D0092E303 /* ObjectAnalytics.cpp */,
CE9E71EA1375A62300759DDC /* ModRules.cpp */,
@@ -1058,11 +1065,8 @@
/* Begin PBXProject section */
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "wagic" */;
compatibilityVersion = "Xcode 3.2";
compatibilityVersion = "Xcode 3.1";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
@@ -1258,8 +1262,9 @@
12B8123F1404B9E20092E303 /* zstream.cpp in Sources */,
12B8124D1404BD0D0092E303 /* IconButton.cpp in Sources */,
12B8124F1404BD0D0092E303 /* ObjectAnalytics.cpp in Sources */,
122F4B501438D553003A9129 /* AIPlayerBaka.cpp in Sources */,
122F4B511438D553003A9129 /* AIPlayerBakaB.cpp in Sources */,
12769486144127380088F6D3 /* AIPlayerBaka.cpp in Sources */,
12769487144127380088F6D3 /* AIPlayerBakaB.cpp in Sources */,
12769488144127380088F6D3 /* TestSuiteAI.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1271,14 +1276,14 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = wagic_Prefix.pch;
GCC_PREPROCESSOR_DEFINITIONS = (
TESTSUITE,
_DEBUG,
IOS,
DEBUG,
DARWIN_NO_CARBON,
@@ -1303,8 +1308,6 @@
);
"New Setting" = "";
PRODUCT_NAME = wagic;
PROVISIONING_PROFILE = "";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
SCAN_ALL_SOURCE_FILES_FOR_INCLUDES = NO;
SDKROOT = iphoneos;
};
@@ -1315,8 +1318,6 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CODE_SIGN_IDENTITY = "iPhone Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = testproject_Prefix.pch;
@@ -1333,8 +1334,6 @@
"\"$(SDKROOT)/usr/lib/gcc/powerpc-apple-darwin9/4.0.1\"",
);
PRODUCT_NAME = testproject;
PROVISIONING_PROFILE = "";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
@@ -1344,18 +1343,16 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)";
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEPLOYMENT_LOCATION = NO;
DEPLOYMENT_POSTPROCESSING = NO;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_PREPROCESSOR_DEFINITIONS = DEBUG;
GCC_VERSION = "";
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = ../../Boost/boost;
PROVISIONING_PROFILE = "";
SDKROOT = iphoneos;
PREBINDING = NO;
SDKROOT = iphoneos3.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
@@ -1366,12 +1363,12 @@
ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_VERSION = "";
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = ../../Boost/boost;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
SDKROOT = iphoneos;
PREBINDING = NO;
SDKROOT = iphoneos4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;