diff Actor.cpp @ 414:d8b3056df4e2

AI_Bored
author Nomad
date Sat, 23 Feb 2013 17:15:36 +0200
parents 111f25d1cc04
children 55684f4eda73
line wrap: on
line diff
--- a/Actor.cpp	Sat Feb 23 16:39:32 2013 +0200
+++ b/Actor.cpp	Sat Feb 23 17:15:36 2013 +0200
@@ -1991,37 +1991,16 @@
     v9->UpdateAnimation();
   }
   else
-    Actor::_402F87(v5, v4, a4);
+    Actor::AI_Bored(v5, v4, a4);
 }
 
 //----- (00403F58) --------------------------------------------------------
-void Actor::_403F58(unsigned int uActorID, signed int uObjID, int uActionLength, AIDirection *a4)
+void Actor::AI_StandOrBored(unsigned int uActorID, signed int uObjID, int uActionLength, AIDirection *a4)
 {
   if (rand() % 2)
-  {
-    Actor::_402F87(uActorID, uObjID, a4);
-    return;
-  }
-
-  assert(uActorID < uNumActors);
-  auto actor = &pActors[uActorID];
-
-  AIDirection a3;
-  if (!a4)
-    a4 = Actor::GetDirectionInfo(8 * uActorID | OBJECT_Actor, uObjID, &a3, 0);
-  
-  actor->uAIState = Standing;
-  if (!uActionLength)
-    actor->uCurrentActionLength = rand() % 256 + 256;
+    AI_Bored(uActorID, uObjID, a4);
   else
-    actor->uCurrentActionLength = uActionLength;
-  actor->uCurrentActionTime = 0;
-  actor->uYawAngle = a4->uYawAngle;
-  actor->uPitchAngle = a4->uPitchAngle;
-  actor->vVelocity.z = 0;
-  actor->vVelocity.y = 0;
-  actor->vVelocity.x = 0;
-  actor->UpdateAnimation();
+    AI_Stand(uActorID, uObjID, uActionLength, a4);
 }
 
 
@@ -2905,6 +2884,8 @@
   unsigned int uActorID; // [sp+34h] [bp-8h]@1
   int v19; // [sp+38h] [bp-4h]@1
 
+  //v14 never filled, maybe it is passed to function but optimized away as local variable
+
   uActorID = a1;
   v4 = a1;
   v5 = &pActors[a1];
@@ -2922,7 +2903,7 @@
   {
     if ( !uActionLength )
       uActionLength = 256;
-    Actor::_403F58(uActorID, 4, uActionLength, &v14);
+    Actor::AI_StandOrBored(uActorID, OBJECT_Player, uActionLength, &v14);
     return;
   }
   if ( pActors[v4].pMonsterInfo.uMovementType == 3 && v19 < 128 )
@@ -3072,54 +3053,59 @@
 }
 
 //----- (00402F87) --------------------------------------------------------
-void Actor::_402F87(unsigned int uActorID, unsigned int uObjID, AIDirection *a4)
+void Actor::AI_Bored(unsigned int uActorID, unsigned int uObjID, AIDirection *a4)
 {
-  int v3; // edi@1
-  AIDirection *v4; // esi@1
-  Actor *v5; // ebx@1
-  SpriteFrame *v6; // ecx@3
+  //int v3; // edi@1
+  //AIDirection *v4; // esi@1
+  //Actor *v5; // ebx@1
+  //SpriteFrame *v6; // ecx@3
   unsigned int v7; // eax@3
-  int v8; // edx@3
+  //int v8; // edx@3
   unsigned int v9; // eax@3
   //int result; // eax@4
   AIDirection a3; // [sp+Ch] [bp-5Ch]@2
-  AIDirection v12; // [sp+28h] [bp-40h]@2
-  AIDirection v13; // [sp+44h] [bp-24h]@2
-  unsigned int v14; // [sp+60h] [bp-8h]@1
-  unsigned int v15; // [sp+64h] [bp-4h]@1
+  //AIDirection v12; // [sp+28h] [bp-40h]@2
+  //AIDirection v13; // [sp+44h] [bp-24h]@2
+  //unsigned int v14; // [sp+60h] [bp-8h]@1
+  //unsigned int v15; // [sp+64h] [bp-4h]@1
+
+  assert(uActorID < uNumActors);
+  auto actor = pActors + uActorID;
 
-  v3 = uActorID;
-  v4 = a4;
-  v5 = &pActors[uActorID];
-  v14 = uObjID;
-  v15 = uActorID;
-  if ( !a4 )
-  {
+  //v3 = uActorID;
+  //v4 = a4;
+  //v5 = &pActors[uActorID];
+  //v14 = uObjID;
+  //v15 = uActorID;
+  if (!a4)
+    a4 = Actor::GetDirectionInfo(8 * uActorID | OBJECT_Actor, uObjID, &a3, 0);
+  /*{
     memcpy(&v13, Actor::GetDirectionInfo(8 * uActorID | OBJECT_Actor, uObjID, &a3, (int)a4), sizeof(v13));
     memcpy(&v12, &v13, sizeof(v12));
     v3 = v15;
     v4 = &v12;
-  }
-  v6 = pSpriteFrameTable->pSpriteSFrames;
-  v5->uYawAngle = LOWORD(v4->uYawAngle);
-  v5->uCurrentActionLength = 8 * v6[v5->pSpriteIDs[ANIM_Bored]].uAnimLength;
-  v7 = stru_5C6E00->Atan2(v5->vPosition.x - pIndoorCamera->pos.x, v5->vPosition.y - pIndoorCamera->pos.y);
-  LOWORD(v8) = v5->uYawAngle;
-  v9 = stru_5C6E00->uIntegerPi + v8 + ((signed int)stru_5C6E00->uIntegerPi >> 3) - v7;
-  if ( BYTE1(v9) & 7 )
+  }*/
+
+  //v6 = pSpriteFrameTable->pSpriteSFrames;
+  actor->uCurrentActionLength = 8 * pSpriteFrameTable->pSpriteSFrames[actor->pSpriteIDs[ANIM_Bored]].uAnimLength;
+
+  v7 = stru_5C6E00->Atan2(actor->vPosition.x - pIndoorCamera->pos.x, actor->vPosition.y - pIndoorCamera->pos.y);
+  //LOWORD(v8) = actor->uYawAngle;
+  v9 = stru_5C6E00->uIntegerPi + actor->uYawAngle + ((signed int)stru_5C6E00->uIntegerPi >> 3) - v7;
+
+  if ( BYTE1(v9) & 7 )      // turned away - just stand
+    Actor::AI_Stand(uActorID, uObjID, actor->uCurrentActionLength, a4);
+  else                      // facing player - play bored anim
   {
-    Actor::AI_Stand(v3, v14, v5->uCurrentActionLength, v4);
-  }
-  else
-  {
-    v5->uAIState = Fidgeting;
-    v5->uCurrentActionTime = 0;
-    v5->vVelocity.z = 0;
-    v5->vVelocity.y = 0;
-    v5->vVelocity.x = 0;
+    actor->uAIState = Fidgeting;
+    actor->uCurrentActionTime = 0;
+    actor->uYawAngle = a4->uYawAngle;
+    actor->vVelocity.z = 0;
+    actor->vVelocity.y = 0;
+    actor->vVelocity.x = 0;
     if ( rand() % 100 < 5 )
-      Actor::PlaySound(v3, 3u);
-    v5->UpdateAnimation();
+      Actor::PlaySound(uActorID, 3);
+    actor->UpdateAnimation();
   }
 }
 
@@ -3311,7 +3297,7 @@
   {
     if ( !uActionLength )
       uActionLength = 256;
-    Actor::_403F58(v5, 4, uActionLength, v10);
+    Actor::AI_StandOrBored(v5, 4, uActionLength, v10);
     return;
   }
   if ( (double)(signed int)v10->uDistance < 307.2 )
@@ -3387,7 +3373,7 @@
     {
       if ( !uActionLength )
         uActionLength = 256;
-      Actor::_403F58(v15, 4, uActionLength, &v13);
+      Actor::AI_StandOrBored(v15, 4, uActionLength, &v13);
     }
     else
     {
@@ -3458,7 +3444,7 @@
     v16 = v10;
     v15 = uActionLength;
     v11 = 4;
-    Actor::_403F58(v5, v11, v15, v16);
+    Actor::AI_StandOrBored(v5, v11, v15, v16);
     return;
   }
   if ( (signed int)v10->uDistance < a5 )
@@ -3468,7 +3454,7 @@
     v11 = v19;
     v16 = v10;
     v15 = uActionLength;
-    Actor::_403F58(v5, v11, v15, v16);
+    Actor::AI_StandOrBored(v5, v11, v15, v16);
     return;
   }
   if ( uActionLength )
@@ -3545,7 +3531,7 @@
     v18 = v9;
     v17 = uActionLength;
     v10 = 4;
-    return Actor::_403F58(v4, v10, v17, v18);
+    return Actor::AI_StandOrBored(v4, v10, v17, v18);
   }
   if ( (double)(signed int)v9->uDistance < 307.2 )
   {
@@ -3554,7 +3540,7 @@
     v10 = v21;
     v18 = v9;
     v17 = uActionLength;
-    return Actor::_403F58(v4, v10, v17, v18);
+    return Actor::AI_StandOrBored(v4, v10, v17, v18);
   }
   if ( uActionLength )
   {