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

Function cDroidManagerInterval

scripts/Merc7.cpp:1791–1846  ·  view source on GitHub ↗

$$ACTION Custom Droid Manager Frame Interval cDroidManagerInterval Manages the droid center This will 'intelligently' assign, create and destroy droids. Parameters: None $$END */

Source from the content-addressed store, hash-verified

1789$$END
1790*/
1791void cDroidManagerInterval() {
1792 // we should check if any object in our list still exists
1793 // if not, and we didn't free it, then the player did
1794 // and we should update DC_EQR to reflect this.
1795 int i;
1796 float roll;
1797 float saving_throw;
1798 float gametime = Game_GetTime();
1799
1800 if (DC_EQR == -100) {
1801 return;
1802 }
1803
1804 for (i = 0; i < DC_N_DROIDS; i++) {
1805 if (dc_nodes[i].handle != OBJECT_HANDLE_NONE) {
1806 if (!qObjExists(dc_nodes[i].handle)) {
1807 cRemoveObjFromDroidManager(dc_nodes[i].handle);
1808 } else {
1809 dc_nodes[i].timer += (gametime - DC_Last_Game_Time);
1810 }
1811 }
1812 }
1813
1814 // okay, sometimes we need to create droids, and other times kill them.
1815 if (DC_EQR < 0) {
1816 // tell a matcen to create a droid.
1817 cDroidManagerCreateNew();
1818 } else if (DC_EQR >= 0) {
1819 int ndroids = 0;
1820 int droids[DC_N_DROIDS];
1821
1822 for (i = 0; i < DC_N_DROIDS; i++) {
1823 if (dc_nodes[i].handle != OBJECT_HANDLE_NONE) {
1824 droids[ndroids++] = i;
1825 }
1826 }
1827
1828 if (ndroids) {
1829 // if we have droids, do a random fate choice roll for them
1830 DCDetermineObjFate(dc_nodes[droids[rand() % ndroids]].handle, false);
1831 // randomly decide whether to add another bot.
1832 roll = (float)(rand() / (float)(RAND_MAX));
1833 saving_throw = (DC_Time_Since_Last_Create / 60.0f) * 0.5f;
1834
1835 if (roll < saving_throw && DC_EQR == 0) {
1836 cDroidManagerCreateNew();
1837 mprintf(0, "DC: RANDOMLY CREATING NEW DROID.\n");
1838 }
1839 }
1840 }
1841
1842 mprintf(0, "DC: Frame Interval DC_EQR = %d\n", DC_EQR);
1843
1844 DC_Time_Since_Last_Create += (gametime - DC_Last_Game_Time);
1845 DC_Last_Game_Time = gametime;
1846}
1847
1848// given an object, check if on list, then determine whether it should be assigned a goal

Callers

nothing calls this directly

Calls 4

qObjExistsFunction · 0.85
cDroidManagerCreateNewFunction · 0.85
DCDetermineObjFateFunction · 0.85

Tested by

no test coverage detected