void CActor::attach_Vehicle(CHolderCustom* vehicle) { if(!vehicle) return; if(m_holder) return; PickupModeOff (); m_holder=vehicle; CKinematicsAnimated* V = smart_cast<CKinematicsAnimated*>(Visual()); R_ASSERT(V); if(!m_holder->attach_Actor(this)){ m_holder=NULL; return; } // temp play animation CCar* car = smart_cast<CCar*>(m_holder); u16 anim_type = car->DriverAnimationType(); SVehicleAnimCollection& anims = m_vehicle_anims->m_vehicles_type_collections[anim_type]; V->PlayCycle (anims.idles[0],FALSE); ResetCallbacks (); u16 head_bone = V->LL_BoneID("bip01_head"); V->LL_GetBoneInstance (u16(head_bone)).set_callback (bctPhysics, VehicleHeadCallback,this); character_physics_support ()->movement()->DestroyCharacter(); mstate_wishful = 0; m_holderID=car->ID (); SetWeaponHideState (INV_STATE_CAR, true); CStepManager::on_animation_start(MotionID(), 0); }
int main(int argc, char* argv[]) { CHelicopter helicopter; cout << "Helicopter: "; helicopter.Move(30); CAirplane airplane; cout << "Airplane: "; airplane.Move(800); CCar car; cout << "Car: "; car.Move(100); CBus bus; cout << "Bus: "; bus.Move(500); CBoat boat; cout << "Boat: "; boat.Move(25); cout << "Boat using <Sail> method: "; boat.Sail(75); return 0; }
void carEngineSoundEffect(int chan, void *stream, int len, void *udata) { CCar *car = (CCar *)udata; float f; unsigned int i, j, k; Sint16 *ip, *ip2; SOUNDT ces = car->getcarEngineSound(); #ifdef F1SPIRIT_DEBUG_MESSAGES output_debug_message("carEngineSoundEffect of %i\n",chan); #endif if (car->get_state()!=2) { // state = 2 is when the car has crashed, thus we don't have to play the engine: // "f" is the factor at which we are modifying the pitch of the engine sample // if "f=2", the sound will be with twice the pitch of the original engine sample. // the formula weare using is: f = ((rpm-2000)/2000)+0.5 f = (car->get_rpm() - 2000.0F) / 2000.0F; if (f < 0) f = 0; f = 0.5F + f; ip = (Sint16 *)stream; ip2 = (Sint16 *)ces->abuf; // Fill the S_carengine_working with a pitch modified version of the engine sample (S_carengine) // Since the sample is stereo and 16bits, each sample is "4 bytes" // "j" is the index that moves over the S_carengine_working sound, // and k = j*f is the index that moves over the S_carengine sound. #ifdef F1SPIRIT_DEBUG_MESSAGES output_debug_message("carengine_position of channel %i is %i (f: %g)\n",chan,car->carengine_position,f); #endif for (i = 0, j = 0;i < len;i += 4, j++) { k = car->carengine_position + (unsigned int)(j * f); while (k*4 >= ces->alen) k -= ces->alen / 4; // Stereo mixing: ip[j*2] = ip2[k * 2]; // L ip[j*2 + 1] = ip2[k * 2 + 1]; // R } car->carengine_position = k; } else { // When the car has crashed, just set the buffer to all 0: ip = (Sint16 *)stream; for (i = 0, j = 0;i < len;i += 4, j++) { ip[j*2]=0; ip[j*2+1]=0; } car->carengine_position = 0; } // if }
void CControllerCB::RigidBodyControllerCallback(neRigidBodyController * controller, float timeStep) { neRigidBody * rb = controller->GetRigidBody(); CCar * car = (CCar *)(rb->GetUserData()); car->CarController(controller); }
void ExpectOperationSucceeds(Op && op, int expectedGear, int expectedSpeed, bool engineIsOn = true) { BOOST_CHECK(op()); BOOST_CHECK_EQUAL(car.IsEngineOn(), engineIsOn); BOOST_CHECK_EQUAL(car.GetGear(), expectedGear); BOOST_CHECK_EQUAL(car.GetSpeed(), abs(expectedSpeed)); BOOST_CHECK(car.GetMovementType() == (expectedSpeed > 0 ? (expectedGear > 0 ? CCar::MovementType::FORWARD : expectedGear == 0 ? CCar::MovementType::NONE : CCar::MovementType::BACK) : CCar::MovementType::STAY)); }
void CheckTransmissionSpeedRange(int gear, int minSpeed, int maxSpeed, int currentSpeed) { ExpectOperationSucceeds([=] { return car.SetGear(gear);}, gear, currentSpeed); ExpectOperationFails([=] { return car.SetSpeed(minSpeed - 1);}); ExpectOperationFails([=] { return car.SetSpeed(maxSpeed + 1);}); ExpectOperationSucceeds([=] { return car.SetSpeed(minSpeed);}, gear, minSpeed); ExpectOperationSucceeds([=] { return car.SetSpeed((minSpeed + maxSpeed) / 2);}, gear, (minSpeed + maxSpeed)/ 2); ExpectOperationSucceeds([=] { return car.SetSpeed(maxSpeed);}, gear, maxSpeed); }
void CreateCar(CGeneralManager* p_obj_man, Script::CStruct* pNodeData) { CCar* pCar = new CCar; Dbg_MsgAssert(pCar, ("Failed to create car.")); // get position, from the node that created us: SkateScript::GetPosition( pNodeData, &pCar->m_pos ); pCar->InitCar(p_obj_man, pNodeData); }
void CActor::steer_Vehicle(float angle) { if(!m_holder) return; CCar* car = smart_cast<CCar*>(m_holder); u16 anim_type = car->DriverAnimationType(); SVehicleAnimCollection& anims=m_vehicle_anims->m_vehicles_type_collections[anim_type]; if(angle==0.f) smart_cast<CKinematicsAnimated*> (Visual())->PlayCycle(anims.idles[0]); else if(angle>0.f) smart_cast<CKinematicsAnimated*> (Visual())->PlayCycle(anims.steer_right); else smart_cast<CKinematicsAnimated*> (Visual())->PlayCycle(anims.steer_left); }
void CarClear () { CCar* c; for (c = head; c; c = c->m_next) c->Park (); ZeroMemory (carmap, sizeof (carmap)); count = 0; }
void ExpectOperationFails(Op && op) { const CCar clone(car); BOOST_CHECK(!op()); BOOST_CHECK_EQUAL(car.IsEngineOn(), clone.IsEngineOn()); BOOST_CHECK_EQUAL(car.GetGear(), clone.GetGear()); BOOST_CHECK_EQUAL(car.GetSpeed(), clone.GetSpeed()); BOOST_CHECK_EQUAL(car.GetMovementType(), clone.GetMovementType()); }
/////////////////// // Change an engine part void Gar_ChangeEnginePart(CPart *pcPart, bool bRemoval, gitem_t *g) { CCar *car = cMainGuy->getCurCar(); // Safety check if(car == NULL) return; // Check if this part can be unbolted if(!car->checkPartRemoval(pcPart->getType())) { Gar_InitSpeechBubble("You cannot take that part off"); return; } // Move the camera if( pcPart->getType() == PRT_BLOCK ) { // Block cGarLocation->startCameraMove(pcPart->getPos(), pcPart->getPos() + CVec(3,3,2)); } else { // Normal part Gar_MoveCamera(pcPart->getPos(), 5); } cGarSection.setEnabled(false); cSidebar.setEnabled(false); cGarLocation->setAngleLimit(false); cGarLocation->setItemCheck(false); System_GetMouse()->Up = 0; // Add an engine pic to the taskbar cGarTaskb.Remove("parts"); cGarTaskb.Remove("tuning"); tGarage->iState = GAR_ENGINEPART; // Setup the part change tPartChange.iNutsGoingon = false; tPartChange.iChange = true; tPartChange.cCar = car; tPartChange.cPart = pcPart; tPartChange.tItem = g; tPartChange.iNutsGoingon = !bRemoval; // Initialize the part change Gar_SetupPartChange(); pcPart->setDrawNuts(true); }
void CarUpdate () { CCar* c; unsigned now; if (!TextureReady () || !EntityReady ()) return; now = GetTickCount (); if (next_update > now) return; next_update = now + UPDATE_INTERVAL; for (c = head; c; c = c->m_next) c->Update (); }
void CarRender () { CCar* c; if (!angles_done) { for (int i = 0 ;i < 360; i++) { angles[i].x = cosf ((float)i * DEGREES_TO_RADIANS) * CAR_SIZE; angles[i].y = sinf ((float)i * DEGREES_TO_RADIANS) * CAR_SIZE; } } glDepthMask (false); glEnable (GL_BLEND); glDisable (GL_CULL_FACE); glBlendFunc (GL_ONE, GL_ONE); glBindTexture (GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, TextureId (TEXTURE_HEADLIGHT)); for (c = head; c; c = c->m_next) c->Render (); glDepthMask (true); }
void __fastcall TGetTrackThread::GetLatestStatus() { //2001.12.25 修正運作方式為只取近期有更動過之資料,以加速大量資料時的處理速度 //2002.5.6 修正運作方式為比對UpdateTime,有更動過才更新 //2002.5.6 將由Database_Local的Database component轉換至本身開啟 sCarStatus CarStatus; memset(&CarStatus,0,sizeof(sCarStatus)); //RESET CarStatus 的記憶體 TQuery* pQArea = new TQuery(NULL); //free in last line pQArea->DatabaseName = "DB_DCH"; pQArea->SQL->Add("SELECT * FROM tArea"); TQuery* pQ_LatestStatus = new TQuery(NULL); //free in the last line pQ_LatestStatus->DatabaseName = "DB_DCH"; pQ_LatestStatus->SQL->Add("SELECT * FROM tLatestStatus"); try { pQArea->Active = true; for(pQ_LatestStatus->Active = true; !pQ_LatestStatus->Eof; pQ_LatestStatus->Next()) { if(Terminated) { //突發性結束 delete pQArea; delete pQ_LatestStatus; return; } AnsiString LocatorNo = pQ_LatestStatus->FieldByName("LocatorNo")->AsString; CCar* pCar = CallCenter_Main_Form->GetCarByLocatorNo(LocatorNo); if(pCar) { //有更動過的資料才更新,以RecvTime來判斷是否更動過資料! TDateTime NewUpdateTime = pQ_LatestStatus->FieldByName("UpdateTime")->AsDateTime; if(pCar->LatestStatusUpdateTime != NewUpdateTime) { pCar->LatestStatusUpdateTime = NewUpdateTime; strcpy(CarStatus.m_szLocatorNo,LocatorNo.c_str()); strcpy(CarStatus.m_szRecvDate,pQ_LatestStatus->FieldByName("RecvDate")->AsString.c_str()); //2002.5.10 轉換RecvTime為六位數 AnsiString RecvTimeStr = pQ_LatestStatus->FieldByName("RecvTime")->AsString.SubString(1,6); strcpy(CarStatus.m_szRecvTime,RecvTimeStr.c_str()); strcpy(CarStatus.m_szSendDate,pQ_LatestStatus->FieldByName("SendDate")->AsString.c_str()); strcpy(CarStatus.m_szSendTime,pQ_LatestStatus->FieldByName("SendTime")->AsString.c_str()); CarStatus.m_iStatus = pQ_LatestStatus->FieldByName("CarStatus")->AsInteger; CarStatus.m_iStatusHandle = pQ_LatestStatus->FieldByName("StatusHandle")->AsInteger; CarStatus.m_iLon = pQ_LatestStatus->FieldByName("Lon")->AsInteger; CarStatus.m_iLat = pQ_LatestStatus->FieldByName("Lat")->AsInteger; CarStatus.m_sSpeed = pQ_LatestStatus->FieldByName("Speed")->AsInteger; CarStatus.m_dMileage = pQ_LatestStatus->FieldByName("Mileage")->AsFloat; //單位公里 CarStatus.ReportRate = pQ_LatestStatus->FieldByName("ReportRate")->AsInteger; //回報頻率 CarStatus.m_szPlaceName = pQ_LatestStatus->FieldByName("PlaceName")->AsString; CarStatus.m_iDistID = pQ_LatestStatus->FieldByName("DistID")->AsInteger; //行政區編號 //取得行政區中文名稱 CarStatus.DistName = NULL; for(pQArea->First(); !pQArea->Eof; pQArea->Next()) { if(CarStatus.m_iDistID == pQArea->FieldByName("AreaID")->AsInteger) { CarStatus.DistName = pQArea->FieldByName("CName")->AsString; break; } } pCar->Update(&CarStatus); pCar->ReportCheckRate = pQ_LatestStatus->FieldByName("ReportChkRate")->AsFloat; //回報檢查頻率 pCar->GPSLock = pQ_LatestStatus->FieldByName("GPSLock")->AsBoolean; memset(&CarStatus,0,sizeof(sCarStatus)); //RESET CarStatus 的記憶體 } } } } catch(EDBEngineError &E) { DataModule1->EstablishConnect(1); } catch(...) { } delete pQArea; delete pQ_LatestStatus; }
void CheckGear(CCar & car, CCar::Gear gear) { BOOST_CHECK(car.GetGear() == gear); }
int _tmain(int argc, _TCHAR* argv[]) { CCar car; map<CCar::Direction, string> directionToString = { { CCar::Direction::FORWARD, "forward" }, { CCar::Direction::BACKWARD, "backward" }, { CCar::Direction::STILL, "still" } }; map<CCar::Err, string> errToStr = { { CCar::Err::EngineTurnedOffSpeed, "Engine turned off, impossible to set given speed." }, { CCar::Err::EngineTurnedOffGear, "Engine turned off, impossible to set given gear." }, { CCar::Err::AlreadyTurnedOff, "Engine is already turned off." }, { CCar::Err::CanNotTurnOff, "Engine can not be turned off at current speed and gear." }, { CCar::Err::InvalidGear, "No such gear." }, { CCar::Err::InvalidSpeed, "Impossible to set given speed." }, { CCar::Err::InvalidSpeedForGivenGear, "Impossible to set given speed at current gear." }, { CCar::Err::InvalidGearForGivenSpeed, "Impossible to set given gear at current speed." } }; map<bool, string> isEngineTurnedOnToStr = { { true, " is turned on" }, { false, " is turned off" }, }; string curQuery; Commands command; int value; while (getline(cin, curQuery)) { curQuery.push_back('\n'); if (AssignCommand(curQuery, command, value)) { switch (command) { case Info: if (car.IsEngineTurnedOn()) { cout << "Engine turned on.\n"; } else { cout << "Engine turned off.\n"; } cout << "Direction - " << directionToString[car.GetDirection()] << ".\n"; cout << "Speed - " << car.GetSpeed() << ".\n"; cout << "Gear - " << car.GetGear() << ".\n"; break; case EngineOn: if (!car.TurnOnEngine()) { cout << "Engine is already turned on.\n"; } break; case EngineOff: if (!car.TurnOffEngine()) { cout << errToStr[car.GetLastErr()] << '\n'; } break; case SetGear: if (!car.SetGear(value)) { cout << errToStr[car.GetLastErr()] << '\n'; } break; case SetSpeed: if (!car.SetSpeed(value)) { cout << errToStr[car.GetLastErr()] << '\n'; } break; } } else { cout << "Available commands:Info, EngineOn, EngineOff, SetSpeed <speed>, SetGear <gear>.\n"; } } return 0; }
//--------------------------------------------------------------------------- void __fastcall TGetTrackThread::Determine_Car_Image_Color() { //2002.5.9 假如車子在畫面上才執行繪製動作 //2002.5.16 解決當車輛狀處理中時(黃色),主地圖車輛顏色未變的問題,去掉了車輛在畫面上才畫的程式 try { //決定車輛顏色狀態 for(int i=0; i<CallCenter_Main_Form->m_pCarList->Count; i++) { if(Terminated) { return; } CCar* pCar = (CCar*)CallCenter_Main_Form->m_pCarList->Items[i]; AnsiString CarID = pCar->GetCarID(); TListItem* pListItem = Form_ViewInfo->GetCarItem(CarID); if(pListItem != NULL) //假如這台車有在ListView則才做 { AnsiString IO = pListItem->SubItems->Strings[IO_STAT]; if(IO == "") { IO = "0000"; } if(IO[pCar->IO_In_Watch] != '1') //假如I/O OFF的時候 { pCar->ImageColor = 5; } else //假如I/O ON的時候 { pCar->ImageColor = 4; } int ACC = pCar->m_Status.m_iStatus % 4; if(ACC < 2) //ACC OFF //假如ACC OFF的時候 { pCar->ImageColor = 3; } for(int i=0; i<Form_ManageState->ListView1->Items->Count; i++) //找尋有狀況的車輛 { if(Terminated) { return; } TListItem* pListItem = Form_ManageState->ListView1->Items->Item[i]; AnsiString CarID = pListItem->Caption; AnsiString Handler = pListItem->SubItems->Strings[2]; AnsiString pCarID = pCar->GetCarID(); if(CarID == pCarID) { if(Handler == "未處理") //假如狀況未處理 { pCar->ImageColor = 1; } else { if(pCar->ImageColor != 1)//假如有發現過未處理狀態則不更動 { pCar->ImageColor = 2; //假如狀況處理中 } } } } } else { //假如車輛沒有在ListView,給他default pCar->ImageColor = 5; } } } catch(...) {} try { //繪製車輛顏色 for(int i=0; i<CallCenter_Main_Form->m_pCarList->Count; i++) { if(Terminated) { return; } CCar* pCar = (CCar*)CallCenter_Main_Form->m_pCarList->Items[i]; if(pCar->m_pImage_Car->Tag > 0)//Unlock { int CarType = 0; int TmpVal = pCar->m_pImage_Car->Tag; while(TmpVal > 5) { CarType++; TmpVal = TmpVal - 5; } if(pCar->m_pImage_Car->Tag != CarType*5 + pCar->ImageColor) //假如與之前的顏色不同才換色 { pCar->m_pImage_Car->Tag = CarType*5 + pCar->ImageColor; CallCenter_Main_Form->ChangeCarImgByTag(pCar->m_pImage_Car,1); } } else //Locked { pCar->m_pImage_Car->Tag = -pCar->m_pImage_Car->Tag; int CarType = 0; int TmpVal = pCar->m_pImage_Car->Tag; while(TmpVal > 5) { CarType++; TmpVal = TmpVal - 5; } pCar->m_pImage_Car->Tag = -1 * (CarType*5 + pCar->ImageColor); CallCenter_Main_Form->ChangeCarImgByTag(pCar->m_pImage_Car,1); } } } catch(...) {} }