void MainMenuState::OnFrame() { float dt=hge->Timer_GetDelta(); static float t=0.0f; int id; static int lastid=0; // If ESCAPE was pressed, tell the GUI to finish // if(hge->Input_GetKeyState(HGEK_ESCAPE)) { lastid=5; gui->Leave(); } // We update the GUI and take an action if // one of the menu items was selected id=gui->Update(dt); if(id == -1) { switch(lastid) { case 1: RequestState("maingame"); break; case 2: RequestState("exit"); break; } } else if(id) { lastid = id; gui->Leave(); } }
void PlacedLightIsDamaged(STRATEGYBLOCK *sbPtr, DAMAGE_PROFILE *damage, int multiple) { PLACED_LIGHT_BEHAV_BLOCK* pl_bhv = sbPtr->SBdataptr; LOCALASSERT(pl_bhv); if(pl_bhv->state==Light_State_Broken) return; #if 1 if((AvP.Network==I_Peer)&&(!InanimateDamageFromNetHost)) { //add light damaged net message AddNetMsg_InanimateObjectDamaged(sbPtr,damage,multiple); return; } else if(AvP.Network==I_Host) { //add light damaged net message if(sbPtr->SBDamageBlock.Health <= 0) AddNetMsg_InanimateObjectDestroyed(sbPtr); } #endif if (!pl_bhv->Indestructable) { if(sbPtr->SBDamageBlock.Health <= 0) { //change to broken sequence if it exists. //otherwise destroy light pl_bhv->state=Light_State_Broken; pl_bhv->on_off_state=Light_OnOff_Off; pl_bhv->sequence=2; pl_bhv->light->LightBright=0; //notify target of destruction if(pl_bhv->destruct_target_sbptr) { RequestState(pl_bhv->destruct_target_sbptr,pl_bhv->destruct_target_request,0); } /* KJL 17:08:44 10/07/98 - Make some sparks */ if (sbPtr->SBdptr) { MakeSprayOfSparks(&sbPtr->SBdptr->ObMat,&sbPtr->SBdptr->ObWorld); } if(pl_bhv->has_broken_sequence) { SetTextureAnimationSequence(sbPtr->shapeIndex,pl_bhv->inan_tac,pl_bhv->sequence); } else { MakeFragments(sbPtr); if(AvP.Network==I_No_Network) DestroyAnyStrategyBlock(sbPtr); else KillLightForRespawn(sbPtr); } } } }
void MainMenuState::OnEnter() { //ÔØÈëÖ÷»Ãæ hge = hgeCreate(HGE_VERSION); // Load sound and textures quad.tex=hge->Texture_Load("data\\tkt.png"); // tex=hge->Texture_Load("cursor.png"); snd=hge->Effect_Load("se\\menu.wav"); if(!quad.tex || !snd) { // If one of the data files is not found, display // an error message and shutdown. MessageBox(NULL, "Can't load BG.PNG or MENU.WAV", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL); RequestState("exit"); return; } // Set up the quad we will use for background animation quad.blend=BLEND_ALPHABLEND | BLEND_COLORMUL | BLEND_NOZWRITE; for(int i=0;i<4;i++) { // Set up z-coordinate of vertices quad.v[i].z=0.5f; // Set up color. The format of DWORD col is 0xAARRGGBB quad.v[i].col=0xFFFFFFFF; } quad.v[0].x=0; quad.v[0].y=0; quad.v[1].x=800; quad.v[1].y=0; quad.v[2].x=800; quad.v[2].y=600; quad.v[3].x=0; quad.v[3].y=600; quad.v[0].tx=0; quad.v[0].ty=0; quad.v[1].tx=640.f/1024; quad.v[1].ty=0; quad.v[2].tx=640.f/1024; quad.v[2].ty=480.f/512; quad.v[3].tx=0; quad.v[3].ty=480.f/512; // Load the font, create the cursor sprite fnt=new hgeFont("data/font1.fnt"); //spr=new hgeSprite(tex,0,0,32,32); // Create and initialize the GUI gui=new hgeGUI(); gui->AddCtrl(new hgeGUIMenuItem(1,fnt,snd,400,340,0.0f,"Start")); gui->AddCtrl(new hgeGUIMenuItem(2,fnt,snd,400,360,0.0f,"Exit")); gui->AddCtrl(new hgeGUIMenuItem(3,fnt,snd,400,380,0.0f,"Replay")); gui->SetNavMode(HGEGUI_UPDOWN);// | HGEGUI_CYCLED); //gui->SetCursor(spr); gui->SetFocus(1); gui->Enter(); }
void LinkSwitchSetSynchData(STRATEGYBLOCK* sbPtr,int status) { LINK_SWITCH_BEHAV_BLOCK *ls_bhv; GLOBALASSERT(sbPtr); ls_bhv = (LINK_SWITCH_BEHAV_BLOCK*)sbPtr->SBdataptr; GLOBALASSERT((ls_bhv->bhvr_type == I_BehaviourLinkSwitch)); if(ls_bhv->TimeUntilNetSynchAllowed>0) { //ignore this attempt to synch the switch return; } //don't try to synch moving switches if(ls_bhv->ls_mode==I_lswitch_moving) { return; } switch(status) { case LINKSWITCHSYNCH_ON : if(!ls_bhv->state) { //this switch should be on RequestState(sbPtr,1,0); } break; case LINKSWITCHSYNCH_OFF : if(ls_bhv->state) { //this switch should be off RequestState(sbPtr,0,0); } break; } }
static void set_link_switch_states_off (LINK_SWITCH_BEHAV_BLOCK * lsbb) { int i=0; LSWITCH_ITEM * lsi = lsbb->lswitch_list; while (lsi[i].bswitch && i < MAX_SWITCHES_FOR_LINK) { BINARY_SWITCH_BEHAV_BLOCK * bsbb = ((BINARY_SWITCH_BEHAV_BLOCK *)lsi[i].bswitch->SBdataptr); // if it's on, tell it to go off if (! ((bsbb->state && bsbb->rest_state) || (!bsbb->state && !bsbb->rest_state)) ) RequestState (lsi->bswitch, 0, 0); i++; } }
/* * Processes the instance * @author Cameron MacIntosh * @param _fDeltaTick The time that has passed since the last frame */ void CAIPlayer::Process(float32 _fDeltaTick) { CPlayer::Process(_fDeltaTick); if(_fDeltaTick>0.0f) { if(this==s_pOriginPlayer) { s_fTime += _fDeltaTick; if(s_fTime>s_fCalcDist) { s_fTime -= s_fCalcDist; s_uiLastCalc ++; if(s_uiLastCalc>=s_uiAITotal) { s_uiLastCalc = 0; } } } if(m_bInitialised&&(!m_pTank->IsTransitioning())) { if((m_pTank->GetDisabled())||(!m_pTank->GetAlive())) { RequestState(AI_STATE_DISABLED); } //changes state if a change has been requested ChangeState(); if(ChangeState()) { //state has changed } else { //state has not changed } m_pCurrentState->Process(_fDeltaTick); } } }
void Server::Connector::UpdateState() { State* newState = RequestState(); delete previousState; previousState = currentState; currentState = newState; }
void LinkSwitchBehaveFun(STRATEGYBLOCK* sbptr) { LINK_SWITCH_BEHAV_BLOCK *ls_bhv; DISPLAYBLOCK* dptr; int i; GLOBALASSERT(sbptr); ls_bhv = (LINK_SWITCH_BEHAV_BLOCK*)sbptr->SBdataptr; GLOBALASSERT((ls_bhv->bhvr_type == I_BehaviourLinkSwitch)); dptr = sbptr->SBdptr; // if(AvP.Network!=I_No_Network) return; /* disable for network game */ /****** What I need to do - check to see if we have a request - requests have different effects depending on the mode - so we have to switch on the mode *****/ if (ls_bhv->ls_dtype == linkswitch_animate_me || ls_bhv->ls_dtype == linkswitch_animate_and_move_me) { if(dptr) dptr->ObTxAnimCtrlBlks = ls_bhv->ls_tac; } if (!ReturnPlayerSecurityClearance(0,ls_bhv->security_clerance) && ls_bhv->security_clerance) { ls_bhv->request = I_no_request; return; } if(ls_bhv->switch_flags && SwitchFlag_UseTriggerVolume) { /*See if switch has been set off*/ int i; for (i=0; i<NumActiveStBlocks; i++) { int needToTest = 0; STRATEGYBLOCK *sbPtr = ActiveStBlockList[i]; if (sbPtr->DynPtr) { if (sbPtr->SBdptr == Player) { needToTest = 1; } else if (sbPtr->I_SBtype == I_BehaviourNetGhost) { NETGHOSTDATABLOCK *ghostData = (NETGHOSTDATABLOCK *)sbPtr->SBdataptr; if ((ghostData->type == I_BehaviourMarinePlayer) ||(ghostData->type == I_BehaviourAlienPlayer) ||(ghostData->type == I_BehaviourPredatorPlayer)) needToTest = 1; } } if(needToTest&& sbPtr->DynPtr->Position.vx > ls_bhv->trigger_volume_min.vx && sbPtr->DynPtr->Position.vx < ls_bhv->trigger_volume_max.vx && sbPtr->DynPtr->Position.vy > ls_bhv->trigger_volume_min.vy && sbPtr->DynPtr->Position.vy < ls_bhv->trigger_volume_max.vy && sbPtr->DynPtr->Position.vz > ls_bhv->trigger_volume_min.vz && sbPtr->DynPtr->Position.vz < ls_bhv->trigger_volume_max.vz) { ls_bhv->request=I_request_on; break; } } } if (ls_bhv->request == I_request_on) { if (ls_bhv->triggered_last) { ls_bhv->request = I_no_request; } else { ls_bhv->triggered_last = Yes; } } else { ls_bhv->triggered_last = No; } if(ls_bhv->switch_always_on) { ls_bhv->request=I_no_request; ls_bhv->state=1; } if(AvP.Network != I_No_Network) { /* Every time a switch is updated there is a time delay of 5 seconds before the switch can next be changed by the host sending synch messages. This prevents the host machine from resetting a switch before it learns that it has been pressed */ if(ls_bhv->request == I_no_request) { ls_bhv->TimeUntilNetSynchAllowed-=RealFrameTime; if(ls_bhv->TimeUntilNetSynchAllowed<0) { ls_bhv->TimeUntilNetSynchAllowed=0; } } else { ls_bhv->TimeUntilNetSynchAllowed=5*ONE_FIXED; } } switch(ls_bhv->ls_mode) { case I_lswitch_timer: { if(ls_bhv->request == I_request_on && !ls_bhv->state) { if(sbptr->shapeIndex!=-1)//don't play a sound if there is no shape { if(!ls_bhv->ls_track || !ls_bhv->ls_track->sound) { if (ls_bhv->soundHandle == SOUND_NOACTIVEINDEX) { Sound_Play(SID_SWITCH1,"eh",&ls_bhv->soundHandle); } } } ls_bhv->timer = ls_bhv->time_for_reset; if (ls_bhv->ls_dtype == binswitch_move_me || ls_bhv->ls_dtype == binswitch_animate_and_move_me) { // moving switch ls_bhv->new_state = 1; ls_bhv->new_request = -1; ls_bhv->ls_track->reverse=0; Start_Track_Playing(ls_bhv->ls_track); ls_bhv->mode_store = ls_bhv->ls_mode; ls_bhv->ls_mode = I_lswitch_moving; } else { ls_bhv->state = 1; } if(ls_bhv->ls_tac) { ls_bhv->ls_tac->tac_sequence = 1; ls_bhv->ls_tac->tac_txah_s = GetTxAnimHeaderFromShape(ls_bhv->ls_tac, (sbptr->shapeIndex)); } } else if(ls_bhv->timer > 0) { ls_bhv->timer -= NormalFrameTime; if(ls_bhv->timer <= 0) { if(sbptr->shapeIndex!=-1)//don't play a sound if there is no shape { if(!ls_bhv->ls_track || !ls_bhv->ls_track->sound) { if (ls_bhv->soundHandle == SOUND_NOACTIVEINDEX) { Sound_Play(SID_SWITCH2,"eh",&ls_bhv->soundHandle); } } } ls_bhv->state = 0; if (ls_bhv->ls_dtype == binswitch_move_me || ls_bhv->ls_dtype == binswitch_animate_and_move_me) { // moving switch ls_bhv->new_state = 0; ls_bhv->new_request = -1; ls_bhv->ls_track->reverse=1; Start_Track_Playing(ls_bhv->ls_track); ls_bhv->mode_store = ls_bhv->ls_mode; ls_bhv->ls_mode = I_lswitch_moving; } if(ls_bhv->ls_tac) { ls_bhv->ls_tac->tac_sequence = 0; ls_bhv->ls_tac->tac_txah_s = GetTxAnimHeaderFromShape(ls_bhv->ls_tac, (sbptr->shapeIndex)); } } } break; } case I_lswitch_toggle: { // if it's off and no request then we can return if (!ls_bhv->state) if(ls_bhv->request == I_no_request) return; /* change the state and request the new state in the target */ if(ls_bhv->request != I_no_request) { if(ls_bhv->ls_dtype == binswitch_move_me || ls_bhv->ls_dtype == binswitch_animate_and_move_me) { // moving switch ls_bhv->new_state = !ls_bhv->state; ls_bhv->new_request = -1; ls_bhv->mode_store = ls_bhv->ls_mode; ls_bhv->ls_mode = I_lswitch_moving; ls_bhv->ls_track->reverse=ls_bhv->state; Start_Track_Playing(ls_bhv->ls_track); } else { ls_bhv->state = !ls_bhv->state; } if(sbptr->shapeIndex!=-1)//don't play a sound if there is no shape { if(!ls_bhv->ls_track || !ls_bhv->ls_track->sound) { if (ls_bhv->soundHandle == SOUND_NOACTIVEINDEX) { Sound_Play(SID_SWITCH1,"eh",&ls_bhv->soundHandle); } } } if(ls_bhv->ls_tac) { ls_bhv->ls_tac->tac_sequence = ls_bhv->state ? 1 : 0; ls_bhv->ls_tac->tac_txah_s = GetTxAnimHeaderFromShape(ls_bhv->ls_tac, (sbptr->shapeIndex)); } } break; } case I_lswitch_wait: { // if it's off and no request then we can return if (!ls_bhv->state) if(ls_bhv->request == I_no_request) return; if(ls_bhv->request == I_request_on) { if(!ls_bhv->state)//can only be switched on if currently off { if(!ls_bhv->ls_track || !ls_bhv->ls_track->sound) { Sound_Play(SID_SWITCH2,"eh",&ls_bhv->soundHandle); } if(ls_bhv->ls_dtype == binswitch_move_me || ls_bhv->ls_dtype == binswitch_animate_and_move_me) { // moving switch ls_bhv->new_state = 1; ls_bhv->new_request = -1; ls_bhv->ls_track->reverse=0; Start_Track_Playing(ls_bhv->ls_track); ls_bhv->mode_store = ls_bhv->ls_mode; ls_bhv->ls_mode = I_lswitch_moving; } else { ls_bhv->state = 1; } } } else if (ls_bhv->request == I_request_off) { if(ls_bhv->state)//can only be switched off if currently on { if(!ls_bhv->ls_track || !ls_bhv->ls_track->sound) { Sound_Play(SID_SWITCH1,"eh",&ls_bhv->soundHandle); } if(ls_bhv->ls_dtype == binswitch_move_me || ls_bhv->ls_dtype == binswitch_animate_and_move_me) { // moving switch ls_bhv->new_state = 0; ls_bhv->new_request = -1; ls_bhv->ls_track->reverse=1; Start_Track_Playing(ls_bhv->ls_track); ls_bhv->mode_store = ls_bhv->ls_mode; ls_bhv->ls_mode = I_lswitch_moving; } else { ls_bhv->state = 0; } } } if(ls_bhv->ls_tac) { ls_bhv->ls_tac->tac_sequence = ls_bhv->state ? 1 : 0; ls_bhv->ls_tac->tac_txah_s = GetTxAnimHeaderFromShape(ls_bhv->ls_tac, (sbptr->shapeIndex)); } break; } case I_lswitch_moving: { textprint ("moving\n"); Update_Track_Position(ls_bhv->ls_track); if (!ls_bhv->ls_track->playing) { ls_bhv->ls_mode = ls_bhv->mode_store; ls_bhv->state = ls_bhv->new_state; if(ls_bhv->ls_tac) { ls_bhv->ls_tac->tac_sequence = ls_bhv->state ? 1 : 0; ls_bhv->ls_tac->tac_txah_s = GetTxAnimHeaderFromShape(ls_bhv->ls_tac, (sbptr->shapeIndex)); } } } break; default: GLOBALASSERT(2<1); } ls_bhv->request = I_no_request; //check to see if the system state has changed if (ls_bhv->system_state) { if (!check_link_switch_states(ls_bhv)) { ls_bhv->system_state = No; //link switch system state is turning off if(!ls_bhv->switch_off_message_none) { for(i=0;i<ls_bhv->num_targets;i++) { RequestState(ls_bhv->ls_targets[i].sbptr,ls_bhv->ls_targets[i].request_message^(!ls_bhv->switch_off_message_same), sbptr); } } } } else { if (check_link_switch_states(ls_bhv)) { ls_bhv->system_state = Yes; //link switch system state is turning on for(i=0;i<ls_bhv->num_targets;i++) { RequestState(ls_bhv->ls_targets[i].sbptr,ls_bhv->ls_targets[i].request_message, sbptr); } } } }
void PlacedHierarchyBehaveFun(STRATEGYBLOCK* sbptr) { PLACED_HIERARCHY_BEHAV_BLOCK *ph_bhv; GLOBALASSERT(sbptr); ph_bhv =(PLACED_HIERARCHY_BEHAV_BLOCK*) sbptr->SBdataptr; GLOBALASSERT((ph_bhv->bhvr_type) == I_BehaviourPlacedHierarchy); if(sbptr->SBdptr) { ProveHModel(&ph_bhv->HModelController,sbptr->SBdptr); } else { ProveHModel_Far(&ph_bhv->HModelController,sbptr); } //update sound if(ph_bhv->HModelController.Playing && ph_bhv->current_seq) { int i,j; int timer=ph_bhv->HModelController.sequence_timer; int keyframe_flags=ph_bhv->HModelController.keyframe_flags; if(keyframe_flags) { for(i=0;i<ph_bhv->num_special_track_points;i++) { if(keyframe_flags & ph_bhv->special_track_points[i].track_point_no) { SPECIAL_TRACK_POINT* stp=&ph_bhv->special_track_points[i]; for(j=0;j<stp->num_targets;j++) { TRACK_POINT_TARGET* tpt=&stp->targets[j]; RequestState(tpt->target_sbptr,tpt->request,0); } } } } for(i=0;i<ph_bhv->current_seq->num_sound_times;i++) { PLACED_HIERARCHY_SOUND_TIMES* s_time=&ph_bhv->current_seq->sound_times[i]; if(s_time->sound) { PLACED_HIERARCHY_SOUND* sound=s_time->sound; //not much point in continuing if the sound wasn't loaded anyway if(sound->sound_loaded) { if(timer>=s_time->start_time && timer<s_time->end_time) { //start sound if not already playing if(!sound->playing) { int dist=VectorDistance(&Player->ObWorld,ph_bhv->sound_location); if(dist<=sound->outer_range) //make sure sound is in range { SOUND3DDATA s3d; s3d.position = *ph_bhv->sound_location; s3d.inner_range = sound->inner_range; s3d.outer_range = sound->outer_range; s3d.velocity.vx = 0; s3d.velocity.vy = 0; s3d.velocity.vz = 0; if(s_time->sound->loop) { Sound_Play ((SOUNDINDEX)sound->sound_loaded->sound_num, "nvpel", &s3d,sound->max_volume,sound->pitch,&sound->activ_no); } else { Sound_Play ((SOUNDINDEX)sound->sound_loaded->sound_num, "nvpe", &s3d,sound->max_volume,sound->pitch,&sound->activ_no); } } sound->playing=1; } //otherwise update its position else { int dist=VectorDistance(&Player->ObWorld,ph_bhv->sound_location); if(sound->activ_no!=SOUND_NOACTIVEINDEX) { if(dist<=sound->outer_range) { SOUND3DDATA s3d; s3d.position = *ph_bhv->sound_location; s3d.inner_range = sound->inner_range; s3d.outer_range = sound->outer_range; s3d.velocity.vx = 0; s3d.velocity.vy = 0; s3d.velocity.vz = 0; Sound_UpdateNew3d (sound->activ_no, &s3d); } else { Sound_Stop(sound->activ_no); } } else { if(dist<=sound->outer_range && sound->loop) { SOUND3DDATA s3d; s3d.position = *ph_bhv->sound_location; s3d.inner_range = sound->inner_range; s3d.outer_range = sound->outer_range; s3d.velocity.vx = 0; s3d.velocity.vy = 0; s3d.velocity.vz = 0; Sound_Play ((SOUNDINDEX)sound->sound_loaded->sound_num, "nvpel", &s3d,sound->max_volume,sound->pitch,&sound->activ_no); } } } } else { //stop sound if(sound->activ_no!=SOUND_NOACTIVEINDEX) { Sound_Stop(sound->activ_no); } sound->playing=0; } } } } } }
static void ProcessFarPAQTargetModule(STRATEGYBLOCK *sbPtr, AIMODULE* targetModule) { NPC_TARGETMODULESTATUS targetStatus; PAQ_STATUS_BLOCK *paqStatusPointer; LOCALASSERT(sbPtr); LOCALASSERT(targetModule); LOCALASSERT((sbPtr->I_SBtype == I_BehaviourPredatorAlien)||(sbPtr->I_SBtype == I_BehaviourQueenAlien)); paqStatusPointer = (PAQ_STATUS_BLOCK *)(sbPtr->SBdataptr); LOCALASSERT(paqStatusPointer); targetStatus = GetTargetAIModuleStatus(sbPtr, targetModule); switch(targetStatus) { case(NPCTM_NoEntryPoint): { /* do nothing */ FarNpc_FlipAround(sbPtr); break; } case(NPCTM_NormalRoom): { /* locate to target */ LocateFarNPCInAIModule(sbPtr, targetModule); break; } case(NPCTM_AirDuct): { /* do nothing - pa-q's can't go in air ducts */ FarNpc_FlipAround(sbPtr); break; } case(NPCTM_LiftTeleport): { /* do nothing - pa-q's can't go into lifts */ FarNpc_FlipAround(sbPtr); break; } case(NPCTM_ProxDoorOpen): { /* locate to target: don't need to move thro'quick, as door is constantly retriggered */ LocateFarNPCInAIModule(sbPtr, targetModule); break; } case(NPCTM_ProxDoorNotOpen): { MODULE *renderModule; renderModule=*(targetModule->m_module_ptrs); /* trigger the door, and set timer to quick so we can catch the door when it's open */ ((PROXDOOR_BEHAV_BLOCK *)renderModule->m_sbptr->SBdataptr)->alienTrigger = 1; break; } case(NPCTM_LiftDoorOpen): { /* do nothing - can't use lifts */ FarNpc_FlipAround(sbPtr); break; } case(NPCTM_LiftDoorNotOpen): { /* do nothing - can't open lift doors */ FarNpc_FlipAround(sbPtr); break; } case(NPCTM_SecurityDoorOpen): { /* locate to target, and move thro' quick as we can't retrigger */ LocateFarNPCInAIModule(sbPtr, targetModule); break; } case(NPCTM_SecurityDoorNotOpen): { MODULE *renderModule; renderModule=*(targetModule->m_module_ptrs); /* do some door opening stuff here. Door should stay open for long enough for us to catch it open next time */ RequestState((renderModule->m_sbptr),1,0); break; } default: { LOCALASSERT(1==0); break; } } }