Esempio n. 1
0
bool Game::pollSource()
{
	if(m_sexprSource == 0)
	{
		return false;
	}

	if(m_sexprSource->sexprReady())
	{
		SExpr sexpr = m_sexprSource->getSExpr();
		
		if(sexpr.type() == NodeType::Unknown)
		{
			return false;
		}
		
		if(sexpr[0] == "status")
		{
			GameState* state = new GameState;
			state->fromSExpr(sexpr);

			pushState(state);
			return true;
		}

        //Ident message
        //("ident" (("0" "MuesAI" "Stephen Mues" "human") ("1" "MuesAI" "Stephen Mues" "zombie")) "0")
		if(sexpr[0] == "ident")
		{
			SExpr ident = sexpr.next().list();
            if(ident.list()[3] == "zombie")
            {
			    m_zombieName = ident.list()[2];
			    m_humanName = ident.next().list()[2];
            }
            else
            {
			    m_humanName = ident.list()[2];
			    m_zombieName = ident.next().list()[2];
            }
		}

		if(sexpr[0] == "notification")
		{
            if(sexpr[1] == Config::instance()->get("user") || atoi(Config::instance()->get("arenaMode").c_str()) > 0)
			{
				cout << "A game was joined by the same player that this visualizer is logged in as" << endl;
                if( atoi(Config::instance()->get("autoJoin").c_str()) > 0 || atoi(Config::instance()->get("arenaMode").c_str()) > 0)
				{
                    cout << "Stopping reader thread" << endl;
					m_nextGame = sexpr[2];
                    Engine::instance()->stopPolling();
					//throw "die";
				}
			}
		}
	}

	return false;
}
Esempio n. 2
0
void Animation::fromSExpr(SExpr in)
{ 
	 m_ids.clear();

	//enum Type{None, Add, Remove, Move, Turn, Attack, Hurt, Eat, Grab, Throw, Give, Build};
	//Sigh
	if(in[0] == "add")
	{
      m_type = Add;
      m_ids.push_back(atoi( in[1].c_str() ));
	}
	else if(in[0] == "move")
	{
      m_type = Move;
      m_ids.push_back(atoi( in[1].c_str() ));
      m_x = atoi( in[2].c_str() );
      m_y = atoi( in[3].c_str() );
	}
	else if(in[0] == "remove")
	{
      m_type = Remove;
      m_ids.push_back(atoi( in[1].c_str() ));
	}
	else if(in[0] == "attack")
	{
		m_type = Attack;
		m_ids.push_back(atoi( in[1].c_str() ));
		m_x = atoi( in[2].c_str() );
		m_y = atoi( in[3].c_str() );
	}
	else if(in[0] == "hurt")
	{
		m_type = Hurt;

		SExpr ids = in.next().list();
	  
		int count = ids.numElements();
		for(int i=0; i < count; ++i)
		{
			m_ids.push_back( atoi( ids[0].c_str() ));
			ids = ids.next();
		}
   }
   else if(in[0] == "turn")
   {
		m_type = Turn;
		m_ids.push_back(atoi( in[1].c_str() ));
		m_x = atoi( in[2].c_str() ); //Facing direction
   }
   //enum Type{None, Add, Remove, Move, Turn, Attack, Hurt, Eat, Grab, Throw, Give, Build};
   else if(in[0] == "eat")
   {
		m_type = Eat;
		m_ids.push_back(atoi( in[1].c_str() ));
		m_ids.push_back(atoi( in[2].c_str() ));
   }
   else if(in[0] == "grab")
   {
		m_type = Grab;
		m_ids.push_back(atoi( in[1].c_str() ));
		m_ids.push_back(atoi( in[2].c_str() ));
   }
   else if(in[0] == "throw")
   {
		m_type = Throw;
		m_ids.push_back(atoi( in[1].c_str() ));
		m_ids.push_back(atoi( in[2].c_str() ));
		m_x = atoi( in[3].c_str() );
		m_y = atoi( in[4].c_str() );
	}
	else if(in[0] == "give")
	{
		m_type = Give;
		m_ids.push_back(atoi( in[1].c_str() ));
		m_ids.push_back(atoi( in[2].c_str() ));
	}
	else if(in[0] == "build")
	{
		m_type = Build;
		m_ids.push_back(atoi( in[1].c_str() ));
		m_x = atoi( in[2].c_str() );
		m_y = atoi( in[3].c_str() );
	}
	else
	{
		//We don't know what this was...
		m_type = None;
	}   
}