MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / DoSteal

Method DoSteal

scripts/AIGame.cpp:1874–2009  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1872}
1873
1874bool SuperThief::DoSteal(int me, int it) {
1875 int max_tries = numSuperThiefableItems;
1876 float gen_perc, perc_chance;
1877 ;
1878 int i;
1879 int count_max, count_num;
1880 bool *attempted_steals;
1881
1882 attempted_steals = (bool *)malloc(numSuperThiefableItems * sizeof(bool));
1883 if (!attempted_steals)
1884 return false;
1885
1886 float ftime = Game_GetFrameTime();
1887 if (ftime == 0)
1888 ftime = 1.0f;
1889 srand(Game_GetTime() / ftime);
1890
1891 for (i = 0; i < numSuperThiefableItems; i++) {
1892 attempted_steals[i] = false;
1893 }
1894
1895 while (max_tries--) {
1896 i = rand() % numSuperThiefableItems;
1897
1898 if (attempted_steals[i]) {
1899 // we already tried this one, try another
1900 max_tries++;
1901 continue;
1902 }
1903
1904 attempted_steals[i] = true;
1905
1906 {
1907 count_max = MAX_STOLEN_WEAPONS;
1908 count_num = memory->num_stolen_weapons;
1909
1910 if (count_num >= count_max) {
1911 mprintf(0, "SUPER THIEF: no mo' room\n");
1912 continue; // we have no more room
1913 }
1914
1915 // mprintf(0,"THIEF: Checking %s\n",TXT(SuperThiefableItems[i].name_idx));
1916
1917 bool can_take = false;
1918 int amount = 0;
1919 char message[256];
1920
1921 switch (SuperThiefableItems[i].type) {
1922 case THIEFABLEITEM_PRIMARY:
1923 // check to see if we can steal the primary
1924 Player_Value(it, VF_GET, PLYSV_I_WEAPON, &amount, SuperThiefableItems[i].index);
1925 if (SuperThiefableItems[i].index != 0 && amount) {
1926 can_take = true;
1927 snprintf(message, sizeof(message), TXT_THIEFSTEAL, TXT(SuperThiefableItems[i].name_idx));
1928 }
1929 break;
1930
1931 case THIEFABLEITEM_SECONDARY:

Callers

nothing calls this directly

Calls 6

Player_ValueFunction · 0.85
Sound_Play3dFunction · 0.85
Obj_WBValueFunction · 0.85
Obj_ValueFunction · 0.85
Obj_CreateFunction · 0.85
vm_VectorNormalizeFunction · 0.70

Tested by

no test coverage detected