LTBOOL CAISenseHearEnemyDisturbance::Update(HOBJECT hStimulus, LTFLOAT fTimeDelta) { if ( !IsCharacter(hStimulus) ) return LTFALSE; CCharacter* pChar = (CCharacter*)g_pLTServer->HandleToObject(hStimulus); CharCoinInfo info; pChar->GetLastCoinInfo(info); if ( /*info.fTime > m_fStimulationTime &&*/ g_pLTServer->GetTime() > info.fTime && g_pLTServer->GetTime() < info.fTime + 0.50f ) { LTFLOAT fDistance = VEC_DIST(info.vPosition, m_pAI->GetPosition()); LTFLOAT fCoinNoiseDistance = g_pAIButeMgr->GetSenses()->fCoinNoiseDistance; fCoinNoiseDistance *= info.fVolume; if ( fDistance < (m_fDistance + fCoinNoiseDistance) ) { React(); // Record the Timestamp m_fTimestamp = info.fTime; // Record the stimulus position m_vStimulusPosition = info.vPosition; return LTTRUE; } } return LTFALSE; }
LTBOOL CAISenseSeeEnemyFootprint::Update(HOBJECT hStimulus, LTFLOAT fTimeDelta) { if ( !IsCharacter(hStimulus) ) return LTFALSE; CCharacter* pChar = (CCharacter*)g_pLTServer->HandleToObject(hStimulus); CTList<CharFootprintInfo*>* plistFootprints = pChar->GetFootprints(); CharFootprintInfo** ppFootprint = plistFootprints->GetItem(TLIT_FIRST); while ( ppFootprint && *ppFootprint ) { CharFootprintInfo* pFootprint = *ppFootprint; if ( m_pAI->IsPositionVisibleFromEye(CAI::DefaultFilterFn, NULL, pFootprint->vPos, (m_fDistanceSqr), LTTRUE) ) { React(); // Record the Timestamp m_fTimestamp = pFootprint->fTimeStamp; return LTTRUE; } ppFootprint = plistFootprints->GetItem(TLIT_NEXT); } return LTFALSE; }
LOCAL void g_fprint_Tstate( FILE *file, Locstate state) { if (is_obstacle_state(state)) { (void) fprintf(file,"(OBSTACLE STATE)\n\n"); return; } g_fprint_raw_Tstate(file,state,Params(state)->dim); #if !defined(COMBUSTION_CODE) (void) fprintf(file,"\n"); #else /* !defined(COMBUSTION_CODE) */ if (Composition_type(state) == PURE_NON_REACTIVE) { (void) fprintf(file,"\n"); return; } (void) fprintf(file,"burned = %s q = %"FFMT" t_crit = %"FFMT"\n", Burned(state) ? "BURNED" : "UNBURNED", Params(state)->q,Params(state)->critical_temperature); if ((Composition_type(state) == PTFLAME) || (Composition_type(state) == THINFLAME)) { (void) fprintf(file,"\n"); return; } (void) fprintf(file,"reaction progress = %"FFMT"\n",React(state)); if (Composition_type(state) == ZND) { (void) fprintf(file,"\n"); return; } (void) fprintf(file," rho1 = %"FFMT"\n\n",Dens1(state)); #endif /* !defined(COMBUSTION_CODE) */ if(g_composition_type() == MULTI_COMP_NON_REACTIVE) { if(Params(state) != NULL && Params(state)->n_comps != 1) { int i; for(i = 0; i < Params(state)->n_comps; i++) (void) fprintf(file,"partial density[%2d] = %"FFMT"\n", i,pdens(state)[i]); (void) fprintf(file,"\n"); } } } /*end g_fprint_Tstate*/
LTBOOL CAISenseSeeAllyDeath::Update(HOBJECT hStimulus, LTFLOAT fTimeDelta) { if ( !IsBody(hStimulus) ) return LTFALSE; if ( m_pAI->IsObjectVisibleFromEye(CAI::BodyFilterFn, NULL, hStimulus, (m_fDistanceSqr), LTTRUE) ) { React(); return LTTRUE; } return LTFALSE; }
LTBOOL CAISenseHearAllyDeath::Update(HOBJECT hStimulus, LTFLOAT fTimeDelta) { if ( !IsBody(hStimulus) ) return LTFALSE; CDeathScene* pDeathScene = g_pCharacterMgr->GetDeathScene(hStimulus); if ( !pDeathScene ) return LTFALSE; // Time has got to be greater than the death scene noise time but not too much greater if ( g_pLTServer->GetTime() > pDeathScene->GetNoiseTime() && g_pLTServer->GetTime() < pDeathScene->GetNoiseTime() + 1.0f ) { // Noise has to be within audible radius LTFLOAT fDistance = VEC_DIST(pDeathScene->GetPosition(), m_pAI->GetPosition()); LTFLOAT fDeathSceneNoiseDistance = g_pAIButeMgr->GetSenses()->fAllyDeathNoiseDistance; fDeathSceneNoiseDistance *= pDeathScene->GetNoiseVolume(); if ( fDistance < (m_fDistance + fDeathSceneNoiseDistance) ) { React(); // Record the stimulus position m_vStimulusPosition = pDeathScene->GetPosition(); return LTTRUE; } } // Gotta check the pain noise too (using same criterion as pain noise) if ( g_pLTServer->GetTime() > pDeathScene->GetLastPainTime() && g_pLTServer->GetTime() < pDeathScene->GetLastPainTime() + 1.0f ) { // LastPain has to be within audible radius LTFLOAT fDistance = VEC_DIST(pDeathScene->GetPosition(), m_pAI->GetPosition()); LTFLOAT fPainNoiseDistance = g_pAIButeMgr->GetSenses()->fAllyPainNoiseDistance; fPainNoiseDistance *= pDeathScene->GetLastPainVolume(); if ( fDistance < (m_fDistance + fPainNoiseDistance) ) { return LTTRUE; } } return LTFALSE; }
LTBOOL CAISenseHearAllyPain::Update(HOBJECT hStimulus, LTFLOAT fTimeDelta) { if ( !IsCharacter(hStimulus) ) return LTFALSE; // Don't react to our own pain if ( hStimulus == GetAI()->GetObject() ) return LTFALSE; // See if we can hear the pain CCharacter* pChar = (CCharacter*)g_pLTServer->HandleToObject(hStimulus); // Time has got to be greater than the pain noise time but not too much greater LTFLOAT fTime = g_pLTServer->GetTime(); if ( (fTime > pChar->GetLastPainTime()) && (fTime < pChar->GetLastPainTime() + 1.0f) ) { // Noise has to be within audible radius LTVector vPainPos; g_pLTServer->GetObjectPos(hStimulus, &vPainPos); LTFLOAT fDistance = VEC_DIST(vPainPos, m_pAI->GetPosition()); LTFLOAT fPainNoiseDistance = g_pAIButeMgr->GetSenses()->fAllyPainNoiseDistance; fPainNoiseDistance *= pChar->GetLastPainVolume(); if ( fDistance < (m_fDistance + fPainNoiseDistance) ) { React(); // Record the Timestamp m_fTimestamp = pChar->GetLastPainTime(); // Record the stimulus position m_vStimulusPosition = vPainPos; return LTTRUE; } } return LTFALSE; }
LTBOOL CAISenseHearEnemyWeaponFire::Update(HOBJECT hStimulus, LTFLOAT fTimeDelta) { if ( !IsCharacter(hStimulus) ) return LTFALSE; CCharacter* pChar = (CCharacter*)g_pLTServer->HandleToObject(hStimulus); CharFireInfo info; pChar->GetLastFireInfo(info); // Make sure this is a recent firing of the weapon... if (info.fTime + 1.0 < g_pLTServer->GetTime() || info.nWeaponId == WMGR_INVALID_ID) return LTFALSE; WEAPON* pWeapon = g_pWeaponMgr->GetWeapon(info.nWeaponId); if (!pWeapon) return LTFALSE; // Get the Distance that fire noise carries LTFLOAT fWeaponFireNoiseDistance = (LTFLOAT)pWeapon->nAIFireSoundRadius; if (info.bSilenced) fWeaponFireNoiseDistance *= 0.25f; // Get the distance from the fire LTFLOAT fDistance = VEC_DIST(info.vFiredPos, m_pAI->GetPosition()); // Are we close enough to hear? if ( fDistance < (m_fDistance + fWeaponFireNoiseDistance) ) { React(); // Record the Timestamp m_fTimestamp = info.fTime; return LTTRUE; } return LTFALSE; }
EXPORT void g_verbose_fprint_state( FILE *file, const char *name, Locstate state) { bool bin_out; int i, dim; float p, c, S, v[SMAXD], speed; static char vname[3][3] = { "vx", "vy", "vz"}; static char mname[3][3] = { "mx", "my", "mz"}; if (name == NULL) name = ""; (void) fprintf(file,"\n%s:\n",name); (void) fprintf(file,"address %p\n",state); if (state == NULL || is_obstacle_state(state)) { (void) fprintf(file,"(OBSTACLE STATE)\n\n"); return; } dim = Params(state)->dim; p = pressure(state); c = sound_speed(state); S = entropy(state); (void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n", "density",Dens(state), "specific internal energy", specific_internal_energy(state)); (void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n","pressure",p, "sound speed",c); (void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n","temperature", temperature(state),"specific entropy",S); speed = 0.0; for (i = 0; i < dim; i++) { v[i] = vel(i,state); speed += sqr(v[i]); (void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n", mname[i],mom(i,state),vname[i],v[i]); } speed = sqrt(speed); (void) fprintf(file,"%-24s = %-"FFMT"","total energy",energy(state)); if (c > 0. && Dens(state) > 0.) (void) fprintf(file," %-24s = %-"FFMT"\n","Mach number",speed / c); else (void) fprintf(file,"\n"); #if defined(TWOD) if (dim == 2) (void) fprintf(file,"%-24s = %-"FFMT"\n","velocity angle", degrees(angle(v[0],v[1]))); #endif /* defined(TWOD) */ fprint_state_type(file,"State type = ",state_type(state)); (void) fprintf(file,"Params state = %llu\n", gas_param_number(Params(state))); bin_out = is_binary_output(); set_binary_output(NO); if (debugging("prt_params")) fprint_Gas_param(file,Params(state)); else (void) fprintf(file,"Gas_param = %llu\n", gas_param_number(Params(state))); set_binary_output(bin_out); //if(p< -2000 || p>10000) //{ // printf("#huge pressure\n"); // clean_up(0); //} #if !defined(COMBUSTION_CODE) (void) fprintf(file,"\n"); #else /* !defined(COMBUSTION_CODE) */ if (Composition_type(state) == PURE_NON_REACTIVE) { (void) fprintf(file,"\n"); return; } (void) fprintf(file,"%-24s = %-12s %-24s = %-"FFMT"\n","burned", Burned(state) ? "BURNED" : "UNBURNED", "q",Params(state)->q); (void) fprintf(file,"%-24s = %-"FFMT"\n","t_crit", Params(state)->critical_temperature); if (Composition_type(state) == PTFLAME) { (void) fprintf(file,"\n"); return; } (void) fprintf(file,"%-24s = %-"FFMT"\n","product density",Prod(state)); (void) fprintf(file,"%-24s = %-"FFMT"\n", "reaction progress",React(state)); if (Composition_type(state) == ZND) { (void) fprintf(file,"\n"); return; } (void) fprintf(file,"%-24s = %-"FFMT"\n","rho1",Dens1(state)); #endif /* !defined(COMBUSTION_CODE) */ (void) fprintf(file,"%-24s = %-24s %-24s = %-"FFMT"\n\n","gamma_set", Local_gamma_set(state)?"YES" : "NO","local_gamma", Local_gamma(state)); if(g_composition_type() == MULTI_COMP_NON_REACTIVE) { if(Params(state) != NULL && Params(state)->n_comps != 1) { for(i = 0; i < Params(state)->n_comps; i++) (void) fprintf(file,"partial density[%2d] = %"FFMT"\n", i,pdens(state)[i]); (void) fprintf(file,"\n"); /* TMP the following print is for the debuging display purpose */ for(i = 0; i < Params(state)->n_comps; i++) (void) fprintf(file,"[%d]Mass fraction = %-"FFMT"\n", i, pdens(state)[i]/Dens(state)); (void) fprintf(file,"\n"); } } } /*end g_verbose_fprint_state*/
LTBOOL CAISenseHearEnemyWeaponImpact::Update(HOBJECT hStimulus, LTFLOAT fTimeDelta) { if ( !IsCharacter(hStimulus) ) return LTFALSE; CCharacter* pChar = (CCharacter*)g_pLTServer->HandleToObject(hStimulus); CharFireInfo info; pChar->GetLastFireInfo(info); // Make sure this is a recent firing of the weapon... if (info.fTime + 1.0 < g_pLTServer->GetTime() || info.nWeaponId == WMGR_INVALID_ID) return LTFALSE; AMMO* pAmmo = g_pWeaponMgr->GetAmmo(info.nAmmoId); if (!pAmmo || !pAmmo->pImpactFX) return LTFALSE; // Get the Distance that the impact noise carries LTFLOAT fWeaponImpactNoiseDistance = (LTFLOAT) pAmmo->pImpactFX->nAISoundRadius; // Scale based on surface types SURFACE* pSurf = g_pSurfaceMgr->GetSurface(info.eSurface); _ASSERT(pSurf); if ( pSurf && !pAmmo->pImpactFX->bAIIgnoreSurface ) { fWeaponImpactNoiseDistance *= pSurf->fImpactNoiseModifier; } // Get the distance from the impact LTFLOAT fDistance = VEC_DIST(info.vImpactPos, m_pAI->GetPosition()); // Are we close enough to hear? (or did it hit us?) if ( (fDistance < (m_fDistance + fWeaponImpactNoiseDistance)) || (info.hObject == GetAI()->GetObject()) ) { React(); // Record the Timestamp m_fTimestamp = info.fTime; return LTTRUE; } else { // If it hit a character (forget if we like him or not), and we can see that character, react. if ( info.hObject && IsCharacter(info.hObject) && (fDistance < (500.0f)) ) { LTVector vPosition; g_pLTServer->GetObjectPos(info.hObject, &vPosition); LTBOOL bVisible = LTFALSE; if ( m_pAI->CanSeeThrough() ) { bVisible = m_pAI->IsObjectPositionVisibleFromEye(CAI::SeeThroughFilterFn, CAI::SeeThroughPolyFilterFn, info.hObject, vPosition, (250000.0f), LTTRUE); } else { bVisible = m_pAI->IsObjectPositionVisibleFromEye(CAI::DefaultFilterFn, NULL, info.hObject, vPosition, (250000.0f), LTTRUE); } if ( bVisible ) { React(); // Record the Timestamp m_fTimestamp = info.fTime; return LTTRUE; } } } return LTFALSE; }