示例#1
0
void CStateParser::ParseStateDef(CTokenizer &tok,CStateManager &StateManager)
{
	while( !tok.CheckToken("[",false) && !tok.AtEndOfFile() )
	{
		//parse state type
		if( tok.CheckToken("type") )
		{
			if( !tok.CheckToken("=") )
			Error("expected =",tok);
         
			//to get a single char   
			char c=tok.GetToken()[0];
			//make sure we use uperchars
			if(c >= 97)
			c-=32;
            
                  
			switch(c)
			{
			case 'S':
				StateManager.SetStateDefType(stand); 
			break;
            
			case 'C':
				StateManager.SetStateDefType(crouch);     
			break;
                        
			case 'A':
				StateManager.SetStateDefType(air); 
			break;
            
			case 'L':
				StateManager.SetStateDefType(liedown);     
			break;
            
			case 'U':
				StateManager.SetStateDefType(untouch);    
			break;
            
			default:
				Error("Unknown statetype",tok);
			break;
                      
                  
			}

		} else if( tok.CheckToken("movetype") )
		{
			if( !tok.CheckToken("=") )
			Error("expected '=' in line ",tok);
            
			//to get a single char   
			char c=tok.GetToken()[0];
			//make sure we use uperchars
			if(c >= 97)
			c-=32;
           
			switch(c)
			{
			case 'A':
				StateManager.SetStateMoveType(attack);
			break;

			case 'I':
				StateManager.SetStateMoveType(idle);
			break;

			case 'H':
				StateManager.SetStateMoveType(hit);
			break;

			case 'U':
				StateManager.SetStateMoveType(untouch);
			break;
            
			default:
				Error("Unknown movetype",tok);
			break;
            
                  
                  
			}      
           
              
         
		} else if( tok.CheckToken("physics") )
		{
			if( !tok.CheckToken("=") )
			Error("expected =",tok);
         
			//to get a single char   
			char c=tok.GetToken()[0];
			//make sure we use uperchars
			if(c >= 97)
			c-=32;
            
                  
			switch(c)
			{
			case 'S':
				StateManager.SetStatePhysicType(stand); 
			break;
            
			case 'C':
				StateManager.SetStatePhysicType(crouch);     
			break;
                        
			case 'A':
				StateManager.SetStatePhysicType(air); 
			break;
            
			case 'N':
				StateManager.SetStatePhysicType(none);     
			break;
            
			case 'U':
				StateManager.SetStatePhysicType(untouch);    
			break;
            
				default:
				Error("Unknown physic type",tok);
			break;
                      
                  
			}
            
            
            
		} else if( tok.CheckToken("anim") )
		{
		if( !tok.CheckToken("=") )
			Error("expected =",tok);
         
			if(!tok.CheckTokenIsNumber())
			Error("Expected a number for anim",tok);
           
			StateManager.SetStateAnim(tok.GetInt());  
      
            
		} else if( tok.CheckToken("velset") )
		{
		if( !tok.CheckToken("=") )
			Error("expected =",tok);
            
		float x=tok.GetFloat();
       
		if( !tok.CheckToken(",") )
			Error("expected ,",tok);
          
		float y=tok.GetFloat();
       
		StateManager.SetVelSet(x,y);     

		} else if( tok.CheckToken("ctrl") )
		{
			if( !tok.CheckToken("=") )
			Error("expected =",tok);
                                 
			if(!tok.CheckTokenIsNumber())
			Error("Expected a number for ctrl",tok);
            
			StateManager.SetStateCtrl(tok.GetInt());    
            
		} else if( tok.CheckToken("poweradd") )
		{
		if( !tok.CheckToken("=") )
			Error("expected =",tok);
            
		if(!tok.CheckTokenIsNumber())
			Error("Expected a number for poweradd",tok);      
            
		StateManager.SetStatePowerAdd(tok.GetInt());  
            
		} else if( tok.CheckToken("juggle") )
		{
		if( !tok.CheckToken("=") )
			Error("expected =",tok);
            
		if(!tok.CheckTokenIsNumber())
			Error("Expected a number for juggle",tok);
           
		StateManager.SetStateJuggle(tok.GetInt());              
            
		} else if( tok.CheckToken("facep2") )
		{
		if( !tok.CheckToken("=") )
			Error("expected =",tok);
            
		if( !tok.CheckTokenIsNumber() )
			Error("Expected a number for facep2",tok);
            
		StateManager.SetStateFaceP2(tok.GetInt());   
            
		} else if( tok.CheckToken("hitdefpersist") )
		{
		if( !tok.CheckToken("=") )
			Error("expected =",tok);
            
		if( !tok.CheckTokenIsNumber() )
			Error("Expected a number for hitdefpersist",tok); 
            
		StateManager.SetStateHitDefPresit(tok.GetInt());   
            
		} else if( tok.CheckToken("movehitpersist") )
		{
		if( !tok.CheckToken("=") )
			Error("expected =",tok);
            
		if( !tok.CheckTokenIsNumber() )
			Error("Expected a number for movehitpersist",tok);
            
		StateManager.SetMoveHitPresit(tok.GetInt());  
            
		} else if( tok.CheckToken("hitcountpersist") )
		{ 
		if( !tok.CheckToken("=") )
			Error("expected =",tok);
            
		if( !tok.CheckTokenIsNumber() )
			Error("Expected a number for hitcountpersist",tok);
            
		StateManager.SetStateHitCounterPresit(tok.GetInt());  
            
            
		} else if( tok.CheckToken("sprpriority") )
		{
			if( !tok.CheckToken("=") )
			Error("expected =",tok); 
            
			if( !tok.CheckTokenIsNumber() )
			Error("Expected a number for sprpriority",tok);
            
			StateManager.SetSprPriority(tok.GetInt()); 
            
		}else //faile in statedef
		{
         
			throw(CError("Unknown token at line %s",tok.GetToken()));
			break;
		}
     

	}
    
}
示例#2
0
//evaluates a primary
void CStateParser::Primary(CTokenizer &tok,CStateManager &StateManager)
{
     //a negate operator
     if( tok.CheckToken("-") )
     {
           //EvaluateExpression(tok,StateManager);
           Primary(tok,StateManager);
           StateManager.AddInstruction(OP_NEG,0,"#");  
     }else if( tok.CheckTokenIsNumber() )  //we have a number
     {
         StateManager.AddInstruction(OP_PUSH,tok.GetFloat(),"#");                       
     }else if( tok.CheckTokenIsQuotedString() ) //it is a "quitedstring"
     {
         StateManager.AddInstruction(OP_PUSH,0,tok.GetToken());  
     }else if( tok.CheckToken("(") ) //here we have to check a lot of possibilitys
     {
         EvaluateExpression(tok,StateManager);
         
         if( !tok.CheckToken(")") )
                Error("Missing )",tok);
         
     }else if( tok.CheckToken("!") )
     {
          Primary(tok,StateManager);
          StateManager.AddInstruction(OP_NOT,0,"#");
     }
     else //check for a trigger name
     {
		 std::string ret = tok.GetToken();
         int i=GetTriggerType(ret.c_str(),tok);
                 
		 if ( i == OP_Vel - OP_Abs) 
		 {
			 if (tok.CheckToken("x"))
			 {
				 StateManager.AddInstruction(OP_Vel,1.0,"#");
			 }
			 else if  (tok.CheckToken("y"))
			 {
				 StateManager.AddInstruction(OP_Vel,0.0,"#");
			 }
		 }else if ( i == OP_Pos - OP_Abs) 
		 {
			 if (tok.CheckToken("x"))
			 {
				 StateManager.AddInstruction(OP_Pos,1.0,"#");
			 }
			 else if  (tok.CheckToken("y"))
			 {
				 StateManager.AddInstruction(OP_Pos,0.0,"#");
			 }
		 }
		 else if ( i == OP_Const - OP_Abs) 
		 {
			 if (!tok.CheckToken("("))
				 Error("Missing (",tok);

			 StateManager.AddInstruction(OP_Const,0.0,tok.GetToken());
			 if (!tok.CheckToken(")"))
				 Error("Missing )",tok);
		 }
		 else if ( i == OP_IfElse - OP_Abs) 
		 {
			 if (!tok.CheckToken("("))
				 Error("Missing (",tok);

			 EvaluateExpression(tok,StateManager);
			 if (!tok.CheckToken(","))
				 Error("Missing ,",tok);

			 Term(tok,StateManager);

			 if (!tok.CheckToken(","))
				 Error("Missing ,",tok);

			 Term(tok,StateManager);

			 StateManager.AddInstruction(OP_IfElse,0,"#");
			 if (!tok.CheckToken(")"))
				 Error("Missing )",tok);
		 }
		 else if (i == OP_StateType - OP_Abs)
		 {
			 if (tok.CheckToken("="))
			 {
				 StateManager.AddInstruction(OP_StateType,0,"#");
				 StateManager.AddInstruction(OP_PUSH,0,tok.GetToken());
				 StateManager.AddInstruction(OP_EQUAL,0,"#");
			 }else if (tok.CheckToken("!="))
			 {
				 StateManager.AddInstruction(OP_StateType,0,"#");
				 StateManager.AddInstruction(OP_PUSH,0,tok.GetToken());
				 StateManager.AddInstruction(OP_NOTEQUAL,0,"#");
			 }
			 
		 }
		 else if (i == OP_P2StateType - OP_Abs)
		 {
			 if (tok.CheckToken("="))
			 {
				 StateManager.AddInstruction(OP_P2StateType,0,"#");
				 StateManager.AddInstruction(OP_PUSH,0,tok.GetToken());
				 StateManager.AddInstruction(OP_EQUAL,0,"#");
			 }else if (tok.CheckToken("!="))
			 {
				 StateManager.AddInstruction(OP_P2StateType,0,"#");
				 StateManager.AddInstruction(OP_PUSH,0,tok.GetToken());
				 StateManager.AddInstruction(OP_NOTEQUAL,0,"#");
			 }

		 }
		 else if (i == OP_P2MoveType - OP_Abs)
		 {
			 if (tok.CheckToken("="))
			 {
				 StateManager.AddInstruction(OP_P2MoveType,0,"#");
				 StateManager.AddInstruction(OP_PUSH,0,tok.GetToken());
				 StateManager.AddInstruction(OP_EQUAL,0,"#");
			 }else if (tok.CheckToken("!="))
			 {
				 StateManager.AddInstruction(OP_P2MoveType,0,"#");
				 StateManager.AddInstruction(OP_PUSH,0,tok.GetToken());
				 StateManager.AddInstruction(OP_NOTEQUAL,0,"#");
			 }

		 }
		 else if (i == OP_GetHitVar - OP_Abs)
		 {
			 if (!tok.CheckToken("("))
				 Error("Missing (",tok);
			 StateManager.AddInstruction(OP_GetHitVar,0,tok.GetToken());
			 if (!tok.CheckToken(")"))
				 Error("Missing )",tok);
		 }
		 else if (i == OP_HitDefAttr - OP_Abs)
		 {
			 while (!tok.AtEndOfLine())
				 tok.GetToken();
		 }
		 else if (i == OP_P2BodyDist - OP_Abs)
		 {
			 while (!tok.AtEndOfLine())
				 tok.GetToken();
		 }
		 else
		 {
			 StateManager.AddInstruction(i+OP_Abs,0,"#");

		 }
      
     }
 
}