void Function::addParameter(Parameter & parameter) { const ConstantString & parameter_name = parameter.getName(); int parameter_index = findParameterIndex(parameter_name); if (parameter_index < 0) { parameter_ptrs_.push_back(¶meter); } }
//------------------------------------------------------------------------------ // receiveMunitionDetonation() -- (Input) handles the Munition Detonation interaction //------------------------------------------------------------------------------ bool NetIO::receiveMunitionDetonation(const RTI::ParameterHandleValuePairSet& theParameters) { // Things we need RTIObjectIdStruct firingObjectIdentifier; RTIObjectIdStruct munitionObjectIdentifier; RTIObjectIdStruct targetObjectIdentifier; simulation::Weapon::Detonation detonationResult = simulation::Weapon::DETONATE_NONE; // --- // Extract the required data from the interaction's parameters // --- RTI::ULong length; char netBuffer[1000]; for (RTI::ULong i = 0 ; i < theParameters.size(); i++ ) { // get the parameter's handed and data (network byte order) RTI::ParameterHandle theHandle = theParameters.getHandle(i); theParameters.getValue(i, netBuffer, length); // Process the parameter switch ( findParameterIndex(theHandle) ) { case DETONATION_RESULT_CODE_MD_PI : { switch ( DetonationResultCodeEnum8( netBuffer[0] ) ) { case DetonationResultCodeOther : detonationResult = simulation::Weapon::DETONATE_OTHER; break; case EntityImpact : detonationResult = simulation::Weapon::DETONATE_ENTITY_IMPACT; break; case EntityProximateDetonation : detonationResult = simulation::Weapon::DETONATE_ENTITY_PROXIMATE_DETONATION; break; case GroundImpact : detonationResult = simulation::Weapon::DETONATE_GROUND_IMPACT; break; case GroundProximateDetonation : detonationResult = simulation::Weapon::DETONATE_GROUND_PROXIMATE_DETONATION; break; case Detonation : detonationResult = simulation::Weapon::DETONATE_DETONATION; break; case None : detonationResult = simulation::Weapon::DETONATE_NONE; break; default : detonationResult = simulation::Weapon::DETONATE_OTHER; break; }; } break; case FIRING_OBJECT_IDENTIFIER_MD_PI : { // Get the object's name RTI::ULong n = RTIObjectIdStruct::ID_SIZE; if (n > length) n = length; base::utStrncpy(reinterpret_cast<char*>(&firingObjectIdentifier.id[0]), sizeof(firingObjectIdentifier.id), netBuffer, n); firingObjectIdentifier.id[n-1] = '\0'; } break; case MUNITION_OBJECT_IDENTIFIER_MD_PI : { // Get the object's name RTI::ULong n = RTIObjectIdStruct::ID_SIZE; if (n > length) n = length; base::utStrncpy(reinterpret_cast<char*>(&munitionObjectIdentifier.id[0]), sizeof(munitionObjectIdentifier.id), netBuffer, n); munitionObjectIdentifier.id[n-1] = '\0'; } break; case TARGET_OBJECT_IDENTIFIER_MD_PI : { // Get the object's name RTI::ULong n = RTIObjectIdStruct::ID_SIZE; if (n > length) n = length; base::utStrncpy(reinterpret_cast<char*>(&targetObjectIdentifier.id[0]), sizeof(targetObjectIdentifier.id), netBuffer, n); targetObjectIdentifier.id[n-1] = '\0'; } break; } } std::cout << "RprFom::Nib::receiveMunitionDetonation() fired(" << firingObjectIdentifier.id << ")" << std::endl; // --- // 1) Find the target (local) player // --- simulation::Player* tPlayer = nullptr; if ( std::strlen(reinterpret_cast<const char*>(targetObjectIdentifier.id)) > 0 ) { simulation::Nib* tNib = findNibByObjectName( reinterpret_cast<char*>(targetObjectIdentifier.id), OUTPUT_NIB); if (tNib != nullptr) tPlayer = tNib->getPlayer(); } // --- // Note: we're only interested (at this time) with our local players being hit // by other networked IPlayers. // --- if (tPlayer != nullptr) { // --- // 2) Find the firing player and munitions (networked) IPlayers // --- simulation::Nib* fNib = nullptr; simulation::Nib* mNib = nullptr; if ( std::strlen(reinterpret_cast<const char*>(firingObjectIdentifier.id)) > 0 ) { fNib = findNibByObjectName( reinterpret_cast<char*>(firingObjectIdentifier.id), INPUT_NIB); } if ( std::strlen(reinterpret_cast<const char*>(munitionObjectIdentifier.id)) > 0 ) { mNib = findNibByObjectName( reinterpret_cast<char*>(munitionObjectIdentifier.id), INPUT_NIB); } // --- // 3) Tell the target player that it was killed by the firing player // --- if (detonationResult == simulation::Weapon::DETONATE_ENTITY_IMPACT) { if (fNib != nullptr) { tPlayer->event(KILL_EVENT,fNib->getPlayer()); } else { tPlayer->event(KILL_EVENT,0); // killed by we don't know by whom } } // --- // 4) Update the mode of the munition IPlayer // --- if (mNib != nullptr) { simulation::Weapon* mPlayer = dynamic_cast<simulation::Weapon*>(mNib->getPlayer()); if (mPlayer != nullptr) { mPlayer->setMode(simulation::Player::DETONATED); mPlayer->setDetonationResults(detonationResult); } mNib->setMode(simulation::Player::DETONATED); } } return true; }