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

Function DCDetermineObjFate

scripts/Merc7.cpp:1852–1897  ·  view source on GitHub ↗

given an object, check if on list, then determine whether it should be assigned a goal and WHICH goal to assign it. new droids should be put to work preferably instead of exiting, but add a little randomness to this. also take into account the current DC_EQR!!!

Source from the content-addressed store, hash-verified

1850// new droids should be put to work preferably instead of exiting, but add a little randomness to
1851// this. also take into account the current DC_EQR!!!
1852void DCDetermineObjFate(int objhandle, bool new_droid) {
1853 int idx;
1854
1855 for (idx = 0; idx < DC_N_DROIDS; idx++) {
1856 if (objhandle == dc_nodes[idx].handle) {
1857 if (dc_nodes[idx].type == -1) {
1858 float roll = (float)(rand() / (float)(RAND_MAX));
1859 float saving_throw = 0.30f + (DC_EQR * 0.15f);
1860
1861 mprintf(0, "DC: Determining fate of DROID [%d] that has no goal.\n", idx);
1862
1863 if (roll < saving_throw && !new_droid) {
1864 // droid will leave droid central
1865 cSendDroidObjToExit(objhandle);
1866 } else {
1867 // droid will go to a free terminal and bump someone off if there are none.
1868 cSendDroidObjToTerm(objhandle);
1869 }
1870 } else if (dc_nodes[idx].goalid == -1) {
1871 // robots already at goal.
1872 float roll = (float)(rand() / (float)(RAND_MAX));
1873 float saving_throw = (dc_nodes[idx].timer / 45.0f) * 0.40f;
1874
1875 mprintf(0, "DC: Determining fate of DROID [%d] after %.2f seconds!\n", idx, dc_nodes[idx].timer);
1876
1877 if (dc_nodes[idx].type == DC_TERM_GOAL) {
1878 if (roll < saving_throw) {
1879 // droid will leave droid central
1880 cSendDroidObjToExit(objhandle);
1881 } else {
1882 // droid will go to a free terminal and bump someone off if there are none.
1883 cSendDroidObjToTerm(objhandle);
1884 }
1885 }
1886 }
1887 // else {
1888 // mprintf(0, "DC: DROID FATE IS ALREADY SEALED. NO CHANGE.\n");
1889 //}
1890 break;
1891 }
1892 }
1893
1894 if (idx == DC_N_DROIDS) {
1895 mprintf(0, "DC: DROID NOT IN LIST!!!\n");
1896 }
1897}
1898
1899// Tell the code to call our functions
1900#define ENABLE_CUSTOM_SAVE_AND_RESTORE

Callers 2

cDroidManagerIntervalFunction · 0.85

Calls 2

cSendDroidObjToExitFunction · 0.85
cSendDroidObjToTermFunction · 0.85

Tested by

no test coverage detected