$$ACTION Custom Tell droid [o:Object] to find a computer terminal in Droid Central. cSendDroidObjToTerm 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 */
| 1710 | $$END |
| 1711 | */ |
| 1712 | void cSendDroidObjToTerm(int objhandle) { |
| 1713 | int i; |
| 1714 | bool free_slot = false; |
| 1715 | |
| 1716 | if (DC_EQR == -100) { |
| 1717 | return; |
| 1718 | } |
| 1719 | |
| 1720 | for (i = 0; i < DC_N_DROIDS; i++) { |
| 1721 | int j; |
| 1722 | |
| 1723 | if (dc_nodes[i].handle == objhandle) { |
| 1724 | // okay, find a free terminal |
| 1725 | int term = FIND_FREE_INDEX(DC_Term_Mask, DC_N_VALID_TERMS, false); |
| 1726 | int goalid = LEVEL_GOAL_UID(0, DC_Goal_Index++); |
| 1727 | |
| 1728 | if (term == -1) { |
| 1729 | // the terminals are full. tell a droid to take a break (exit) |
| 1730 | // and put this droid in its place. |
| 1731 | for (j = 0; j < DC_N_DROIDS; j++) { |
| 1732 | if (dc_nodes[i].handle != OBJECT_HANDLE_NONE && dc_nodes[i].type == DC_TERM_GOAL) { |
| 1733 | cSendDroidObjToExit(dc_nodes[i].handle); |
| 1734 | term = dc_nodes[i].type_index; |
| 1735 | break; |
| 1736 | } |
| 1737 | } |
| 1738 | if (j == DC_N_DROIDS) { |
| 1739 | // this is IMPOSSIBLE if the sequencing and logic i have is right. |
| 1740 | // if there was no terminal, the above code checks for a full terminal and deallocates it. |
| 1741 | // but just in case... |
| 1742 | term = rand() % DC_N_VALID_TERMS; |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | // just in case, deallocate exit if this droid was leaving before... |
| 1747 | if (dc_nodes[i].type == DC_EXIT_GOAL) { |
| 1748 | DC_Exit_Mask &= ~(1 << dc_nodes[i].type_index); |
| 1749 | } |
| 1750 | |
| 1751 | mprintf(0, "DC: SENDING DROID [%d] to term %d (%x)\n", i, term, DC_Valid_Term_Handles[term]); |
| 1752 | |
| 1753 | aAIGoalGotoObject(objhandle, DC_Valid_Term_Handles[term], GOAL_PRIORITY_LOW, |
| 1754 | GF_FORCE_AWARENESS | GF_ORIENT_VELOCITY, goalid); |
| 1755 | dc_nodes[i].type = DC_TERM_GOAL; // specify terminal to be allocated. |
| 1756 | dc_nodes[i].type_index = term; |
| 1757 | dc_nodes[i].goalid = goalid; |
| 1758 | dc_nodes[i].timer = 0.0f; |
| 1759 | DC_Term_Mask |= (1 << term); |
| 1760 | break; |
| 1761 | } |
| 1762 | if (dc_nodes[i].handle == OBJECT_HANDLE_NONE) { |
| 1763 | free_slot = true; |
| 1764 | } |
| 1765 | } |
| 1766 | |
| 1767 | if (i == DC_N_DROIDS) { |
| 1768 | if (free_slot) { |
| 1769 | mprintf(0, "DC: Sending an unmanaged droid to term. Adding...\n"); |
no test coverage detected