| 7204 | } |
| 7205 | |
| 7206 | void MultiDoClientInventoryUseItem(int slot, uint8_t *data) { |
| 7207 | int count = 0; |
| 7208 | int type; |
| 7209 | int id; |
| 7210 | uint32_t hash; |
| 7211 | |
| 7212 | // Only the server receives this |
| 7213 | MULTI_ASSERT_NOMESSAGE(Netgame.local_role == LR_SERVER); |
| 7214 | SKIP_HEADER(data, &count); |
| 7215 | |
| 7216 | type = MultiGetUshort(data, &count); |
| 7217 | hash = MultiGetUint(data, &count); |
| 7218 | |
| 7219 | bool is_counter_measure = false; |
| 7220 | |
| 7221 | if (hash == 0xFFFFFFFF) { |
| 7222 | // object use |
| 7223 | int server_objnum; |
| 7224 | server_objnum = type; |
| 7225 | |
| 7226 | mprintf(0, "Inven: use request objnum %d\n", server_objnum); |
| 7227 | |
| 7228 | // the objnum coming in better be in our object list |
| 7229 | ASSERT(server_objnum >= 0 && server_objnum < MAX_OBJECTS); |
| 7230 | ASSERT(Objects[server_objnum].type != OBJ_NONE); |
| 7231 | |
| 7232 | mprintf(0, "Client is asking me to use objnum %d\n", server_objnum); |
| 7233 | |
| 7234 | // convert type to objhandle |
| 7235 | type = Objects[server_objnum].handle; |
| 7236 | id = -1; |
| 7237 | } else { |
| 7238 | // type/id use |
| 7239 | if (type == OBJ_WEAPON) { |
| 7240 | id = MultiMatchWeapon(hash); |
| 7241 | is_counter_measure = true; |
| 7242 | } else { |
| 7243 | id = MultiMatchGeneric(hash); |
| 7244 | } |
| 7245 | |
| 7246 | mprintf(0, "Client is asking me to use T=%d ID=%d\n", type, id); |
| 7247 | } |
| 7248 | |
| 7249 | if (is_counter_measure) { |
| 7250 | if (Players[slot].counter_measures.FindPos(type, id)) { |
| 7251 | mprintf(0, "I found it, so I'm going to use it\n"); |
| 7252 | if (Players[slot].counter_measures.UsePos(&Objects[Players[slot].objnum])) { |
| 7253 | // Tell clients to remove this item |
| 7254 | MultiSendInventoryRemoveItem(slot, type, id); |
| 7255 | } |
| 7256 | } else { |
| 7257 | mprintf(0, "But I couldn't find it in my copy of his inventory\n"); |
| 7258 | } |
| 7259 | } else { |
| 7260 | if (Players[slot].inventory.FindPos(type, id)) { |
| 7261 | if (id == -1) { |
| 7262 | mprintf(0, "I found it, so I'm going to use it, type=%d id=%d\n", type, id); |
| 7263 | } else { |
no test coverage detected