Osiris_BindScriptsToObject Purpose: Call this function after an object has been created to bind all the scripts associated with it to the object. This function must be called near the end of it's initialization, to make sure that all fields have been filled in. This function does not call any events. This function will also load any dll's needed for it's game script. returns false if nothing was
| 1433 | // This function will also load any dll's needed for it's game script. |
| 1434 | // returns false if nothing was bound. |
| 1435 | bool Osiris_BindScriptsToObject(object *obj) { |
| 1436 | ASSERT(obj->osiris_script == NULL); |
| 1437 | if (obj->osiris_script) // already has a script bound! |
| 1438 | return true; |
| 1439 | |
| 1440 | if ((Game_mode & GM_MULTI) && (Netgame.local_role != LR_SERVER)) { |
| 1441 | // no scripts for a client! |
| 1442 | return false; |
| 1443 | } |
| 1444 | |
| 1445 | // make sure the object is valid |
| 1446 | if (!CANBEASSIGNEDSCRIPT(obj)) { |
| 1447 | // invalid object |
| 1448 | return false; |
| 1449 | } |
| 1450 | int real_type; |
| 1451 | real_type = (obj->type == OBJ_DUMMY) ? obj->dummy_type : obj->type; |
| 1452 | |
| 1453 | if (!CANTYPEBEASSIGNEDSCRIPT(real_type)) { |
| 1454 | // invalid type |
| 1455 | return false; |
| 1456 | } |
| 1457 | |
| 1458 | int dll_id, gos_id; |
| 1459 | void *gos_instance; |
| 1460 | tOSIRISScript *os; |
| 1461 | |
| 1462 | bool isdoor = (bool)(real_type == OBJ_DOOR); |
| 1463 | bool iscustomonly = (bool)HAVECUSTOMONLY(real_type); |
| 1464 | char *default_module_name; |
| 1465 | char *page_name; |
| 1466 | |
| 1467 | if (iscustomonly) { |
| 1468 | // this object can only have a custom script for it (i.e. OBJ_CAMERA) |
| 1469 | default_module_name = NULL; |
| 1470 | page_name = NULL; |
| 1471 | } else { |
| 1472 | if (isdoor) { |
| 1473 | default_module_name = Doors[obj->id].module_name; |
| 1474 | page_name = Doors[obj->id].name; |
| 1475 | } else { |
| 1476 | if (obj->custom_default_module_name) { |
| 1477 | // we have a custom default script |
| 1478 | default_module_name = obj->custom_default_module_name; |
| 1479 | } else { |
| 1480 | // use what was set in Object_info |
| 1481 | default_module_name = Object_info[obj->id].module_name; |
| 1482 | } |
| 1483 | |
| 1484 | if (obj->custom_default_script_name) { |
| 1485 | // we have a custom default script |
| 1486 | page_name = obj->custom_default_script_name; |
| 1487 | } else { |
| 1488 | // use what was set in Object_info |
| 1489 | if (Object_info[obj->id].script_name_override[0] != '\0') |
| 1490 | page_name = Object_info[obj->id].script_name_override; |
| 1491 | else |
| 1492 | page_name = Object_info[obj->id].name; |
no test coverage detected