void TeamSensorSystem::update (void) { if (numSensors > 0) { #if 0 //DEBUGGING for (long k = 0; k < numContacts; k++) { MoverPtr mover = (MoverPtr)ObjectManager->get(contacts[k]); Assert(mover->getContactInfo()->teams[teamId] == k, 0, " Bad teams/contact link "); } #endif if (Team::teams[teamId] == Team::home) SoundSystem::largestSensorContact = -1; //--------------------------------- // First, update actual scanning... for (long i = 0; i < numSensors; i++) sensors[i]->updateScan(); if (Team::teams[teamId]->rosterSize < NUM_CONTACT_UPDATES_PER_PASS) numContactUpdatesPerPass = Team::teams[teamId]->rosterSize; else numContactUpdatesPerPass = NUM_CONTACT_UPDATES_PER_PASS; //-------------------------------- // Now, update current contacts... for (i = 0; i < numContactUpdatesPerPass; i++) { if (curContactUpdate >= numSensors) curContactUpdate = 0; sensors[curContactUpdate]->updateContacts(); curContactUpdate++; } } }
SensorSystemPtr TeamSensorSystem::findBestSpotter (MoverPtr contact, long* status) { ContactInfoPtr contactInfo = contact->getContactInfo(); if (!contactInfo) { char s[256]; sprintf(s, "TeamSensorSystem.findBestSpotter: NULL contactInfo for objClass %d partID %d team %d", contact->getObjectClass(), contact->getPartId(), contact->getTeamId()); STOP((s)); } SensorSystemPtr bestSensor = NULL; long bestStatus = CONTACT_NONE; for (long i = 0; i < MAX_SENSORS; i++) if (contactInfo->sensors[i] != 255) { SensorSystemPtr sensor = SensorManager->getSensor(i); if (sensor && sensor->owner && (teamId == sensor->owner->getTeamId())) { long status = sensor->calcContactStatus(contact); if (status >= bestStatus) { bestSensor = sensor; bestStatus = status; } } } if (status) *status = bestStatus; return(bestSensor); }
void TeamSensorSystem::modifyContact(SensorSystemPtr sensor, MoverPtr contact, int32_t contactStatus) { ContactInfoPtr contactInfo = contact->getContactInfo(); if(contactInfo->teamSpotter[teamId] == sensor->owner->getHandle()) { int32_t curStatus = contactInfo->contactStatus[teamId]; if(contactStatus > curStatus) contactInfo->contactStatus[teamId] = contactStatus; else if(contactStatus < curStatus) { int32_t bestStatus; SensorSystemPtr bestSensor = findBestSpotter(contact, &bestStatus); contactInfo->contactStatus[teamId] = bestStatus; contactInfo->teamSpotter[teamId] = bestSensor->owner->getHandle(); } } else { int32_t curStatus = contactInfo->contactStatus[teamId]; if(contactStatus > curStatus) { contactInfo->contactStatus[teamId] = contactStatus; contactInfo->teamSpotter[teamId] = sensor->owner->getHandle(); } } }
bool SensorSystem::isContact (MoverPtr mover) { if (mover->getFlag(OBJECT_FLAG_REMOVED)) return(false); if (notShutdown) return(mover->getContactInfo()->getSensor(id) < 255); for (long i = 0; i < numContacts; i++) if ((contacts[i] & 0x7FFF) == mover->getHandle()) return(true); return(false); }
void SensorSystem::modifyContact(MoverPtr mover, bool visual) { int32_t contactNum = mover->getContactInfo()->getSensor(id); if(contactNum < MAX_CONTACTS_PER_SENSOR) { if(visual) contacts[contactNum] = mover->getHandle() | 0x8000; else contacts[contactNum] = mover->getHandle(); } if(notShutdown) master->modifyContact(this, mover, visual ? CONTACT_VISUAL : getSensorQuality()); }
void TeamSensorSystem::removeContact(SensorSystemPtr sensor, MoverPtr contact) { ContactInfoPtr contactInfo = contact->getContactInfo(); contactInfo->sensors[sensor->id] = 255; contactInfo->contactCount[teamId]--; Assert(contactInfo->contactCount[teamId] != 255, 0, "FUDGE"); if(contactInfo->contactCount[teamId] == 0) { int32_t contactIndex = contactInfo->teams[teamId]; Assert(contactIndex < 0xFFFF, contactIndex, " 0xFFFF "); MoverPtr removedContact = (MoverPtr)ObjectManager->get(contacts[contactIndex]); Assert(removedContact == contact, contactIndex, " TeamSensorSystem.removeContact: bad contact "); contactInfo->teams[teamId] = 0xFFFF; contactInfo->contactStatus[teamId] = CONTACT_NONE; contactInfo->teamSpotter[teamId] = 0; numContacts--; if((numContacts > 0) && (contactIndex != numContacts)) { //----------------------------------------------- // Fill vacated slot with contact in last slot... contacts[contactIndex] = contacts[numContacts]; MoverPtr mover = (MoverPtr)ObjectManager->get(contacts[numContacts]); mover->getContactInfo()->teams[teamId] = contactIndex; } } else if(contactInfo->teamSpotter[teamId] == sensor->owner->getHandle()) { if(sensor->owner->getObjectClass() == BATTLEMECH) Assert(sensor != nullptr, 0, " dumb "); int32_t bestStatus; SensorSystemPtr bestSensor = findBestSpotter(contact, &bestStatus); // Assert(bestSensor != nullptr, 0, " hit "); if(bestSensor) { contact->contactInfo->contactStatus[teamId] = bestStatus; contact->contactInfo->teamSpotter[teamId] = bestSensor->owner->getHandle(); } } }
void TeamSensorSystem::addContact (SensorSystemPtr sensor, MoverPtr contact, long contactIndex, long contactStatus) { Assert(numContacts < MAX_CONTACTS_PER_TEAM, numContacts, " TeamSensorSystem.addContact: max team contacts "); ContactInfoPtr contactInfo = contact->getContactInfo(); contactInfo->sensors[sensor->id] = contactIndex; contactInfo->contactCount[teamId]++; if (contactInfo->contactStatus[teamId] < contactStatus) { contactInfo->contactStatus[teamId] = contactStatus; contactInfo->teamSpotter[teamId] = sensor->owner->getHandle(); } if (contactInfo->contactCount[teamId] == 1) { contacts[numContacts] = contact->getHandle(); contactInfo->teams[teamId] = numContacts; numContacts++; sensor->numExclusives++; } }
void SensorSystem::removeContact(int32_t contactIndex) { //----------------------------------------------- // This assumes the contactIndex is legitimate... MoverPtr contact = (MoverPtr)ObjectManager->get(contacts[contactIndex] & 0x7FFF); Assert(contact != nullptr, contacts[contactIndex] & 0x7FFF, " SensorSystem.removeContact: bad contact "); numContacts--; if((numContacts > 0) && (contactIndex != numContacts)) { //----------------------------------------------- // Fill vacated slot with contact in last slot... contacts[contactIndex] = contacts[numContacts]; MoverPtr contact = (MoverPtr)ObjectManager->get(contacts[numContacts] & 0x7FFF); contact->getContactInfo()->sensors[id] = contactIndex; } if(notShutdown) master->removeContact(this, contact); }
long TeamSensorSystem::getContactStatus (MoverPtr mover, bool includingAllies) { if (mover->getFlag(OBJECT_FLAG_REMOVED)) return(CONTACT_NONE); return(mover->getContactInfo()->getContactStatus(Team::teams[teamId]->getId(), true)); }
void SensorSystem::removeContact (MoverPtr contact) { long contactIndex = contact->getContactInfo()->getSensor(id); if (contactIndex < 255) removeContact(contactIndex); }