Erwan
- Card Primitives system. Check Royal Assassin in RV, 10E, M10 - Please review, is sets/primitives a good directory? Should we rename MTGCard into "CardPrint"? - Unfortunately for now it is not possible to "override" a Primitive. A card that links to a primitive but also defines new "values" will create its own data and ignore the data in the "linked" primitive for the time being. I hope to solve that at some point...
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/Blocker.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardSelector.o objs/ConstraintResolver.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.o objs/Logger.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGRules.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/Pos.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/ShopItem.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/Token.o objs/Translate.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/Tasks.o
|
||||
OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/Blocker.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/ConstraintResolver.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.o objs/Logger.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGRules.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/Pos.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/ShopItem.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/Token.o objs/Translate.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/Tasks.o
|
||||
DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS))
|
||||
|
||||
RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache)
|
||||
|
||||
@@ -851,40 +851,24 @@ mana={X}{2}{R}{R}
|
||||
auto=lord(creature) x/-x
|
||||
[/card]
|
||||
[card]
|
||||
text={T}: Add {G} to your mana pool.
|
||||
auto={T}: Add {G}
|
||||
id=129559
|
||||
name=Forest
|
||||
primitive=Forest
|
||||
rarity=L
|
||||
type=Basic Land
|
||||
subtype=Forest
|
||||
[/card]
|
||||
[card]
|
||||
text={T}: Add {G} to your mana pool.
|
||||
auto={T}: Add {G}
|
||||
id=129560
|
||||
name=Forest
|
||||
primitive=Forest
|
||||
rarity=L
|
||||
type=Basic Land
|
||||
subtype=Forest
|
||||
[/card]
|
||||
[card]
|
||||
text={T}: Add {G} to your mana pool.
|
||||
auto={T}: Add {G}
|
||||
id=129561
|
||||
name=Forest
|
||||
primitive=Forest
|
||||
rarity=L
|
||||
type=Basic Land
|
||||
subtype=Forest
|
||||
[/card]
|
||||
[card]
|
||||
text={T}: Add {G} to your mana pool.
|
||||
auto={T}: Add {G}
|
||||
id=129562
|
||||
name=Forest
|
||||
primitive=Forest
|
||||
rarity=L
|
||||
type=Basic Land
|
||||
subtype=Forest
|
||||
[/card]
|
||||
[card]
|
||||
text={2}, {T}: You gain 1 life.
|
||||
@@ -2093,16 +2077,9 @@ subtype=Merfolk
|
||||
toughness=2
|
||||
[/card]
|
||||
[card]
|
||||
text={T}: Destroy target tapped creature.
|
||||
id=129708
|
||||
auto={T}:destroy target(creature[tapped])
|
||||
name=Royal Assassin
|
||||
primitive=Royal Assassin
|
||||
rarity=R
|
||||
type=Creature
|
||||
mana={1}{B}{B}
|
||||
power=1
|
||||
subtype=Human Assassin
|
||||
toughness=1
|
||||
[/card]
|
||||
[card]
|
||||
text=Forestwalk (This creature is unblockable as long as defending player controls a Forest.)
|
||||
|
||||
@@ -440,40 +440,24 @@ power=2
|
||||
toughness=3
|
||||
[/card]
|
||||
[card]
|
||||
text={T}: Add {G} to your mana pool.
|
||||
auto={T}:Add {G}
|
||||
id=174927
|
||||
name=Forest
|
||||
primitive=Forest
|
||||
rarity=L
|
||||
type=Basic Land
|
||||
subtype=Forest
|
||||
[/card]
|
||||
[card]
|
||||
text={T}: Add {G} to your mana pool.
|
||||
auto={T}:Add {G}
|
||||
id=174930
|
||||
name=Forest
|
||||
rarity=L
|
||||
type=Basic Land
|
||||
subtype=Forest
|
||||
[/card]
|
||||
[card]
|
||||
text={T}: Add {G} to your mana pool.
|
||||
auto={T}:Add {G}
|
||||
id=174928
|
||||
name=Forest
|
||||
primitive=Forest
|
||||
rarity=L
|
||||
type=Basic Land
|
||||
subtype=Forest
|
||||
[/card]
|
||||
[card]
|
||||
text={T}: Add {G} to your mana pool.
|
||||
auto={T}:Add {G}
|
||||
id=174929
|
||||
name=Forest
|
||||
primitive=Forest
|
||||
rarity=L
|
||||
[/card]
|
||||
[card]
|
||||
id=174930
|
||||
primitive=Forest
|
||||
rarity=L
|
||||
type=Basic Land
|
||||
subtype=Forest
|
||||
[/card]
|
||||
[card]
|
||||
text=Flying Whenever another artifact enters the battlefield under your control, Glaze Fiend gets +2/+2 until end of turn.
|
||||
|
||||
@@ -1502,14 +1502,7 @@ rarity=U
|
||||
[/card]
|
||||
[card]
|
||||
id=191318
|
||||
name=Royal Assassin
|
||||
mana={1}{B}{B}
|
||||
type=Creature
|
||||
subtype=Human Assassin
|
||||
power=1
|
||||
toughness=1
|
||||
text={T}: Destroy target tapped creature.
|
||||
auto={T}:destroy target(creature[tapped])
|
||||
primitive=Royal Assassin
|
||||
rarity=R
|
||||
[/card]
|
||||
[card]
|
||||
|
||||
@@ -1824,16 +1824,9 @@ mana={4}
|
||||
type=Artifact
|
||||
[/card]
|
||||
[card]
|
||||
text={T}: Destroy target tapped creature.
|
||||
auto={T}:destroy target(creature[tapped])
|
||||
id=1175
|
||||
name=Royal Assassin
|
||||
primitive=Royal Assassin
|
||||
rarity=R
|
||||
mana={1}{B}{B}
|
||||
type=Creature
|
||||
subtype=Human Assassin
|
||||
power=1
|
||||
toughness=1
|
||||
[/card]
|
||||
[card]
|
||||
text=As an additional cost to cast Sacrifice, sacrifice a creature. Add to your mana pool an amount of black mana equal to the sacrificed creature's converted mana cost.
|
||||
|
||||
19
projects/mtg/bin/Res/sets/primitives/mtg.txt
Normal file
19
projects/mtg/bin/Res/sets/primitives/mtg.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
#Primitives Pack for Wagic the Homebrew.
|
||||
#Please keep these card alphabetized, and try to have the "name=" line at the top of each card
|
||||
[card]
|
||||
name=Forest
|
||||
text={T}: Add {G} to your mana pool.
|
||||
auto={T}: Add {G}
|
||||
type=Basic Land
|
||||
subtype=Forest
|
||||
[/card]
|
||||
[card]
|
||||
name=Royal Assassin
|
||||
text={T}: Destroy target tapped creature.
|
||||
auto={T}:destroy target(creature[tapped])
|
||||
type=Creature
|
||||
mana={1}{B}{B}
|
||||
power=1
|
||||
subtype=Human Assassin
|
||||
toughness=1
|
||||
[/card]
|
||||
82
projects/mtg/include/CardPrimitive.h
Normal file
82
projects/mtg/include/CardPrimitive.h
Normal file
@@ -0,0 +1,82 @@
|
||||
#ifndef _CARDPRIMITIVE_H_
|
||||
#define _CARDPRIMITIVE_H_
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "ManaCost.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CardPrimitive {
|
||||
protected:
|
||||
ManaCost manaCost;
|
||||
vector<string> ftdText;
|
||||
int init();
|
||||
string lcname;
|
||||
|
||||
public:
|
||||
string text;
|
||||
string name;
|
||||
|
||||
int colors[Constants::MTG_NB_COLORS];
|
||||
map<int,int> basicAbilities;
|
||||
map<string,string> magicTexts;
|
||||
string magicText;
|
||||
int alias;
|
||||
string spellTargetType;
|
||||
int power;
|
||||
int toughness;
|
||||
vector<int>types;
|
||||
CardPrimitive();
|
||||
CardPrimitive(CardPrimitive * source);
|
||||
|
||||
void setColor(int _color, int removeAllOthers = 0);
|
||||
void setColor(string _color, int removeAllOthers = 0);
|
||||
void removeColor(int color);
|
||||
int getColor();
|
||||
int hasColor(int _color);
|
||||
int countColors();
|
||||
|
||||
int has(int ability);
|
||||
|
||||
void setText(string value);
|
||||
const char * getText();
|
||||
|
||||
void addMagicText(string value);
|
||||
void addMagicText(string value, string zone);
|
||||
|
||||
void setName(string value);
|
||||
const string getName() const;
|
||||
const string getLCName() const;
|
||||
|
||||
void addType(char * type_text);
|
||||
void addType(int id);
|
||||
void setType(const char * type_text);
|
||||
void setSubtype( string value);
|
||||
int removeType(string value, int removeAll = 0);
|
||||
int removeType(int value, int removeAll = 0);
|
||||
bool hasSubtype(int _subtype);
|
||||
bool hasSubtype(const char * _subtype);
|
||||
bool hasSubtype(string _subtype);
|
||||
bool hasType(int _type);
|
||||
bool hasType(const char * type);
|
||||
|
||||
void setManaCost(string value);
|
||||
ManaCost * getManaCost();
|
||||
bool isCreature();
|
||||
bool isLand();
|
||||
bool isSpell();
|
||||
|
||||
void setPower(int _power);
|
||||
int getPower();
|
||||
void setToughness(int _toughness);
|
||||
int getToughness();
|
||||
|
||||
const vector<string>& formattedText();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "../include/MTGDefinitions.h"
|
||||
#include "../include/MTGCard.h"
|
||||
#include "../include/CardPrimitive.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
using std::map;
|
||||
@@ -16,7 +17,7 @@ class Cmp1 { // compares cards by their name
|
||||
bool operator()(MTGCard * card1, MTGCard * card2) const {
|
||||
if (!card2) return true;
|
||||
if (!card1) return false;
|
||||
int result = card1->name.compare(card2->name);
|
||||
int result = card1->data->name.compare(card2->data->name);
|
||||
if (!result) return card1->getMTGId() < card2->getMTGId();
|
||||
return ( result < 0);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@ class GameStateMenu: public GameState, public JGuiListener
|
||||
int mVolume;
|
||||
char nbcardsStr[400];
|
||||
vector<string> langs;
|
||||
vector<string> primitives;
|
||||
int primitivesLoadCounter;
|
||||
|
||||
DIR *mDip;
|
||||
struct dirent *mDit;
|
||||
@@ -45,6 +47,7 @@ class GameStateMenu: public GameState, public JGuiListener
|
||||
void loadLangMenu();
|
||||
bool langChoices;
|
||||
void runTest(); //!!
|
||||
void listPrimitives();
|
||||
public:
|
||||
GameStateMenu(GameApp* parent);
|
||||
virtual ~GameStateMenu();
|
||||
|
||||
@@ -16,51 +16,31 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "ManaCost.h"
|
||||
class CardPrimitive;
|
||||
|
||||
using namespace std;
|
||||
|
||||
class MTGCard {
|
||||
protected:
|
||||
int mtgid;
|
||||
ManaCost manaCost;
|
||||
char rarity;
|
||||
char image_name[MTGCARD_NAME_SIZE];
|
||||
vector<string> ftdText;
|
||||
int init();
|
||||
string lcname;
|
||||
int init();
|
||||
|
||||
public:
|
||||
string text;
|
||||
string name;
|
||||
|
||||
int colors[Constants::MTG_NB_COLORS];
|
||||
map<int,int> basicAbilities;
|
||||
map<string,string> magicTexts;
|
||||
string magicText;
|
||||
int alias;
|
||||
string spellTargetType;
|
||||
int power;
|
||||
int toughness;
|
||||
int setId;
|
||||
int nb_types;
|
||||
int types[MAX_TYPES_PER_CARD];
|
||||
CardPrimitive * data;
|
||||
|
||||
MTGCard();
|
||||
MTGCard(int set_id);
|
||||
MTGCard(MTGCard * source);
|
||||
|
||||
void setColor(int _color, int removeAllOthers = 0);
|
||||
void setColor(string _color, int removeAllOthers = 0);
|
||||
void removeColor(int color);
|
||||
int getColor();
|
||||
int hasColor(int _color);
|
||||
int countColors();
|
||||
|
||||
void setMTGId(int id);
|
||||
int getMTGId();
|
||||
int getId();
|
||||
|
||||
int has(int ability);
|
||||
|
||||
|
||||
char getRarity();
|
||||
void setRarity(char _rarity);
|
||||
@@ -68,40 +48,8 @@ class MTGCard {
|
||||
//void setImageName( char * value);
|
||||
char * getImageName ();
|
||||
|
||||
void setText(string value);
|
||||
const char * getText();
|
||||
void setPrimitive(CardPrimitive * cp);
|
||||
|
||||
void addMagicText(string value);
|
||||
void addMagicText(string value, string zone);
|
||||
|
||||
void setName(string value);
|
||||
const string getName() const;
|
||||
const string getLCName() const;
|
||||
|
||||
void addType(char * type_text);
|
||||
void addType(int id);
|
||||
void setType(const char * type_text);
|
||||
void setSubtype( string value);
|
||||
int removeType(string value, int removeAll = 0);
|
||||
int removeType(int value, int removeAll = 0);
|
||||
bool hasSubtype(int _subtype);
|
||||
bool hasSubtype(const char * _subtype);
|
||||
bool hasSubtype(string _subtype);
|
||||
bool hasType(int _type);
|
||||
bool hasType(const char * type);
|
||||
|
||||
void setManaCost(string value);
|
||||
ManaCost * getManaCost();
|
||||
bool isCreature();
|
||||
bool isLand();
|
||||
bool isSpell();
|
||||
|
||||
void setPower(int _power);
|
||||
int getPower();
|
||||
void setToughness(int _toughness);
|
||||
int getToughness();
|
||||
|
||||
const vector<string>& formattedText();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define _MTG_CARD_INSTANCE_H_
|
||||
|
||||
#include "MTGCard.h"
|
||||
#include "CardPrimitive.h"
|
||||
#include "MTGGameZones.h"
|
||||
#include "MTGAbility.h"
|
||||
#include "WResourceManager.h"
|
||||
@@ -24,7 +25,7 @@ struct Pos;
|
||||
#include <list>
|
||||
using namespace std;
|
||||
|
||||
class MTGCardInstance: public MTGCard, public Damageable {
|
||||
class MTGCardInstance: public CardPrimitive, public MTGCard, public Damageable {
|
||||
protected:
|
||||
int untapping;
|
||||
int nb_damages;
|
||||
@@ -41,6 +42,7 @@ class MTGCardInstance: public MTGCard, public Damageable {
|
||||
int addBlocker(MTGCardInstance * c);
|
||||
int removeBlocker(MTGCardInstance * c);
|
||||
int setAttacker(int value);
|
||||
int init();
|
||||
public:
|
||||
MTGGameZone * currentZone;
|
||||
Pos* view;
|
||||
|
||||
@@ -15,6 +15,7 @@ using std::string;
|
||||
|
||||
class GameApp;
|
||||
class MTGCard;
|
||||
class CardPrimitive;
|
||||
|
||||
#define SET_METADATA "setinfo.txt"
|
||||
|
||||
@@ -80,10 +81,8 @@ extern MTGSets setlist;
|
||||
|
||||
class MTGAllCards {
|
||||
private:
|
||||
MTGCard * tempCard;
|
||||
#if defined (_DEBUG)
|
||||
bool committed;
|
||||
#endif
|
||||
MTGCard * tempCard; //used by parser
|
||||
CardPrimitive * tempPrimitive; //used by parser
|
||||
protected:
|
||||
int conf_read_mode;
|
||||
int colorsCount[Constants::MTG_NB_COLORS];
|
||||
@@ -95,6 +94,7 @@ private:
|
||||
|
||||
vector<int> ids;
|
||||
map<int, MTGCard *> collection;
|
||||
map<string,CardPrimitive *>primitives;
|
||||
MTGAllCards();
|
||||
~MTGAllCards();
|
||||
MTGCard * _(int id);
|
||||
@@ -102,7 +102,7 @@ private:
|
||||
MTGAllCards(const char * config_file, const char * set_name);
|
||||
MTGCard * getCardById(int id);
|
||||
MTGCard * getCardByName(string name);
|
||||
int load(const char * config_file, const char * setName, int autoload = 1);
|
||||
int load(const char * config_file, const char * setName = NULL, int autoload = 1);
|
||||
int countByType(const char * _type);
|
||||
int countByColor(int color);
|
||||
int countBySet(int setId);
|
||||
@@ -110,7 +110,9 @@ private:
|
||||
int totalCards();
|
||||
int randomCardId();
|
||||
private:
|
||||
int processConfLine(string s, MTGCard* card);
|
||||
int processConfLine(string s, MTGCard* card, CardPrimitive * primitive);
|
||||
bool addCardToCollection(MTGCard * card, int setId);
|
||||
bool addPrimitive(CardPrimitive * primitive, MTGCard * card = NULL);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ void AIStats::Render(){
|
||||
if (stat->value > 0){
|
||||
MTGCard * card = GameApp::collection->getCardById(stat->source);
|
||||
if (card) {
|
||||
sprintf(buffer, "%s %i", card->getName().c_str(), stat->value);
|
||||
sprintf(buffer, "%s %i", card->data->getName().c_str(), stat->value);
|
||||
f->DrawString(buffer,x0+5,10 + 16 *(float)i);
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ void UntapBlocker::Update(float dt){
|
||||
_target->getUntapBlockers()->Add(this);
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
char buf[4096];
|
||||
sprintf(buf, "Adding Blocker to %s \n", _target->model->getName().c_str());
|
||||
sprintf(buf, "Adding Blocker to %s \n", _target->getName().c_str());
|
||||
OutputDebugString(buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ bool CardDescriptor::valueInRange(int comparisonMode, int value, int criterion){
|
||||
|
||||
MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card){
|
||||
int found = 1;
|
||||
for (int i = 0; i< nb_types; i++){
|
||||
for (size_t i = 0; i< types.size(); i++){
|
||||
found = 0;
|
||||
if (types[i] >= 0){
|
||||
|
||||
@@ -101,7 +101,7 @@ MTGCardInstance * CardDescriptor::match_or(MTGCardInstance * card){
|
||||
|
||||
MTGCardInstance * CardDescriptor::match_and(MTGCardInstance * card){
|
||||
MTGCardInstance * match = card;
|
||||
for (int i = 0; i< nb_types; i++){
|
||||
for (size_t i = 0; i< types.size(); i++){
|
||||
if (types[i] >= 0){
|
||||
if (!card->hasSubtype(types[i]) && !(Subtypes::subtypesList->find(card->getLCName(),false) == types[i])){
|
||||
match = NULL;
|
||||
|
||||
@@ -117,14 +117,16 @@ void CardGui::Render()
|
||||
PlayGuiObject::Render();
|
||||
}
|
||||
|
||||
|
||||
|
||||
JQuad * CardGui::alternateThumbQuad(MTGCard * card){
|
||||
JQuad * q;
|
||||
|
||||
if(card->countColors() > 1){
|
||||
if(card->data->countColors() > 1){
|
||||
q = resources.RetrieveTempQuad("gold_thumb.jpg");
|
||||
}
|
||||
else{
|
||||
switch(card->getColor())
|
||||
switch(card->data->getColor())
|
||||
{
|
||||
case Constants::MTG_COLOR_ARTIFACT : q = resources.RetrieveTempQuad("artifact_thumb.jpg");break;
|
||||
case Constants::MTG_COLOR_GREEN: q = resources.RetrieveTempQuad("green_thumb.jpg");break;
|
||||
@@ -148,10 +150,10 @@ void CardGui::alternateRender(MTGCard * card, const Pos& pos){
|
||||
|
||||
float x = pos.actX;
|
||||
|
||||
if(card->countColors() > 1) {
|
||||
if(card->data->countColors() > 1) {
|
||||
q = resources.RetrieveTempQuad("gold.jpg");
|
||||
} else {
|
||||
switch(card->getColor())
|
||||
switch(card->data->getColor())
|
||||
{
|
||||
case Constants::MTG_COLOR_ARTIFACT: q = resources.RetrieveTempQuad("artifact.jpg");break;
|
||||
case Constants::MTG_COLOR_GREEN: q = resources.RetrieveTempQuad("green.jpg");break;
|
||||
@@ -178,7 +180,7 @@ void CardGui::alternateRender(MTGCard * card, const Pos& pos){
|
||||
|
||||
{
|
||||
char name[4096];
|
||||
sprintf(name, _(card->getName()).c_str());
|
||||
sprintf(name, _(card->data->getName()).c_str());
|
||||
float w = font->GetStringWidth(name) * 0.8 * pos.actZ;
|
||||
if (w > BigWidth - 30)
|
||||
font->SetScale((BigWidth - 30) / w);
|
||||
@@ -188,24 +190,24 @@ void CardGui::alternateRender(MTGCard * card, const Pos& pos){
|
||||
// Write the description
|
||||
{
|
||||
font->SetScale(0.8 * pos.actZ);
|
||||
const std::vector<string> txt = card->formattedText();
|
||||
const std::vector<string> txt = card->data->formattedText();
|
||||
unsigned i = 0;
|
||||
for (std::vector<string>::const_iterator it = txt.begin(); it != txt.end(); ++it, ++i)
|
||||
font->DrawString(it->c_str(), x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (-BigHeight/2 + 80 + 11 * i)*pos.actZ);
|
||||
}
|
||||
|
||||
// Write the strength
|
||||
if (card->isCreature())
|
||||
if (card->data->isCreature())
|
||||
{
|
||||
char buffer[32];
|
||||
sprintf(buffer, "%i/%i", card->power, card->toughness);
|
||||
sprintf(buffer, "%i/%i", card->data->power, card->data->toughness);
|
||||
float w = font->GetStringWidth(buffer) * 0.8;
|
||||
font->DrawString(buffer, x + (65 - w / 2)*pos.actZ, pos.actY + (106)*pos.actZ);
|
||||
}
|
||||
|
||||
// Mana
|
||||
{
|
||||
ManaCost* manacost = card->getManaCost();
|
||||
ManaCost* manacost = card->data->getManaCost();
|
||||
ManaCostHybrid* h;
|
||||
unsigned int j = 0;
|
||||
unsigned char t = (JGE::GetInstance()->GetTime() / 3) & 0xFF;
|
||||
@@ -259,12 +261,12 @@ void CardGui::alternateRender(MTGCard * card, const Pos& pos){
|
||||
//types
|
||||
{
|
||||
string s = "";
|
||||
for (int i = card->nb_types - 1; i > 0; --i)
|
||||
for (int i = card->data->types.size() - 1; i > 0; --i)
|
||||
{
|
||||
s += _(Subtypes::subtypesList->find(card->types[i]));
|
||||
s += _(Subtypes::subtypesList->find(card->data->types[i]));
|
||||
s += " - ";
|
||||
}
|
||||
s += _(Subtypes::subtypesList->find(card->types[0]));
|
||||
s += _(Subtypes::subtypesList->find(card->data->types[0]));
|
||||
font->DrawString(s.c_str(), x + (22 - BigWidth / 2)*pos.actZ, pos.actY + (49 - BigHeight / 2)*pos.actZ);
|
||||
}
|
||||
|
||||
@@ -290,7 +292,7 @@ void CardGui::alternateRender(MTGCard * card, const Pos& pos){
|
||||
break;
|
||||
}
|
||||
|
||||
switch(card->getColor())
|
||||
switch(card->data->getColor())
|
||||
{
|
||||
case Constants::MTG_COLOR_BLACK:
|
||||
case Constants::MTG_COLOR_GREEN:
|
||||
|
||||
305
projects/mtg/src/CardPrimitive.cpp
Normal file
305
projects/mtg/src/CardPrimitive.cpp
Normal file
@@ -0,0 +1,305 @@
|
||||
#include "../include/CardPrimitive.h"
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../include/MTGDeck.h"
|
||||
#include "../include/config.h"
|
||||
#include "../include/Subtypes.h"
|
||||
#include "../include/Translate.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
CardPrimitive::CardPrimitive(){
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
CardPrimitive::CardPrimitive(CardPrimitive * source){
|
||||
for(map<int,int>::const_iterator it = source->basicAbilities.begin(); it != source->basicAbilities.end(); ++it){
|
||||
basicAbilities[it->first] = source->basicAbilities[it->first];
|
||||
}
|
||||
|
||||
for (size_t i = 0; i< source->types.size(); i++){
|
||||
types.push_back(source->types[i]);
|
||||
}
|
||||
for (int i = 0; i< Constants::MTG_NB_COLORS; i++){
|
||||
colors[i] = source->colors[i];
|
||||
}
|
||||
manaCost.copy(source->getManaCost());
|
||||
|
||||
text = source->text;
|
||||
setName(source->name);
|
||||
|
||||
power = source->power;
|
||||
toughness = source->toughness;
|
||||
|
||||
magicText = source->magicText;
|
||||
for(map<string,string>::const_iterator it = source->magicTexts.begin(); it != source->magicTexts.end(); ++it){
|
||||
magicTexts[it->first] = source->magicTexts[it->first];
|
||||
}
|
||||
spellTargetType = source->spellTargetType;
|
||||
alias = source->alias;
|
||||
}
|
||||
|
||||
int CardPrimitive::init(){
|
||||
basicAbilities.clear();
|
||||
|
||||
types.clear();
|
||||
|
||||
for (int i = 0; i< Constants::MTG_NB_COLORS; i++){
|
||||
colors[i] = 0;
|
||||
}
|
||||
|
||||
magicText = "";
|
||||
magicTexts.clear();
|
||||
spellTargetType = "";
|
||||
alias = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const vector<string>& CardPrimitive::formattedText()
|
||||
{
|
||||
if (ftdText.empty())
|
||||
{
|
||||
std::string s = _(text);
|
||||
std::string::size_type found = s.find_first_of("{}");
|
||||
while (found!=string::npos)
|
||||
{
|
||||
s[found] = '/';
|
||||
found = s.find_first_of("{}", found + 1);
|
||||
}
|
||||
std::string::size_type len = 30;
|
||||
while (s.length() > 0)
|
||||
{
|
||||
std::string::size_type cut = s.find_first_of("., \t)", 0);
|
||||
if (cut >= len || cut == string::npos)
|
||||
{
|
||||
ftdText.push_back(s.substr(0,len));
|
||||
if (s.length() > len)
|
||||
s = s.substr(len, s.length() - len);
|
||||
else
|
||||
s = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string::size_type newcut = cut;
|
||||
while (newcut < len && newcut != string::npos)
|
||||
{
|
||||
cut = newcut;
|
||||
newcut = s.find_first_of("., \t)", newcut + 1);
|
||||
}
|
||||
ftdText.push_back(s.substr(0,cut+1));
|
||||
if (s.length() > cut+1)
|
||||
s = s.substr(cut+1,s.length() - cut - 1);
|
||||
else
|
||||
s = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
return ftdText;
|
||||
}
|
||||
|
||||
|
||||
bool CardPrimitive::isCreature(){
|
||||
return hasSubtype(Subtypes::TYPE_CREATURE);
|
||||
}
|
||||
bool CardPrimitive::isLand(){
|
||||
return hasSubtype(Subtypes::TYPE_LAND);
|
||||
}
|
||||
bool CardPrimitive::isSpell(){
|
||||
return (!isCreature() && !isLand());
|
||||
}
|
||||
|
||||
void CardPrimitive::setColor(string _color, int removeAllOthers){
|
||||
if(_color.compare("blue")==0) return setColor(Constants::MTG_COLOR_BLUE,removeAllOthers);
|
||||
if(_color.compare("red")==0) return setColor(Constants::MTG_COLOR_RED,removeAllOthers);
|
||||
if(_color.compare("green")==0) return setColor(Constants::MTG_COLOR_GREEN,removeAllOthers);
|
||||
if(_color.compare("black")==0) return setColor(Constants::MTG_COLOR_BLACK,removeAllOthers);
|
||||
if(_color.compare("white")==0) return setColor(Constants::MTG_COLOR_WHITE,removeAllOthers);
|
||||
}
|
||||
|
||||
void CardPrimitive::setColor(int _color, int removeAllOthers){
|
||||
if (removeAllOthers){
|
||||
for (int i=0; i<Constants::MTG_NB_COLORS; i++){
|
||||
colors[i] = 0;
|
||||
}
|
||||
}
|
||||
colors[_color] = 1;
|
||||
}
|
||||
|
||||
void CardPrimitive::removeColor(int _color){
|
||||
colors[_color] = 0;
|
||||
}
|
||||
|
||||
int CardPrimitive::getColor(){
|
||||
for (int i=1; i<Constants::MTG_NB_COLORS; i++){
|
||||
if (colors[i]){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int CardPrimitive::hasColor(int color){
|
||||
return (colors[color]);
|
||||
}
|
||||
|
||||
int CardPrimitive::countColors(){
|
||||
int result = 0;
|
||||
for(int i=Constants::MTG_COLOR_GREEN;i<=Constants::MTG_COLOR_WHITE;i++){
|
||||
if (hasColor(i)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void CardPrimitive::setManaCost(string s){
|
||||
ManaCost::parseManaCost(s, &manaCost);
|
||||
for (int i = Constants::MTG_COLOR_GREEN; i <= Constants::MTG_COLOR_WHITE; i++){
|
||||
if (manaCost.hasColor(i)){
|
||||
setColor(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CardPrimitive::setType(const char * _type_text){
|
||||
setSubtype(_type_text);
|
||||
}
|
||||
|
||||
void CardPrimitive::addType(char * _type_text){
|
||||
setSubtype(_type_text);
|
||||
}
|
||||
|
||||
void CardPrimitive::setSubtype( string value){
|
||||
int id = Subtypes::subtypesList->find(value);
|
||||
addType(id);
|
||||
}
|
||||
|
||||
void CardPrimitive::addType(int id){
|
||||
types.push_back(id);
|
||||
}
|
||||
|
||||
|
||||
//TODO Definitely move some of these functions to CardInstance. There is no reason to remove a type from an CardPrimitive since they represent the Database
|
||||
//Removes a type from the types of a given card
|
||||
//If removeAll is true, removes all occurences of this type, otherwise only removes the first occurence
|
||||
int CardPrimitive::removeType(string value, int removeAll){
|
||||
|
||||
int id = Subtypes::subtypesList->find(value);
|
||||
return removeType(id, removeAll);
|
||||
}
|
||||
|
||||
int CardPrimitive::removeType(int id, int removeAll){
|
||||
int result = 0;
|
||||
for (int i = types.size() -1 ; i >=0; i--){
|
||||
if (types[i] == id){
|
||||
types.erase(types.begin()+i);
|
||||
result++;
|
||||
if (!removeAll) return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void CardPrimitive::setText( string value){
|
||||
text = value;
|
||||
}
|
||||
|
||||
const char * CardPrimitive::getText(){
|
||||
return text.c_str();
|
||||
}
|
||||
|
||||
void CardPrimitive::addMagicText(string value){
|
||||
std::transform( value.begin(), value.end(), value.begin(),::tolower );
|
||||
if (magicText.size()) magicText.append("\n");
|
||||
magicText.append(value);
|
||||
}
|
||||
|
||||
void CardPrimitive::addMagicText(string value, string key){
|
||||
std::transform( value.begin(), value.end(), value.begin(),::tolower );
|
||||
if (magicTexts[key].size()) magicTexts[key].append("\n");
|
||||
magicTexts[key].append(value);
|
||||
}
|
||||
|
||||
void CardPrimitive::setName( string value){
|
||||
name = value;
|
||||
lcname = value;
|
||||
std::transform( lcname.begin(), lcname.end(),lcname.begin(),::tolower );
|
||||
//This is a bug fix for plague rats and the "foreach ability"
|
||||
//Right now we add names as types, so that they get recognized
|
||||
if (lcname.at(value.length()-1) == 's') Subtypes::subtypesList->find(lcname);
|
||||
}
|
||||
|
||||
const string CardPrimitive::getName() const{
|
||||
return name;
|
||||
}
|
||||
|
||||
const string CardPrimitive::getLCName() const{
|
||||
return lcname;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ManaCost* CardPrimitive::getManaCost(){
|
||||
return &manaCost;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool CardPrimitive::hasType(int _type){
|
||||
for (size_t i = 0; i<types.size(); i++)
|
||||
if (types[i] == _type)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CardPrimitive::hasSubtype(int _subtype){
|
||||
return hasType(_subtype);
|
||||
}
|
||||
|
||||
bool CardPrimitive::hasType(const char * _type){
|
||||
int id = Subtypes::subtypesList->find(_type);
|
||||
return hasType(id);
|
||||
}
|
||||
|
||||
|
||||
bool CardPrimitive::hasSubtype(const char * _subtype){
|
||||
int id = Subtypes::subtypesList->find(_subtype);
|
||||
return hasType(id);
|
||||
}
|
||||
|
||||
bool CardPrimitive::hasSubtype(string _subtype){
|
||||
int id = Subtypes::subtypesList->find(_subtype);
|
||||
return hasType(id);
|
||||
}
|
||||
|
||||
|
||||
int CardPrimitive::has(int basicAbility){
|
||||
return basicAbilities[basicAbility];
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
// Creature specific
|
||||
//---------------------------------------------
|
||||
void CardPrimitive::setPower(int _power){
|
||||
power = _power;
|
||||
}
|
||||
|
||||
int CardPrimitive::getPower(){
|
||||
return power;
|
||||
}
|
||||
|
||||
void CardPrimitive::setToughness(int _toughness){
|
||||
toughness = _toughness;
|
||||
}
|
||||
|
||||
int CardPrimitive::getToughness(){
|
||||
return toughness;
|
||||
}
|
||||
@@ -49,13 +49,13 @@ void DeckDataWrapper::updateCounts(MTGCard * card, int increment){
|
||||
MTGCard * current = (*it).first;
|
||||
colors[Constants::MTG_NB_COLORS] += (*it).second;
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++){
|
||||
if (current->hasColor(i)) colors[i]+=(*it).second;
|
||||
if (current->data->hasColor(i)) colors[i]+=(*it).second;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
colors[Constants::MTG_NB_COLORS] += increment;
|
||||
for (int i = 0; i < Constants::MTG_NB_COLORS; i++){
|
||||
if (card->hasColor(i)) colors[i]+=increment;
|
||||
if (card->data->hasColor(i)) colors[i]+=increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ int DeckDataWrapper::count(MTGCard * card){
|
||||
}
|
||||
|
||||
int DeckDataWrapper::countByName(MTGCard * card){
|
||||
string name = card->name;
|
||||
string name = card->data->name;
|
||||
int total = 0;
|
||||
map<MTGCard *,int,Cmp1>::iterator it,it_origin;
|
||||
it = cards.find(card);
|
||||
@@ -97,7 +97,7 @@ int DeckDataWrapper::countByName(MTGCard * card){
|
||||
|
||||
while(it !=cards.end()){
|
||||
MTGCard * _card = (*it).first;
|
||||
if (name.compare(_card->name) !=0){
|
||||
if (name.compare(_card->data->name) !=0){
|
||||
it = cards.end();
|
||||
}else{
|
||||
total+= (*it).second;
|
||||
@@ -110,7 +110,7 @@ int DeckDataWrapper::countByName(MTGCard * card){
|
||||
it--;
|
||||
while(1){
|
||||
MTGCard * _card = (*it).first;
|
||||
if (name.compare(_card->name) !=0){
|
||||
if (name.compare(_card->data->name) !=0){
|
||||
break;
|
||||
}else{
|
||||
total+= (*it).second;
|
||||
@@ -137,7 +137,7 @@ MTGCard * DeckDataWrapper::getNext(MTGCard * previous, int color){
|
||||
if (it == cards.end()) return NULL;
|
||||
MTGCard * card = (*it).first;
|
||||
if (card == previous) return NULL;
|
||||
if ((*it).second >0 && (color ==-1 || card->hasColor(color))){
|
||||
if ((*it).second >0 && (color ==-1 || card->data->hasColor(color))){
|
||||
return card;
|
||||
}
|
||||
}
|
||||
@@ -156,7 +156,7 @@ MTGCard * DeckDataWrapper::getPrevious(MTGCard * next, int color){
|
||||
if (it == cards.end()) return NULL;
|
||||
MTGCard * card = (*it).first;
|
||||
if (card == next) return NULL;
|
||||
if ((*it).second >0 && (color ==-1 || card->hasColor(color))){
|
||||
if ((*it).second >0 && (color ==-1 || card->data->hasColor(color))){
|
||||
return card;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +188,9 @@ void GameApp::Create()
|
||||
char buf[512];
|
||||
sprintf(buf, "size of MTGCard : %i\n" , sizeof(MTGCard));
|
||||
OutputDebugString(buf);
|
||||
|
||||
sprintf(buf, "size of CardPrimitive : %i\n" , sizeof(CardPrimitive));
|
||||
OutputDebugString(buf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ bool GameStateAwards::enterSet(int setid){
|
||||
MTGAllCards * c = GameApp::collection;
|
||||
for(it = c->collection.begin();it!=c->collection.end();it++){
|
||||
if(it->second && it->second->setId == setid && it->second->getId() >= 0) //Add only non-tokens from this set.
|
||||
spoiler->Add(NEW WGuiItem(it->second->name));
|
||||
spoiler->Add(NEW WGuiItem(it->second->data->name));
|
||||
}
|
||||
spoiler->Entering(0);
|
||||
WGuiCardImage * wi = NEW WGuiCardImage(setSrc);
|
||||
@@ -254,20 +254,20 @@ bool GameStateAwards::enterStats(int option){
|
||||
MTGCard * c = it->first;
|
||||
if(!c)
|
||||
continue;
|
||||
if(!c->isLand() && (many == NULL || it->second > dupes)){
|
||||
if(!c->data->isLand() && (many == NULL || it->second > dupes)){
|
||||
many = c;
|
||||
dupes = it->second;
|
||||
}
|
||||
unique++;
|
||||
counts[c->setId]+=it->second;
|
||||
if(costly == NULL
|
||||
|| c->getManaCost()->getConvertedCost() > costly->getManaCost()->getConvertedCost())
|
||||
|| c->data->getManaCost()->getConvertedCost() > costly->data->getManaCost()->getConvertedCost())
|
||||
costly = c;
|
||||
|
||||
if(c->isCreature() && (strong == NULL || c->getPower() > strong->getPower()))
|
||||
if(c->data->isCreature() && (strong == NULL || c->data->getPower() > strong->data->getPower()))
|
||||
strong = c;
|
||||
|
||||
if(c->isCreature() && (tough == NULL || c->getToughness() > tough->getToughness()))
|
||||
if(c->data->isCreature() && (tough == NULL || c->data->getToughness() > tough->data->getToughness()))
|
||||
tough = c;
|
||||
|
||||
}
|
||||
@@ -288,7 +288,7 @@ bool GameStateAwards::enterStats(int option){
|
||||
detailview->Add(NEW WGuiItem(buf));
|
||||
|
||||
if(many){
|
||||
sprintf(buf,_("Most Duplicates: %i (%s)").c_str(),dupes,many->getName().c_str());
|
||||
sprintf(buf,_("Most Duplicates: %i (%s)").c_str(),dupes,many->data->getName().c_str());
|
||||
detailview->Add(NEW WGuiItem(buf));
|
||||
}
|
||||
if(setid >= 0){
|
||||
@@ -296,15 +296,15 @@ bool GameStateAwards::enterStats(int option){
|
||||
detailview->Add(NEW WGuiItem(buf));
|
||||
}
|
||||
if(costly){
|
||||
sprintf(buf,_("Highest Mana Cost: %i (%s)").c_str(),costly->getManaCost()->getConvertedCost(),costly->getName().c_str());
|
||||
sprintf(buf,_("Highest Mana Cost: %i (%s)").c_str(),costly->data->getManaCost()->getConvertedCost(),costly->data->getName().c_str());
|
||||
detailview->Add(NEW WGuiItem(buf));
|
||||
}
|
||||
if(strong){
|
||||
sprintf(buf,_("Most Powerful: %i (%s)").c_str(),strong->getPower(),strong->getName().c_str());
|
||||
sprintf(buf,_("Most Powerful: %i (%s)").c_str(),strong->data->getPower(),strong->data->getName().c_str());
|
||||
detailview->Add(NEW WGuiItem(buf));
|
||||
}
|
||||
if(tough){
|
||||
sprintf(buf,_("Toughest: %i (%s)").c_str(),tough->getToughness(),strong->getName().c_str());
|
||||
sprintf(buf,_("Toughest: %i (%s)").c_str(),tough->data->getToughness(),strong->data->getName().c_str());
|
||||
detailview->Add(NEW WGuiItem(buf));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ void GameStateDeckViewer::Update(float dt)
|
||||
int rnd = (rand() % 20);
|
||||
price = pricelist->getPrice(card->getMTGId()) / 2;
|
||||
price = price - price * (rnd -10)/100;
|
||||
sprintf(buffer,"%s : %i %s",_(card->getName()).c_str(),price,_("credits").c_str());
|
||||
sprintf(buffer,"%s : %i %s",_(card->data->getName()).c_str(),price,_("credits").c_str());
|
||||
sellMenu = NEW SimpleMenu(2,this,Constants::MAIN_FONT,SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer);
|
||||
sellMenu->Add(20,"Yes");
|
||||
sellMenu->Add(21,"No","",true);
|
||||
@@ -439,7 +439,7 @@ void GameStateDeckViewer::renderSlideBar(){
|
||||
currentPos += it->second;
|
||||
else
|
||||
for (; it != end; ++it)
|
||||
if (it->first->hasColor(colorFilter)) currentPos += it->second;
|
||||
if (it->first->data->hasColor(colorFilter)) currentPos += it->second;
|
||||
}
|
||||
float cursor_pos = bar_size * currentPos / total;
|
||||
|
||||
@@ -1045,7 +1045,7 @@ void GameStateDeckViewer::updateStats() {
|
||||
}
|
||||
|
||||
while (current){
|
||||
currentCost = current->getManaCost();
|
||||
currentCost = current->data->getManaCost();
|
||||
convertedCost = currentCost->getConvertedCost();
|
||||
currentCount = myDeck->cards[current];
|
||||
|
||||
@@ -1055,10 +1055,10 @@ void GameStateDeckViewer::updateStats() {
|
||||
convertedCost = STATS_MAX_MANA_COST;
|
||||
}
|
||||
stw.countCardsPerCost[convertedCost] += currentCount;
|
||||
if (current->isCreature()) {
|
||||
if (current->data->isCreature()) {
|
||||
stw.countCreaturesPerCost[convertedCost] += currentCount;
|
||||
stw.totalCreatureCost += convertedCost * currentCount;
|
||||
} else if (current->isSpell()) {
|
||||
} else if (current->data->isSpell()) {
|
||||
stw.countSpellsPerCost[convertedCost] += currentCount;
|
||||
stw.totalSpellCost += convertedCost * currentCount;
|
||||
}
|
||||
@@ -1073,7 +1073,7 @@ void GameStateDeckViewer::updateStats() {
|
||||
cin = new MTGCardInstance(current, NULL);
|
||||
|
||||
vector<string> abilityStrings;
|
||||
string thisstring = current->magicText;
|
||||
string thisstring = current->data->magicText;
|
||||
StringExplode(thisstring, "\n", &abilityStrings);
|
||||
|
||||
/*char buf[4096];
|
||||
@@ -1090,8 +1090,8 @@ void GameStateDeckViewer::updateStats() {
|
||||
//OutputDebugString("M ");
|
||||
for (int j=0; j<Constants::MTG_NB_COLORS;j++){
|
||||
if (amp->output->hasColor(j)) {
|
||||
if (current->isLand()) {
|
||||
if (current->hasType("Basic")) {
|
||||
if (current->data->isLand()) {
|
||||
if (current->data->hasType("Basic")) {
|
||||
stw.countBasicLandsPerColor[j] += currentCount;
|
||||
} else {
|
||||
stw.countLandsPerColor[j] += currentCount;
|
||||
@@ -1112,12 +1112,12 @@ void GameStateDeckViewer::updateStats() {
|
||||
// a. regular costs
|
||||
for (int j=0; j<Constants::MTG_NB_COLORS;j++){
|
||||
stw.totalCostPerColor[j] += currentCost->getCost(j)*currentCount;
|
||||
if (current->hasColor(j)) {
|
||||
if (current->data->hasColor(j)) {
|
||||
// Add to the per cost and color counter
|
||||
stw.countCardsPerCostAndColor[convertedCost][j] += currentCount;
|
||||
if (current->isCreature()) {
|
||||
if (current->data->isCreature()) {
|
||||
stw.countCreaturesPerCostAndColor[convertedCost][j] += currentCount;
|
||||
} else if (current->isSpell()) {
|
||||
} else if (current->data->isSpell()) {
|
||||
stw.countSpellsPerCostAndColor[convertedCost][j] += currentCount;
|
||||
}
|
||||
}
|
||||
@@ -1174,7 +1174,7 @@ int GameStateDeckViewer::countCardsByType(const char * _type) {
|
||||
|
||||
MTGCard * current = myDeck->getNext();
|
||||
while (current){
|
||||
if(current->hasType(_type)){
|
||||
if(current->data->hasType(_type)){
|
||||
result += myDeck->cards[current];
|
||||
}
|
||||
current = myDeck->getNext(current);
|
||||
@@ -1225,7 +1225,7 @@ void GameStateDeckViewer::renderCard(int id, float rotation){
|
||||
JRenderer::GetInstance()->RenderQuad(quad, x , y , 0.0f,scale,scale);
|
||||
if (showName){
|
||||
char buffer[4096];
|
||||
sprintf(buffer, "%s", _(card->getName()).c_str());
|
||||
sprintf(buffer, "%s", _(card->data->getName()).c_str());
|
||||
float scaleBackup = mFont->GetScale();
|
||||
mFont->SetScale(scale);
|
||||
mFont->DrawString(buffer,x - 100*scale ,y - 145*scale);
|
||||
|
||||
@@ -74,6 +74,7 @@ GameStateMenu::GameStateMenu(GameApp* parent): GameState(parent)
|
||||
mVolume = 0;
|
||||
scroller = NULL;
|
||||
langChoices = false;
|
||||
primitivesLoadCounter = -1;
|
||||
}
|
||||
|
||||
GameStateMenu::~GameStateMenu() {}
|
||||
@@ -316,6 +317,25 @@ void GameStateMenu::loadLangMenu(){
|
||||
resetDirectory();
|
||||
}
|
||||
|
||||
void GameStateMenu::listPrimitives(){
|
||||
resetDirectory();
|
||||
if (!mDip){
|
||||
mDip = opendir("Res/sets/primitives/");
|
||||
}
|
||||
|
||||
while ((mDit = readdir(mDip))){
|
||||
string filename = "Res/sets/primitives/";
|
||||
filename += mDit->d_name;
|
||||
std::ifstream file(filename.c_str());
|
||||
if(!file) continue;
|
||||
file.close();
|
||||
primitives.push_back(filename);
|
||||
}
|
||||
resetDirectory();
|
||||
primitivesLoadCounter = 0;
|
||||
}
|
||||
|
||||
|
||||
void GameStateMenu::Update(float dt)
|
||||
{
|
||||
timeIndex += dt * 2;
|
||||
@@ -332,6 +352,13 @@ void GameStateMenu::Update(float dt)
|
||||
subMenuController->Update(dt);
|
||||
break;
|
||||
case MENU_STATE_MAJOR_LOADING_CARDS :
|
||||
if (primitivesLoadCounter == -1) listPrimitives();
|
||||
if (primitivesLoadCounter < (int)(primitives.size())){
|
||||
mParent->collection->load(primitives[primitivesLoadCounter].c_str() );
|
||||
primitivesLoadCounter++;
|
||||
break;
|
||||
}
|
||||
primitivesLoadCounter = primitives.size() + 1;
|
||||
if (mReadConf){
|
||||
mParent->collection->load(mCurrentSetFileName, mCurrentSetName);
|
||||
}else{
|
||||
@@ -342,6 +369,13 @@ void GameStateMenu::Update(float dt)
|
||||
//Remove temporary translations
|
||||
Translator::GetInstance()->tempValues.clear();
|
||||
|
||||
//Debug
|
||||
#ifdef _DEBUG
|
||||
char buf[4096];
|
||||
sprintf(buf, "\n==\nTotal MTGCard: %i\nTotal CardPrimitives: %i\n==\n", mParent->collection->collection.size(), mParent->collection->primitives.size());
|
||||
OutputDebugString(buf);
|
||||
#endif
|
||||
|
||||
//Force default, if necessary.
|
||||
if(options[Options::ACTIVE_PROFILE].str == "")
|
||||
options[Options::ACTIVE_PROFILE].str = "Default";
|
||||
@@ -488,7 +522,10 @@ void GameStateMenu::Render()
|
||||
if (mCurrentSetName[0]) {
|
||||
sprintf(text, _("LOADING SET: %s").c_str(), mCurrentSetName);
|
||||
}else{
|
||||
sprintf(text,"LOADING...");
|
||||
if (primitivesLoadCounter <= (int)(primitives.size()))
|
||||
sprintf(text,"LOADING PRIMITIVES");
|
||||
else
|
||||
sprintf(text,"LOADING...");
|
||||
}
|
||||
mFont->DrawString(text,SCREEN_WIDTH/2,SCREEN_HEIGHT/2,JGETEXT_CENTER);
|
||||
}else{
|
||||
|
||||
@@ -903,7 +903,7 @@ int AbilityFactory::getAbilities(vector<MTGAbility *> * v, Spell * spell, MTGCar
|
||||
if (card->alias && magicText.size() == 0 && !dest){
|
||||
MTGCard * c = GameApp::collection->getCardById(card->alias);
|
||||
if (!c) return 0;
|
||||
magicText = c->magicText;
|
||||
magicText = c->data->magicText;
|
||||
}
|
||||
string line;
|
||||
int size = magicText.size();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "../include/MTGDeck.h"
|
||||
#include "../include/config.h"
|
||||
#include "../include/MTGCard.h"
|
||||
#include "../include/CardPrimitive.h"
|
||||
#include "../include/Subtypes.h"
|
||||
#include "../include/Translate.h"
|
||||
|
||||
@@ -23,161 +24,23 @@ MTGCard::MTGCard(int set_id){
|
||||
setId = set_id;
|
||||
}
|
||||
MTGCard::MTGCard(MTGCard * source){
|
||||
for(map<int,int>::const_iterator it = source->basicAbilities.begin(); it != source->basicAbilities.end(); ++it){
|
||||
basicAbilities[it->first] = source->basicAbilities[it->first];
|
||||
}
|
||||
|
||||
for (int i = 0; i< MAX_TYPES_PER_CARD; i++){
|
||||
types[i] = source->types[i];
|
||||
}
|
||||
nb_types = source->nb_types;
|
||||
for (int i = 0; i< Constants::MTG_NB_COLORS; i++){
|
||||
colors[i] = source->colors[i];
|
||||
}
|
||||
manaCost.copy(source->getManaCost());
|
||||
|
||||
text = source->text;
|
||||
setName(source->name);
|
||||
strcpy(image_name, source->image_name);
|
||||
|
||||
rarity = source->rarity;
|
||||
power = source->power;
|
||||
toughness = source->toughness;
|
||||
mtgid = source->mtgid;
|
||||
setId = source->setId;
|
||||
magicText = source->magicText;
|
||||
for(map<string,string>::const_iterator it = source->magicTexts.begin(); it != source->magicTexts.end(); ++it){
|
||||
magicTexts[it->first] = source->magicTexts[it->first];
|
||||
}
|
||||
spellTargetType = source->spellTargetType;
|
||||
alias = source->alias;
|
||||
data = source->data;
|
||||
|
||||
}
|
||||
|
||||
int MTGCard::init(){
|
||||
nb_types = 0;
|
||||
basicAbilities.clear();
|
||||
|
||||
for (int i = 0; i< MAX_TYPES_PER_CARD; i++){
|
||||
types[i] = 0;
|
||||
}
|
||||
for (int i = 0; i< Constants::MTG_NB_COLORS; i++){
|
||||
colors[i] = 0;
|
||||
}
|
||||
setId = 0;
|
||||
mtgid = 0;
|
||||
magicText = "";
|
||||
magicTexts.clear();
|
||||
spellTargetType = "";
|
||||
alias = 0;
|
||||
data = NULL;
|
||||
rarity = Constants::RARITY_C;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const vector<string>& MTGCard::formattedText()
|
||||
{
|
||||
if (ftdText.empty())
|
||||
{
|
||||
std::string s = _(text);
|
||||
std::string::size_type found = s.find_first_of("{}");
|
||||
while (found!=string::npos)
|
||||
{
|
||||
s[found] = '/';
|
||||
found = s.find_first_of("{}", found + 1);
|
||||
}
|
||||
std::string::size_type len = 30;
|
||||
while (s.length() > 0)
|
||||
{
|
||||
std::string::size_type cut = s.find_first_of("., \t)", 0);
|
||||
if (cut >= len || cut == string::npos)
|
||||
{
|
||||
ftdText.push_back(s.substr(0,len));
|
||||
if (s.length() > len)
|
||||
s = s.substr(len, s.length() - len);
|
||||
else
|
||||
s = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string::size_type newcut = cut;
|
||||
while (newcut < len && newcut != string::npos)
|
||||
{
|
||||
cut = newcut;
|
||||
newcut = s.find_first_of("., \t)", newcut + 1);
|
||||
}
|
||||
ftdText.push_back(s.substr(0,cut+1));
|
||||
if (s.length() > cut+1)
|
||||
s = s.substr(cut+1,s.length() - cut - 1);
|
||||
else
|
||||
s = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
return ftdText;
|
||||
}
|
||||
|
||||
|
||||
bool MTGCard::isCreature(){
|
||||
return hasSubtype(Subtypes::TYPE_CREATURE);
|
||||
}
|
||||
bool MTGCard::isLand(){
|
||||
return hasSubtype(Subtypes::TYPE_LAND);
|
||||
}
|
||||
bool MTGCard::isSpell(){
|
||||
return (!isCreature() && !isLand());
|
||||
}
|
||||
|
||||
void MTGCard::setColor(string _color, int removeAllOthers){
|
||||
if(_color.compare("blue")==0) return setColor(Constants::MTG_COLOR_BLUE,removeAllOthers);
|
||||
if(_color.compare("red")==0) return setColor(Constants::MTG_COLOR_RED,removeAllOthers);
|
||||
if(_color.compare("green")==0) return setColor(Constants::MTG_COLOR_GREEN,removeAllOthers);
|
||||
if(_color.compare("black")==0) return setColor(Constants::MTG_COLOR_BLACK,removeAllOthers);
|
||||
if(_color.compare("white")==0) return setColor(Constants::MTG_COLOR_WHITE,removeAllOthers);
|
||||
}
|
||||
|
||||
void MTGCard::setColor(int _color, int removeAllOthers){
|
||||
if (removeAllOthers){
|
||||
for (int i=0; i<Constants::MTG_NB_COLORS; i++){
|
||||
colors[i] = 0;
|
||||
}
|
||||
}
|
||||
colors[_color] = 1;
|
||||
}
|
||||
|
||||
void MTGCard::removeColor(int _color){
|
||||
colors[_color] = 0;
|
||||
}
|
||||
|
||||
int MTGCard::getColor(){
|
||||
for (int i=1; i<Constants::MTG_NB_COLORS; i++){
|
||||
if (colors[i]){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int MTGCard::hasColor(int color){
|
||||
return (colors[color]);
|
||||
}
|
||||
|
||||
int MTGCard::countColors(){
|
||||
int result = 0;
|
||||
for(int i=Constants::MTG_COLOR_GREEN;i<=Constants::MTG_COLOR_WHITE;i++){
|
||||
if (hasColor(i)) result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void MTGCard::setManaCost(string s){
|
||||
ManaCost::parseManaCost(s, &manaCost);
|
||||
for (int i = Constants::MTG_COLOR_GREEN; i <= Constants::MTG_COLOR_WHITE; i++){
|
||||
if (manaCost.hasColor(i)){
|
||||
setColor(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MTGCard::setMTGId(int id){
|
||||
mtgid = id;
|
||||
@@ -203,145 +66,10 @@ void MTGCard::setRarity(char _rarity){
|
||||
rarity = _rarity;
|
||||
}
|
||||
|
||||
void MTGCard::setType(const char * _type_text){
|
||||
setSubtype(_type_text);
|
||||
}
|
||||
|
||||
void MTGCard::addType(char * _type_text){
|
||||
setSubtype(_type_text);
|
||||
}
|
||||
|
||||
void MTGCard::setSubtype( string value){
|
||||
int id = Subtypes::subtypesList->find(value);
|
||||
addType(id);
|
||||
}
|
||||
|
||||
void MTGCard::addType(int id){
|
||||
types[nb_types] = id;
|
||||
nb_types++;
|
||||
}
|
||||
|
||||
|
||||
//TODO Definitely move some of these functions to MTGCardInstance. There is no reason to remove a type from an MTGCard since they represent the Database
|
||||
//Removes a type from the types of a given card
|
||||
//If removeAll is true, removes all occurences of this type, otherwise only removes the first occurence
|
||||
int MTGCard::removeType(string value, int removeAll){
|
||||
|
||||
int id = Subtypes::subtypesList->find(value);
|
||||
return removeType(id, removeAll);
|
||||
}
|
||||
|
||||
int MTGCard::removeType(int id, int removeAll){
|
||||
int result = 0;
|
||||
for (int i = nb_types -1 ; i >=0; i--){
|
||||
if (types[i] == id){
|
||||
types[i] = types[nb_types -1];
|
||||
nb_types--;
|
||||
result++;
|
||||
if (!removeAll) return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
char * MTGCard::getImageName(){
|
||||
return image_name;
|
||||
}
|
||||
|
||||
|
||||
void MTGCard::setText( string value){
|
||||
text = value;
|
||||
}
|
||||
|
||||
const char * MTGCard::getText(){
|
||||
return text.c_str();
|
||||
}
|
||||
|
||||
void MTGCard::addMagicText(string value){
|
||||
std::transform( value.begin(), value.end(), value.begin(),::tolower );
|
||||
if (magicText.size()) magicText.append("\n");
|
||||
magicText.append(value);
|
||||
}
|
||||
|
||||
void MTGCard::addMagicText(string value, string key){
|
||||
std::transform( value.begin(), value.end(), value.begin(),::tolower );
|
||||
if (magicTexts[key].size()) magicTexts[key].append("\n");
|
||||
magicTexts[key].append(value);
|
||||
}
|
||||
|
||||
void MTGCard::setName( string value){
|
||||
name = value;
|
||||
lcname = value;
|
||||
std::transform( lcname.begin(), lcname.end(),lcname.begin(),::tolower );
|
||||
//This is a bug fix for plague rats and the "foreach ability"
|
||||
//Right now we add names as types, so that they get recognized
|
||||
if (lcname.at(value.length()-1) == 's') Subtypes::subtypesList->find(lcname);
|
||||
}
|
||||
|
||||
const string MTGCard::getName() const{
|
||||
return name;
|
||||
}
|
||||
|
||||
const string MTGCard::getLCName() const{
|
||||
return lcname;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ManaCost* MTGCard::getManaCost(){
|
||||
return &manaCost;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool MTGCard::hasType(int _type){
|
||||
for (int i = 0; i<nb_types; i++)
|
||||
if (types[i] == _type)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MTGCard::hasSubtype(int _subtype){
|
||||
return hasType(_subtype);
|
||||
}
|
||||
|
||||
bool MTGCard::hasType(const char * _type){
|
||||
int id = Subtypes::subtypesList->find(_type);
|
||||
return hasType(id);
|
||||
}
|
||||
|
||||
|
||||
bool MTGCard::hasSubtype(const char * _subtype){
|
||||
int id = Subtypes::subtypesList->find(_subtype);
|
||||
return hasType(id);
|
||||
}
|
||||
|
||||
bool MTGCard::hasSubtype(string _subtype){
|
||||
int id = Subtypes::subtypesList->find(_subtype);
|
||||
return hasType(id);
|
||||
}
|
||||
|
||||
|
||||
int MTGCard::has(int basicAbility){
|
||||
return basicAbilities[basicAbility];
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
// Creature specific
|
||||
//---------------------------------------------
|
||||
void MTGCard::setPower(int _power){
|
||||
power = _power;
|
||||
}
|
||||
|
||||
int MTGCard::getPower(){
|
||||
return power;
|
||||
}
|
||||
|
||||
void MTGCard::setToughness(int _toughness){
|
||||
toughness = _toughness;
|
||||
}
|
||||
|
||||
int MTGCard::getToughness(){
|
||||
return toughness;
|
||||
}
|
||||
void MTGCard::setPrimitive(CardPrimitive * cp){
|
||||
data = cp;
|
||||
}
|
||||
@@ -19,12 +19,12 @@ MTGCardInstance MTGCardInstance::ExtraRules[] = {MTGCardInstance(), MTGCardInsta
|
||||
|
||||
|
||||
|
||||
MTGCardInstance::MTGCardInstance(): MTGCard(), Damageable(0), view(NULL){
|
||||
MTGCardInstance::MTGCardInstance(): CardPrimitive(), MTGCard(), Damageable(0), view(NULL){
|
||||
LOG("==Creating MTGCardInstance==");
|
||||
initMTGCI();
|
||||
LOG("==Creating MTGCardInstance Successful==");
|
||||
}
|
||||
MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to): MTGCard(card), Damageable(card->getToughness()), view(NULL){
|
||||
MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to): CardPrimitive(card->data),MTGCard(card), Damageable(card->data->getToughness()), view(NULL){
|
||||
LOG("==Creating MTGCardInstance==");
|
||||
initMTGCI();
|
||||
model = card;
|
||||
@@ -43,30 +43,30 @@ MTGCardInstance::MTGCardInstance(MTGCard * card, MTGPlayerCards * arg_belongs_to
|
||||
|
||||
void MTGCardInstance::copy(MTGCardInstance * card){
|
||||
MTGCard * source = card->model;
|
||||
for(map<int,int>::const_iterator it = source->basicAbilities.begin(); it != source->basicAbilities.end(); ++it){
|
||||
CardPrimitive * data = source->data;
|
||||
for(map<int,int>::const_iterator it = data->basicAbilities.begin(); it != data->basicAbilities.end(); ++it){
|
||||
int i = it->first;
|
||||
basicAbilities[i] = source->basicAbilities[i];
|
||||
basicAbilities[i] = data->basicAbilities[i];
|
||||
}
|
||||
for (int i = 0; i< MAX_TYPES_PER_CARD; i++){
|
||||
types[i] = source->types[i];
|
||||
for (size_t i = 0; i< data->types.size(); i++){
|
||||
types.push_back(data->types[i]);
|
||||
}
|
||||
nb_types = source->nb_types;
|
||||
for (int i = 0; i< Constants::MTG_NB_COLORS; i++){
|
||||
colors[i] = source->colors[i];
|
||||
colors[i] = data->colors[i];
|
||||
}
|
||||
manaCost.copy(source->getManaCost());
|
||||
manaCost.copy(data->getManaCost());
|
||||
|
||||
text = source->text;
|
||||
setName(source->name);
|
||||
text = data->text;
|
||||
setName(data->name);
|
||||
|
||||
power = source->power;
|
||||
toughness = source->toughness;
|
||||
power = data->power;
|
||||
toughness = data->toughness;
|
||||
life = toughness;
|
||||
lifeOrig = life;
|
||||
|
||||
magicText = source->magicText;
|
||||
spellTargetType = source->spellTargetType;
|
||||
alias = source->alias;
|
||||
magicText = data->magicText;
|
||||
spellTargetType = data->spellTargetType;
|
||||
alias = data->alias;
|
||||
|
||||
//Now this is dirty...
|
||||
int backupid = mtgid;
|
||||
@@ -86,6 +86,14 @@ MTGCardInstance::~MTGCardInstance(){
|
||||
SAFE_DELETE(previous);
|
||||
LOG("==Deleting MTGCardInstance Succesfull==");
|
||||
}
|
||||
|
||||
int MTGCardInstance::init(){
|
||||
MTGCard::init();
|
||||
CardPrimitive::init();
|
||||
data = this;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void MTGCardInstance::initMTGCI(){
|
||||
sample = "";
|
||||
model=NULL;
|
||||
@@ -110,6 +118,7 @@ void MTGCardInstance::initMTGCI(){
|
||||
regenerateTokens = 0;
|
||||
blocked = false;
|
||||
currentZone = NULL;
|
||||
data = this; //an MTGCardInstance point to itself for data, allows to update it without killing the underlying database item
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +128,7 @@ const string MTGCardInstance::getDisplayName() const {
|
||||
|
||||
void MTGCardInstance::addType(int type){
|
||||
bool before = hasType(type);
|
||||
MTGCard::addType(type);
|
||||
CardPrimitive::addType(type);
|
||||
WEvent * e = NEW WEventCardChangeType(this,type,before,true);
|
||||
GameObserver::GetInstance()->receiveEvent(e);
|
||||
}
|
||||
@@ -143,7 +152,7 @@ int MTGCardInstance::removeType(string value,int removeAll){
|
||||
|
||||
int MTGCardInstance::removeType(int id, int removeAll){
|
||||
bool before = hasType(id);
|
||||
int result = MTGCard::removeType(id,removeAll);
|
||||
int result = CardPrimitive::removeType(id,removeAll);
|
||||
bool after = hasType(id);
|
||||
WEvent * e = NEW WEventCardChangeType(this,id,before,after);
|
||||
GameObserver::GetInstance()->receiveEvent(e);
|
||||
@@ -567,7 +576,7 @@ JSample * MTGCardInstance::getSample(){
|
||||
if(sample.size())
|
||||
return resources.RetrieveSample(sample);
|
||||
|
||||
for (int i = nb_types-1; i>0; i--){
|
||||
for (int i = types.size()-1; i>0; i--){
|
||||
string type = Subtypes::subtypesList->find(types[i]);
|
||||
type = type + ".wav";
|
||||
js = resources.RetrieveSample(type);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../include/Translate.h"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
using std::string;
|
||||
|
||||
#include <JGE.h>
|
||||
@@ -13,13 +14,13 @@ using std::string;
|
||||
#endif
|
||||
|
||||
//MTGAllCards
|
||||
int MTGAllCards::processConfLine(string s, MTGCard *card){
|
||||
int MTGAllCards::processConfLine(string s, MTGCard *card, CardPrimitive * primitive){
|
||||
unsigned int i = s.find_first_of("=");
|
||||
if (i == string::npos){
|
||||
#if defined (_DEBUG)
|
||||
if (s.size() && s[0] == '#') return 0;
|
||||
char buffer[4096];
|
||||
sprintf(buffer, "MTGDECK: Bad Line in %s/_cards.dat:\n %s\n", setlist[card->setId].c_str(), s.c_str());
|
||||
sprintf(buffer, "MTGDECK: Bad Line:\n %s\n", s.c_str());
|
||||
OutputDebugString(buffer);
|
||||
#endif
|
||||
return 0;
|
||||
@@ -28,21 +29,27 @@ int MTGAllCards::processConfLine(string s, MTGCard *card){
|
||||
string value = s.substr(i+1);
|
||||
|
||||
if(key.compare( "auto")==0){
|
||||
card->addMagicText(value);
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
primitive->addMagicText(value);
|
||||
}
|
||||
else if(key.find("auto") == 0){
|
||||
card->addMagicText(value,key.substr(4));
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
primitive->addMagicText(value,key.substr(4));
|
||||
}
|
||||
else if(key.compare( "alias")==0){
|
||||
card->alias=atoi(value.c_str());
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
primitive->alias=atoi(value.c_str());
|
||||
}
|
||||
else if(key.compare( "target")==0){
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
std::transform( value.begin(), value.end(), value.begin(),::tolower );
|
||||
card->spellTargetType=value;
|
||||
primitive->spellTargetType=value;
|
||||
}
|
||||
else if(key.compare( "text")==0){
|
||||
card->setText(value);
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
primitive->setText(value);
|
||||
}else if (key.compare("abilities")==0){
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
//Specific Abilities
|
||||
std::transform( value.begin(), value.end(), value.begin(),::tolower );
|
||||
while (value.size()){
|
||||
@@ -58,94 +65,111 @@ int MTGAllCards::processConfLine(string s, MTGCard *card){
|
||||
for (int j = Constants::NB_BASIC_ABILITIES-1; j >=0 ; j--){
|
||||
size_t found = attribute.find(Constants::MTGBasicAbilities[j]);
|
||||
if (found != string::npos){
|
||||
card->basicAbilities[j] = 1;
|
||||
primitive->basicAbilities[j] = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(key.compare("id")==0){
|
||||
if (!card) card = NEW MTGCard();
|
||||
card->setMTGId(atoi(value.c_str()));
|
||||
}else if(key.compare("name")==0){
|
||||
card->setName(value);
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
primitive->setName(value);
|
||||
}else if(key.compare("rarity")==0){
|
||||
if (!card) card = NEW MTGCard();
|
||||
card->setRarity (value.c_str()[0]);
|
||||
}else if(key.compare("mana")==0){
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
std::transform( value.begin(), value.end(), value.begin(),::tolower );
|
||||
card->setManaCost(value);
|
||||
primitive->setManaCost(value);
|
||||
} else if(key.compare("color")==0){
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
std::transform( value.begin(), value.end(), value.begin(),::tolower );
|
||||
card->setColor(value,1);
|
||||
primitive->setColor(value,1);
|
||||
}else if(key.compare("type")==0){
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
switch(value.c_str()[0]){
|
||||
case 'C':
|
||||
case 'c':
|
||||
card->setType( "Creature");
|
||||
primitive->setType( "Creature");
|
||||
break;
|
||||
case 'A':
|
||||
case 'a':
|
||||
card->setType( "Artifact");
|
||||
card->setColor(Constants::MTG_COLOR_ARTIFACT);
|
||||
primitive->setType( "Artifact");
|
||||
primitive->setColor(Constants::MTG_COLOR_ARTIFACT);
|
||||
if (value.c_str()[8] == ' ' && value.c_str()[9] == 'C')
|
||||
card->setSubtype("Creature");
|
||||
primitive->setSubtype("Creature");
|
||||
break;
|
||||
case 'E':
|
||||
case 'e':
|
||||
card->setType( "Enchantment");
|
||||
primitive->setType( "Enchantment");
|
||||
break;
|
||||
case 'S':
|
||||
case 's':
|
||||
card->setType( "Sorcery");
|
||||
primitive->setType( "Sorcery");
|
||||
break;
|
||||
case 'B'://Basic Land
|
||||
case 'b':
|
||||
card->setColor(Constants::MTG_COLOR_LAND);
|
||||
card->setType("Land");
|
||||
card->setType("Basic");
|
||||
primitive->setColor(Constants::MTG_COLOR_LAND);
|
||||
primitive->setType("Land");
|
||||
primitive->setType("Basic");
|
||||
break;
|
||||
case 'L':
|
||||
case 'l':
|
||||
card->setColor(Constants::MTG_COLOR_LAND);
|
||||
card->setType( "Land");
|
||||
primitive->setColor(Constants::MTG_COLOR_LAND);
|
||||
primitive->setType( "Land");
|
||||
break;
|
||||
case 'I':
|
||||
case 'i':
|
||||
card->setType( "Instant");
|
||||
primitive->setType( "Instant");
|
||||
break;
|
||||
default:
|
||||
card->setType( "Error");
|
||||
primitive->setType( "Error");
|
||||
#if defined (_DEBUG)
|
||||
char buffer[4096];
|
||||
sprintf(buffer, "MTGDECK: Bad Card Type in %s/_cards.dat:\n %s\n", setlist[card->setId].c_str(), s.c_str());
|
||||
OutputDebugString(buffer);
|
||||
if (primitive) {
|
||||
char buffer[4096];
|
||||
sprintf(buffer, "MTGDECK: Bad Card Type\n %s\n", s.c_str());
|
||||
OutputDebugString(buffer);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
}
|
||||
}else if(key.compare("power")==0){
|
||||
card->setPower (atoi(value.c_str()));
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
primitive->setPower (atoi(value.c_str()));
|
||||
}else if(key.compare("subtype")==0){
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
while (value.size()){
|
||||
unsigned int found = value.find(" ");
|
||||
if (found != string::npos){
|
||||
card->setSubtype(value.substr(0,found));
|
||||
primitive->setSubtype(value.substr(0,found));
|
||||
value = value.substr(found+1);
|
||||
}else{
|
||||
card->setSubtype(value);
|
||||
primitive->setSubtype(value);
|
||||
value = "";
|
||||
}
|
||||
}
|
||||
}else if(key.compare("toughness")==0){
|
||||
card->setToughness(atoi(value.c_str()));
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
primitive->setToughness(atoi(value.c_str()));
|
||||
}else if(key.compare("kicker")==0){
|
||||
if(!primitive) primitive = NEW CardPrimitive();
|
||||
std::transform( value.begin(), value.end(), value.begin(),::tolower );
|
||||
if (ManaCost * cost = card->getManaCost()){
|
||||
if (ManaCost * cost = primitive->getManaCost()){
|
||||
cost->kicker = ManaCost::parseManaCost(value);
|
||||
}
|
||||
}else if(key.compare("primitive")==0){
|
||||
if(!card) card = NEW MTGCard();
|
||||
card->setPrimitive(primitives[value]);
|
||||
}else{
|
||||
string error = "MTGDECK Parsing Error:" + s + "\n";
|
||||
OutputDebugString(error.c_str());
|
||||
}
|
||||
|
||||
tempPrimitive = primitive;
|
||||
tempCard = card;
|
||||
|
||||
return i;
|
||||
|
||||
@@ -159,18 +183,18 @@ void MTGAllCards::initCounters(){
|
||||
|
||||
void MTGAllCards::init(){
|
||||
tempCard = NULL;
|
||||
tempPrimitive = NULL;
|
||||
total_cards = 0;
|
||||
initCounters();
|
||||
#if defined (_DEBUG)
|
||||
committed = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
int MTGAllCards::load(const char * config_file, const char * set_name,int autoload){
|
||||
conf_read_mode = 0;
|
||||
int set_id = setlist.Add(set_name);
|
||||
int set_id = 0;
|
||||
|
||||
if (set_name) set_id = setlist.Add(set_name);
|
||||
|
||||
std::ifstream setFile(config_file);
|
||||
|
||||
@@ -190,13 +214,15 @@ MTGAllCards::~MTGAllCards(){
|
||||
}
|
||||
|
||||
void MTGAllCards::destroyAllCards(){
|
||||
map<int,MTGCard *>::iterator it;
|
||||
|
||||
for (it = collection.begin(); it!=collection.end(); it++) delete(it->second);
|
||||
|
||||
|
||||
for (map<int,MTGCard *>::iterator it = collection.begin(); it!=collection.end(); it++) delete(it->second);
|
||||
collection.clear();
|
||||
ids.clear();
|
||||
|
||||
for (map<string,CardPrimitive *>::iterator it = primitives.begin(); it!=primitives.end(); it++) delete(it->second);
|
||||
primitives.clear();
|
||||
|
||||
}
|
||||
|
||||
MTGAllCards::MTGAllCards(const char * config_file, const char * set_name){
|
||||
@@ -232,7 +258,7 @@ int MTGAllCards::countByType(const char * _type){
|
||||
map<int,MTGCard *>::iterator it;
|
||||
for (it = collection.begin(); it!=collection.end(); it++){
|
||||
MTGCard * c = it->second;
|
||||
if(c->hasType(_type)){
|
||||
if(c->data->hasType(_type)){
|
||||
result++;
|
||||
}
|
||||
}
|
||||
@@ -248,7 +274,7 @@ int MTGAllCards::countByColor(int color){
|
||||
map<int,MTGCard *>::iterator it;
|
||||
for (it = collection.begin(); it!=collection.end(); it++){
|
||||
MTGCard * c = it->second;
|
||||
int j = c->getColor();
|
||||
int j = c->data->getColor();
|
||||
|
||||
colorsCount[j]++;
|
||||
}
|
||||
@@ -260,6 +286,58 @@ int MTGAllCards::totalCards(){
|
||||
return (total_cards);
|
||||
}
|
||||
|
||||
bool MTGAllCards::addCardToCollection(MTGCard * card, int setId){
|
||||
card->setId = setId;
|
||||
int newId = card->getId();
|
||||
if (collection.find(newId) != collection.end()){
|
||||
char outBuf[4096];
|
||||
sprintf(outBuf,"warning, card id collision! : %i\n", newId);
|
||||
OutputDebugString (outBuf);
|
||||
SAFE_DELETE(card);
|
||||
return false;
|
||||
}
|
||||
|
||||
ids.push_back(newId);
|
||||
|
||||
collection[newId] = card; //Push card into collection.
|
||||
MTGSetInfo * si = setlist.getInfo(setId);
|
||||
if(si)
|
||||
si->count(card); //Count card in set info
|
||||
|
||||
total_cards++;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool MTGAllCards::addPrimitive(CardPrimitive * primitive, MTGCard * card){
|
||||
string key;
|
||||
if (card) {
|
||||
std::stringstream ss;
|
||||
ss << card->getId();
|
||||
ss >> key;
|
||||
}
|
||||
else key = primitive->name;
|
||||
if (primitives.find(key) != primitives.end()){
|
||||
//ERROR
|
||||
//Todo move the deletion somewhere else ?
|
||||
#ifdef _DEBUG
|
||||
OutputDebugString("MTGDECK: primitives conflict:");
|
||||
OutputDebugString(key.c_str());
|
||||
OutputDebugString("\n");
|
||||
SAFE_DELETE(primitive);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
//translate cards text
|
||||
Translator * t = Translator::GetInstance();
|
||||
map<string,string>::iterator it = t->tempValues.find(primitive->name);
|
||||
if (it != t->tempValues.end()) {
|
||||
primitive->setText(it->second);
|
||||
}
|
||||
primitives[key] = primitive;
|
||||
return true;
|
||||
}
|
||||
|
||||
int MTGAllCards::readConfLine(std::ifstream &file, int set_id){
|
||||
|
||||
@@ -271,47 +349,22 @@ int MTGAllCards::readConfLine(std::ifstream &file, int set_id){
|
||||
switch(conf_read_mode) {
|
||||
case 0:
|
||||
if (s[0] == '['){
|
||||
#if defined (_DEBUG)
|
||||
if (tempCard && !committed){
|
||||
OutputDebugString("MTGDECK: Card not committed before creating new one, Memory leak risk\n ");
|
||||
OutputDebugString(tempCard->getName().c_str());
|
||||
OutputDebugString("\n");
|
||||
}
|
||||
committed = false;
|
||||
#endif
|
||||
tempCard = NEW MTGCard(set_id);
|
||||
conf_read_mode = 1;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (s[0] == '[' && s[1] == '/'){
|
||||
conf_read_mode = 0;
|
||||
int newId = tempCard->getId();
|
||||
if (collection.find(newId) != collection.end()){
|
||||
char outBuf[4096];
|
||||
sprintf(outBuf,"warning, card id collision! : %i - %s\n", newId, tempCard->name.c_str());
|
||||
OutputDebugString (outBuf);
|
||||
SAFE_DELETE(tempCard);
|
||||
}else{
|
||||
ids.push_back(newId);
|
||||
//translate cards text
|
||||
Translator * t = Translator::GetInstance();
|
||||
map<string,string>::iterator it = t->tempValues.find(tempCard->name);
|
||||
if (it != t->tempValues.end()) {
|
||||
tempCard->setText(it->second);
|
||||
}
|
||||
collection[newId] = tempCard; //Push card into collection.
|
||||
MTGSetInfo * si = setlist.getInfo(set_id);
|
||||
if(si)
|
||||
si->count(tempCard); //Count card in set info
|
||||
|
||||
total_cards++;
|
||||
#if defined (_DEBUG)
|
||||
committed = true;
|
||||
#endif
|
||||
if (tempPrimitive) addPrimitive (tempPrimitive,tempCard);
|
||||
if (tempCard){
|
||||
addCardToCollection(tempCard, set_id);
|
||||
if (tempPrimitive) tempCard->setPrimitive(tempPrimitive);
|
||||
}
|
||||
tempCard = NULL;
|
||||
tempPrimitive = NULL;
|
||||
|
||||
}else{
|
||||
processConfLine(s, tempCard);
|
||||
processConfLine(s, tempCard, tempPrimitive);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -354,7 +407,7 @@ MTGCard * MTGAllCards::getCardByName(string name){
|
||||
for (it = collection.begin(); it!=collection.end(); it++){
|
||||
MTGCard * c = it->second;
|
||||
if (setId!=-1 && setId != c->setId) continue;
|
||||
string cardName = c->name;
|
||||
string cardName = c->data->name;
|
||||
std::transform(cardName.begin(), cardName.end(), cardName.begin(),::tolower );
|
||||
if (cardName.compare(name) == 0) return c;
|
||||
|
||||
@@ -462,7 +515,7 @@ int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, c
|
||||
MTGCard * card = database->_(i);
|
||||
int r = card->getRarity();
|
||||
if (r != Constants::RARITY_T && (rarity == -1 || r==rarity) &&
|
||||
(!_subtype || card->hasSubtype(subtype))
|
||||
(!_subtype || card->data->hasSubtype(subtype))
|
||||
){
|
||||
int ok = 0;
|
||||
|
||||
@@ -476,7 +529,7 @@ int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, c
|
||||
|
||||
if (ok){
|
||||
for (int j=0; j < Constants::MTG_NB_COLORS; ++j){
|
||||
if (unallowedColors[j] && card->hasColor(j)){
|
||||
if (unallowedColors[j] && card->data->hasColor(j)){
|
||||
ok = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ int MTGBlockRule::reactToClick(MTGCardInstance * card){
|
||||
currentOpponent = game->currentPlayer->game->inPlay->getNextAttacker(currentOpponent);
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
char buf[4096];
|
||||
sprintf(buf,"Defenser Toggle %s \n", card->model->getName().c_str());
|
||||
sprintf(buf,"Defenser Toggle %s \n", card->getName().c_str());
|
||||
OutputDebugString(buf);
|
||||
#endif
|
||||
candefend = card->toggleDefenser(currentOpponent);
|
||||
@@ -258,8 +258,8 @@ MTGMomirRule::MTGMomirRule(int _id, MTGAllCards * _collection):MTGAbility(_id, N
|
||||
if (!initialized){
|
||||
for (size_t i = 0; i < collection->ids.size(); i++){
|
||||
MTGCard * card = collection->collection[collection->ids[i]];
|
||||
if (card->isCreature()){
|
||||
int convertedCost = card->getManaCost()->getConvertedCost();
|
||||
if (card->data->isCreature()){
|
||||
int convertedCost = card->data->getManaCost()->getConvertedCost();
|
||||
if (convertedCost>20) continue;
|
||||
pool[convertedCost].push_back(card->getMTGId());
|
||||
}
|
||||
|
||||
@@ -130,10 +130,10 @@ void ShopItem::Render(){
|
||||
if (card){
|
||||
if (nameCount){
|
||||
char buffer[512];
|
||||
sprintf(buffer, "%s (%i)", _(card->name).c_str(), nameCount );
|
||||
sprintf(buffer, "%s (%i)", _(card->data->name).c_str(), nameCount );
|
||||
mText = buffer;
|
||||
}else{
|
||||
mText = _(card->name).c_str();
|
||||
mText = _(card->data->name).c_str();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9,00"
|
||||
Version="9.00"
|
||||
Name="mtg"
|
||||
ProjectGUID="{53024371-2293-4D40-8ECF-FCB470B50DA1}"
|
||||
TargetFrameworkVersion="131072"
|
||||
@@ -354,6 +354,10 @@
|
||||
RelativePath=".\src\CardGui.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\CardPrimitive.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\CardSelector.cpp"
|
||||
>
|
||||
@@ -761,6 +765,10 @@
|
||||
RelativePath=".\include\CardGui.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\CardPrimitive.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\CardSelector.h"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user