diff --git a/code/game/VehicleWheelsX2.cpp b/code/game/VehicleWheelsX2.cpp index db807dd4..9b5179bc 100644 --- a/code/game/VehicleWheelsX2.cpp +++ b/code/game/VehicleWheelsX2.cpp @@ -35,13 +35,13 @@ VehicleWheelsX2::VehicleWheelsX2() m_iGear = 1; m_iRPM = 0; gravity = 1.0; - m_fDifferentialRatio = 4.8800001; - m_fGearEfficiency = 0.69999999; - m_fGearRatio[0] = -2.9400001; - m_fGearRatio[1] = 2.9400001; - m_fGearRatio[2] = 1.9400001; - m_fGearRatio[3] = 1.0; - m_fAccelerator = 0.0; + m_fDifferentialRatio = 4.8800001f; + m_fGearEfficiency = 0.69999999f; + m_fGearRatio[0] = -2.9400001f; + m_fGearRatio[1] = 2.9400001f; + m_fGearRatio[2] = 1.9400001f; + m_fGearRatio[3] = 1.0f; + m_fAccelerator = 0.0f; m_bAutomatic = qtrue; m_bBackSlipping = qfalse; m_bFrontSlipping = qfalse; diff --git a/code/game/VehicleWheelsX4.cpp b/code/game/VehicleWheelsX4.cpp index 54a9f72a..59aea106 100644 --- a/code/game/VehicleWheelsX4.cpp +++ b/code/game/VehicleWheelsX4.cpp @@ -35,13 +35,13 @@ VehicleWheelsX4::VehicleWheelsX4() m_iGear = 1; m_iRPM = 0; gravity = 1.0; - m_fDifferentialRatio = 4.8800001; - m_fGearEfficiency = 0.69999999; - m_fGearRatio[0] = -2.9400001; - m_fGearRatio[1] = 2.9400001; - m_fGearRatio[2] = 1.9400001; - m_fGearRatio[3] = 1.0; - m_fAccelerator = 0.0; + m_fDifferentialRatio = 4.8800001f; + m_fGearEfficiency = 0.69999999f; + m_fGearRatio[0] = -2.9400001f; + m_fGearRatio[1] = 2.9400001f; + m_fGearRatio[2] = 1.9400001f; + m_fGearRatio[3] = 1.0f; + m_fAccelerator = 0.0f; m_bBackSlipping = qfalse; m_bAutomatic = qtrue; m_bFrontSlipping = qfalse; diff --git a/code/game/actor.cpp b/code/game/actor.cpp index e22bfb86..a8fe7062 100644 --- a/code/game/actor.cpp +++ b/code/game/actor.cpp @@ -324,8 +324,8 @@ Event EV_Actor_SetAimMotionAnim ( "setaimmotionanim", EV_DEFAULT, - "ss", - "anim_crouch anim_stand", + "sss", + "anim_crouch anim_stand anim_high", "Set aim motion animation (handler scripts only)" ); @@ -2489,8 +2489,8 @@ CLASS_DECLARATION( SimpleActor, Actor, "Actor" ) { NULL, NULL } }; -Actor::GlobalFuncs_t Actor::GlobalFuncs[ MAX_GLOBAL_FUNCS ]; -const_str Actor::m_csThinkNames[ MAX_GLOBAL_FUNCS ] = { +Actor::GlobalFuncs_t Actor::GlobalFuncs[NUM_THINKS]; +const_str Actor::m_csThinkNames[NUM_THINKS] = { STRING_VOID, STRING_TURRET, STRING_COVER, @@ -2527,7 +2527,7 @@ const_str Actor::m_csThinkNames[ MAX_GLOBAL_FUNCS ] = { STRING_NOCLIP, STRING_DEAD }; -const_str Actor::m_csThinkStateNames[ MAX_THINKMAP ] = { +const_str Actor::m_csThinkStateNames[ NUM_THINKSTATES ] = { STRING_VOID, STRING_IDLE, STRING_PAIN, @@ -2573,7 +2573,7 @@ Actor::Actor() takedamage = DAMAGE_AIM; m_fFovDot = cos( 0.5 * m_fFov * M_PI / 180 ); m_eAnimMode = 0; - m_eEmotionMode = EMOTION_NONE; + Anim_Emotion(EMOTION_NONE); m_bDoPhysics = true; path_failed_time = 0; health = 100; @@ -2646,7 +2646,7 @@ Actor::Actor() memset( &m_pPotentialCoverNode, 0, sizeof( m_pPotentialCoverNode ) ); m_iPotentialCoverCount = 0; m_pCoverNode = NULL; - m_csSpecialAttack = 0; + m_csSpecialAttack = STRING_NULL; m_sCurrentPathNodeIndex = -1; m_iDisguiseLevel = 1; m_iNextDisguiseTime = 1; @@ -2784,7 +2784,7 @@ void Actor::MoveTo m_bScriptGoalValid = true; } - SetThinkIdle( THINKSTATE_ATTACK ); + SetThinkIdle(THINK_RUNNER); } /* @@ -2894,27 +2894,7 @@ void Actor::AimAt } else { - Listener *l = ev->GetListener(1); - if (m_aimNode) - { - if (m_aimNode->IsSubclassOfTempWaypoint()) - { - delete m_aimNode; - } - m_aimNode = NULL; - } - if (l) - { - if (!checkInheritance(&SimpleEntity::ClassInfo, l->classinfo())) - { - ScriptError("Bad aim node with classname '%s' specified for '%s' at (%f %f %f)\n", l->getClassname(), TargetName().c_str(), origin.x, origin.y, origin.z); - } - else - { - m_aimNode = (SimpleEntity*)l; - } - } - + SetAimNode(ev->GetListener(1)); } SetThinkIdle( m_aimNode != NULL ? THINK_AIM : THINK_IDLE); @@ -3069,7 +3049,7 @@ void Actor::InitThinkStates ) { - for (size_t i = 0; i < MAX_THINKMAP; i++) + for (size_t i = 0; i < NUM_THINKSTATES; i++) { m_ThinkMap[i] = THINK_VOID; } @@ -3079,7 +3059,6 @@ void Actor::InitThinkStates m_ThinkStates[i] = THINKSTATE_VOID; } - m_bDirtyThinkState = false; m_ThinkMap[THINKSTATE_VOID] = THINK_VOID; m_ThinkMap[THINKSTATE_IDLE] = THINK_IDLE; @@ -3087,12 +3066,13 @@ void Actor::InitThinkStates m_ThinkMap[THINKSTATE_KILLED] = THINK_KILLED; m_ThinkMap[THINKSTATE_ATTACK] = THINK_TURRET; m_ThinkMap[THINKSTATE_CURIOUS] = THINK_CURIOUS; - m_ThinkMap[THINKSTATE_DISGUISE] = THINKSTATE_DISGUISE; + m_ThinkMap[THINKSTATE_DISGUISE] = THINK_DISGUISE_SALUTE; m_ThinkMap[THINKSTATE_GRENADE] = THINK_GRENADE; m_ThinkMap[THINKSTATE_NOCLIP] = THINK_NOCLIP; m_ThinkLevel = THINKLEVEL_NORMAL; m_ThinkState = THINKSTATE_VOID; + m_bDirtyThinkState = false; } @@ -3187,7 +3167,7 @@ void Actor::UpdateEnemy { if (level.inttime > iMaxDirtyTime + m_iEnemyCheckTime) - Actor::UpdateEnemyInternal(); + UpdateEnemyInternal(); } /* @@ -3203,8 +3183,12 @@ void Actor::UpdateEnemyInternal ) { + + for (Sentient *pSent = level.m_HeadSentient[1 - m_Team]; pSent; pSent = pSent->m_NextSentient) + { m_PotentialEnemies.AddPotentialEnemy(pSent); + } m_PotentialEnemies.CheckEnemies(this); @@ -3560,7 +3544,7 @@ void Actor::Init { g_showinfo = gi.Cvar_Get("g_showinfo", "0", NULL); - for (int i = 0; i < MAX_GLOBAL_FUNCS; i++) + for (int i = 0; i < NUM_THINKS; i++) { GlobalFuncs[i].ThinkState = NULL; GlobalFuncs[i].BeginState = NULL; @@ -3778,7 +3762,7 @@ bool Actor::AttackEntryAnimation if (level.inttime >= level.m_iAttackEntryAnimTime + 3000) { - float distSq = (m_Enemy->origin - origin).lengthXY(true); + float distSq = (m_Enemy->origin - origin).lengthXYSquared(); if (m_bNoSurprise || distSq >= 65536) //256 sq { @@ -3829,10 +3813,7 @@ bool Actor::AttackEntryAnimation if ( rand() > distSq * 0.0026041667) //rand() / 0x17F { //FIXME: macro - m_eNextAnimMode = 1; - m_csNextAnimString = STRING_ANIM_STANDSHOCK_SCR; - - m_bNextForceStart = true; + StartAnimation(1, STRING_ANIM_STANDSHOCK_SCR); m_bNoSurprise = true; m_bNewEnemy = false; @@ -3902,8 +3883,8 @@ Check for thinkstate transition. */ bool Actor::CheckForTransition ( - int state, - int level + eThinkState state, + eThinkLevel level ) { @@ -3958,8 +3939,7 @@ bool Actor::PassesTransitionConditions_Attack ) { - if( level.inttime > m_iEnemyCheckTime ) - UpdateEnemyInternal(); + UpdateEnemy(0); if( m_bLockThinkState ) return false; @@ -3999,8 +3979,7 @@ bool Actor::PassesTransitionConditions_Disguise m_iNextDisguiseTime = level.inttime + 200; - if( level.inttime > m_iEnemyCheckTime + 200 ) - UpdateEnemyInternal(); + UpdateEnemy(200); if( !m_Enemy ) return false; @@ -4056,9 +4035,7 @@ bool Actor::PassesTransitionConditions_Curious ) { - - if( level.inttime > m_iEnemyCheckTime + 200 ) - UpdateEnemyInternal(); + UpdateEnemy(200); if( m_bLockThinkState ) return false; @@ -4130,10 +4107,12 @@ void Actor::ThinkStateTransitions //GlobalFuncs_t *func;// = &GlobalFuncs[m_Think[m_ThinkLevel]]; + //loop on all think levels. for (newThinkLevel = NUM_THINKLEVELS -1; newThinkLevel >= 0 ; newThinkLevel--) { newThinkState = m_ThinkStates[newThinkLevel]; - if (newThinkState) + //a new think level is found if it's think state is not THINKSTATE_VOID + if (newThinkState != THINKSTATE_VOID) { break; } @@ -4143,15 +4122,14 @@ void Actor::ThinkStateTransitions { if (newThinkLevel != m_ThinkLevel || m_ThinkState != newThinkState) { - m_ThinkLevel = newThinkLevel; - m_ThinkState = newThinkState; + m_ThinkLevel = (eThinkLevel)newThinkLevel; + m_ThinkState = (eThinkState)newThinkState; m_Think[newThinkLevel] = m_ThinkMap[newThinkState]; } else { RestartState(); } - } else { @@ -4163,15 +4141,17 @@ void Actor::ThinkStateTransitions EndState(i); } } + if (newThinkLevel > m_ThinkLevel) { SuspendState(); - m_ThinkLevel = newThinkLevel; + m_ThinkLevel = (eThinkLevel)newThinkLevel; m_ThinkState = m_ThinkStates[newThinkLevel]; m_Think[newThinkLevel] = m_ThinkMap[m_ThinkState]; BeginState(); + m_Think[m_ThinkLevel] = m_ThinkMap[m_ThinkState]; } else { @@ -4183,21 +4163,23 @@ void Actor::ThinkStateTransitions m_Think[newThinkLevel] = m_ThinkMap[m_ThinkState]; BeginState(); + m_Think[m_ThinkLevel] = m_ThinkMap[m_ThinkState]; } else { - m_ThinkLevel = newThinkLevel; - m_ThinkState = newThinkState = m_ThinkStates[newThinkLevel]; + m_ThinkLevel = (eThinkLevel)newThinkLevel; + m_ThinkState = m_ThinkStates[newThinkLevel]; - if (m_Think[newThinkLevel] != m_ThinkMap[newThinkState]) + if (m_Think[newThinkLevel] != m_ThinkMap[m_ThinkState]) { EndState(newThinkLevel); - m_Think[newThinkLevel] = m_ThinkMap[newThinkState]; + m_Think[m_ThinkLevel] = m_ThinkMap[m_ThinkState]; BeginState(); + m_Think[m_ThinkLevel] = m_ThinkMap[m_ThinkState]; } else { @@ -4205,8 +4187,6 @@ void Actor::ThinkStateTransitions } } } - - } } @@ -4223,8 +4203,9 @@ void Actor::TransitionState ) { - // not found in ida - + //fixme: this is an inline function. + m_State = iNewState; + m_iStateTime = level.inttime + iPadTime; } /* @@ -4240,7 +4221,6 @@ void Actor::ChangeAnim ) { - //FIXME: needs organization. if (m_pAnimThread) { if (g_scripttrace->integer && m_pAnimThread->CanScriptTracePrint()) @@ -4253,8 +4233,9 @@ void Actor::ChangeAnim { delete sc; } + Com_Printf("ChangeAnim: m_pAnimThread aborted\n"); } - //FIXME: macro + if (m_ThinkState != THINKSTATE_ATTACK) { if (m_ThinkState > THINKSTATE_ATTACK) @@ -4265,28 +4246,8 @@ void Actor::ChangeAnim AnimFinished(m_iMotionSlot, true); if (m_bActionAnimSet && !m_bLevelActionAnim) AnimFinished(m_iActionSlot, true); - if (m_bSayAnimSet && !m_bLevelSayAnim) - { AnimFinished(m_iSaySlot, true); - - //FIXME: macro - m_fCrossblendTime = 0.5; - - m_pAnimThread = m_Anim.Create(this); - - if (m_pAnimThread) - { - if (g_scripttrace->integer) - { - if (m_pAnimThread->CanScriptTracePrint()) - Com_Printf("+++ Change Anim\n"); - } - m_pAnimThread->Register(STRING_EMPTY, this); - - m_pAnimThread->StartTiming(); - } - } } else { @@ -4294,28 +4255,9 @@ void Actor::ChangeAnim AnimFinished(m_iMotionSlot, true); if (m_bActionAnimSet) AnimFinished(m_iActionSlot, true); - if (m_bSayAnimSet) - { - if (m_bLevelSayAnim == 2) - { - //FIXME: macro - m_fCrossblendTime = 0.5; + if (m_bSayAnimSet && m_bLevelSayAnim != 2) + AnimFinished(m_iSaySlot, true); - m_pAnimThread = m_Anim.Create(this); - - if (m_pAnimThread) - { - if (g_scripttrace->integer) - { - if (m_pAnimThread->CanScriptTracePrint()) - Com_Printf("+++ Change Anim\n"); - } - m_pAnimThread->Register(STRING_EMPTY, this); - - m_pAnimThread->StartTiming(); - } - } - } } } @@ -4326,30 +4268,9 @@ void Actor::ChangeAnim if (m_bMotionAnimSet && !m_bLevelMotionAnim) AnimFinished(m_iMotionSlot, true); if (m_bActionAnimSet && !m_bLevelActionAnim) - Actor::AnimFinished(m_iActionSlot, true); - + AnimFinished(m_iActionSlot, true); if (m_bSayAnimSet && !m_bLevelSayAnim) - { AnimFinished(m_iSaySlot, true); - - //LABEL_14: - //FIXME: macro - m_fCrossblendTime = 0.5; - - m_pAnimThread = m_Anim.Create(this); - - if (m_pAnimThread) - { - if (g_scripttrace->integer) - { - if (m_pAnimThread->CanScriptTracePrint()) - Com_Printf("+++ Change Anim\n"); - } - m_pAnimThread->Register(STRING_EMPTY, this); - - m_pAnimThread->StartTiming(); - } - } } else { @@ -4357,30 +4278,39 @@ void Actor::ChangeAnim AnimFinished(m_iMotionSlot, true); if (m_bActionAnimSet) AnimFinished(m_iActionSlot, true); - - if (m_bSayAnimSet == 0) - { - //FIXME: macro - m_fCrossblendTime = 0.5; - - m_pAnimThread = m_Anim.Create(this); - - if (m_pAnimThread) - { - if (g_scripttrace->integer) - { - if (m_pAnimThread->CanScriptTracePrint()) - Com_Printf("+++ Change Anim\n"); - } - m_pAnimThread->Register(STRING_EMPTY, this); - - m_pAnimThread->StartTiming(); - } - } + if (m_bSayAnimSet) + AnimFinished(m_iSaySlot, true); } } - + + } + else + { + if (m_bMotionAnimSet) + AnimFinished(m_iMotionSlot, true); + if (m_bActionAnimSet) + AnimFinished(m_iActionSlot, true); + if (m_bSayAnimSet && m_bLevelSayAnim != 2) + AnimFinished(m_iSaySlot, true); + } + + //FIXME: macro + m_fCrossblendTime = 0.5; + + m_pAnimThread = m_Anim.Create(this); + + if (m_pAnimThread) + { + if (g_scripttrace->integer) + { + if (m_pAnimThread->CanScriptTracePrint()) + Com_Printf("+++ Change Anim\n"); + } + m_pAnimThread->Register(STRING_EMPTY, this); + + m_pAnimThread->StartTiming(); + Com_Printf("ChangeAnim: m_pAnimThread started\n"); } } @@ -4523,12 +4453,13 @@ void Actor::UpdateAnim { m_bAnimating = true; SimpleActor::UpdateAim(); - if (UpdateSelectedAnimation()) + if (SimpleActor::UpdateSelectedAnimation()) { + Com_Printf("ChangeAnim\n"); ChangeAnim(); } - - if (Director.iPaused-- == 1) + Director.iPaused--; + if (!Director.iPaused) { Director.ExecuteRunning(); } @@ -4548,7 +4479,7 @@ void Actor::UpdateAnim if (!m_bSayAnimSet && !m_bDog) { - UpdateEmotion(); + SimpleActor::UpdateEmotion(); } //FIXME: macro @@ -4558,7 +4489,7 @@ void Actor::UpdateAnim //FIXME: better notation if (!((m_bUpdateAnimDoneFlags >> slot) & 1) ) { - UpdateAnimSlot(slot); + SimpleActor::UpdateAnimSlot(slot); } } @@ -4570,8 +4501,6 @@ void Actor::UpdateAnim UseSyncTime(slot, 1); fAnimTime = AnimTime(slot); fAnimWeight = edict->s.frameInfo[slot].weight; - //FIXME: macro - if (time == INFINITY) { Com_Printf("ent %i, targetname '%s', anim '%s', slot %i, fAnimTime %f, fAnimWeight %f\n", @@ -4595,6 +4524,8 @@ void Actor::UpdateAnim { SetSyncRate(time / total_weight); } + + PostAnimate(); } /* @@ -4976,7 +4907,7 @@ bool Actor::CanTossGrenadeThroughHint } fTemp = sqrt(fRange * (fDist * (fGravity * 0.5 * vHintDelta.lengthXY()))); - fTemp2 = (vHintDelta.z * fDistSquared - vDelta.z * vHintDelta.lengthXY(true)) * fGravity * 0.5; + fTemp2 = (vHintDelta.z * fDistSquared - vDelta.z * vHintDelta.lengthXYSquared()) * fGravity * 0.5; fTemp3 = fTemp / vHintDelta.lengthXY(); pvVel->x = vHintDelta.x * fTemp3; @@ -5289,7 +5220,7 @@ bool Actor::CanGetGrenadeFromAToB vDelta2 = vHint - vFrom; fDot = DotProduct2D(vDelta2, vDelta); - if (fDot >= 0 && fDot * fDot <= vDelta.lengthXY(true) * vDelta2.lengthXY(true) * 0.89999998) + if (fDot >= 0 && fDot * fDot <= vDelta.lengthXYSquared() * vDelta2.lengthXYSquared() * 0.89999998) { vStart = GrenadeThrowPoint(vFrom, vDelta2, STRING_ANIM_GRENADETOSS_SCR); if (CanTossGrenadeThroughHint(apHint[i], vStart, vTo, bDesperate, pvVel, peMode)) @@ -5566,7 +5497,8 @@ void Actor::Think m_bNeedReload = false; mbBreakSpecialAttack = false; - if (!--Director.iPaused) + Director.iPaused--; + if (!Director.iPaused) Director.ExecuteRunning(); //gi.DPrintf("Actor::Think 5: entnum %d, classname: %s\n", entnum, G_GetEntity(0) ? G_GetEntity(0)->getClassname() : ""); @@ -5729,7 +5661,7 @@ void Actor::GetMoveInfo DoFailSafeMove(m_Path.NextNode()->point); } } - else if (velocity.lengthXY(true) < -0.69999999 && level.inttime >= m_Path.Time() + 1000) + else if (velocity.lengthXYSquared() < -0.69999999 && level.inttime >= m_Path.Time() + 1000) { m_Path.ReFindPath(origin, this); } @@ -5936,7 +5868,7 @@ void Actor::EventGiveWeapon e1.AddConstString(STRING_GLOBAL_WEAPON_SCR); e1.AddString(weapName); - + glbs.Printf("EventGiveWeapon script: %s weapName: %s \n", Director.GetString(STRING_GLOBAL_WEAPON_SCR).c_str(), weapName.c_str()); ExecuteScript(&e1); } @@ -6441,7 +6373,7 @@ void Actor::CuriousSound SetEnemyPos(sound_origin); - SetThinkState(THINKSTATE_VOID, m_ThinkLevel); + EndCurrentThinkState(); SetThinkState(THINKSTATE_CURIOUS, THINKLEVEL_NORMAL); m_pszDebugState = (char *)G_AIEventStringFromType(iType); @@ -6469,6 +6401,7 @@ void Actor::WeaponSound { Sentient *pOwner; + gi.Printf("Actor::WeaponSound"); if (originator->IsSubclassOfWeapon()) { pOwner = ((Weapon *)originator)->GetOwner(); @@ -6648,30 +6581,10 @@ void Actor::GrenadeNotification ) { - bool bCanSee = false, bInFOV = false; if (!m_pGrenade) { - if (originator == m_Enemy) + if (CanSeeFOV(originator)) { - bInFOV = EnemyInFOV(0); - bCanSee = CanSeeEnemy(0); - } - else - { - bInFOV = InFOV(originator->centroid, m_fFov, m_fFovDot); - if (bInFOV) - { - if (gi.AreasConnected(edict->r.areanum, originator->edict->r.areanum)) - { - bCanSee = CanSeeFrom(EyePosition(), originator); - } - } - - } - if (bCanSee && bInFOV) - { - - assert(originator->IsSubclassOfProjectile()); SetGrenade(originator); @@ -6815,23 +6728,23 @@ void Actor::RaiseAlertnessForEventType switch (iType) { case AI_EVENT_WEAPON_FIRE: - fAmount = 0.2; + fAmount = 0.2f; case AI_EVENT_WEAPON_IMPACT: - fAmount = 0.1; + fAmount = 0.1f; case AI_EVENT_EXPLOSION: - fAmount = 0.4; + fAmount = 0.4f; case AI_EVENT_AMERICAN_VOICE: case AI_EVENT_AMERICAN_URGENT: if (m_Team == TEAM_AMERICAN) return; - fAmount = 0.25; + fAmount = 0.25f; case AI_EVENT_MISC: - fAmount = 0.02; + fAmount = 0.02f; case AI_EVENT_MISC_LOUD: case AI_EVENT_FOOTSTEP: - fAmount = 0.05; + fAmount = 0.05f; case AI_EVENT_GRENADE: - fAmount = 0.04; + fAmount = 0.04f; break; case AI_EVENT_GERMAN_VOICE: case AI_EVENT_GERMAN_URGENT: @@ -6975,7 +6888,7 @@ bool Actor::WithinVisionDistance Vector vDelta = ent->origin - origin; //it's basically the same as vDelta.length() < fRadius, //but this is faster because sqrt in vDelta.length() is slower than multiplication. - return vDelta.lengthSquared() < fRadius * fRadius; + return vDelta.lengthSquared() < Square(fRadius); } return false; @@ -7011,7 +6924,7 @@ bool Actor::InFOV float fDot = DotProduct2D(delta, orientation[0]); if (fDot >= 0) { - bInFov = Square(fDot) > delta.lengthXY(true) * Square(check_fovdot); + bInFov = Square(fDot) > delta.lengthXYSquared() * Square(check_fovdot); } } @@ -7031,24 +6944,18 @@ bool Actor::EnemyInFOV ) { - bool inFov; if (level.inttime > iMaxDirtyTime + m_iEnemyFovCheckTime) { - inFov = m_bEnemyInFOV; - if (InFOV(m_Enemy->origin, m_fFov, m_fFovDot) != inFov) + bool bInFov = InFOV(m_Enemy->centroid, m_fFov, m_fFovDot); + if (m_bEnemyInFOV != bInFov) { - inFov = true; - m_bEnemyInFOV = inFov; + m_bEnemyInFOV = !m_bEnemyInFOV; m_iEnemyFovChangeTime = level.inttime; } m_iEnemyFovCheckTime = level.inttime; } - else - { - inFov = m_bEnemyInFOV; - } - return inFov; + return m_iEnemyFovCheckTime; } /* @@ -7064,7 +6971,6 @@ bool Actor::InFOV ) { - //Proposed. Not sure if there are other checks. return InFOV(pos, m_fFov, m_fFovDot); } @@ -7081,8 +6987,14 @@ bool Actor::InFOV ) { - //Proposed. Not sure if there are other checks. - return InFOV(ent->origin, m_fFov, m_fFovDot); + if (ent == m_Enemy) + { + return EnemyInFOV(0); + } + else + { + return InFOV(ent->centroid, m_fFov, m_fFovDot); + } } bool Actor::CanSeeNoFOV @@ -7091,8 +7003,19 @@ bool Actor::CanSeeNoFOV ) { - // not found in ida - return false; + if (ent == m_Enemy) + { + return CanSeeEnemy(0); + } + else + { + bool bCanSee = false; + if (gi.AreasConnected(edict->r.areanum, ent->edict->r.areanum)) + { + bCanSee = CanSeeFrom(EyePosition(), ent); + } + return bCanSee; + } } bool Actor::CanSeeFOV @@ -7101,8 +7024,20 @@ bool Actor::CanSeeFOV ) { - // not found in ida - return false; + //fixme: this is an inline function. + if (ent == m_Enemy) + { + return CanSeeEnemyFOV(0, 0); + } + else + { + bool bCanSee = false; + if (InFOV(ent->centroid, m_fFov, m_fFovDot) && gi.AreasConnected(edict->r.areanum, ent->edict->r.areanum)) + { + bCanSee = CanSeeFrom(EyePosition(), ent); + } + return bCanSee; + } } bool Actor::CanSeeEnemyFOV @@ -7112,8 +7047,7 @@ bool Actor::CanSeeEnemyFOV ) { - // not found in ida - return false; + return EnemyInFOV(iMaxFovDirtyTime) && CanSeeEnemy(iMaxSightDirtyTime); } /* @@ -7462,6 +7396,7 @@ void Actor::DefaultPain ) { + gi.Printf("DefaultPain event"); SetThink(THINKSTATE_PAIN, THINK_PAIN); HandlePain(ev); @@ -7480,6 +7415,7 @@ void Actor::HandlePain ) { + gi.Printf("HandlePain"); Event e1(EV_Listener_ExecuteScript); if (m_bEnablePain) { @@ -7490,7 +7426,6 @@ void Actor::HandlePain { e1.AddValue(ev->GetValue(i)); } - ExecuteScript(&e1); SetThinkState(THINKSTATE_PAIN, THINKLEVEL_PAIN); @@ -7537,6 +7472,7 @@ void Actor::EventPain GlobalFuncs_t *func = &GlobalFuncs[m_Think[m_ThinkLevel]]; + gi.Printf("pain event"); if (func->Pain) (this->*func->Pain)(ev); } @@ -7595,7 +7531,6 @@ void Actor::HandleKilled ClearThinkStates(); - //FIXME: macros SetThinkState(THINKSTATE_KILLED, THINKLEVEL_KILLED); gi.DPrintf("Waittill death unregisterd\n"); @@ -7751,6 +7686,7 @@ bool Actor::NoticeShot ) { + gi.Printf("Notice shot"); if (pShooter->m_Team != m_Team) { return true; @@ -7786,24 +7722,8 @@ bool Actor::NoticeFootstep { if (m_Team == pPedestrian->m_Team || pPedestrian->m_bIsDisguised) return false; - if (pPedestrian == m_Enemy) - { - if (EnemyInFOV(0) && CanSeeEnemy(0)) - { - return false; - } - } - else - { - if (InFOV(pPedestrian->centroid, m_fFov, m_fFovDot) && gi.AreasConnected(edict->r.areanum, pPedestrian->edict->r.areanum)) - { - if (CanSeeFrom(EyePosition(), pPedestrian)) - { - return false; - } - } - } - return true; + + return !CanSeeFOV(pPedestrian); } /* @@ -7822,24 +7742,8 @@ bool Actor::NoticeVoice { if (IsSquadMate(pVocallist)) return false; - if (pVocallist == m_Enemy) - { - if (EnemyInFOV(0) && CanSeeEnemy(0)) - { - return false; - } - } - else - { - if (InFOV(pVocallist->centroid, m_fFov, m_fFovDot) && gi.AreasConnected(edict->r.areanum, pVocallist->edict->r.areanum)) - { - if (CanSeeFrom(EyePosition(), pVocallist)) - { - return false; - } - } - } - return true; + + return !CanSeeFOV(pVocallist); } /* @@ -7957,7 +7861,8 @@ void Actor::ForwardLook ) { - // not found in ida + //fixme: this is an inline function. + m_bHasDesiredLookAngles = false; } /* @@ -8145,14 +8050,19 @@ void Actor::IdlePoint { if (m_pPointEntity) { - float yaw = AngleNormalize180(origin[1] - angles[1] + 30); + Vector delta = m_pPointEntity->centroid - origin; + Vector v2; + VectorNormalize(delta); + v2 = delta.toAngles(); + + float yaw = AngleNormalize180(v2[1] - angles[1] + 30); if (yaw > 100) yaw = 100; if (yaw < -80) yaw = -80; - m_vLUpperArmDesiredAngles[0] = origin[0]; + m_vLUpperArmDesiredAngles[0] = v2[0]; m_vLUpperArmDesiredAngles[1] = yaw; - m_vLUpperArmDesiredAngles[2] = origin[2]; + m_vLUpperArmDesiredAngles[2] = v2[2]; } else { @@ -8384,7 +8294,7 @@ void Actor::IdleTurn } Director.iPaused--; - if (Director.iPaused == 1) + if (!Director.iPaused) { Director.ExecuteRunning(); } @@ -8545,6 +8455,12 @@ bool Actor::SoundSayAnim return false; } +static bool UnknownAnim(char *name, dtiki_t *tiki) +{ + ScriptException::next_bIsForAnim = true; + ScriptError("unknown animation '%s' in '%s'", name, tiki->a->name); +} + /* =============== Actor::EventSetAnim @@ -8851,6 +8767,8 @@ void Actor::EventSetAimMotionAnim ) { + int anim_crouch, anim_stand, anim_high; + const_str name; if (ev->NumArgs() != 3) { ScriptError("bad number of arguments"); @@ -8858,28 +8776,28 @@ void Actor::EventSetAimMotionAnim //FIXME: maybe inline func ? - const_str anim = ev->GetConstString(1); - int animnum = gi.Anim_NumForName(edict->tiki, Director.GetString(anim).c_str()); - if (animnum == -1) + name = ev->GetConstString(1); + anim_crouch = gi.Anim_NumForName(edict->tiki, Director.GetString(name).c_str()); + if (anim_crouch == -1) { ScriptException::next_bIsForAnim = 1; - ScriptError("unknown animation '%s' in '%s'", Director.GetString(anim).c_str(), edict->tiki->a->name); + ScriptError("unknown animation '%s' in '%s'", Director.GetString(name).c_str(), edict->tiki->a->name); } - const_str anim2 = ev->GetConstString(2); - int animnum2 = gi.Anim_NumForName(edict->tiki, Director.GetString(anim2).c_str()); - if (animnum2 == -1) + name = ev->GetConstString(2); + anim_stand = gi.Anim_NumForName(edict->tiki, Director.GetString(name).c_str()); + if (anim_stand == -1) { ScriptException::next_bIsForAnim = 1; - ScriptError("unknown animation '%s' in '%s'", Director.GetString(anim2).c_str(), edict->tiki->a->name); + ScriptError("unknown animation '%s' in '%s'", Director.GetString(name).c_str(), edict->tiki->a->name); } - const_str anim3 = ev->GetConstString(3); - int animnum3 = gi.Anim_NumForName(edict->tiki, Director.GetString(anim3).c_str()); - if (animnum3 == -1) + name = ev->GetConstString(3); + anim_high = gi.Anim_NumForName(edict->tiki, Director.GetString(name).c_str()); + if (anim_high == -1) { ScriptException::next_bIsForAnim = 1; - ScriptError("unknown animation '%s' in '%s'", Director.GetString(anim3).c_str(), edict->tiki->a->name); + ScriptError("unknown animation '%s' in '%s'", Director.GetString(name).c_str(), edict->tiki->a->name); } @@ -8890,9 +8808,9 @@ void Actor::EventSetAimMotionAnim ChangeMotionAnim(); m_bMotionAnimSet = true; UpdateAimMotion(); - StartAimMotionAnimSlot(0, animnum); - StartAimMotionAnimSlot(1, animnum2); - StartAimMotionAnimSlot(2, animnum3); + StartAimMotionAnimSlot(0, anim_crouch); + StartAimMotionAnimSlot(1, anim_stand); + StartAimMotionAnimSlot(2, anim_high); m_iMotionSlot = GetMotionSlot(1); parm.motionfail = qfalse; } @@ -9700,17 +9618,17 @@ void Actor::MovePathGoal if (fSlowdownSpeed > fMoveSpeed + 0.001 && fSlowdownSpeed > 0.4 * sv_runspeed->value) { m_fPathGoalTime = 0; - m_eNextAnimMode = 3; - m_csNextAnimString = NULL; - m_NextAnimLabel = m_Anim; - m_bNextForceStart = true; + StartAnimation(3, m_Anim); MovePath(fMoveSpeed); } else { MovePath(fSlowdownSpeed); if (level.time >= m_fPathGoalTime) + { m_eAnimMode = 1; + Com_Printf("m_eAnimMode MovePathGoal \n"); + } } } @@ -9899,11 +9817,10 @@ void Actor::UpdateAngles { float max_change, error, dist; - vec3_t new_angles; if (!m_YawAchieved) { - + error = m_DesiredYaw - angles[1]; if (error <= 180) { @@ -9929,10 +9846,7 @@ void Actor::UpdateAngles { max_change = -dist; } - new_angles[0] = angles[0] + max_change; - new_angles[1] = angles[1] + max_change; - new_angles[2] = angles[2] + max_change; - setAngles(new_angles); + setAngles(Vector{0, angles[1] + max_change, 0}); } } @@ -10034,7 +9948,7 @@ void Actor::FaceMotion { delta = origin - m_vOriginHistory[m_iCurrentHistory]; - if (delta.lengthXY(true) >= 1) + if (delta.lengthXYSquared() >= 1) { if (dir[1] *delta[0] + dir[0] * delta[1] > 0) { @@ -10181,7 +10095,7 @@ void Actor::FaceEnemyOrMotion if (m_Path.CurrentNodeIndex() != m_sCurrentPathNodeIndex) { float fDot = DotProduct2D(vDelta, m_Path.CurrentDelta()); - m_bFaceEnemy = fDot <= 0 || vDelta.lengthXY(true) * 4096 >= fDot * fDot; + m_bFaceEnemy = fDot <= 0 || vDelta.lengthXYSquared() * 4096 >= fDot * fDot; m_sCurrentPathNodeIndex = m_Path.CurrentNodeIndex(); } @@ -11482,9 +11396,11 @@ void Actor::UpdateBoneControllers() m_fTorsoCurrentTurnSpeed = fAng5; + //only yaw (left/right) angles are allowed. torsoAngles[0] = 0.0; torsoAngles[2] = 0.0; SetControllerAngles(TORSO_TAG, torsoAngles); + //gi.Printf("Torso angles: %f %f %f\n", torsoAngles.x, torsoAngles.y, torsoAngles.z); fAng6 = error - fAng5; } @@ -11591,6 +11507,7 @@ void Actor::UpdateBoneControllers() } SetControllerAngles(HEAD_TAG, headAngles); + //gi.Printf("Head angles: %f %f %f\n", headAngles.x, headAngles.y, headAngles.z); Vector armAngles = GetControllerAngles(ARMS_TAG); @@ -11620,9 +11537,9 @@ void Actor::UpdateBoneControllers() fAng15 = -(level.frametime * m_fLUpperArmTurnSpeed); } - - SetControllerAngles(ARMS_TAG, Vector(m_vLUpperArmDesiredAngles[0], fAng15 + armAngles[1], 0)); - + Vector newArmAngles(m_vLUpperArmDesiredAngles[0], fAng15 + armAngles[1], 0); + SetControllerAngles(ARMS_TAG, newArmAngles); + //gi.Printf("Arm angles: %f %f %f\n", newArmAngles.x, newArmAngles.y, newArmAngles.z); ///////////////////////////////////////////// return; @@ -12216,7 +12133,7 @@ bool Actor::MoveToPatrolCurrentNode } delta = PathDelta(); } - return m_fMoveDoneRadiusSquared >= delta.lengthXY(true); + return m_fMoveDoneRadiusSquared >= delta.lengthXYSquared(); } @@ -12372,7 +12289,7 @@ int Actor::GetThinkType int result = 0; while (m_csThinkNames[result] != csName) { - if (++result > MAX_GLOBAL_FUNCS - 1) + if (++result > NUM_THINKS - 1) { ScriptError("unknown think type '%s'", Director.GetString(csName).c_str()); } @@ -12384,13 +12301,13 @@ int Actor::GetThinkType =============== Actor::SetThink -Set current think. +Modifies think num of current thinkstate inside m_ThinkMap. =============== */ void Actor::SetThink ( - int state, - int think + eThinkState state, + eThinkNum think ) { @@ -12408,11 +12325,11 @@ Set think to idle. */ void Actor::SetThinkIdle ( - int think_idle + eThinkNum think_idle ) { - int think_curious; + eThinkNum think_curious; switch (think_idle) { @@ -12454,8 +12371,8 @@ Set thinkstate. */ void Actor::SetThinkState ( - int state, - int level + eThinkState state, + eThinkLevel level ) { @@ -12514,7 +12431,7 @@ void Actor::ClearThinkStates { for (int i = 0; i <= NUM_THINKLEVELS -1; i++) { - SetThinkState(THINKSTATE_VOID, i); + SetThinkState(THINKSTATE_VOID, (eThinkLevel)i); } } @@ -12612,7 +12529,8 @@ void Actor::EventSetTypeIdle ) { - int think = GetThinkType(ev->GetConstString(1)); + eThinkNum think = (eThinkNum)GetThinkType(ev->GetConstString(1)); + glbs.Printf("EventSetTypeIdle %s : %d\n", ev->GetString(1).c_str(), think); if (!Actor::GlobalFuncs[think].IsState(THINKSTATE_IDLE)) { SetThinkIdle(THINK_IDLE); @@ -12637,7 +12555,9 @@ void Actor::EventSetTypeAttack ) { - int think = GetThinkType(ev->GetConstString(1)); + eThinkNum think = (eThinkNum)GetThinkType(ev->GetConstString(1)); + glbs.Printf("EventSetTypeAttack %s : %d\n", ev->GetString(1).c_str(), think); + //check if the wanted think is an attack one. if (!Actor::GlobalFuncs[think].IsState(THINKSTATE_ATTACK)) { SetThink(THINKSTATE_ATTACK, THINK_TURRET); @@ -12663,7 +12583,8 @@ void Actor::EventSetTypeDisguise ) { - int think = GetThinkType(ev->GetConstString(1)); + eThinkNum think = (eThinkNum)GetThinkType(ev->GetConstString(1)); + glbs.Printf("EventSetTypeDisguise %s : %d\n", ev->GetString(1).c_str(), think); if (!Actor::GlobalFuncs[think].IsState(THINKSTATE_DISGUISE)) { SetThink(THINKSTATE_DISGUISE, THINK_DISGUISE_SALUTE); @@ -12712,9 +12633,9 @@ void Actor::EventSetTypeGrenade ) { - - int think = GetThinkType(ev->GetConstString(1)); - if (!(&GlobalFuncs[think])->IsState(THINKSTATE_GRENADE)) + eThinkNum think = (eThinkNum)GetThinkType(ev->GetConstString(1)); + glbs.Printf("EventSetTypeGrenade %s : %d\n", ev->GetString(1).c_str(), think); + if (!Actor::GlobalFuncs[think].IsState(THINKSTATE_GRENADE)) { SetThink(THINKSTATE_GRENADE, THINK_GRENADE); @@ -12829,8 +12750,9 @@ void Actor::EventDistToEnemy if (m_Enemy) { Vector distV = origin - m_Enemy->origin; - dist = sqrt(DotProduct(distV, distV)); + dist = distV.length(); } + ev->AddFloat(dist); } void Actor::EventGetInterval @@ -13384,7 +13306,7 @@ bool Actor::ShortenPathToAttack { if (PathExists() && !PathComplete() && PathAvoidsSquadMates()) { - for (auto current_node = CurrentPathNode(); current_node > LastPathNode(); current_node--) + for (auto current_node = CurrentPathNode(); current_node >= LastPathNode(); current_node--) { Vector dist = current_node->point - origin; if (dist * dist >= fMinDist * fMinDist) @@ -13669,7 +13591,7 @@ qboolean Actor::setModel } name += model; } - //gi.DPrintf2("Actor::setModel(): name: %s, model: %s, headModel: %s, headSkin: %s\n", name.c_str(), model.c_str(), headModel.c_str(), headSkin.c_str()); + gi.DPrintf2("Actor::setModel(): name: %s, model: %s, headModel: %s, headSkin: %s\n", name.c_str(), model.c_str(), headModel.c_str(), headSkin.c_str()); level.skel_index[edict->s.number] = -1; return gi.setmodel(edict, name); } @@ -14610,7 +14532,7 @@ void Actor::DontFaceWall return; } - if (velocity.lengthXY(true) > Square(8)) + if (velocity.lengthXYSquared() > Square(8)) { m_eDontFaceWallMode = 2; return; @@ -14755,9 +14677,9 @@ void Actor::ClearStates ) { - for (int i = 0; i < MAX_THINKMAP; i++) + for (int i = 0; i < NUM_THINKSTATES; i++) { - SetThink(i, THINK_VOID); + SetThink((eThinkState)i, THINK_VOID); } } @@ -15077,7 +14999,7 @@ bool Actor::EnemyIsDisguised ) { - return ( m_bEnemyIsDisguised || m_Enemy->m_bIsDisguised ) && ( !m_bForceAttackPlayer && m_ThinkState != THINKSTATE_ATTACK ); + return ( m_bEnemyIsDisguised || (m_Enemy && m_Enemy->m_bIsDisguised) ) && ( !m_bForceAttackPlayer && m_ThinkState != THINKSTATE_ATTACK ); } void Actor::setOriginEvent diff --git a/code/game/actor.h b/code/game/actor.h index b43f96cf..d0256231 100644 --- a/code/game/actor.h +++ b/code/game/actor.h @@ -157,60 +157,60 @@ typedef struct // Actor flags #define ACTOR_FLAG_NOISE_HEARD 0 -#define ACTOR_FLAG_INVESTIGATING 1 +#define ACTOR_FLAG_INVESTIGATING 1 #define ACTOR_FLAG_DEATHGIB 2 -#define ACTOR_FLAG_DEATHFADE 3 -#define ACTOR_FLAG_NOCHATTER 4 +#define ACTOR_FLAG_DEATHFADE 3 +#define ACTOR_FLAG_NOCHATTER 4 #define ACTOR_FLAG_INACTIVE 5 -#define ACTOR_FLAG_ANIM_DONE 6 +#define ACTOR_FLAG_ANIM_DONE 6 #define ACTOR_FLAG_STATE_DONE_TIME_VALID 7 -#define ACTOR_FLAG_AI_ON 8 +#define ACTOR_FLAG_AI_ON 8 #define ACTOR_FLAG_LAST_CANSEEENEMY 9 #define ACTOR_FLAG_LAST_CANSEEENEMY_NOFOV 10 #define ACTOR_FLAG_DIALOG_PLAYING 11 -#define ACTOR_FLAG_ALLOW_TALK 12 +#define ACTOR_FLAG_ALLOW_TALK 12 #define ACTOR_FLAG_DAMAGE_ONCE_ON 13 #define ACTOR_FLAG_DAMAGE_ONCE_DAMAGED 14 -#define ACTOR_FLAG_BOUNCE_OFF 15 +#define ACTOR_FLAG_BOUNCE_OFF 15 #define ACTOR_FLAG_NOTIFY_OTHERS_AT_DEATH 16 -#define ACTOR_FLAG_HAS_THING1 17 -#define ACTOR_FLAG_HAS_THING2 18 -#define ACTOR_FLAG_HAS_THING3 19 -#define ACTOR_FLAG_HAS_THING4 20 +#define ACTOR_FLAG_HAS_THING1 17 +#define ACTOR_FLAG_HAS_THING2 18 +#define ACTOR_FLAG_HAS_THING3 19 +#define ACTOR_FLAG_HAS_THING4 20 #define ACTOR_FLAG_LAST_ATTACK_HIT 21 -#define ACTOR_FLAG_STARTED 22 +#define ACTOR_FLAG_STARTED 22 #define ACTOR_FLAG_ALLOW_HANGBACK 23 #define ACTOR_FLAG_USE_GRAVITY 24 #define ACTOR_FLAG_SPAWN_FAILED 25 -#define ACTOR_FLAG_FADING_OUT 26 +#define ACTOR_FLAG_FADING_OUT 26 #define ACTOR_FLAG_DEATHSHRINK 27 -#define ACTOR_FLAG_DEATHSINK 28 -#define ACTOR_FLAG_STAYSOLID 29 -#define ACTOR_FLAG_STUNNED 30 -#define ACTOR_FLAG_ALLOW_FALL 31 -#define ACTOR_FLAG_FINISHED 32 -#define ACTOR_FLAG_IN_LIMBO 33 -#define ACTOR_FLAG_CAN_WALK_ON_OTHERS 34 -#define ACTOR_FLAG_PUSHABLE 35 -#define ACTOR_FLAG_LAST_TRY_TALK 36 -#define ACTOR_FLAG_ATTACKABLE_BY_ACTORS 37 -#define ACTOR_FLAG_TARGETABLE 38 -#define ACTOR_FLAG_ATTACK_ACTORS 39 +#define ACTOR_FLAG_DEATHSINK 28 +#define ACTOR_FLAG_STAYSOLID 29 +#define ACTOR_FLAG_STUNNED 30 +#define ACTOR_FLAG_ALLOW_FALL 31 +#define ACTOR_FLAG_FINISHED 32 +#define ACTOR_FLAG_IN_LIMBO 33 +#define ACTOR_FLAG_CAN_WALK_ON_OTHERS 34 +#define ACTOR_FLAG_PUSHABLE 35 +#define ACTOR_FLAG_LAST_TRY_TALK 36 +#define ACTOR_FLAG_ATTACKABLE_BY_ACTORS 37 +#define ACTOR_FLAG_TARGETABLE 38 +#define ACTOR_FLAG_ATTACK_ACTORS 39 #define ACTOR_FLAG_IMMORTAL 40 #define ACTOR_FLAG_TURNING_HEAD 41 #define ACTOR_FLAG_DIE_COMPLETELY 42 #define ACTOR_FLAG_BLEED_AFTER_DEATH 43 -#define ACTOR_FLAG_IGNORE_STUCK_WARNING 44 +#define ACTOR_FLAG_IGNORE_STUCK_WARNING 44 #define ACTOR_FLAG_IGNORE_OFF_GROUND_WARNING 45 #define ACTOR_FLAG_ALLOWED_TO_KILL 46 #define ACTOR_FLAG_TOUCH_TRIGGERS 47 #define ACTOR_FLAG_IGNORE_WATER 48 #define ACTOR_FLAG_NEVER_IGNORE_SOUNDS 49 #define ACTOR_FLAG_SIMPLE_PATHFINDING 50 -#define ACTOR_FLAG_HAVE_MOVED 51 +#define ACTOR_FLAG_HAVE_MOVED 51 #define ACTOR_FLAG_NO_PAIN_SOUNDS 52 #define ACTOR_FLAG_UPDATE_BOSS_HEALTH 53 -#define ACTOR_FLAG_IGNORE_PAIN_FROM_ACTORS 54 +#define ACTOR_FLAG_IGNORE_PAIN_FROM_ACTORS 54 #define ACTOR_FLAG_DAMAGE_ALLOWED 55 #define ACTOR_FLAG_ALWAYS_GIVE_WATER 56 @@ -220,11 +220,8 @@ typedef struct #define ACTOR_FLAG_MAX 56 #define MAX_ORIGIN_HISTORY 4 -#define MAX_THINKMAP 9 -#define MAX_THINKLEVELS 29 #define MAX_COVER_NODES 16 #define MAX_BODYQUEUE 5 -#define MAX_GLOBAL_FUNCS 35 typedef enum { @@ -257,15 +254,19 @@ typedef struct { vec3_t pos[ 1 ]; } FallPath; -#define THINKSTATE_VOID 0 -#define THINKSTATE_IDLE 1 -#define THINKSTATE_PAIN 2 -#define THINKSTATE_KILLED 3 -#define THINKSTATE_ATTACK 4 -#define THINKSTATE_CURIOUS 5 -#define THINKSTATE_DISGUISE 6 -#define THINKSTATE_GRENADE 7 -#define THINKSTATE_NOCLIP 8 +enum eThinkState +{ + THINKSTATE_VOID, + THINKSTATE_IDLE, + THINKSTATE_PAIN, + THINKSTATE_KILLED, + THINKSTATE_ATTACK, + THINKSTATE_CURIOUS, + THINKSTATE_DISGUISE, + THINKSTATE_GRENADE, + THINKSTATE_NOCLIP, + NUM_THINKSTATES, +}; #define AI_EVENT_NONE 0 #define AI_EVENT_WEAPON_FIRE 1 @@ -280,7 +281,7 @@ typedef struct { #define AI_EVENT_FOOTSTEP 10 #define AI_EVENT_GRENADE 11 -enum thinkNums +enum eThinkNum { THINK_VOID, THINK_TURRET, @@ -316,10 +317,11 @@ enum thinkNums THINK_BALCONY_KILLED, THINK_WEAPONLESS, THINK_NOCLIP, - THINK_DEAD + THINK_DEAD, + NUM_THINKS, }; -enum thinkLevelNums +enum eThinkLevel { THINKLEVEL_NORMAL, //I think it should be THINKLEVEL_IDLE THINKLEVEL_PAIN, @@ -352,27 +354,36 @@ class Actor : public SimpleActor }; public: - /* GlobalFuncs: contains different funcs needed for each actor think/thinkstate */ - static GlobalFuncs_t GlobalFuncs[MAX_GLOBAL_FUNCS]; + /* GlobalFuncs: contains different funcs needed for each actor think + * think is basically a mode for the actor + * when m_ThinkLevel changes, new think value is inside m_Think + * to access current think : m_Think[m_ThinkLevel] + * to access GlobalFuncs related to current think + * GlobalFuncs[m_Think[m_ThinkLevel]]; + **/ + static GlobalFuncs_t GlobalFuncs[NUM_THINKS]; /* const string array containig think names */ - static const_str m_csThinkNames[MAX_GLOBAL_FUNCS]; + static const_str m_csThinkNames[NUM_THINKS]; /* const string array containig think state names */ - static const_str m_csThinkStateNames[MAX_THINKMAP]; + static const_str m_csThinkStateNames[NUM_THINKSTATES]; /* map contating every think value for each thinkstate */ - int m_ThinkMap[MAX_THINKMAP]; + eThinkNum m_ThinkMap[NUM_THINKSTATES]; /* think state for every think level */ - int m_ThinkStates[NUM_THINKLEVELS]; + eThinkState m_ThinkStates[NUM_THINKLEVELS]; /* think value for every think level */ - int m_Think[NUM_THINKLEVELS]; - /* current think level */ - int m_ThinkLevel; - /* current think state */ - int m_ThinkState; + eThinkNum m_Think[NUM_THINKLEVELS]; + /* current think level + * think levels are more like priorities + * highest level is used. + **/ + eThinkLevel m_ThinkLevel; + /* current think state*/ + eThinkState m_ThinkState; /* current state (different than think state) */ int m_State; /* current state change time */ int m_iStateTime; - /* should block think state ? */ + /* should lock think state ? */ bool m_bLockThinkState; /* think state changed */ bool m_bDirtyThinkState; @@ -685,7 +696,7 @@ public: void FixAIParameters( void ); bool AttackEntryAnimation( void ); void CheckForThinkStateTransition( void ); - bool CheckForTransition( int state, int level ); + bool CheckForTransition( eThinkState state, eThinkLevel level ); bool PassesTransitionConditions_Grenade( void ); bool PassesTransitionConditions_Attack( void ); bool PassesTransitionConditions_Disguise( void ); @@ -1092,9 +1103,9 @@ public: void EventSetAccuracy( Event *ev ); void EventGetAccuracy( Event *ev ); int GetThinkType( const_str csName ); - void SetThink( int state, int think ); - void SetThinkIdle( int think_idle ); - void SetThinkState( int state, int level ); + void SetThink( eThinkState state, eThinkNum think ); + void SetThinkIdle( eThinkNum think_idle ); + void SetThinkState( eThinkState state, eThinkLevel level ); void EndCurrentThinkState( void ); void ClearThinkStates( void ); int CurrentThink( void ) const; @@ -1294,19 +1305,19 @@ inline void Actor::Archive { SimpleActor::Archive( arc ); - for( int i = MAX_THINKMAP - 1; i >= 0; i-- ) + for( int i = NUM_THINKSTATES - 1; i >= 0; i-- ) { - arc.ArchiveInteger( &m_ThinkMap[ i ] ); + ArchiveEnum(m_ThinkMap[i], eThinkNum); } for( int i = NUM_THINKLEVELS - 1; i >= 0; i-- ) { - arc.ArchiveInteger( &m_ThinkStates[ i ] ); - arc.ArchiveInteger( &m_Think[ i ] ); + ArchiveEnum(m_ThinkStates[i], eThinkState); + ArchiveEnum(m_Think[i], eThinkNum); } - arc.ArchiveInteger( &m_ThinkLevel ); - arc.ArchiveInteger( &m_ThinkState); + ArchiveEnum(m_ThinkLevel, eThinkLevel); + ArchiveEnum(m_ThinkState, eThinkState); arc.ArchiveInteger( &m_State); arc.ArchiveInteger( &m_iStateTime); arc.ArchiveBool( &m_bLockThinkState); diff --git a/code/game/actor_animapi.cpp b/code/game/actor_animapi.cpp index fba865df..e4739a22 100644 --- a/code/game/actor_animapi.cpp +++ b/code/game/actor_animapi.cpp @@ -54,10 +54,7 @@ void SimpleActor::Anim_Attack ) { - m_eNextAnimMode = 1; - m_csNextAnimString = NULL; - m_NextAnimLabel = m_AttackHandler; - m_bNextForceStart = false; + DesiredAnimation(1, m_AttackHandler); } void SimpleActor::Anim_Sniper @@ -66,10 +63,7 @@ void SimpleActor::Anim_Sniper ) { - m_eNextAnimMode = 1; - m_csNextAnimString = NULL; - m_NextAnimLabel = m_SniperHandler; - m_bNextForceStart = false; + DesiredAnimation(1, m_SniperHandler); } void SimpleActor::Anim_Aim @@ -78,9 +72,7 @@ void SimpleActor::Anim_Aim ) { - m_eNextAnimMode = 1; - m_csNextAnimString = STRING_ANIM_AIM_SCR; - m_bNextForceStart = false; + DesiredAnimation(1, STRING_ANIM_AIM_SCR); } void SimpleActor::Anim_Shoot @@ -89,9 +81,7 @@ void SimpleActor::Anim_Shoot ) { - m_eNextAnimMode = 1; - m_csNextAnimString = STRING_ANIM_SHOOT_SCR; - m_bNextForceStart = false; + DesiredAnimation(1, STRING_ANIM_SHOOT_SCR); } void SimpleActor::Anim_Idle @@ -100,9 +90,7 @@ void SimpleActor::Anim_Idle ) { - m_eNextAnimMode = 1; - m_csNextAnimString = STRING_ANIM_IDLE_SCR; - m_bNextForceStart = false; + DesiredAnimation(1, STRING_ANIM_IDLE_SCR); } void SimpleActor::Anim_Crouch @@ -111,9 +99,7 @@ void SimpleActor::Anim_Crouch ) { - m_eNextAnimMode = 1; - m_csNextAnimString = STRING_ANIM_CROUCH_SCR; - m_bNextForceStart = false; + DesiredAnimation(1, STRING_ANIM_CROUCH_SCR); } void SimpleActor::Anim_Prone @@ -122,9 +108,7 @@ void SimpleActor::Anim_Prone ) { - m_eNextAnimMode = 1; - m_csNextAnimString = STRING_ANIM_PRONE_SCR; - m_bNextForceStart = false; + DesiredAnimation(1, STRING_ANIM_PRONE_SCR); } void SimpleActor::Anim_Stand @@ -133,9 +117,7 @@ void SimpleActor::Anim_Stand ) { - m_eNextAnimMode = 1; - m_csNextAnimString = STRING_ANIM_STAND_SCR; - m_bNextForceStart = false; + DesiredAnimation(1, STRING_ANIM_STAND_SCR); } void SimpleActor::Anim_Cower @@ -144,9 +126,7 @@ void SimpleActor::Anim_Cower ) { - m_eNextAnimMode = 1; - m_csNextAnimString = STRING_ANIM_COWER_SCR; - m_bNextForceStart = false; + DesiredAnimation(1, STRING_ANIM_COWER_SCR); } void SimpleActor::Anim_Killed @@ -155,10 +135,8 @@ void SimpleActor::Anim_Killed ) { - m_eAnimMode = 1; - m_csNextAnimString = NULL; - m_NextAnimLabel = m_DeathHandler; - m_bNextForceStart = false; + Com_Printf("m_eAnimMode Anim_Killed \n"); + DesiredAnimation(1, m_DeathHandler); } void SimpleActor::Anim_StartPain @@ -167,10 +145,9 @@ void SimpleActor::Anim_StartPain ) { - m_eAnimMode = 1; - m_csNextAnimString = NULL; - m_NextAnimLabel = m_PainHandler; - m_bNextForceStart = true; + Com_Printf("m_eAnimMode Anim_StartPain \n"); + StartAnimation(1, m_PainHandler); + } void SimpleActor::Anim_Pain @@ -189,9 +166,7 @@ void SimpleActor::Anim_CrouchRunTo ) { - m_csNextAnimString = STRING_ANIM_CROUCH_RUN_SCR; - m_eNextAnimMode = eAnimMode; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_CROUCH_RUN_SCR); } void SimpleActor::Anim_CrouchWalkTo @@ -200,9 +175,7 @@ void SimpleActor::Anim_CrouchWalkTo ) { - m_csNextAnimString = STRING_ANIM_CROUCH_WALK_SCR; - m_eNextAnimMode = eAnimMode; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_CROUCH_WALK_SCR); } void SimpleActor::Anim_StandRunTo @@ -211,9 +184,7 @@ void SimpleActor::Anim_StandRunTo ) { - m_csNextAnimString = STRING_ANIM_RUN_SCR; - m_eNextAnimMode = eAnimMode; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_RUN_SCR); } void SimpleActor::Anim_StandWalkTo @@ -222,9 +193,7 @@ void SimpleActor::Anim_StandWalkTo ) { - m_csNextAnimString = STRING_ANIM_WALK_SCR; - m_eNextAnimMode = eAnimMode; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_WALK_SCR); } void SimpleActor::Anim_RunTo @@ -233,9 +202,7 @@ void SimpleActor::Anim_RunTo ) { - m_bNextForceStart = false; - m_csNextAnimString = GetRunAnim(); - m_eNextAnimMode = eAnimMode; + DesiredAnimation(eAnimMode, GetRunAnim()); } void SimpleActor::Anim_WalkTo @@ -244,9 +211,7 @@ void SimpleActor::Anim_WalkTo ) { - m_bNextForceStart = false; - m_csNextAnimString = GetWalkAnim(); - m_eNextAnimMode = eAnimMode; + DesiredAnimation(eAnimMode, GetWalkAnim()); } void SimpleActor::Anim_RunAwayFiring @@ -255,9 +220,7 @@ void SimpleActor::Anim_RunAwayFiring ) { - m_csNextAnimString = STRING_ANIM_RUNAWAYFIRING_SCR; - m_eNextAnimMode = eAnimMode; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_RUNAWAYFIRING_SCR); } void SimpleActor::Anim_RunToShooting @@ -266,9 +229,7 @@ void SimpleActor::Anim_RunToShooting ) { - m_csNextAnimString = STRING_ANIM_RUN_SHOOT_SCR; - m_eNextAnimMode = eAnimMode; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_RUN_SHOOT_SCR); } void SimpleActor::Anim_RunToAlarm @@ -277,9 +238,7 @@ void SimpleActor::Anim_RunToAlarm ) { - m_csNextAnimString = STRING_ANIM_RUNTO_ALARM_SCR; - m_eNextAnimMode = eAnimMode; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_RUNTO_ALARM_SCR); } void SimpleActor::Anim_RunToCasual @@ -288,9 +247,7 @@ void SimpleActor::Anim_RunToCasual ) { - m_csNextAnimString = STRING_ANIM_RUNTO_CASUAL_SCR; - m_eNextAnimMode = eAnimMode; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_RUNTO_CASUAL_SCR); } void SimpleActor::Anim_RunToCover @@ -299,9 +256,7 @@ void SimpleActor::Anim_RunToCover ) { - m_csNextAnimString = STRING_ANIM_RUNTO_COVER_SCR; - m_eNextAnimMode = eAnimMode; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_RUNTO_COVER_SCR); } void SimpleActor::Anim_RunToDanger @@ -310,9 +265,7 @@ void SimpleActor::Anim_RunToDanger ) { - m_csNextAnimString = STRING_ANIM_RUNTO_DANGER_SCR; - m_eNextAnimMode = eAnimMode; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_RUNTO_DANGER_SCR); } void SimpleActor::Anim_RunToDive @@ -321,9 +274,7 @@ void SimpleActor::Anim_RunToDive ) { - m_csNextAnimString = STRING_ANIM_RUNTO_DIVE_SCR; - m_eNextAnimMode = eAnimMode; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_RUNTO_DIVE_SCR); } void SimpleActor::Anim_RunToFlee @@ -332,9 +283,7 @@ void SimpleActor::Anim_RunToFlee ) { - m_eNextAnimMode = eAnimMode; - m_csNextAnimString = STRING_ANIM_RUNTO_FLEE_SCR; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_RUNTO_FLEE_SCR); } void SimpleActor::Anim_RunToInOpen @@ -343,9 +292,7 @@ void SimpleActor::Anim_RunToInOpen ) { - m_eNextAnimMode = eAnimMode; - m_csNextAnimString = STRING_ANIM_RUNTO_INOPEN_SCR; - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_RUNTO_INOPEN_SCR); } void SimpleActor::Anim_Emotion @@ -386,14 +333,11 @@ void SimpleActor::Anim_FullBody { if( m_csAnimName == csFullBodyAnim ) { - m_bNextForceStart = false; + DesiredAnimation(eAnimMode, STRING_ANIM_FULLBODY_SCR); } else { - m_bNextForceStart = true; m_csAnimName = csFullBodyAnim; + StartAnimation(eAnimMode, STRING_ANIM_FULLBODY_SCR); } - - m_csNextAnimString = STRING_ANIM_FULLBODY_SCR; - m_eNextAnimMode = eAnimMode; } diff --git a/code/game/actor_animcurious.cpp b/code/game/actor_animcurious.cpp index 249457c1..36c13cc4 100644 --- a/code/game/actor_animcurious.cpp +++ b/code/game/actor_animcurious.cpp @@ -47,11 +47,9 @@ void Actor::Begin_AnimCurious DoForceActivate(); m_csMood = STRING_CURIOUS; - m_bNextForceStart = true; - m_YawAchieved = true; - m_eNextAnimMode = m_AnimMode; + StartAnimation(m_AnimMode, m_csAnimScript); + StopTurning(); m_iCuriousTime = level.inttime; - m_csNextAnimString = m_csAnimScript; } void Actor::Think_AnimCurious @@ -67,6 +65,7 @@ void Actor::Think_AnimCurious m_pszDebugState = ""; LookAtCuriosity(); TimeOutCurious(); + DesiredAnimation(m_AnimMode, m_csAnimScript); CheckForThinkStateTransition(); PostThink( false ); } diff --git a/code/game/actor_curious.cpp b/code/game/actor_curious.cpp index cb94119c..ade4e625 100644 --- a/code/game/actor_curious.cpp +++ b/code/game/actor_curious.cpp @@ -47,7 +47,7 @@ void Actor::Begin_Curious { Vector vDelta; - float fDistSquared; + //float fDistSquared; DoForceActivate(); m_csMood = STRING_CURIOUS; @@ -202,6 +202,7 @@ void Actor::Think_Curious ContinueAnimation(); //LABEL_16: CheckForThinkStateTransition(); + glbs.Printf("Think_Curious CheckForThinkStateTransition 1\n"); PostThink(true); return; } @@ -221,11 +222,13 @@ void Actor::Think_Curious { if (level.inttime > m_iCuriousTime + 500) { + glbs.Printf("Think_Curious m_Enemy: %s EnemyIsDisguised: %s\n", m_Enemy ? "true": "false", EnemyIsDisguised() ? "true" : "false"); SetThinkState(THINKSTATE_IDLE, THINKLEVEL_NORMAL); m_iCuriousTime = 0; } } CheckForThinkStateTransition(); + glbs.Printf("Think_Curious CheckForThinkStateTransition 2\n"); PostThink(true); return; } @@ -244,6 +247,7 @@ void Actor::Think_Curious } } CheckForThinkStateTransition(); + glbs.Printf("Think_Curious CheckForThinkStateTransition 3\n"); PostThink(true); return; } @@ -288,6 +292,7 @@ void Actor::Think_Curious LookAtCuriosity(); } CheckForThinkStateTransition(); + glbs.Printf("Think_Curious CheckForThinkStateTransition 4\n"); PostThink(true); return; } @@ -334,6 +339,7 @@ void Actor::Think_Curious LookAtCuriosity(); } CheckForThinkStateTransition(); + glbs.Printf("Think_Curious CheckForThinkStateTransition 5\n"); PostThink(true); return; } @@ -352,6 +358,7 @@ void Actor::Think_Curious } } CheckForThinkStateTransition(); + glbs.Printf("Think_Curious CheckForThinkStateTransition 6\n"); PostThink(true); return; } @@ -395,6 +402,7 @@ void Actor::Think_Curious LookAtCuriosity(); } CheckForThinkStateTransition(); + glbs.Printf("Think_Curious CheckForThinkStateTransition 7\n"); PostThink(true); return; } @@ -411,6 +419,7 @@ void Actor::Think_Curious } } CheckForThinkStateTransition(); + glbs.Printf("Think_Curious CheckForThinkStateTransition 8\n"); PostThink(true); return; } @@ -506,7 +515,6 @@ void Actor::SetCuriousAnimHint ( int iAnimHint ) - { m_iCuriousAnimHint = iAnimHint; } diff --git a/code/game/actor_disguise_rover.cpp b/code/game/actor_disguise_rover.cpp index 68978bfd..800d3028 100644 --- a/code/game/actor_disguise_rover.cpp +++ b/code/game/actor_disguise_rover.cpp @@ -190,6 +190,6 @@ void Actor::Think_DisguiseRover assert(!"invalid think state"); } - CheckForTransition(THINKSTATE_GRENADE, 0); + CheckForTransition(THINKSTATE_GRENADE, THINKLEVEL_NORMAL); PostThink(true); } diff --git a/code/game/actor_disguise_sentry.cpp b/code/game/actor_disguise_sentry.cpp index 3d13cffe..7a67edcb 100644 --- a/code/game/actor_disguise_sentry.cpp +++ b/code/game/actor_disguise_sentry.cpp @@ -189,7 +189,7 @@ void Actor::Think_DisguiseSentry assert(!"invalid think state"); break; } - CheckForTransition(THINKSTATE_GRENADE, 0); + CheckForTransition(THINKSTATE_GRENADE, THINKLEVEL_NORMAL); PostThink(true); } } diff --git a/code/game/actor_grenade.cpp b/code/game/actor_grenade.cpp index 6bf6659b..6180c506 100644 --- a/code/game/actor_grenade.cpp +++ b/code/game/actor_grenade.cpp @@ -62,7 +62,7 @@ bool Actor::Grenade_Acquire if (PathComplete()) { m_bHasDesiredLookAngles = false; - if (m_pGrenade->velocity.lengthXY(true) >= 1024) + if (m_pGrenade->velocity.lengthXYSquared() >= 1024) { Anim_Stand(); } @@ -119,7 +119,7 @@ void Actor::Grenade_Flee ) { - float origin_ratio; + //float origin_ratio; float fMinCloseDistSquared; float fCosAngle; float fSinAngle; @@ -180,7 +180,7 @@ void Actor::Grenade_Flee else { - if ((origin - m_vGrenadePos).lengthXY(true) >= 100352 + if ((origin - m_vGrenadePos).lengthXYSquared() >= 100352 || !G_SightTrace( centroid, vec_zero, @@ -302,7 +302,7 @@ void Actor::Grenade_MartyrAcquire m_pGrenade->velocity = vec_zero; //weird ? m_pGrenade->velocity is vec_zero ??? - if (m_pGrenade->velocity.lengthXY(true) < 1024) + if (m_pGrenade->velocity.lengthXYSquared() < 1024) { m_pGrenade->velocity = vec_zero; @@ -315,7 +315,7 @@ void Actor::Grenade_MartyrAcquire { Anim_RunToCasual(3); m_csPathGoalEndAnimScript = STRING_ANIM_GRENADEMARTYR_SCR; - if ((origin-m_vGrenadePos).lengthXY(true) > 16384) + if ((origin-m_vGrenadePos).lengthXYSquared() > 16384) { FaceMotion(); } @@ -491,7 +491,7 @@ void Actor::Begin_Grenade } vDelta = m_vGrenadePos - origin; vDelta.z = 0; - fDistSquared = vDelta.lengthXY(true); + fDistSquared = vDelta.lengthXYSquared(); if (fDistSquared >= 65536) { m_eGrenadeState = AI_GRENSTATE_FLEE; diff --git a/code/game/actor_idle.cpp b/code/game/actor_idle.cpp index 7b5c9521..5a8b1941 100644 --- a/code/game/actor_idle.cpp +++ b/code/game/actor_idle.cpp @@ -42,6 +42,7 @@ void Actor::Begin_Idle ) { + glbs.Printf("Begin_Idle\n"); m_csMood = m_csIdleMood; ClearPath(); } @@ -67,7 +68,6 @@ void Actor::IdleThink ) { - //FIXME: revision IdlePoint(); IdleLook(); if (PathExists() && PathComplete()) @@ -78,28 +78,23 @@ void Actor::IdleThink { SetPathToNotBlockSentient((Sentient *)G_GetEntity(0)); } - if (!PathExists()) + + if (PathExists()) { - Anim_Idle(); - IdleTurn(); - PostThink(true); + Anim_WalkTo(2); + if (PathDist() <= 128.0) + IdleTurn(); + else + FaceMotion(); } else { - //FIXME: macros - Anim_WalkTo(2); - - if (PathDist() <= 128.0) - { - IdleTurn(); - PostThink(true); - } - else - { - FaceMotion(); - } + Anim_Idle(); + IdleTurn(); } + PostThink(true); + } @@ -116,12 +111,9 @@ bool Actor::PassesTransitionConditions_Idle ) { + glbs.Printf("PassesTransitionConditions_Idle\n"); - if (m_bEnableEnemy) - { - if (level.inttime > m_iEnemyCheckTime + 500) - UpdateEnemyInternal(); - } + UpdateEnemy(500); if (m_bLockThinkState) return false; diff --git a/code/game/actor_killed.cpp b/code/game/actor_killed.cpp index bb2ffc6e..decf0205 100644 --- a/code/game/actor_killed.cpp +++ b/code/game/actor_killed.cpp @@ -58,7 +58,7 @@ void Actor::Begin_Killed PostEvent( e1, - 0.05); + 0.05f); m_State = 700; m_iStateTime = level.inttime; } diff --git a/code/game/actor_machinegunner.cpp b/code/game/actor_machinegunner.cpp index 29049891..d99d3876 100644 --- a/code/game/actor_machinegunner.cpp +++ b/code/game/actor_machinegunner.cpp @@ -170,7 +170,7 @@ void Actor::Think_MachineGunner ThinkHoldGun(); return; } - if (m_ThinkStates[0] != THINKSTATE_IDLE) + if (m_ThinkStates[THINKLEVEL_NORMAL] != THINKSTATE_IDLE) { BecomeTurretGuy(); return; @@ -208,10 +208,10 @@ void Actor::ThinkHoldGun float machine_gunner_hands_up_stand; float heightDiff; float right; - vec3_t newOrigin; + //vec3_t newOrigin; Vector offset; Vector start; - vec3_t new_angles; + //vec3_t new_angles; Vector vForward; UpdateEyeOrigin(); @@ -249,11 +249,11 @@ void Actor::ThinkHoldGun if (m_State == 1201) { - heightDiff = 71.6; + heightDiff = 71.6f; } else { - heightDiff = 71.8; + heightDiff = 71.8f; } machine_gunner_hands_up_stand = origin[2] - (m_pTurret->origin[2] - heightDiff); diff --git a/code/game/actor_noclip.cpp b/code/game/actor_noclip.cpp index aa6ed74e..e0bfd741 100644 --- a/code/game/actor_noclip.cpp +++ b/code/game/actor_noclip.cpp @@ -55,7 +55,7 @@ void Actor::Think_NoClip Vector total_offset; Vector total_offset_unit; float total_dist; - vec3_t frame_offset; + //vec3_t frame_offset; float frame_dist; m_pszDebugState = ""; diff --git a/code/game/actor_turret.cpp b/code/game/actor_turret.cpp index 58e3ef68..b317c676 100644 --- a/code/game/actor_turret.cpp +++ b/code/game/actor_turret.cpp @@ -180,7 +180,7 @@ void Actor::Think_Turret if (m_State != 109) { if (m_State != 104 - || (origin - m_vHome).lengthXY(true) <= 0.64f * m_fLeashSquared + 64.0f + || (origin - m_vHome).lengthXYSquared() <= 0.64f * m_fLeashSquared + 64.0f || !State_Turret_RunHome(false) ) { m_pszDebugState = "Idle"; @@ -784,13 +784,13 @@ void Actor::State_Turret_Reacquire ) { - Sentient *v1; // ecx + /*Sentient *v1; // ecx float v2; // ST08_4 float v3; // ST0C_4 Sentient *v4; // ecx float v5; // ST08_4 float v6; // ST0C_4 - + */ if (PathExists() && !PathComplete()) { if (CanMovePathWithLeash()) diff --git a/code/game/actorenemy.cpp b/code/game/actorenemy.cpp index 84f1a405..04e33812 100644 --- a/code/game/actorenemy.cpp +++ b/code/game/actorenemy.cpp @@ -90,7 +90,7 @@ int ActorEnemy::UpdateThreat Vector vDelta; m_iThreat = 0; - m_fCurrentRangeSquared = 1e38; + m_fCurrentRangeSquared = 1e38f; if (m_pEnemy->m_bIsDisguised || m_fTotalVisibility < 1) return m_iThreat; @@ -278,13 +278,13 @@ float ActorEnemy::UpdateLMRF { //FIXME: variable names, I did my best Vector vDelta; - float fFarPlane, fLMRF = 8, fMinSightTime, fFovScale, fForward, fNormalizedRange, fRangeScale, fRange, fMaxRange; + float fFarPlane, fLMRF, /*fMinSightTime,*/ fFovScale, fForward, /*fNormalizedRange,*/ fRangeScale, fRange/*, fMaxRange*/ ; float fTmp1, fTmp2, fTmp3; *pbInFovAndRange = false; *pbVisible = false; - vDelta = pSelf->origin - GetEnemy()->origin; + vDelta = pSelf->EyePosition() - GetEnemy()->origin; fFarPlane = world->farplane_distance; @@ -298,30 +298,30 @@ float ActorEnemy::UpdateLMRF } - if (Square(fRange) < vDelta.lengthXY(true)) + if (vDelta.lengthXYSquared() > Square(fRange)) { - return fLMRF; + return 8.0; } fForward = vDelta.lengthXY(); if (-DotProduct2D(vDelta, pSelf->m_vEyeDir) < 0) { - return fLMRF; + return 8.0; } fTmp2 = 128.0 - DotProduct2D(vDelta, pSelf->m_vEyeDir); if (fForward * pSelf->m_fFovDot > fTmp2) { - return fLMRF; + return 8.0; } *pbInFovAndRange = true; if (!pSelf->CanSee(m_pEnemy, 0, 0)) { - return fLMRF; + return 8.0; } *pbVisible = true; @@ -392,7 +392,7 @@ ActorEnemy *ActorEnemySet::AddPotentialEnemy NewEnemy.m_pEnemy = pEnemy; - NewEnemy.m_fCurrentRangeSquared = 1e38; + NewEnemy.m_fCurrentRangeSquared = 1e38f; NewEnemy.m_iLastSightChangeTime = 0; NewEnemy.m_vLastKnownPos = vec_zero; @@ -451,25 +451,28 @@ void ActorEnemySet::CheckEnemies { float fRangeSquared; bool bVisible; - bool bInFovAndRange = false; - int nChecked; - int iThreat; + bool bInFovAndRange; + //int nChecked; + //int iThreat; float fVisibility; ActorEnemy *pActorEnemy; - for (int i = 1; i < m_Enemies.NumObjects();i++) + + + for (int i = 1; i <= m_Enemies.NumObjects();i++) { - pActorEnemy = &m_Enemies[i]; + pActorEnemy = &m_Enemies[i-1]; if (!pActorEnemy->m_pEnemy - || pActorEnemy->m_pEnemy->m_Team != pSelf->m_Team + || pActorEnemy->m_pEnemy->m_Team == pSelf->m_Team || pActorEnemy->m_pEnemy->IsDead() || level.inttime > pActorEnemy->m_iAddTime + 10000 || pActorEnemy->m_pEnemy->m_iThreatBias == THREATBIAS_IGNOREME) { m_Enemies.RemoveObjectAt(i); - i--; + i--;//decrease i in order to not miss next object in container. } } + if (!m_Enemies.NumObjects()) { m_iCurrentThreat = 0; @@ -481,7 +484,7 @@ void ActorEnemySet::CheckEnemies } else { - for (int i = 0; !bInFovAndRange && i < m_Enemies.NumObjects(); i++) + for (int i = 0; i < m_Enemies.NumObjects(); i++) { m_iCheckCount++; if (m_iCheckCount > m_Enemies.NumObjects()) @@ -495,11 +498,7 @@ void ActorEnemySet::CheckEnemies if (pActorEnemy->m_pEnemy == m_pCurrentEnemy) { m_iCurrentThreat = 0; - if (m_pCurrentEnemy) - { - //delete m_pCurrentEnemy; - m_pCurrentEnemy = NULL; - } + m_pCurrentEnemy = NULL; m_fCurrentVisibility = 0.0; } } @@ -509,18 +508,13 @@ void ActorEnemySet::CheckEnemies { if (pActorEnemy->m_pEnemy == m_pCurrentEnemy) { - m_iCurrentThreat = 0; - if (m_pCurrentEnemy) - { - //delete m_pCurrentEnemy; - m_pCurrentEnemy = NULL; - } m_fCurrentVisibility = fVisibility; } } else { m_pCurrentEnemy = pActorEnemy->m_pEnemy; + m_fCurrentVisibility = fVisibility; } if (g_showawareness->integer) @@ -548,28 +542,29 @@ void ActorEnemySet::CheckEnemies pActorEnemy->m_bVisible = false; pActorEnemy->m_iLastSightChangeTime = level.inttime; } + + if (bInFovAndRange) + { + break; + } } if (m_pCurrentEnemy && m_pCurrentEnemy->IsDead()) { - if (m_pCurrentEnemy) - { - //delete m_pCurrentEnemy; - m_pCurrentEnemy = NULL; - } + m_pCurrentEnemy = NULL; m_iCurrentThreat = 0; m_fCurrentVisibility = 0.0; } m_iCurrentThreat = 0; - fRangeSquared = 1e37; + fRangeSquared = 1e37f; if (m_fCurrentVisibility >= 1) { - for (int i = 0;i < m_Enemies.NumObjects(); i++) + for (int i = 1;i <= m_Enemies.NumObjects(); i++) { - pActorEnemy = &m_Enemies[i]; + pActorEnemy = &m_Enemies[i-1]; pActorEnemy->UpdateThreat(pSelf); if (m_iCurrentThreat < pActorEnemy->m_iThreat || m_iCheckCount == pActorEnemy->m_iThreat && fRangeSquared > pActorEnemy->m_fCurrentRangeSquared) { @@ -582,11 +577,7 @@ void ActorEnemySet::CheckEnemies if ((!m_pCurrentEnemy || !m_pCurrentEnemy->m_bIsDisguised) && m_iCurrentThreat <= 0) { - if (m_pCurrentEnemy) - { - //delete m_pCurrentEnemy; - m_pCurrentEnemy = NULL; - } + m_pCurrentEnemy = NULL; m_iCurrentThreat = 0; m_fCurrentVisibility = 0.0; } diff --git a/code/game/animate.cpp b/code/game/animate.cpp index f46dea0c..a3985958 100644 --- a/code/game/animate.cpp +++ b/code/game/animate.cpp @@ -503,7 +503,7 @@ void Animate::SetSyncTime( float s ) void Animate::UseSyncTime(int slot, int sync) { int v3; // eax - unsigned int v4; // eax + //unsigned int v4; // eax int v5; // eax if (sync) @@ -550,7 +550,7 @@ void Animate::PostAnimate( void ) deltaSyncTime = syncTime; - if( pauseSyncTime == 0.0f ) + if( !pauseSyncTime ) { syncTime = 1.0f / syncRate * level.frametime + deltaSyncTime; } @@ -609,27 +609,42 @@ void Animate::PostAnimate( void ) animFlags[ i ] &= ~ANIM_NODELTA; - if( ( animFlags[ i ] & ANIM_SYNC && edict->s.frameInfo[ i ].time > animtimes[ i ] ) || - ( edict->s.frameInfo[ i ].time > animtimes[ i ] - 0.01f ) ) + bool bTemp; + if (animFlags[i] & ANIM_SYNC) { - if( animFlags[ i ] & ANIM_LOOP ) + bTemp = edict->s.frameInfo[i].time < animtimes[i]; + } + else + { + bTemp = edict->s.frameInfo[i].time < animtimes[i] - 0.01f; + } + if( !bTemp ) + { + if (animFlags[i] & ANIM_LOOP) { - animFlags[ i ] |= ANIM_FINISHED; + animFlags[i] |= ANIM_FINISHED; - if( edict->s.frameInfo[ i ].time > animtimes[ i ] ) + do { - edict->s.frameInfo[ i ].time = 0; + edict->s.frameInfo[i].time -= animtimes[i]; + } while (edict->s.frameInfo[i].time >= animtimes[i]); + + if (edict->s.frameInfo[i].time < 0) + { + edict->s.frameInfo[i].time = 0; } + } else { - if( startTime != animtimes[ i ] ) + if (startTime != animtimes[i]) { - animFlags[ i ] |= ANIM_FINISHED; + animFlags[i] |= ANIM_FINISHED; } - edict->s.frameInfo[ i ].time = animtimes[ i ]; + edict->s.frameInfo[i].time = animtimes[i]; } + } } diff --git a/code/game/entity.cpp b/code/game/entity.cpp index 253359ab..9ab4e5fd 100644 --- a/code/game/entity.cpp +++ b/code/game/entity.cpp @@ -1115,7 +1115,7 @@ Event EV_SetShaderData "ff", "data0 data1", "sets the shader controllers for this entity.", - EV_RETURN + EV_NORMAL ); Event EV_Entity_SetVelocity ( diff --git a/code/game/g_main.cpp b/code/game/g_main.cpp index 0bb32404..8e839bdd 100644 --- a/code/game/g_main.cpp +++ b/code/game/g_main.cpp @@ -103,10 +103,9 @@ void QDECL G_Error( int type, const char *fmt, ... ) va_end( argptr ); // need to manually crash otherwise visual studio fuck up with the stack pointer... - *( int * )0 = 0; + //*( int * )0 = 0; - assert( 0 ); - SV_Error( type, text ); + assert( !text ); } void* G_Malloc( int size ) @@ -251,10 +250,13 @@ G_InitGame */ void G_InitGame( int levelTime, int randomSeed ) { - G_Printf( "------- Game Initialization -------\n" ); + G_Printf( "==== InitGame ====\n" ); G_Printf( "gamename: %s\n", GAMEVERSION ); G_Printf( "gamedate: %s\n", __DATE__ ); + SV_Error = gi.Error; + gi.Error = G_Error; + srand( randomSeed ); CVAR_Init(); @@ -276,6 +278,7 @@ void G_InitGame( int levelTime, int randomSeed ) PlayerBot::Init(); sv_numtraces = 0; + sv_numpmtraces = 0; if( developer->integer && !g_gametype->integer ) { @@ -552,7 +555,7 @@ void G_RunFrame( int levelTime, int frameTime ) if( actor->IsSubclassOfActor() ) { actor->m_bUpdateAnimDoneFlags = 0; - if( actor->m_bAnimating != 0 ) + if( actor->m_bAnimating ) actor->PreAnimate(); } } @@ -1467,9 +1470,6 @@ gameExport_t* GetGameAPI( gameImport_t *import ) gi = *import; #ifdef _DEBUG - SV_Error = gi.Error; - gi.Error = G_Error; - //SV_Malloc = gi.Malloc; ///gi.Malloc = G_Malloc; diff --git a/code/game/navigate.cpp b/code/game/navigate.cpp index e1f2acf0..84484509 100644 --- a/code/game/navigate.cpp +++ b/code/game/navigate.cpp @@ -378,7 +378,7 @@ const_str PathNode::GetSpecialAttack else { if( nodeflags >= 0 ) - return 0; + return STRING_NULL; iSpecialAttack = 2; csAnimation = STRING_ANIM_OVERATTACK_SCR; @@ -398,7 +398,7 @@ const_str PathNode::GetSpecialAttack fRangeSquared = vDelta[ 0 ] * vDelta[ 0 ] + vDelta[ 1 ] * vDelta[ 1 ]; if( fRangeSquared < g_AttackParms[ iSpecialAttack ].fMinRangeSquared || fRangeSquared > g_AttackParms[ iSpecialAttack ].fMaxRangeSquared ) - return 0; + return STRING_NULL; fMinAngle = atan2( vDelta[ 0 ], vDelta[ 1 ] ) * ( 180.0f / M_PI ) - angles[ 1 ]; @@ -426,16 +426,16 @@ const_str PathNode::GetSpecialAttack if( g_AttackParms[ iSpecialAttack ].fMinAngle <= g_AttackParms[ iSpecialAttack ].fMaxAngle ) { if( g_AttackParms[ iSpecialAttack ].fMinAngle > fMaxAngle ) - return 0; + return STRING_NULL; } else { if( g_AttackParms[ iSpecialAttack ].fMinAngle <= fMaxAngle ) - return 0; + return STRING_NULL; } if( fMaxAngle > g_AttackParms[ iSpecialAttack ].fMaxAngle ) - return 0; + return STRING_NULL; return csAnimation; } diff --git a/code/game/sentient.cpp b/code/game/sentient.cpp index dd0e0198..8ed8684a 100644 --- a/code/game/sentient.cpp +++ b/code/game/sentient.cpp @@ -4588,7 +4588,7 @@ void Sentient::UpdateFootsteps iTagNum = gi.Tag_NumForName(edict->tiki, "Bip01 R Foot"); if (iTagNum >= 0) { - m_bFootOnGround_Right = G_TIKI_IsOnGround(edict, iTagNum, 13.653847); + m_bFootOnGround_Right = G_TIKI_IsOnGround(edict, iTagNum, 13.653847f); } else { @@ -4600,7 +4600,7 @@ void Sentient::UpdateFootsteps iTagNum = gi.Tag_NumForName(edict->tiki, "Bip01 R Foot"); if (iTagNum >= 0) { - if (G_TIKI_IsOnGround(edict, iTagNum, 13.461539)) + if (G_TIKI_IsOnGround(edict, iTagNum, 13.461539f)) { BroadcastAIEvent(10, G_AIEventRadius(10)); } @@ -4613,7 +4613,7 @@ void Sentient::UpdateFootsteps iTagNum = gi.Tag_NumForName(edict->tiki, "Bip01 L Foot"); if (iTagNum >= 0) { - m_bFootOnGround_Left = G_TIKI_IsOnGround(edict, iTagNum, 13.653847); + m_bFootOnGround_Left = G_TIKI_IsOnGround(edict, iTagNum, 13.653847f); } else { @@ -4625,7 +4625,7 @@ void Sentient::UpdateFootsteps iTagNum = gi.Tag_NumForName(edict->tiki, "Bip01 R Foot"); if (iTagNum >= 0) { - if (G_TIKI_IsOnGround(edict, iTagNum, 13.461539)) + if (G_TIKI_IsOnGround(edict, iTagNum, 13.461539f)) { BroadcastAIEvent(10, G_AIEventRadius(10)); } diff --git a/code/game/simpleactor.cpp b/code/game/simpleactor.cpp index ec88c2bc..fb756d2a 100644 --- a/code/game/simpleactor.cpp +++ b/code/game/simpleactor.cpp @@ -49,7 +49,7 @@ SimpleActor::SimpleActor() m_fAimLimit_up = 60.0f; m_fAimLimit_down = -60.0f; - m_csNextAnimString = 0; + m_csNextAnimString = STRING_NULL; m_bNextForceStart = false; m_fCrossblendTime = 0.5f; m_csCurrentPosition = STRING_STAND; @@ -500,13 +500,51 @@ bool SimpleActor::PathAvoidsSquadMates ) const { + + Entity* player; + float fDelta; + float fDistSoFar; + float fDistCap; + float vDelta2[2]; + float vMins[3]; + float vMaxs[3]; + float vPos[3]; + Sentient *pOther; + Sentient *pBuddy[256]; + int iNumBuddies; + int i; + float fRatio; + if (ai_pathchecktime->value <= 0.0) return true; - - if ((G_GetEntity(0)->origin - origin).lengthXY(true) > Square(ai_pathcheckdist->value)) + player = G_GetEntity(0); + if (!player) { return true; } + + player = G_GetEntity(0); + player = G_GetEntity(0); + + fDelta = (player->origin - origin).lengthXYSquared(); + if (fDelta > Square(ai_pathcheckdist->value)) + { + return true; + } + + fDistSoFar = 0; + for (auto pNode = CurrentPathNode(); pNode >= LastPathNode(); pNode--) + { + if (fDistSoFar <= 0) + { + break; + } + //fDistCap = (ai_pathchecktime->value * 250.0) + 0.001 - fDistSoFar; + + //if (pNode->point[2] > fDistCap) + { + } + } // FIXME: stub STUB(); return false; @@ -636,8 +674,8 @@ void SimpleActor::StopTurning ) { - // not found in ida - STUB(); + //fixme: this is an inline function. + m_YawAchieved = true; } void SimpleActor::SetDesiredYaw @@ -679,7 +717,7 @@ void SimpleActor::UpdateEmotion int anim; if (IsDead()) { - m_eEmotionMode = EMOTION_DEAD; + Anim_Emotion(EMOTION_DEAD); } anim = GetEmotionAnim(); @@ -761,8 +799,11 @@ int SimpleActor::GetEmotionAnim assert(!"Unknown value for m_csMood"); return -1; } + else + { + emotionanim = "facial_idle_neutral"; + } - emotionanim = "facial_idle_neutral"; } else if (m_csMood == STRING_CURIOUS) { @@ -773,12 +814,16 @@ int SimpleActor::GetEmotionAnim assert(!"Unknown value for m_csMood"); return -1; } + else + { + + } } if (emotionanim == NULL) { emotionanim = "facial_idle_anger"; - assert(!"Unexpected behaviour in SimpleActor::GetEmotionAnim"); + //assert(!"Unexpected behaviour in SimpleActor::GetEmotionAnim"); } anim = gi.Anim_NumForName(edict->tiki, emotionanim); @@ -1151,8 +1196,8 @@ void SimpleActor::ChangeMotionAnim ) { - int lastMotionSlot; - int firstMotionSlot; + //int lastMotionSlot; + //int firstMotionSlot; int iSlot; int i; @@ -1169,7 +1214,7 @@ void SimpleActor::ChangeMotionAnim { StartCrossBlendAnimSlot(iSlot); } - m_AnimDialogHigh ^= 1; // toggle + m_AnimDialogHigh = !m_AnimDialogHigh; } @@ -1256,19 +1301,24 @@ void SimpleActor::UpdateAim if (m_bAimAnimSet) { + dir = -m_DesiredGunDir[0]; + aimForwardSlot = GetActionSlot(0); aimUpSlot = aimForwardSlot + 1; aimDownSlot = aimForwardSlot + 2; - dir = -m_DesiredGunDir[0]; - if (dir <= 180 && dir < -180) + if (dir <= 180) { - dir += 360; + if (dir < -180) + { + dir += 360; + } } else { dir -= 360; } + float factor; if (dir < 0) { @@ -1283,7 +1333,7 @@ void SimpleActor::UpdateAim } else { - if (dir < m_fAimLimit_up) + if (dir > m_fAimLimit_up) dir = m_fAimLimit_up; factor = dir / m_fAimLimit_up; @@ -1574,37 +1624,37 @@ void SimpleActor::EventSetEmotion switch (ev->GetConstString(1)) { case STRING_EMOTION_NONE: - m_eEmotionMode = EMOTION_NONE; + Anim_Emotion(EMOTION_NONE); break; case STRING_EMOTION_NEUTRAL: - m_eEmotionMode = EMOTION_NEUTRAL; + Anim_Emotion(EMOTION_NEUTRAL); break; case STRING_EMOTION_WORRY: - m_eEmotionMode = EMOTION_WORRY; + Anim_Emotion(EMOTION_WORRY); break; case STRING_EMOTION_PANIC: - m_eEmotionMode = EMOTION_PANIC; + Anim_Emotion(EMOTION_PANIC); break; case STRING_EMOTION_FEAR: - m_eEmotionMode = EMOTION_FEAR; + Anim_Emotion(EMOTION_FEAR); break; case STRING_EMOTION_DISGUST: - m_eEmotionMode = EMOTION_DISGUST; + Anim_Emotion(EMOTION_DISGUST); break; case STRING_EMOTION_ANGER: - m_eEmotionMode = EMOTION_ANGER; + Anim_Emotion(EMOTION_ANGER); break; case STRING_EMOTION_AIMING: - m_eEmotionMode = EMOTION_AIMING; + Anim_Emotion(EMOTION_AIMING); break; case STRING_EMOTION_DETERMINED: - m_eEmotionMode = EMOTION_DETERMINED; + Anim_Emotion(EMOTION_DETERMINED); break; case STRING_EMOTION_DEAD: - m_eEmotionMode = EMOTION_DEAD; + Anim_Emotion(EMOTION_DEAD); break; case STRING_EMOTION_CURIOUS: - m_eEmotionMode = EMOTION_CURIOUS; + Anim_Emotion(EMOTION_CURIOUS); break; default: assert(!"Unknown emotion mode specified in script."); @@ -1666,8 +1716,10 @@ void SimpleActor::DesiredAnimation ) { - // not found in ida - STUB(); + //fixme: this is an inline function. + m_eNextAnimMode = eAnimMode; + m_csNextAnimString = csAnimString; + m_bNextForceStart = false; } void SimpleActor::StartAnimation @@ -1677,8 +1729,10 @@ void SimpleActor::StartAnimation ) { - // not found in ida - STUB(); + //fixme: this is an inline function. + m_eNextAnimMode = eAnimMode; + m_csNextAnimString = csAnimString; + m_bNextForceStart = true; } void SimpleActor::DesiredAnimation @@ -1688,8 +1742,11 @@ void SimpleActor::DesiredAnimation ) { - // not found in ida - STUB(); + //fixme: this is an inline function. + m_eNextAnimMode = eAnimMode; + m_csNextAnimString = STRING_NULL; + m_NextAnimLabel = AnimLabel; + m_bNextForceStart = false; } void SimpleActor::StartAnimation @@ -1699,8 +1756,11 @@ void SimpleActor::StartAnimation ) { - // not found in ida - STUB(); + //fixme: this is an inline function. + m_eNextAnimMode = eAnimMode; + m_csNextAnimString = STRING_NULL; + m_NextAnimLabel = AnimLabel; + m_bNextForceStart = true; } void SimpleActor::ContinueAnimationAllowNoPath @@ -1712,7 +1772,7 @@ void SimpleActor::ContinueAnimationAllowNoPath if (m_eNextAnimMode < 0) { m_bNextForceStart = false; - m_csNextAnimString = NULL; + m_csNextAnimString = STRING_NULL; m_eNextAnimMode = m_eAnimMode; m_NextAnimLabel = m_Anim; } @@ -1724,17 +1784,19 @@ void SimpleActor::ContinueAnimation ) { - if (m_eNextAnimMode < 0) + int eAnimMode = m_eNextAnimMode; + if (eAnimMode < 0) { m_bNextForceStart = false; - m_csNextAnimString = NULL; + m_csNextAnimString = STRING_NULL; m_eNextAnimMode = m_eAnimMode; m_NextAnimLabel = m_Anim; + eAnimMode = m_eAnimMode; } - if (m_eAnimMode <= 3 && !PathExists()) + if (eAnimMode <= 3 && !PathExists()) { - assert(!DumpCallTrace("ContinueAnimation() called on a pathed animation, but no path exists")); + //assert(!DumpCallTrace("ContinueAnimation() called on a pathed animation, but no path exists")); Anim_Stand(); } } @@ -1754,19 +1816,69 @@ bool SimpleActor::UpdateSelectedAnimation ) { - - if (m_csNextAnimString == NULL) + if (m_csNextAnimString == STRING_NULL) { - if (!m_bNextForceStart && m_pAnimThread == NULL && m_eAnimMode == m_eNextAnimMode && m_Anim == m_NextAnimLabel) - { - m_bStartPathGoalEndAnim = false; - m_eNextAnimMode = -1; - return false; - } - else + if (m_bNextForceStart) { m_Anim = m_NextAnimLabel; - //LABEL_7: + m_eAnimMode = m_eNextAnimMode; + if (m_eNextAnimMode != 3) + SetPathGoalEndAnim(STRING_EMPTY); + m_bStartPathGoalEndAnim = false; + m_eNextAnimMode = -1; + return true; + } + + if (m_pAnimThread) + { + if (m_eAnimMode == m_eNextAnimMode) + { + if (m_Anim == m_NextAnimLabel) + { + m_bStartPathGoalEndAnim = false; + m_eNextAnimMode = -1; + return false; + } + } + } + m_Anim = m_NextAnimLabel; + m_eAnimMode = m_eNextAnimMode; + if (m_eNextAnimMode != 3) + SetPathGoalEndAnim(STRING_EMPTY); + m_bStartPathGoalEndAnim = false; + m_eNextAnimMode = -1; + return true; + } + + if (m_bNextForceStart) + { + + Com_Printf("UpdateSelectedAnimation\n"); + m_Anim.TrySetScript(m_csNextAnimString); + m_eAnimMode = m_eNextAnimMode; + if (m_eNextAnimMode != 3) + SetPathGoalEndAnim(STRING_EMPTY); + m_bStartPathGoalEndAnim = false; + m_eNextAnimMode = -1; + return true; + } + + if (!m_pAnimThread || m_eAnimMode != m_eNextAnimMode) + { + m_Anim.TrySetScript(m_csNextAnimString); + m_eAnimMode = m_eNextAnimMode; + if (m_eNextAnimMode != 3) + SetPathGoalEndAnim(STRING_EMPTY); + m_bStartPathGoalEndAnim = false; + m_eNextAnimMode = -1; + return true; + } + + if (m_fPathGoalTime <= level.time) + { + if (!m_Anim.IsFile(m_csNextAnimString)) + { + m_Anim.TrySetScript(m_csNextAnimString); m_eAnimMode = m_eNextAnimMode; if (m_eNextAnimMode != 3) SetPathGoalEndAnim(STRING_EMPTY); @@ -1775,27 +1887,16 @@ bool SimpleActor::UpdateSelectedAnimation return true; } } - else if (m_bNextForceStart || m_pAnimThread != NULL || m_eAnimMode != m_eNextAnimMode || (m_fPathGoalTime <= level.time && !m_Anim.IsFile(m_csNextAnimString))) + + m_eNextAnimMode = -1; + if (m_bStartPathGoalEndAnim) { - m_Anim.TrySetScript(Director.GetString(m_csNextAnimString)); - m_eAnimMode = m_eNextAnimMode; - if (m_eNextAnimMode != 3) - SetPathGoalEndAnim(STRING_EMPTY); m_bStartPathGoalEndAnim = false; - m_eNextAnimMode = -1; - return true; - } - else - { - m_eNextAnimMode = -1; - if (m_bStartPathGoalEndAnim) + + if (!m_Anim.IsFile(m_csPathGoalEndAnimScript)) { - m_bStartPathGoalEndAnim = false; - if (!m_Anim.IsFile(m_csPathGoalEndAnimScript)) - { - m_Anim.TrySetScript(Director.GetString(m_csPathGoalEndAnimScript)); - return true; - } + m_Anim.TrySetScript(m_csPathGoalEndAnimScript); + return true; } } return false; diff --git a/code/game/weapon.cpp b/code/game/weapon.cpp index 178ef0b5..061bfd55 100644 --- a/code/game/weapon.cpp +++ b/code/game/weapon.cpp @@ -4375,7 +4375,7 @@ void Weapon::MakeNoise if( attached && ( next_noise_time <= level.time || force ) ) { - BroadcastAIEvent( 8, radius ); + BroadcastAIEvent(AI_EVENT_MISC, radius ); next_noise_time = level.time + 1; } } diff --git a/code/globalcpp/class.cpp b/code/globalcpp/class.cpp index 7f9a2f6f..fdab964f 100644 --- a/code/globalcpp/class.cpp +++ b/code/globalcpp/class.cpp @@ -576,7 +576,7 @@ void ClassDef::BuildEventResponses( void ) numclasses++; } - CLASS_DPrintf( "\n------------------\nEvent system initialized: " + glbs.DPrintf( "\n------------------\nEvent system initialized: " "%d classes %d events %d total memory in response list\n\n", numclasses, Event::NumEventCommands(), amount ); } diff --git a/code/globalcpp/const_str.h b/code/globalcpp/const_str.h index 8af4bc32..21ab0773 100644 --- a/code/globalcpp/const_str.h +++ b/code/globalcpp/const_str.h @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA enum { + STRING_NULL = 0, STRING_EMPTY = 1, STRING_TOUCH, STRING_BLOCK, STRING_TRIGGER, STRING_USE, STRING_DAMAGE,STRING_LOCATION, diff --git a/code/globalcpp/gamescript.cpp b/code/globalcpp/gamescript.cpp index 10032903..edc606b1 100644 --- a/code/globalcpp/gamescript.cpp +++ b/code/globalcpp/gamescript.cpp @@ -198,9 +198,9 @@ bool StateScript::AddLabel( const_str label, unsigned char *pos, bool private_se s.key = label; s.isprivate = private_section; - if( !label_list.findKeyValue( 0 ) ) + if( !label_list.findKeyValue(STRING_NULL) ) { - label_list.addKeyValue( 0 ) = s; + label_list.addKeyValue(STRING_NULL) = s; } reverse_label_list.AddObject( &s ); @@ -258,7 +258,7 @@ const_str StateScript::NearestLabel( unsigned char *pos ) { unsigned int offset = pos - m_Parent->m_ProgBuffer; unsigned int bestOfs = 0; - const_str label = 0; + const_str label = STRING_NULL; for( int i = 1; i <= reverse_label_list.NumObjects(); i++ ) { @@ -282,7 +282,7 @@ const_str StateScript::NearestLabel( unsigned char *pos ) GameScript::GameScript() { - m_Filename = 0; + m_Filename = STRING_NULL; successCompile = false; m_ProgBuffer = NULL; @@ -367,7 +367,7 @@ void ArchiveOpcode( Archiver& arc, unsigned char *code ) __exec: if( !arc.Loading() ) { - index = archivedEvents.AddUniqueObject( *reinterpret_cast< unsigned int * >( code + 2 ) ); + index = archivedEvents.AddUniqueObject( *reinterpret_cast< const_str * >( code + 2 ) ); } arc.ArchiveUnsigned( &index ); @@ -411,7 +411,7 @@ __exec: case OP_STORE_STRING: if( !arc.Loading() ) { - index = archivedStrings.AddUniqueObject( *reinterpret_cast< unsigned int * >( code + 1 ) ); + index = archivedStrings.AddUniqueObject( *reinterpret_cast< const_str * >( code + 1 ) ); } arc.ArchiveUnsigned( &index ); diff --git a/code/globalcpp/listener.cpp b/code/globalcpp/listener.cpp index 4c70d0a8..f35b3ff3 100644 --- a/code/globalcpp/listener.cpp +++ b/code/globalcpp/listener.cpp @@ -423,6 +423,7 @@ void L_InitEvents( void ) g_eventstats = gi.Cvar_Get( "g_eventstats", "0", 0 ); #endif + gi.Printf("L_InitEvents\n"); Event::LoadEvents(); ClassDef::BuildEventResponses(); @@ -2222,7 +2223,7 @@ bool Event::GetBoolean( int pos ) GetConstString ======================= */ -int Event::GetConstString( int pos ) +const_str Event::GetConstString( int pos ) { ScriptVariable& variable = GetValue( pos ); @@ -3439,13 +3440,13 @@ void Listener::CancelWaiting( const_str name ) } } - if( !DisableListenerNotify ) + for (int i = stoppedListeners.NumObjects(); i > 0; i--) { - for( int i = stoppedListeners.NumObjects(); i > 0; i-- ) - { - Listener *listener = stoppedListeners.ObjectAt( i ); + Listener *listener = stoppedListeners.ObjectAt(i); - if( listener ) + if (listener) + { + if (!DisableListenerNotify) { listener->StoppedNotify(); } @@ -3480,17 +3481,16 @@ void Listener::CancelWaitingAll() m_WaitForList = NULL; if( !DisableListenerNotify ) + StoppedWaitFor(STRING_NULL, false ); + + for (int i = stoppedListeners.NumObjects(); i > 0; i--) { - StoppedWaitFor( 0, false ); + Listener *listener = stoppedListeners.ObjectAt(i); - for( int i = stoppedListeners.NumObjects(); i > 0; i-- ) + if (listener) { - Listener *listener = stoppedListeners.ObjectAt( i ); - - if( listener ) - { + if (!DisableListenerNotify) listener->StoppedNotify(); - } } } } diff --git a/code/globalcpp/listener.h b/code/globalcpp/listener.h index 06b77d83..ad419ee5 100644 --- a/code/globalcpp/listener.h +++ b/code/globalcpp/listener.h @@ -358,7 +358,7 @@ public: bool GetBoolean( int pos ); - int GetConstString( int pos ); + const_str GetConstString( int pos ); Entity *GetEntity( int pos ); diff --git a/code/globalcpp/scriptmaster.cpp b/code/globalcpp/scriptmaster.cpp index 6b1f7efa..84245790 100644 --- a/code/globalcpp/scriptmaster.cpp +++ b/code/globalcpp/scriptmaster.cpp @@ -8996,6 +8996,16 @@ void ScriptThread::StoppedWaitFor( const_str name, bool bDeleting ) } } +ScriptThread *ScriptThread::CreateThreadInternal(const ScriptVariable& label) +{ + return m_ScriptVM->GetScriptClass()->CreateThreadInternal(label); +} + +ScriptThread * ScriptThread::CreateScriptInternal(const ScriptVariable & label) +{ + return m_ScriptVM->GetScriptClass()->CreateScriptInternal(label); +} + void ScriptThread::Pause() { Stop(); @@ -9018,35 +9028,27 @@ void ScriptThread::Stop( void ) void ScriptThread::Wait( float time ) { - Stop(); - - m_ScriptVM->m_ThreadState = THREAD_WAITING; - - Director.AddTiming( this, time ); + StartTiming(time); m_ScriptVM->Suspend(); } void ScriptThread::StartTiming(float time) { - if (m_ScriptVM->ThreadState() == THREAD_WAITING) - { - m_ScriptVM->m_ThreadState = THREAD_RUNNING; - Director.RemoveTiming(this); - } - else if (m_ScriptVM->ThreadState() == THREAD_SUSPENDED) - { - m_ScriptVM->m_ThreadState = THREAD_RUNNING; - CancelWaitingAll(); - } + Stop(); m_ScriptVM->m_ThreadState = THREAD_WAITING; + if (time < 0) + { + time = 0; + } + Director.AddTiming(this, time); } void ScriptThread::StartTiming(void) { - StartTiming(level.inttime); + StartTiming(0);//start timing now } CLASS_DECLARATION( Listener, ScriptThread, NULL ) diff --git a/code/globalcpp/scriptmaster.h b/code/globalcpp/scriptmaster.h index 60182678..462c1706 100644 --- a/code/globalcpp/scriptmaster.h +++ b/code/globalcpp/scriptmaster.h @@ -199,11 +199,13 @@ public: void operator delete( void *ptr ); #endif - virtual void Archive( Archiver &arc ); + virtual void Archive( Archiver &arc ) override; void ArchiveInternal( Archiver& arc ); - virtual void StartedWaitFor( void ); - virtual void StoppedNotify( void ); - virtual void StoppedWaitFor( const_str name, bool bDeleting ); + virtual void StartedWaitFor( void ) override; + virtual void StoppedNotify( void ) override; + virtual void StoppedWaitFor( const_str name, bool bDeleting ) override; + virtual ScriptThread *CreateThreadInternal(const ScriptVariable& label) override; + virtual ScriptThread *CreateScriptInternal(const ScriptVariable& label) override; ScriptThread(); ScriptThread( ScriptClass *scriptClass, unsigned char *pCodePos ); diff --git a/code/globalcpp/scriptvariable.cpp b/code/globalcpp/scriptvariable.cpp index 4c7ad4b0..62f9a0c7 100644 --- a/code/globalcpp/scriptvariable.cpp +++ b/code/globalcpp/scriptvariable.cpp @@ -1444,7 +1444,7 @@ void ScriptVariable::setConstArrayValue( ScriptVariable *pVar, unsigned int size #ifndef NO_SCRIPTENGINE -int ScriptVariable::constStringValue( void ) const +const_str ScriptVariable::constStringValue( void ) const { if( GetType() == VARIABLE_CONSTSTRING ) { @@ -1663,9 +1663,7 @@ void ScriptVariable::operator*=( const ScriptVariable& value ) break; case VARIABLE_VECTOR + VARIABLE_VECTOR * VARIABLE_MAX: // ( vector ) * ( vector ) - m_data.vectorValue[ 0 ] = m_data.vectorValue[ 0 ] * value.m_data.vectorValue[ 0 ]; - m_data.vectorValue[ 1 ] = m_data.vectorValue[ 1 ] * value.m_data.vectorValue[ 1 ]; - m_data.vectorValue[ 2 ] = m_data.vectorValue[ 2 ] * value.m_data.vectorValue[ 2 ]; + setFloatValue(DotProduct(m_data.vectorValue, value.m_data.vectorValue)); break; } } diff --git a/code/globalcpp/scriptvariable.h b/code/globalcpp/scriptvariable.h index db9bf7e5..a4479e7d 100644 --- a/code/globalcpp/scriptvariable.h +++ b/code/globalcpp/scriptvariable.h @@ -205,7 +205,7 @@ public: void setConstArrayValue( ScriptVariable *pVar, unsigned int size ); #ifndef NO_SCRIPTENGINE - int constStringValue( void ) const; + const_str constStringValue( void ) const; void setConstStringValue( const_str s ); #endif diff --git a/code/globalcpp/vector.h b/code/globalcpp/vector.h index 2821fac1..2ef46f9a 100644 --- a/code/globalcpp/vector.h +++ b/code/globalcpp/vector.h @@ -120,7 +120,8 @@ public: float length( void ) const; float lengthfast( void ) const; float lengthSquared( void ) const; - float lengthXY( bool squared = false ) const; + float lengthXY() const; + float lengthXYSquared() const; float normalize( void ); void normalizefast( void ); void EulerNormalize( void ); @@ -548,9 +549,25 @@ inline float Vector::lengthfast( void ) const // // Returns: float - length of the vector in the xy plane //---------------------------------------------------------------- -inline float Vector::lengthXY( bool squared ) const +inline float Vector::lengthXY() const { - return squared ? (x * x) + (y * y) : sqrt(( x * x ) + ( y * y )); + return sqrt(( x * x ) + ( y * y )); +} + +//---------------------------------------------------------------- +// Name: lengthXYSquared +// Class: Vector +// +// Description: Returns length of the vector squared (using only the x +// and y components +// +// Parameters: None +// +// Returns: float - squared length of the vector in the xy plane +//---------------------------------------------------------------- +inline float Vector::lengthXYSquared() const +{ + return ( x * x ) + ( y * y ); } //---------------------------------------------------------------- diff --git a/other/RyBack/ida/fgamededmohaa.idb b/other/RyBack/ida/fgamededmohaa.idb index cc609103..bac90222 100644 Binary files a/other/RyBack/ida/fgamededmohaa.idb and b/other/RyBack/ida/fgamededmohaa.idb differ diff --git a/other/RyBack/ida/gamex86.dll b/other/RyBack/ida/gamex86.dll new file mode 100644 index 00000000..79c46267 Binary files /dev/null and b/other/RyBack/ida/gamex86.dll differ diff --git a/other/RyBack/ida/gamex86.idb b/other/RyBack/ida/gamex86.idb new file mode 100644 index 00000000..533940ee Binary files /dev/null and b/other/RyBack/ida/gamex86.idb differ diff --git a/other/RyBack/ida/ida.h b/other/RyBack/ida/ida.h index 25e268b2..896fbce8 100644 --- a/other/RyBack/ida/ida.h +++ b/other/RyBack/ida/ida.h @@ -3465,17 +3465,17 @@ typedef struct spawnsort_s { } spawnsort_t; typedef struct SafePtr2_s { - struct Class *ptr; + void *_vptr$; struct SafePtr2_s *prev; struct SafePtr2_s *next; - void *_vptr$; + void *ptr; } SafePtr2_t, SafePtr; typedef struct SentientSPtr_s { - struct Class *ptr; + void *_vptr$; struct SafePtr2_s *prev; struct SafePtr2_s *next; - Sentient_t *_vptr$; + Sentient_t *ptr; } SentientSPtr_t; typedef struct WeaponSPtr_s { @@ -3486,10 +3486,10 @@ typedef struct WeaponSPtr_s { } WeaponSPtr_t; typedef struct SentientSPtr2_s { - struct Sentient_t *ptr; + void *_vptr$; struct SafePtr2_s *prev; struct SafePtr2_s *next; - Sentient_t *_vptr$; + Sentient_t *ptr; } SentientSPtr2_t; @@ -3595,6 +3595,11 @@ typedef struct con_map_enum_s { con_set_enum_t m_Set_Enum; } con_map_enum_t; +typedef struct con_timer_Element_s { + Class_t *obj; + int inttime; +} con_timer_Element_t; + typedef struct con_timer_s { Class_t baseClass; Container_t m_Elements;