void SelectWeapon(const char* name, const CTimeValue& time) { if(m_curWeapon != m_weapons.end() && m_curWeapon->m_name == name)//entered current vehicle { return; } DeselectWeapon(time);//deselect old one //find it and add if needed TWeapons::iterator it = std::lower_bound(m_weapons.begin(), m_weapons.end(), CONST_TEMP_STRING(name), SWeaponCompare()); if(it == m_weapons.end()) { m_curWeapon = m_weapons.insert(m_weapons.end(), SWeapon(name)); } else { if(it->m_name == name) { m_curWeapon = it; } else { m_curWeapon = m_weapons.insert(it, SWeapon(name)); } } m_selected = time; }
// addWeaponToInventory // add to component void CWeaponComponent::addWeaponToInventory( const char* weaponName ) { SWeapon* weapon = getWeapon(weaponName); if ( weapon == NULL ) { CGameConfig::SWeaponInfo* wpInfo = CGameConfig::getInstance()->getWeaponByName(weaponName); if ( wpInfo ) { CGameObject *wpObj = new CGameObject(NULL); // load model if ( wpInfo->model.empty() == false ) { CColladaMeshComponent *collada = new CColladaMeshComponent(wpObj); collada->loadScene(wpInfo->model.c_str()); wpObj->addComponent(collada); wpObj->initComponent(); } wpObj->setVisible(false); wpObj->setParent(m_gameObject); m_weapons.push_back( SWeapon() ); SWeapon& w = m_weapons.back(); w.m_obj = wpObj; w.m_num = 1; w.m_info = wpInfo; // find type of weapon for (int i = (int)Unknown; i < (int)NumWPType; i++) { if ( wpInfo->type == k_weaponTypeString[i] ) { w.m_type = (EWeaponType)i; break; } } switch (w.m_type) { case Gun: { CGunComponent *gun = new CGunComponent(wpObj, wpInfo); wpObj->addComponent(gun); } break; } wpObj->initComponent(); } } else { weapon->m_num++; } }