Ejemplo n.º 1
0
static struct FSAState *CreateNFA(LPXMLDTDVALIDATOR vp, XMLCP *cp, struct FSAState *next)
{
	struct FSAState *sp, *n1, *n2;
	switch(cp->rep) {
		case 0: 
			return CreateNFA2(vp, cp, next);
		case '*':
			CHKMEM(n1 = AddState(vp));
			CHKMEM(sp = CreateNFA2(vp, cp, n1));
			CHKMEM(AddTran(n1, sp, (void*)epsilon));
			CHKMEM(AddTran(n1, next, (void*)epsilon));
			return n1;
		case '+':
			CHKMEM(n1 = AddState(vp));
			CHKMEM(n2 = AddState(vp));
			CHKMEM(sp = CreateNFA2(vp, cp, n2));
			CHKMEM(AddTran(n1, sp, (void*)epsilon));
			CHKMEM(AddTran(n2, sp, (void*)epsilon));
			CHKMEM(AddTran(n2, next, (void*)epsilon));
			return n1;
		case '?':
			CHKMEM(n1 = AddState(vp));
			CHKMEM(sp = CreateNFA2(vp, cp, next));
			CHKMEM(AddTran(n1, sp, (void*)epsilon));
			CHKMEM(AddTran(n1, next, (void*)epsilon));
			return n1;
	}
	return NULL;
}
Ejemplo n.º 2
0
void InstallStates(FActorInfo *info, AActor *defaults)
{
	// First ensure we have a valid spawn state.
	FState * state = FindState(defaults, info->Class, "Spawn");

	// Stateless actors that are direct subclasses of AActor
	// have their spawnstate default to something that won't
	// immediately destroy them.
	if (state == &AActor::States[2] && info->Class->ParentClass == RUNTIME_CLASS(AActor))
	{
		AddState("Spawn", &AActor::States[0]);
	}
	else if (state == NULL)
	{
		// A NULL spawn state will crash the engine so set it to something that will make
		// the actor disappear as quickly as possible.
		AddState("Spawn", &AActor::States[2]);
	}

	if (info->StateList != NULL) 
	{
		info->StateList->Destroy();
		free(info->StateList);
	}
	info->StateList = CreateStateLabelList(StateLabels);

	// Cache these states as member veriables.
	defaults->SpawnState = info->FindState(NAME_Spawn);
	defaults->SeeState = info->FindState(NAME_See);
	// Melee and Missile states are manipulated by the scripted marines so they
	// have to be stored locally
	defaults->MeleeState = info->FindState(NAME_Melee);
	defaults->MissileState = info->FindState(NAME_Missile);
}
Ejemplo n.º 3
0
void workbench_controller::Init() {
	//read attributes from file
	readIniFileAttr();

	om = getHandleManager<workbench_controller>();	//list handle beacon in game

	id_wb = ++workbench_controller::id_curr_max_wb;
	full_name = "workbench_" + to_string(id_wb);

	if (statemap.empty()) {
		AddState("idle", (statehandler)&workbench_controller::Idle);
		AddState("inactive", (statehandler)&workbench_controller::Inactive);
		AddState("busy", (statehandler)&workbench_controller::Busy);
	}

	SetHandleMeInit();				//need to be initialized after all handles, ¿awake/init?

	out[INACTIVE] = "INACTIVE";
	out[INACTIVE_TAKEN] = "INACTIVE_TAKEN";
	out[BUSY] = "BUSY";

	SetMyEntity(); //needed in case address Entity moved by handle_manager
	GET_MY(me_transform, TCompTransform);
	VEC3 curr_pos = me_transform->getPosition();

	SBB::postInt(full_name, INACTIVE);		//init my state on the board
	SBB::postVEC3(full_name, curr_pos);

	//Init mesages data
	msg_empty.pos = curr_pos;
	msg_empty.name = full_name;
	msg_taken.name = full_name;

	ChangeState("idle");
}
Ejemplo n.º 4
0
//! Initializes the state table
void MarioFSM::Init()
{
	AddState(new MarioStateIdle(), State_Idle);
	AddState(new MarioStateRunning(), State_Running);
	AddState(new MarioStatePrepareJump(), State_PrepareJump);
	AddState(new MarioStateFlying(), State_Flying);

	SwitchState(State_Idle);
}
Ejemplo n.º 5
0
FSM::GPlaying::GPlaying()
{
   m_iResetStateID = 0;

   // Create the sub state machine content
   AddState(GStateSPtr(new GInGame) );
   AddState(GStateSPtr(new GSavingGame) );
   AddState(GStateSPtr(new GCredits) );
}
Ejemplo n.º 6
0
// atomic operations
Nfa* AtomicMakeNfaBySingleC( Context* con, const char c ) {
	AddSymbol( con, c );
	Nfa* ret = AddNfa( con );
	Node* start = AddNode( con );
	State* ss = MakeState( con );
	AddState( start, ss);
	Node* end = AddNode( con );
	ss = MakeState( con );
	AddState( end, ss);
	AddEdge( start, end, c );
	ret->starts = start;
	ret->accepts = end;
	return ret;
}
Ejemplo n.º 7
0
Nfa* AtomicClosureNfa( Context* con, Nfa* in ) {
	Node* 	n1 = AddNode( con );
	AddState( n1, MakeState( con ) );
	AddEdge( n1, in->starts, EPSILON );
	Node* 	n2 = AddNode( con );
	AddState( n2, MakeState( con ) );
	AddEdge( in->accepts, n2, EPSILON );

	AddEdge( in->accepts, in->starts, EPSILON );
	AddEdge( n1, n2, EPSILON );

	in->starts = n1;
	in->accepts = n2;
	return in;
}
Ejemplo n.º 8
0
    void AddSearchPattern(const std::string& pattern)
    {
        if (pattern.empty())
        {
            return;
        }

        int currentState = 0;
        for (const auto& chr : pattern)
        {
            const int charIdx = chr - 'a';

            if (mTransitionMatrix[currentState][charIdx] == -1)
            {
                mTransitionMatrix[currentState][charIdx] = mTransitionMatrix.size();

                currentState = mTransitionMatrix[currentState][charIdx];

                AddState();
            }
        }

        mOutputTable[currentState] |= (1 << mDictionary.size());
        mDictionary.push_back(pattern);
    }
Ejemplo n.º 9
0
	Animatable::Animatable(const Animatable& other)
	{
		for (auto state : other.mStates)
		{
			AnimationState* newState = mnew AnimationState(*state);
			AddState(newState);
		}
	}
Ejemplo n.º 10
0
void VScrollBarOverlayWindow::ThumbInsideSlider()
{
  if (!HasState(ThumbState::INSIDE_SLIDER))
  {
    AddState(ThumbState::INSIDE_SLIDER);
    UpdateTexture();
  }
}
Ejemplo n.º 11
0
static int InitValidator(LPXMLDTDVALIDATOR v) 
{
	struct ElementDecl *e, *ee;
	struct FSAState *s;
	LPXMLVECTOR *declAtts;
	void **d;

	ee = (struct ElementDecl *)_XMLVector_GetIterP(v->ElementDecls, e);
	for (; e!=ee; e++) {
		/* important: every 1. content particle contains a pointer to
		hastablebucket in its name, we MUST assign hashtable data here,
		we cannot alter the cpNames table when DTD parsing is in progress! */
		
		d = (void**)XMLHTable_GetData(v->parser->prt->cpNames, (XMLHTABLEBUCKET*)e->cp->name);
		if (*d != EMPTYSTR) continue; /* duplicate declaration */
		*d = e;
	
		switch (e->type) {
			case XMLCTYPE_ANY: 
			case XMLCTYPE_EMPTY: break;
			case XMLCTYPE_MIXED: if (!e->cp->children) /* simple #PCDATA */
									 break; 
				/* note that we can't easily simplify the (e) type
				content models (which is actually XMLCTYPE_CHOICE) 
				- since we must allow (e)* or ((e))? etc. */
			default:
			v->fsa = XMLVector_Create(&e->fsa, 4, sizeof(struct FSAState*));
			if (!e->fsa) return 0;
			s = AddState(v);
			if (!s) return 0;
			SET_SMARK(s, SMARK_FINAL, 1);
			e->startState = CreateNFA(v, e->cp, s);
			if (!e->startState) return 0;

#ifdef PRINT_FSA
			PrintFSA(e, "NFA");
			if (!NFAtoDFA(v, e)) return 0;
			PrintFSA(e, "DFA");		
#else	
			if (!NFAtoDFA(v, e)) return 0;
#endif
		}
		if (v->parser->prt->declAttTable) {
			declAtts = XMLHTable_Lookup(v->parser->prt->declAttTable, e->name);
			if (declAtts) {
				e->declAtts = *(declAtts+1);
				if (e->declAtts->length > 1) 
					qsort((void*)e->declAtts->array, e->declAtts->length, 
						sizeof(XMLATTDECL), attcmp);
			}
		}
	}

	v->ElementTable = v->parser->prt->cpNames;
	v->cpNodesPool = v->parser->prt->cpNodesPool; 
	return 1;
}
Ejemplo n.º 12
0
	AnimationState* Animatable::AddState(const String& name, const Animation& animation, const AnimationMask& mask,
											 float weight)
	{
		AnimationState* res = mnew AnimationState(name);
		res->animation = animation;
		res->mask = mask;
		res->weight = weight;
		return AddState(res);
	}
Ejemplo n.º 13
0
void Game_Battler::ChangeHp(int hp) {
	if (!IsDead()) {
		SetHp(GetHp() + hp);

		// Death
		if (GetHp() <= 0) {
			AddState(RPG::State::kDeathID);
		}
	}
}
Ejemplo n.º 14
0
Nfa* AtomicOrNfa( Context* con, Nfa* first, Nfa* second ) {
	Node* 	n1 = AddNode( con );
	AddState( n1, MakeState( con ) );
	AddEdge( n1, first->starts, EPSILON );
	AddEdge( n1, second->starts, EPSILON );

	Node* 	n2 = AddNode( con );
	AddState( n2, MakeState( con ) );
	AddEdge( first->accepts, n2, EPSILON );
	AddEdge( second->accepts, n2, EPSILON );

	Nfa* 	nfa = AddNfa( con );
	nfa->starts = n1;
	nfa->accepts = n2;

	RemoveNfa( con, first );
	RemoveNfa( con, second );
	return nfa;
}
Ejemplo n.º 15
0
//Deletes all previous states and adds provided state to the list
//Used if new state is to be the main state and the previous state
//is no longer required e.g. from menu to playing a level
void GamestateManager::ChangeState(Gamestate *_state)
{
	for(unsigned int i = 0; i < m_gameStates.size(); i++)
	{
		delete m_gameStates.at(i);
		m_gameStates.clear();
	}

	AddState(_state);
}
Ejemplo n.º 16
0
//==============================================================
// DhcpStateMachine::WaitBeforeRenewalState
//==============================================================
DhcpStateMachine::DhcpStateMachine(
    /* [in] */ IContext* context,
    /* [in] */ StateMachine* controller,
    /* [in] */ const String& intf)
    : StateMachine(TAG)
    , mController(controller)
    , mContext(context)
    , mInterfaceName(intf)
    , mRegisteredForPreDhcpNotification(FALSE)
{
    mDefaultState = new DefaultState(this);
    mStoppedState = new StoppedState(this);
    mWaitBeforeStartState = new WaitBeforeStartState(this);
    mRunningState = new RunningState(this);
    mWaitBeforeRenewalState = new WaitBeforeRenewalState(this);

    mContext->GetSystemService(IContext::ALARM_SERVICE, (IInterface**)&mAlarmManager);
    AutoPtr<IIntent> dhcpRenewalIntent;
    CIntent::New(ACTION_DHCP_RENEW, NULL, (IIntent**)&dhcpRenewalIntent);
    AutoPtr<IPendingIntentHelper> intentHelper;
    CPendingIntentHelper::AcquireSingleton((IPendingIntentHelper**)&intentHelper);
    intentHelper->GetBroadcast(mContext, DHCP_RENEW, dhcpRenewalIntent, 0, (IPendingIntent**)&mDhcpRenewalIntent);

    AutoPtr<IPowerManager> powerManager;
    mContext->GetSystemService(IContext::POWER_SERVICE, (IInterface**)&powerManager);
    powerManager->NewWakeLock(IPowerManager::PARTIAL_WAKE_LOCK, WAKELOCK_TAG, (IPowerManagerWakeLock**)&mDhcpRenewWakeLock);
    mDhcpRenewWakeLock->SetReferenceCounted(FALSE);

    mBroadcastReceiver = new MyBroadcastReceiver(this);
    AutoPtr<IIntentFilter> intentFilter;
    CIntentFilter::New(ACTION_DHCP_RENEW, (IIntentFilter**)&intentFilter);
    AutoPtr<IIntent> intent;
    mContext->RegisterReceiver(mBroadcastReceiver, intentFilter, (IIntent**)&intent);

    AddState(mDefaultState);
    AddState(mStoppedState, mDefaultState);
    AddState(mWaitBeforeStartState, mDefaultState);
    AddState(mRunningState, mDefaultState);
    AddState(mWaitBeforeRenewalState, mDefaultState);

    SetInitialState(mStoppedState);
}
Ejemplo n.º 17
0
Archivo: doc.cpp Proyecto: EdgarTx/wx
csDiagramCommand::csDiagramCommand(const wxString& name, csDiagramDocument *doc,
    csCommandState* onlyState):
  wxCommand(true, name)
{
  m_doc = doc;

  if (onlyState)
  {
    AddState(onlyState);
  }
}
Ejemplo n.º 18
0
	Animatable& Animatable::operator=(const Animatable& other)
	{
		RemoveAllStates();

		for (auto state : other.mStates)
		{
			AnimationState* newState = mnew AnimationState(*state);
			AddState(newState);
		}

		return *this;
	}
void CPlayerBase::addBasicStates() {
	AddState("idle", (statehandler)&CPlayerBase::Idle);
	AddState("moving", (statehandler)&CPlayerBase::Moving);
	AddState("start_falling", (statehandler)&CPlayerBase::StartFalling);
	AddState("falling", (statehandler)&CPlayerBase::Falling);
	AddState("jumping", (statehandler)&CPlayerBase::Jumping);
	AddState("die", (statehandler)&CPlayerBase::Die);
	AddState("win", (statehandler)&CPlayerBase::Win);
	initBaseAttributes();
}
Ejemplo n.º 20
0
Silo::Silo()
:   WorldObject(),
    m_numNukesLaunched(0)
{
    SetType( TypeSilo );

    strcpy( bmpImageFilename, "graphics/sam.bmp" );

    m_radarRange = 20;
    m_selectable = true;

    m_currentState = 1;
    m_life = 25;

    m_nukeSupply = 10;

    AddState( LANGUAGEPHRASE("state_silonuke"), 120, 120, 10, Fixed::MAX, true, 10, 1 );         
    AddState( LANGUAGEPHRASE("state_airdefense"), 340, 20, 10, 30, true );

    InitialiseTimers();
}
Ejemplo n.º 21
0
Nuke::Nuke()
:   MovingObject(),
    m_prevDistanceToTarget( Fixed::MAX ),
    m_newLongitude(0),
    m_newLatitude(0),
    m_targetLocked(false)
{
    SetType( TypeNuke );

    strcpy( bmpImageFilename, "graphics/nuke.bmp" );

    m_radarRange = 0;
    m_speed = Fixed::Hundredths(20);
    m_selectable = true;
    m_maxHistorySize = -1;
    m_range = Fixed::MAX;
    m_turnRate = Fixed::Hundredths(1);
    m_movementType = MovementTypeAir;

    AddState( LANGUAGEPHRASE("state_ontarget"), 0, 0, 0, Fixed::MAX, false );
    AddState( LANGUAGEPHRASE("state_disarm"), 100, 0, 0, 0, false );
}
Ejemplo n.º 22
0
	//! Initializes the state table
	void Boss3FSM::Init()
	{
		AddState(snew Boss3StateIntro(), State_Intro);
		AddState(snew Boss3StateIdle(), State_Idle);
		AddState(snew Boss3StateSweep(), State_Sweep);
		AddState(snew Boss3StateCoreShot(), State_CoreShot);
		AddState(snew Boss3StateRetreat(), State_Retreat);
		AddState(snew Boss3StateExploding(), State_Exploding);
		AddState(snew Boss3StateInactive(), State_Inactive);
		SwitchState(State_Intro);
	}	
Ejemplo n.º 23
0
bool Game_Battler::UseSkill(int skill_id) {
	const RPG::Skill& skill = Data::skills[skill_id - 1];

	bool was_used = false;

	switch (skill.type) {
		case RPG::Skill::Type_normal:
		case RPG::Skill::Type_subskill:
			// Only takes care of healing skills outside of battle,
			// the other skill logic is in Game_BattleAlgorithm

			if (!(skill.scope == RPG::Skill::Scope_ally ||
				skill.scope == RPG::Skill::Scope_party ||
				skill.scope == RPG::Skill::Scope_self)) {
				return false;
			}

			// Skills only increase hp and sp outside of battle
			if (skill.power > 0 && skill.affect_hp && !HasFullHp()) {
				was_used = true;
				ChangeHp(skill.power);
			}

			if (skill.power > 0 && skill.affect_sp && !HasFullSp()) {
				was_used = true;
				ChangeSp(skill.power);
			}

			for (int i = 0; i < (int)skill.state_effects.size(); i++) {
				if (skill.state_effects[i]) {
					if (skill.state_effect) {
						was_used |= !HasState(Data::states[i].ID);
						AddState(Data::states[i].ID);
					} else {
						was_used |= HasState(Data::states[i].ID);
						RemoveState(Data::states[i].ID);
					}
				}
			}
		case RPG::Skill::Type_teleport:
		case RPG::Skill::Type_escape:
			// ToDo: Show Teleport/Escape target menu
			break;
		case RPG::Skill::Type_switch:
			Game_Switches[skill.switch_id] = true;
			return true;
	}

	return was_used;
}
Ejemplo n.º 24
0
bool Game_Battler::UseSkill(int skill_id) {
	const RPG::Skill* skill = ReaderUtil::GetElement(Data::skills, skill_id);
	if (!skill) {
		Output::Warning("UseSkill: Can't use skill with invalid ID %d", skill_id);
		return false;
	}

	bool was_used = false;

	if (skill->type == RPG::Skill::Type_normal || skill->type >= RPG::Skill::Type_subskill) {
		// Only takes care of healing skills outside of battle,
		// the other skill logic is in Game_BattleAlgorithm

		if (!(skill->scope == RPG::Skill::Scope_ally ||
			  skill->scope == RPG::Skill::Scope_party ||
			  skill->scope == RPG::Skill::Scope_self)) {
			return false;
		}

		// Skills only increase hp and sp outside of battle
		if (skill->power > 0 && skill->affect_hp && !HasFullHp()) {
			was_used = true;
			ChangeHp(skill->power);
		}

		if (skill->power > 0 && skill->affect_sp && !HasFullSp()) {
			was_used = true;
			ChangeSp(skill->power);
		}

		for (int i = 0; i < (int) skill->state_effects.size(); i++) {
			if (skill->state_effects[i]) {
				if (skill->state_effect) {
					was_used |= !HasState(Data::states[i].ID);
					AddState(Data::states[i].ID);
				} else {
					was_used |= HasState(Data::states[i].ID);
					RemoveState(Data::states[i].ID);
				}
			}
		}
	} else if (skill->type == RPG::Skill::Type_teleport || skill->type == RPG::Skill::Type_escape) {
		was_used = true;
	} else if (skill->type == RPG::Skill::Type_switch) {
		Game_Switches[skill->switch_id] = true;
		was_used = true;
	}

	return was_used;
}
Ejemplo n.º 25
0
bool ABScene::init()
{
	do 
	{
		mlBasic = ABasicLayer::create();
		addChild(mlBasic,0);
		AddState(mlBasic);

		e_State = 1;
		return true;
	} while (false);
	return false;

}
Ejemplo n.º 26
0
void Game_Enemy::ChangeHp(int hp) {
	SetHp(GetHp() + hp);

	if (this->hp == 0) {
		// Death
		SetGauge(0);
		SetDefending(false);
		SetCharged(false);
		RemoveAllStates();
		AddState(1);
	} else {
		// Back to life
		RemoveState(1);
	}
}
//==============================================================
// SupplicantStateTracker
//==============================================================
SupplicantStateTracker::SupplicantStateTracker(
    /* [in] */ IContext* c,
    /* [in] */ WifiStateMachine* wsm,
    /* [in] */ WifiConfigStore* wcs,
    /* [in] */ ILooper* l)
    : StateMachine(TAG, l)
    , mWifiStateMachine(wsm)
    , mWifiConfigStore(wcs)
    , mAuthenticationFailuresCount(0)
    , mAssociationRejectCount(0)
    , mAuthFailureInSupplicantBroadcast(FALSE)
    , mNetworksDisabledDuringConnect(FALSE)
    , mContext(c)
    , mUninitializedState(new UninitializedState(this))
    , mDefaultState(new DefaultState(this))
    , mInactiveState(new InactiveState(this))
    , mDisconnectState(new DisconnectedState(this))
    , mScanState(new ScanState(this))
    , mHandshakeState(new HandshakeState(this))
    , mCompletedState(new CompletedState(this))
    , mDormantState(new DormantState(this))
{
    AutoPtr<IInterface> service;
    AutoPtr<IServiceManager> serviceManager;
    CServiceManager::AcquireSingleton((IServiceManager**)&serviceManager);
    serviceManager->GetService(IBatteryStats::SERVICE_NAME, (IInterface**)&service);
    mBatteryStats = IIBatteryStats::Probe(service);
    AddState(mDefaultState);
    AddState(mUninitializedState, mDefaultState);
    AddState(mInactiveState, mDefaultState);
    AddState(mDisconnectState, mDefaultState);
    AddState(mScanState, mDefaultState);
    AddState(mHandshakeState, mDefaultState);
    AddState(mCompletedState, mDefaultState);
    AddState(mDormantState, mDefaultState);

    SetInitialState(mUninitializedState);
    SetLogRecSize(50);
    SetLogOnlyTransitions(TRUE);

    //start the state machine
    Start();
}
Ejemplo n.º 28
0
City::City()
:   WorldObject(),
    m_name(NULL),
    m_country(NULL),
    m_population(-1),
    m_capital(false),
    m_numStrikes(0),
    m_dead(0)
{
    SetType( TypeCity );
    
    m_name = strdup("City");

    strcpy( bmpImageFilename, "graphics/city.bmp" );

    m_radarRange = 0;
    AddState( "City", 0, 0, 5, 0, false );
}
Ejemplo n.º 29
0
void Game_Actor::AddEquipmentStates() {
	if (!Player::IsRPG2k3()) {
		return;
	}

	auto checkEquip = [this](const RPG::Item* item) {
		if (item && item->state_effect) {
			for (int i = 0; i < (int)item->state_set.size(); i++) {
				if (item->state_set[i]) {
					AddState(i + 1);
				}
			}
		}
	};
	checkEquip(GetShield());
	checkEquip(GetArmor());
	checkEquip(GetHelmet());
	checkEquip(GetAccessory());
}
Ejemplo n.º 30
0
void EpsilonClosure( Context* con, Node *dfa_node, State* s ) {
	if ( s == NULL ) return;
	DestorySSE();
	while ( s != NULL ) {
		PushSSE( s );
		s = s->next;
	}

	while ( ssetop != NULL ) {
		State* st = PopSSE();

		StateEdge* se = sequeue;
		while ( se != NULL ) {
			if ( se->w == EPSILON && se->from->dummy == st->dummy && !FindState( dfa_node, se->to ) ) {
				AddState( dfa_node, MakeDfaState( con, se->to->dummy ) );
				PushSSE( se->to );
			}
			se = se->next;
		}
	}
	return;
}