comparison Actor.cpp @ 1881:fa3d4b400b8d

Actor::AI_RandomMove minor cleanup
author Grumpy7
date Fri, 18 Oct 2013 09:31:35 +0200
parents 52e98d25cd64
children b3191dddab9f
comparison
equal deleted inserted replaced
1880:52e98d25cd64 1881:fa3d4b400b8d
1817 Actor::AI_Pursue1(uActorID, sTargetPid, uActorID, 64, pDir); 1817 Actor::AI_Pursue1(uActorID, sTargetPid, uActorID, 64, pDir);
1818 } 1818 }
1819 1819
1820 //----- (004032B2) -------------------------------------------------------- 1820 //----- (004032B2) --------------------------------------------------------
1821 void Actor::AI_RandomMove( unsigned int uActor_id, unsigned int uTarget_id, int radius, int uActionLength ) 1821 void Actor::AI_RandomMove( unsigned int uActor_id, unsigned int uTarget_id, int radius, int uActionLength )
1822 { 1822 {
1823 unsigned int v4; // edi@1
1824 Actor *v5; // esi@1 1823 Actor *v5; // esi@1
1825 int v6; // ebx@1 1824 int x; // ebx@1
1826 int v7; // ST08_4@1 1825 int absy; // eax@1
1827 int v8; // eax@1
1828 unsigned int v9; // ebx@11 1826 unsigned int v9; // ebx@11
1829 int v10; // ebx@13 1827 int v10; // ebx@13
1830 signed __int16 v11; // cx@17 1828 AIDirection notInitializedBecauseShouldBeRandom; // [sp+Ch] [bp-30h]@7
1831 unsigned int v12; // [sp-8h] [bp-44h]@10
1832 AIDirection *v13; // [sp-4h] [bp-40h]@10
1833 AIDirection v14; // [sp+Ch] [bp-30h]@7
1834 int v15; // [sp+28h] [bp-14h]@11
1835 unsigned int v16; // [sp+2Ch] [bp-10h]@1 1829 unsigned int v16; // [sp+2Ch] [bp-10h]@1
1836 int y; // [sp+30h] [bp-Ch]@1 1830 int y; // [sp+30h] [bp-Ch]@1
1837 unsigned int uActorID; // [sp+34h] [bp-8h]@1 1831 int absx; // [sp+38h] [bp-4h]@1
1838 int v19; // [sp+38h] [bp-4h]@1 1832
1839
1840 //v14 never filled, maybe it is passed to function but optimized away as local variable
1841
1842 uActorID = uActor_id;
1843 v4 = uActor_id;
1844 v5 = &pActors[uActor_id]; 1833 v5 = &pActors[uActor_id];
1845 v16 = uTarget_id; 1834 v16 = uTarget_id;
1846 v6 = v5->vInitialPosition.x - v5->vPosition.x; 1835 x = v5->vInitialPosition.x - v5->vPosition.x;
1847 v7 = v5->vInitialPosition.x - v5->vPosition.x;
1848 y = v5->vInitialPosition.y - v5->vPosition.y; 1836 y = v5->vInitialPosition.y - v5->vPosition.y;
1849 v19 = abs(v7); 1837 absx = abs(x);
1850 v8 = abs(y); 1838 absy = abs(y);
1851 if ( v19 <= v8 ) 1839 if ( absx <= absy )
1852 v19 = v8 + (v19 >> 1); 1840 absx = absy + (absx / 2 );
1853 else 1841 else
1854 v19 += v8 >> 1; 1842 absx = absx + absy / 2;
1855 if ( MonsterStats::BelongsToSupertype(v5->pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) ) 1843 if ( MonsterStats::BelongsToSupertype(v5->pMonsterInfo.uID, MONSTER_SUPERTYPE_TREANT) )
1856 { 1844 {
1857 if ( !uActionLength ) 1845 if ( !uActionLength )
1858 uActionLength = 256; 1846 uActionLength = 256;
1859 Actor::AI_StandOrBored(uActorID, OBJECT_Player, uActionLength, &v14); 1847 Actor::AI_StandOrBored(uActor_id, OBJECT_Player, uActionLength, &notInitializedBecauseShouldBeRandom);
1860 return; 1848 return;
1861 } 1849 }
1862 if ( pActors[v4].pMonsterInfo.uMovementType == 3 && v19 < 128 ) 1850 if ( pActors[uActor_id].pMonsterInfo.uMovementType == 3 && absx < 128 )
1863 { 1851 {
1864 Actor::AI_Stand(uActorID, uTarget_id, 256, &v14); 1852 Actor::AI_Stand(uActor_id, uTarget_id, 256, &notInitializedBecauseShouldBeRandom);
1865 return; 1853 return;
1866 } 1854 }
1867 v15 = (rand() & 0xF) << 12; 1855 absx += ((rand() & 0xF) * radius) / 16;
1868 v19 += (unsigned __int64)(v15 * (signed __int64)radius) >> 16; 1856 v9 = (stru_5C6E00->uIntegerDoublePi - 1) & stru_5C6E00->Atan2(x, y);
1869 v9 = (stru_5C6E00->uIntegerDoublePi - 1) & stru_5C6E00->Atan2(v6, y);
1870 if ( rand() % 100 < 25 ) 1857 if ( rand() % 100 < 25 )
1871 { 1858 {
1872 Actor::StandAwhile(uActorID); 1859 Actor::StandAwhile(uActor_id);
1873 return; 1860 return;
1874 } 1861 }
1875 v10 = v9 + rand() % 256 - 128; 1862 v10 = v9 + rand() % 256 - 128;
1876 if ( abs(v10 - v5->uYawAngle) > 256 && !(v5->uAttributes & 0x200000) ) 1863 if ( abs(v10 - v5->uYawAngle) > 256 && !(v5->uAttributes & 0x200000) )
1877 { 1864 {
1878 Actor::AI_Stand(uActorID, uTarget_id, 256, &v14); 1865 Actor::AI_Stand(uActor_id, uTarget_id, 256, &notInitializedBecauseShouldBeRandom);
1879 return; 1866 return;
1880 } 1867 }
1881 v5->uYawAngle = v10; 1868 v5->uYawAngle = v10;
1882 if ( v5->uMovementSpeed) 1869 if ( v5->uMovementSpeed)
1883 v5->uCurrentActionLength = 32 * v19 / v5->uMovementSpeed; 1870 v5->uCurrentActionLength = 32 * absx / v5->uMovementSpeed;
1884 else 1871 else
1885 v5->uCurrentActionLength = 0; 1872 v5->uCurrentActionLength = 0;
1886 v5->uCurrentActionTime = 0; 1873 v5->uCurrentActionTime = 0;
1887 v5->uAIState = Tethered; 1874 v5->uAIState = Tethered;
1888 if ( rand() % 100 < 2 ) 1875 if ( rand() % 100 < 2 )
1889 Actor::PlaySound(uActorID, 3u); 1876 Actor::PlaySound(uActor_id, 3u);
1890 v5->UpdateAnimation(); 1877 v5->UpdateAnimation();
1891 } 1878 }
1892 1879
1893 //----- (004031C1) -------------------------------------------------------- 1880 //----- (004031C1) --------------------------------------------------------
1894 char __fastcall Actor::_4031C1_update_job(unsigned int uActorID, signed int a2, int a3) 1881 char __fastcall Actor::_4031C1_update_job(unsigned int uActorID, signed int a2, int a3)