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()); }
long TeamSensorSystem::getContacts (GameObjectPtr looker, long* contactList, long contactCriteria, long sortType) { if ((sortType != CONTACT_SORT_NONE) && !looker) return(0); static float sortValues[MAX_CONTACTS_PER_SENSOR]; float CV = 0; long numValidContacts = 0; long handleList[MAX_CONTACTS_PER_SENSOR]; for (long i = 0; i < numContacts; i++) { MoverPtr mover = (MoverPtr)ObjectManager->get(contacts[i]); if (!meetsCriteria(looker, mover, contactCriteria)) continue; handleList[numValidContacts] = mover->getHandle(); switch (sortType) { case CONTACT_SORT_NONE: sortValues[numValidContacts] = 0.0; break; case CONTACT_SORT_CV: CV = (float)mover->getCurCV(); sortValues[numValidContacts] = CV; break; case CONTACT_SORT_DISTANCE: sortValues[numValidContacts] = looker->distanceFrom(mover->getPosition()); break; } numValidContacts++; } if ((numValidContacts > 0) && (sortType != CONTACT_SORT_NONE)) { //--------------------------------------------------------- // BIG ASSUMPTION HERE: That a mech will not have more than // MAX_CONTACTS_PER_SENSOR contacts. if (!SensorSystem::sortList) { SensorSystem::sortList = new SortList; if (!SensorSystem::sortList) Fatal(0, " Unable to create Contact sortList "); SensorSystem::sortList->init(MAX_CONTACTS_PER_SENSOR); } bool descendSort = true; if (sortType == CONTACT_SORT_DISTANCE) descendSort = false; SensorSystem::sortList->clear(descendSort); for (long contact = 0; contact < numValidContacts; contact++) { SensorSystem::sortList->setId(contact, handleList[contact]); SensorSystem::sortList->setValue(contact, sortValues[contact]); } SensorSystem::sortList->sort(descendSort); for (contact = 0; contact < numValidContacts; contact++) contactList[contact] = SensorSystem::sortList->getId(contact); } else if (contactList) for (long contact = 0; contact < numValidContacts; contact++) contactList[contact] = handleList[contact]; return(numValidContacts); }
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::addContact (MoverPtr mover, bool visual) { Assert(!isContact(mover), 0, " SensorSystem.addContact: already contact "); if (numContacts < MAX_CONTACTS_PER_SENSOR) { contacts[numContacts] = mover->getHandle(); if (visual) contacts[numContacts] |= VISUAL_CONTACT_FLAG; if (notShutdown) master->addContact(this, mover, numContacts, visual ? CONTACT_VISUAL : getSensorQuality()); numContacts++; } }
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 TeamSensorSystem::updateContactList (void) { numAllContacts = 0; for (long i = 0; i < ObjectManager->getNumMovers(); i++) { MoverPtr mover = ObjectManager->getMover(i); if (mover) { long bestStatus = CONTACT_NONE; for (long i = 0; i < Team::numTeams; i++) { if (Team::teams[teamId]->isFriendly(Team::teams[i])) if (mover->contactInfo->contactStatus[i] > bestStatus) bestStatus = mover->contactInfo->contactStatus[i]; } mover->contactInfo->allContactStatus[teamId] = bestStatus; if (bestStatus != CONTACT_NONE) { allContacts[numAllContacts++] = mover->getHandle(); } } } }
void SensorSystem::updateContacts (void) { if ((masterIndex == -1) || (range < 0.0)) return; if (!enabled()) { clearContacts(); return; } //--------------------------------------------------------------------- // If we've already scanned this frame, don't bother updating contacts. // Otherwise, update contacts... if (scenarioTime == lastScanUpdate) return; long i = 0; while (i < numContacts) { MoverPtr contact = (MoverPtr)ObjectManager->get(contacts[i] & 0x7FFF); long contactStatus = calcContactStatus(contact); if (contactStatus == CONTACT_NONE) removeContact(i); else { contacts[i] = contact->getHandle(); if (contactStatus == CONTACT_VISUAL) contacts[i] |= 0x8000; modifyContact(contact, contactStatus == CONTACT_VISUAL); /* if (teamContactStatus < contactStatus) { //-------------------------------------------------- // Better sensor info, so update the team sensors... contactInfo->contactStatus[owner->getTeamId()] = contactStatus; contactInfo->teamSpotter[owner->getTeamId()] = (unsigned char)owner->getHandle(); } */ i++; } } }