- Lords are now taken into account in AI statistics. (To display information, uncomment RENDER_AI_STATS in config.h)
- fixed a potential segfault with NoFizzle
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-12-03 02:05:03 +00:00
parent 88d771b3be
commit ea3ed7061f
8 changed files with 66 additions and 2 deletions

View File

@@ -69,6 +69,7 @@ class AIPlayer: public Player{
void End(){};
virtual int displayStack() {return 0;};
int receiveEvent(WEvent * event);
void Render();
AIStats * stats;
ManaCost * getPotentialMana(MTGCardInstance * card = NULL);
AIPlayer(MTGPlayerCards * deck, string deckFile, string deckFileSmall);

View File

@@ -3,7 +3,11 @@
#define STATS_PLAYER_MULTIPLIER 15
#define STATS_CREATURE_MULTIPLIER 10
#define STATS_AURA_MULTIPLIER 9
//floats
#define STATS_AURA_MULTIPLIER 0.9
#define STATS_LORD_MULTIPLIER 0.5
#include <list>
#include <string>
using std::list;
@@ -38,6 +42,7 @@ class AIStats{
bool isInTop(MTGCardInstance * card, unsigned int max, bool tooSmallCountsForTrue = true );
void updateStatsCard(MTGCardInstance * cardInstance, Damage * damage, float multiplier = 1.0);
int receiveEvent(WEvent * event);
void Render();
};
#endif

View File

@@ -238,7 +238,7 @@ class AAFizzler:public ActivatedAbility{
int resolve(){
Spell * _target = (Spell *) target;
if(_target->source->has(Constants::NOFIZZLE))
if(target && _target->source->has(Constants::NOFIZZLE))
return 0;
game->mLayers->stackLayer()->Fizzle(_target);
return 1;

View File

@@ -39,6 +39,7 @@ class Player: public Damageable{
string deckFileSmall;
virtual int receiveEvent(WEvent * event){return 0;};
virtual void Render(){};
};
class HumanPlayer: public Player{

View File

@@ -37,4 +37,9 @@
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
// Debug options - comment/uncomment as needed
#ifdef _DEBUG
//#define RENDER_AI_STATS
#endif
#endif

View File

@@ -743,6 +743,12 @@ int AIPlayer::receiveEvent(WEvent * event){
return 0;
}
void AIPlayer::Render(){
#ifdef RENDER_AI_STATS
if (getStats()) getStats()->Render();
#endif
}
int AIPlayerBaka::Act(float dt){
GameObserver * g = GameObserver::GetInstance();

View File

@@ -4,6 +4,7 @@
#include "../include/Player.h"
#include "../include/MTGCardInstance.h"
#include "../include/WEvent.h"
#include "../include/AllAbilities.h"
bool compare_aistats(AIStat * first, AIStat * second){
float damage1 = first->value / first->occurences;
@@ -59,6 +60,24 @@ int AIStats::receiveEvent(WEvent * event){
updateStatsCard(aura,damage, STATS_AURA_MULTIPLIER);
}
}
GameObserver * g = GameObserver::GetInstance();
//Lords
map<MTGCardInstance *, int> lords;
for (int i = 1; i < g->mLayers->actionLayer()->mCount; i++){ //0 is not a mtgability...hackish
MTGAbility * a = ((MTGAbility *)g->mLayers->actionLayer()->mObjects[i]);
if (ALord * al = dynamic_cast<ALord*>(a)) {
if (al->cards.find(card)!= al->cards.end() && opponentZone->hasCard(al->source)){
lords[al->source] = 1;
}
}
}
if (size_t nb = lords.size()){
for (map<MTGCardInstance *, int>::iterator it = lords.begin();it !=lords.end();++it){
updateStatsCard(it->first,damage, STATS_LORD_MULTIPLIER/nb);
}
}
stats.sort(compare_aistats); //this could be slow, if it is, let's run it only at the end of the turn
return 1; //is this meant to return 0 or 1?
}
@@ -126,3 +145,27 @@ void AIStats::save(){
}
}
void AIStats::Render(){
GameObserver * g = GameObserver::GetInstance();
float x0 = 10;
if (player == g->players[1]) x0 = 280;
JRenderer::GetInstance()->FillRoundRect(x0,10,200,180,5,ARGB(50,0,0,0));
JLBFont * f = resources.GetJLBFont("simon");
int i = 0;
char buffer[512];
list<AIStat *>::iterator it;
for (it = stats.begin(); it !=stats.end(); ++it){
if (i>10) break;
AIStat * stat = *it;
if (stat->value > 0){
MTGCard * card = GameApp::collection->getCardById(stat->source);
if (card) {
sprintf(buffer, "%s %i", card->getName().c_str(), stat->value);
f->DrawString(buffer,x0+5,10 + 16 *i);
i++;
}
}
}
}

View File

@@ -298,6 +298,9 @@ void GameObserver::Render()
JRenderer::GetInstance()->DrawRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,ARGB(255,255,0,0));
if (waitForExtraPayment)
waitForExtraPayment->Render();
for (int i = 0; i < nbPlayers; ++i){
players[i]->Render();
}
}