Class Reference problem

If you have a question about the SVN and the code, or if you have code to propose then please post in this forum.
Do not post request here.

Class Reference problem

Postby rodrigo.demoura » Tue Apr 26, 2011 1:33 pm

Guys I have a stupid question

I'm trying to create a rule that all first and second main, the game check if there are active creatures in play.

I have included a new instance GameObserver in class but I can not access the function.

Code: Select all
GameObserver.h

public:
     void activeCreature();


Code: Select all
GameObserver.cpp
...
...
...
void GameObserver::NextGamePhase ()
{
...
...
...
case Constants::MTG_PHASE_FIRSTMAIN:
   activeCreature();
   break;
...
...
...
}
void GameObserver::activeCreature()
{
}


When I debug the code it does not go to class
when I watch the Function refer to gameapp::Resume(void)
what I doing wrong :?:
rodrigo.demoura
 
Posts: 46
Joined: Wed Jun 02, 2010 6:31 pm

Re: Class Reference problem

Postby wololo » Wed Apr 27, 2011 10:07 am

looking at the code this should work, did you try to set breakpoints? There are many cases where this could be returning before reaching this part of the code...
Also what are your settings for phase skip automation? I'm always worried about the side effects of that function
wololo
Site Admin
 
Posts: 3709
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: Class Reference problem

Postby Zethfox » Wed Apr 27, 2011 11:34 am

put it in gameobserver::gameStateBasedEffects()

that is where that check belongs, it should look like this....

if (currentGamePhase == Constants::MTG_PHASE_FIRSTMAIN || currentGamePhase == Constants::MTG_PHASE_SECONDMAIN)
{
activeCreature(currentPlayer);
}

have activeCreature contain a variable...
void GameObserver::activeCreature(Player * player)
{
if(!player)
return;
if(player->countCardByType("creature") < 1)
gameOver = player;//exact code......
}
and declare it in activeCreature()

GameObserver.h
public:
void activeCreature(Player * player = NULL);

this should go most likely above the "player life checks" in that section.

the reason i say it belongs there is becuase it is a statebased effect to determine winning or losing...
if a player at ANY POINT, doesn't have an active creature, then they lose.
i would even go as far as removing it from the if statement, and running it every update cycle.
Zethfox
 
Posts: 2785
Joined: Thu Jun 10, 2010 11:28 pm

Re: Class Reference problem

Postby wololo » Wed Apr 27, 2011 11:42 am

Zethfox wrote:put it in gameobserver::gameStateBasedEffects()

that is where that check belongs, it should look like this....


A bit off topic but I'm not a big fan of this function, as you know. It's super expensive and running every frame. I personally wouldn't suggest anybody to add anything to this function that I plan to deprecate at some point.
There are much more clever ways to check for the lack of creatures accurately without doing it every frame, through events. For example call the function everytime a card moves in or out of the Battlefield. That's much much more efficient.

Lot's of people nowadays tend to believe that you can solve everything with more ram and cpu power, forgetting that there are efficient and inefficient ways to do things ;)
wololo
Site Admin
 
Posts: 3709
Joined: Wed Oct 15, 2008 12:42 am
Location: Japan

Re: Class Reference problem

Postby rodrigo.demoura » Wed Apr 27, 2011 4:55 pm

Tks for the replies

Is so weird, every time I create a new build, the function is registered to another function
rodrigo.demoura
 
Posts: 46
Joined: Wed Jun 02, 2010 6:31 pm

Re: Class Reference problem

Postby Zethfox » Wed Apr 27, 2011 9:10 pm

that might be becuase whatever function you copied it from, or whatever function it is supposed to be like already has an identical function doing exactly the same calls. im willing to bet that your function is linking directly to gameobserver::gamestatebasedeffects
Zethfox
 
Posts: 2785
Joined: Thu Jun 10, 2010 11:28 pm

Re: Class Reference problem

Postby rodrigo.demoura » Wed May 04, 2011 3:17 pm

Guys,
I do not know if that doubt keep this post or open a new one.
But I'll keep here for now :mrgreen:

I'm not able to to correctly use the "TargetChooserFactory. How do I allow the player to choose the creature.

Code: Select all
void GameObserver::activepokemon()
{
         MTGGameZone * zone = currentPlayer->game->inPlay;
         if (zone->nb_cards == 0 )return;

        for (int k = zone->nb_cards - 1; k >= 0; k--)
        {
            MTGCardInstance * card = zone->cards[k];
            if (card && card->isActive())
            {
                return;
            }
        }
       
      
      TargetChooserFactory tf;
                     
      TargetChooser * tc = tf.createTargetChooser("creature|myBattlefield",NULL);
      
      if(tc->validTargetsExist())
      {
          MTGCardInstance * _target = (MTGCardInstance *) tc;
          _target->addType(Subtypes::TYPE_ACTIVE);
         tc->targetter = NULL;         
         return;

      } 

     
      SAFE_DELETE(tc);

      return;
       

}
rodrigo.demoura
 
Posts: 46
Joined: Wed Jun 02, 2010 6:31 pm

Advertising


Return to SVN & Programmers' section

Who is online

Users browsing this forum: No registered users and 0 guests