Osiris_DetachScriptsFromObject Purpose: Call this function when an object is about to be destroyed. This will unbind and remove all scripts associated with that object. This function does not call any events.
| 1770 | // Call this function when an object is about to be destroyed. This will unbind and remove |
| 1771 | // all scripts associated with that object. This function does not call any events. |
| 1772 | void Osiris_DetachScriptsFromObject(object *obj) { |
| 1773 | if ((Game_mode & GM_MULTI) && (Netgame.local_role != LR_SERVER)) { |
| 1774 | // no scripts for a client! |
| 1775 | return; |
| 1776 | } |
| 1777 | |
| 1778 | // make sure the object is valid |
| 1779 | if (!CANHAVEANYSCRIPT(obj)) { |
| 1780 | // invalid object |
| 1781 | return; |
| 1782 | } |
| 1783 | |
| 1784 | if (!obj->osiris_script) { |
| 1785 | return; |
| 1786 | } |
| 1787 | |
| 1788 | // free the memory for the allocated script |
| 1789 | tOSIRISSCRIPTID osid; |
| 1790 | osid.objhandle = obj->handle; |
| 1791 | osid.type = OBJECT_SCRIPT; |
| 1792 | Osiris_FreeMemoryForScript(&osid); |
| 1793 | |
| 1794 | int dll_id; |
| 1795 | tOSIRISScript *os; |
| 1796 | |
| 1797 | os = obj->osiris_script; |
| 1798 | |
| 1799 | // free up the scripts for the object, starting with it's default script |
| 1800 | if (os->default_script.script_instance) { |
| 1801 | // first we need to free the instance |
| 1802 | dll_id = os->default_script.DLLID; |
| 1803 | |
| 1804 | #ifdef OSIRISDEBUG |
| 1805 | tRefObj *prev = NULL, *node = OSIRIS_loaded_modules[dll_id].RefRoot; |
| 1806 | while (node) { |
| 1807 | if (node->objnum == OBJNUM(obj)) { |
| 1808 | // free this node |
| 1809 | if (prev) |
| 1810 | prev->next = node->next; |
| 1811 | else { |
| 1812 | ASSERT(node == OSIRIS_loaded_modules[dll_id].RefRoot); |
| 1813 | OSIRIS_loaded_modules[dll_id].RefRoot = node->next; |
| 1814 | } |
| 1815 | |
| 1816 | mem_free(node); |
| 1817 | break; |
| 1818 | } |
| 1819 | prev = node; |
| 1820 | node = node->next; |
| 1821 | } |
| 1822 | ASSERT(node); // make sure we found the node |
| 1823 | #endif |
| 1824 | |
| 1825 | ASSERT(OSIRIS_loaded_modules[dll_id].flags & OSIMF_INUSE); |
| 1826 | if (OSIRIS_loaded_modules[dll_id].flags & OSIMF_INUSE) { |
| 1827 | |
| 1828 | OSIRIS_loaded_modules[dll_id].DestroyInstance(os->default_script.script_id, os->default_script.script_instance); |
| 1829 |
no test coverage detected