void CDialogScriptHelper::Action (const CGameObject* pSpeakerGO, LPCSTR dialog_id, LPCSTR phrase_id) const { for(u32 i = 0; i<Actions().size(); ++i) { luabind::functor<void> lua_function; THROW(*Actions()[i]); bool functor_exists = ai().script_engine().functor(*Actions()[i] ,lua_function); THROW3(functor_exists, "Cannot find phrase dialog script function", *Actions()[i]); lua_function (pSpeakerGO->lua_game_object(), dialog_id); } TransferInfo(smart_cast<const CInventoryOwner*>(pSpeakerGO)); }
void ActionListSwitch::GenerateCaseMap() { Datum& cases = Actions(); Datum::DatumType switchType = Datum::DatumType::UNKNOWN; if (cases.Size() > 0) { delete mCaseMap; mCaseMap = new Hashmap<Datum, ActionListSwitchCase*>(cases.Size()); Datum* conditionDatum = Search((*this)[ATTRIBUTE_SWITCH_VALUE].Get<std::string>()); if (conditionDatum == nullptr) { std::stringstream str; str << "Undefined variable: " << (*this)[ATTRIBUTE_SWITCH_VALUE].Get<std::string>(); throw std::exception(str.str().c_str()); } switchType = conditionDatum->Type(); } for (uint32_t i = 0; i < cases.Size(); i++) { ActionListSwitchCase* switchCase = cases.Get<Scope>(i).As<ActionListSwitchCase>(); if (switchCase == nullptr) continue; if (switchCase->DefaultCase) { Adopt(ActionListSwitchCase::ATTRIBUTE_DEFAULT, *switchCase); } else { Datum d; d.SetType(switchType); d.SetFromString(switchCase->operator[](ActionListSwitchCase::ATTRIBUTE_CASE_VALUE).Get<std::string>()); mCaseMap->Insert(d, switchCase); } } }
void CPhraseScript::Action(const CGameObject* pSpeakerGO1, const CGameObject* pSpeakerGO2, LPCSTR dialog_id, LPCSTR phrase_id) const { TransferInfo(smart_cast<const CInventoryOwner*>(pSpeakerGO1)); for(u32 i = 0; i<Actions().size(); ++i) { luabind::functor<void> lua_function; THROW(*Actions()[i]); bool functor_exists = ai().script_engine().functor(*Actions()[i] ,lua_function); THROW3(functor_exists, "Cannot find phrase dialog script function", *Actions()[i]); try { lua_function (pSpeakerGO1->lua_game_object(), pSpeakerGO2->lua_game_object(), dialog_id, phrase_id); } catch (...) { } } }
void UpAttack::doAction() { if (isReady()) { isActive = true; _lastTimeActivated = TimeManager::GetInstance()->time; } Actions(); }
void ActionListSwitch::Update(WorldState& worldState) { if (mCaseMap == nullptr) return; Datum* conditionDatum = Search((*this)[ATTRIBUTE_SWITCH_VALUE].Get<std::string>()); assert(conditionDatum != nullptr); Hashmap<Datum, ActionListSwitchCase*>::Iterator caseIterator = mCaseMap->Find(*conditionDatum); if (caseIterator == mCaseMap->end()) { // execute default case if (IsAttribute(ActionListSwitchCase::ATTRIBUTE_DEFAULT)) { Scope& defaultActionScope = (*this)[ActionListSwitchCase::ATTRIBUTE_DEFAULT].Get<Scope>(); ActionListSwitchCase* defaultCase = defaultActionScope.AssertiveAs<ActionListSwitchCase>(); worldState.action = defaultCase; defaultCase->Update(worldState); } } else { ActionListSwitchCase* matchingCase = (*caseIterator).second; worldState.action = matchingCase; matchingCase->Update(worldState); if (!matchingCase->MustBreak) { Datum& cases = Actions(); std::uint32_t i; for (i = 0; i < cases.Size(); i++) { if (&cases.Get<Scope>(i) == matchingCase) { ++i; break; } } for (; i < cases.Size(); i++) { Scope& nextCase = cases.Get<Scope>(i); assert(nextCase.Is(ActionListSwitchCase::TypeIdClass())); matchingCase = static_cast<ActionListSwitchCase*>(&nextCase); worldState.action = matchingCase; matchingCase->Update(worldState); if (matchingCase->MustBreak) break; } } } }
int GameLoop() { Timer Timer; int Frame = 0; bool quit = false; SDL_Event PollEvent; while(!quit) { int frameTicks = Timer.start(); while(SDL_PollEvent(&PollEvent)) { if(PollEvent.type == SDL_QUIT) { quit = true; break; } if(HandleInput(PollEvent, frameTicks) == -1) { quit = true; break; } } if(quit == true) break; Actions(frameTicks); SDL_FillRect(screen, &(screen->clip_rect), backgroundColor); DrawCamera(); DrawUI(); if(SDL_Flip(screen) == -1) return 1; //Cap the frame rate if( Timer.get_ticks() < 1000 / MAX_FPS ) { int delay = ( 1000 / MAX_FPS ) - Timer.get_ticks(); SDL_Delay(delay); } Frame++; if(Frame % MAX_FPS == 0) Frame = 0; } return 0; }
int AlphaBeta(board state, int depth, int alpha, int beta, int player, int * bestX, int * bestY) //AlphaBeta { int X,Y, numacts, i, value; int Xacts[64], Yacts[64]; //maximum of 64 (actually 60) possible moves board child; if (timelimit1){ currenttime = clock(); if (deadline < currenttime) return 0; } if (CutoffTest(state, depth)) return Evaluate(state); numacts = Actions(state, player, Xacts, Yacts); if (player == 1){//the MAX player (us) for (i=0; i<numacts; i++) { Result(state, child, player, Xacts[i], Yacts[i]); value = AlphaBeta(child, depth-1, alpha, beta, -player, &X, &Y); if (timelimit1 && deadline < currenttime) return 0; //checking if we've reached the timelimit if applicable if (value > alpha) { alpha = value; *bestX = Xacts[i]; *bestY = Yacts[i]; } if (beta <= alpha)//beta cut-off break; } return alpha; } else { for (i=0; i<numacts; i++) { Result(state, child, player, Xacts[i], Yacts[i]); value = AlphaBeta(child, depth-1, alpha, beta, -player, &X, &Y); if (timelimit1 && deadline < currenttime) return 0; //checking if we've reached the time limit if applicable if (value < beta) { beta = value; *bestX = Xacts[i]; *bestY = Yacts[i]; } if (beta <= alpha)//alpha cutoff break; } return beta; } }
void le::AI::UpdateAI( vector<BasicPersonages*> vPersonage ) { ViewAI->UpdateViewAI( vPersonage ); Actions(); }
void DigitalBrain::FrameExec(SimObjectType* curTargetList, SimObjectType* curTarget) { maxGs = af->MaxGs(); maxGs = max (maxGs, 2.5F); // 2002-03-15 MN if we've flamed out // and our speed is below minvcas, put the wheels out so that there is a chance to land if (self->af->Fuel() <= 0.0F && self->af->vcas < self->af->MinVcas()){ // Set Landed flag now, so that RegroupAircraft can be called in Eom.cpp - // have the maintenance crew tow us back to the airbase ;-) //TJL 02/19/04 Flame out = Eject for Digital pilots //SetATCFlag(Landed); //af->gearHandle = 1.0F; self->Eject(); rStick = -0.3f;//Roll while the plane dies } else { // make sure the wheels are up after takeoff if (self->curWaypoint && self->curWaypoint->GetWPAction() != WP_TAKEOFF){ af->gearHandle = -1.0F; } else if (!self->OnGround()){ //Cobra stop Naval aircraft flying around with gear down af->gearHandle = -1.0F; } } // assume we're not going to be firing in this frame ClearFlag (MslFireFlag | GunFireFlag); // check to see if our leader is dead and if not set leader to next in // flight (and/or ourself) CheckLead(); // FRB - Keep radar sweeping while in CombatAP if ((self->IsPlayer())&&(g_bwoeir)) self->targetUpdateRate = (VU_TIME)(.01 * SEC_TO_MSEC); else self->targetUpdateRate = (VU_TIME)(5 * SEC_TO_MSEC); // Find a threat/target DoTargeting(); // Make Decisions SetCurrentTactic(); // Set the controls Actions(); // RV - Biker - Enable shooting missiles if flight lead is AI if (flightLead && !flightLead->IsPlayer() && missileShotTimer >= SimLibElapsedTime + 4.9 * 60 * 60 * SEC_TO_MSEC) { missileShotTimer = SimLibElapsedTime; } // has the target changed? if (targetPtr != lastTarget){ lastTarget = targetPtr; ataddot = 10.0F; rangeddot = 10.0F; } // edg: check stick settings for bad values if ( rStick < -1.0f ) rStick = -1.0f; else if ( rStick > 1.0f ) rStick = 1.0f; if ( pStick < -1.0f ) pStick = -1.0f; else if ( pStick > 1.0f ) pStick = 1.0f; //me123 unload if roll input is 1 (to rool faster and eleveate the f4 bug) if (fabs(rStick) >0.9f && groundAvoidNeeded == FALSE) pStick = 0.0f; if ( throtl < 0.0f ) throtl = 0.0f; else if ( throtl > 1.5f ) throtl = 1.5f; // RV - Biker - Don't allow AB when low on fuel or on ground if (IsSetATC(SaidFumes) || IsSetATC(SaidFlameout) || (self->OnGround() && GetCurrentMode() != TakeoffMode)) { throtl = min(1.0f, throtl); } }