$$ACTION Custom Tell droid [o:Object] to find an exit from Droid Central. cSendDroidObjToExit Sends a message to a droid to find an exit. Sends droid out of Droid Central. If object is not a member of droid central, it adds it. Parameters: Object: A robot $$END */
| 1650 | $$END |
| 1651 | */ |
| 1652 | void cSendDroidObjToExit(int objhandle) { |
| 1653 | int i; |
| 1654 | bool free_slot = false; |
| 1655 | |
| 1656 | if (DC_EQR == -100) { |
| 1657 | return; |
| 1658 | } |
| 1659 | |
| 1660 | for (i = 0; i < DC_N_DROIDS; i++) { |
| 1661 | if (dc_nodes[i].handle == objhandle) { |
| 1662 | // okay, find a free exit |
| 1663 | int exit = FIND_FREE_INDEX(DC_Exit_Mask, DC_N_VALID_EXITS, true); |
| 1664 | int goalid = LEVEL_GOAL_UID(0, DC_Goal_Index++); |
| 1665 | |
| 1666 | // deallocate terminal if this droid was working at one!! |
| 1667 | if (dc_nodes[i].type == DC_TERM_GOAL) { |
| 1668 | DC_Term_Mask &= ~(1 << dc_nodes[i].type_index); |
| 1669 | } |
| 1670 | |
| 1671 | mprintf(0, "DC: SENDING DROID [%d] to exit %d (%x)\n", i, exit, DC_Valid_Exit_Handles[exit]); |
| 1672 | |
| 1673 | aAIGoalGotoObject(objhandle, DC_Valid_Exit_Handles[exit], GOAL_PRIORITY_LOW, |
| 1674 | GF_FORCE_AWARENESS | GF_ORIENT_VELOCITY, goalid); |
| 1675 | dc_nodes[i].type = DC_EXIT_GOAL; |
| 1676 | dc_nodes[i].type_index = exit; |
| 1677 | dc_nodes[i].goalid = goalid; |
| 1678 | dc_nodes[i].timer = 0.0f; |
| 1679 | DC_Exit_Mask |= (1 << exit); // reserve index |
| 1680 | |
| 1681 | break; |
| 1682 | } |
| 1683 | if (dc_nodes[i].handle == OBJECT_HANDLE_NONE) { |
| 1684 | free_slot = true; |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | if (i == DC_N_DROIDS) { |
| 1689 | if (free_slot) { |
| 1690 | mprintf(0, "DC: Sending an unmanaged droid to exit. Adding...\n"); |
| 1691 | cAddObjToDroidManager(objhandle); |
| 1692 | cSendDroidObjToExit(objhandle); // recursive... safeguards should be already implemented above |
| 1693 | } else { |
| 1694 | // THING TO DO: should be force an object to leave here?? |
| 1695 | mprintf(0, "DC: Droid Manager is Full!! We should force a droid to exit.\n"); |
| 1696 | } |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | /* |
| 1701 | $$ACTION |
no test coverage detected