• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Vehicle类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中Vehicle的典型用法代码示例。如果您正苦于以下问题:C++ Vehicle类的具体用法?C++ Vehicle怎么用?C++ Vehicle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Vehicle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: PropagateChildLivery

/**
 * Propagate a livery change to a group's children.
 * @param g Group.
 */
void PropagateChildLivery(const Group *g)
{
	/* Company colour data is indirectly cached. */
	Vehicle *v;
	FOR_ALL_VEHICLES(v) {
		if (v->group_id == g->index && (!v->IsGroundVehicle() || v->IsFrontEngine())) {
			for (Vehicle *u = v; u != nullptr; u = u->Next()) {
				u->colourmap = PAL_NONE;
				u->InvalidateNewGRFCache();
			}
		}
	}

	Group *cg;
	FOR_ALL_GROUPS(cg) {
		if (cg->parent == g->index) {
			if (!HasBit(cg->livery.in_use, 0)) cg->livery.colour1 = g->livery.colour1;
			if (!HasBit(cg->livery.in_use, 1)) cg->livery.colour2 = g->livery.colour2;
			PropagateChildLivery(cg);
		}
	}
}
开发者ID:OpenTTD,项目名称:OpenTTD,代码行数:26,代码来源:group_cmd.cpp


示例2: AssignFields

bool Controller::AssignFields(templateIO& myArr, std::string type, Vehicle& neededUnit, VehicleGun& newGun)
{
	neededUnit.SetName(myArr.myStringArr[0]);
	neededUnit.SetArmor(true, 0, myArr.myIntArr[0]);
	neededUnit.SetArmor(true, 90, myArr.myIntArr[1]);
	neededUnit.SetArmor(true, 180, myArr.myIntArr[2]);
	neededUnit.SetArmor(false, 0, myArr.myIntArr[3]);
	neededUnit.SetArmor(false, 90, myArr.myIntArr[4]);
	neededUnit.SetArmor(false, 180, myArr.myIntArr[5]);
	neededUnit.SetBDurability(myArr.myIntArr[6]);
	neededUnit.SetTDurability(myArr.myIntArr[7]);
	neededUnit.SetADurability(100);
	neededUnit.SetTMDurability(100);
	neededUnit.SetEDurability(100);
	neededUnit.SetEngineFueled(true);
	neededUnit.MyGun->SetAmmoType(newGun.GetAmmoType());
	neededUnit.MyGun->SetArmorPiercing(newGun.GetArmorPiercing());
	neededUnit.MyGun->SetDamage(newGun.GetDamage());
	neededUnit.MyGun->SetName(newGun.GetName());
	return true;
}
开发者ID:WaildCat,项目名称:Cursovaya,代码行数:21,代码来源:Controller.cpp


示例3: CraftWeapon

/**
 * Loads the craft from a YAML file.
 * @param node YAML node.
 * @param mod Mod for the saved game.
 * @param save Pointer to the saved game.
 */
void Craft::load(const YAML::Node &node, const Mod *mod, SavedGame *save)
{
	MovingTarget::load(node);
	_id = node["id"].as<int>(_id);
	_fuel = node["fuel"].as<int>(_fuel);
	_damage = node["damage"].as<int>(_damage);

	size_t j = 0;
	for (YAML::const_iterator i = node["weapons"].begin(); i != node["weapons"].end(); ++i)
	{
		if (_rules->getWeapons() > j)
		{
			std::string type = (*i)["type"].as<std::string>();
			if (type != "0" && mod->getCraftWeapon(type))
			{
				CraftWeapon *w = new CraftWeapon(mod->getCraftWeapon(type), 0);
				w->load(*i);
				_weapons[j] = w;
			}
			else
			{
				_weapons[j] = 0;
			}
			j++;
		}
	}

	_items->load(node["items"]);
	for (std::map<std::string, int>::iterator i = _items->getContents()->begin(); i != _items->getContents()->end();)
	{
		if (std::find(mod->getItemsList().begin(), mod->getItemsList().end(), i->first) == mod->getItemsList().end())
		{
			_items->getContents()->erase(i++);
		}
		else
		{
			++i;
		}
	}
	for (YAML::const_iterator i = node["vehicles"].begin(); i != node["vehicles"].end(); ++i)
	{
		std::string type = (*i)["type"].as<std::string>();
		if (mod->getItem(type))
		{
			Vehicle *v = new Vehicle(mod->getItem(type), 0, 4);
			v->load(*i);
			_vehicles.push_back(v);
		}
	}
	_status = node["status"].as<std::string>(_status);
	_lowFuel = node["lowFuel"].as<bool>(_lowFuel);
	_mission = node["mission"].as<bool>(_mission);
	_interceptionOrder = node["interceptionOrder"].as<int>(_interceptionOrder);
	if (const YAML::Node name = node["name"])
	{
		_name = Language::utf8ToWstr(name.as<std::string>());
	}
	if (const YAML::Node &dest = node["dest"])
	{
		std::string type = dest["type"].as<std::string>();
		int id = dest["id"].as<int>();
		if (type == "STR_BASE")
		{
			returnToBase();
		}
		else if (type == "STR_UFO")
		{
			for (std::vector<Ufo*>::iterator i = save->getUfos()->begin(); i != save->getUfos()->end(); ++i)
			{
				if ((*i)->getId() == id)
				{
					setDestination(*i);
					break;
				}
			}
		}
		else if (type == "STR_WAYPOINT")
		{
			for (std::vector<Waypoint*>::iterator i = save->getWaypoints()->begin(); i != save->getWaypoints()->end(); ++i)
			{
				if ((*i)->getId() == id)
				{
					setDestination(*i);
					break;
				}
			}
		}
		else if (type == "STR_ALIEN_BASE")
		{
			for (std::vector<AlienBase*>::iterator i = save->getAlienBases()->begin(); i != save->getAlienBases()->end(); ++i)
			{
				if ((*i)->getId() == id)
				{
					setDestination(*i);
//.........这里部分代码省略.........
开发者ID:JonnyH,项目名称:shoes-diary,代码行数:101,代码来源:Craft.cpp


示例4: UpdateAI

        void UpdateAI(const uint32 uiDiff)
        {
            npc_escortAI::UpdateAI(uiDiff);

            if (!UpdateVictim())
                return;

            if (uiBuffTimer <= uiDiff)
            {
                if (!me->HasAura(SPELL_SHIELD))
                    DoCastSpellShield();

                uiBuffTimer = urand(30000, 45000);
            }else uiBuffTimer -= uiDiff;

            if (uiChargeTimer <= uiDiff)
            {
                Map::PlayerList const& players = me->GetMap()->GetPlayers();
                if (me->GetMap()->IsDungeon() && !players.isEmpty())
                {
                    for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
                    {
                        Player* player = itr->getSource();
                        if (player && !player->isGameMaster() && me->IsInRange(player, 8.0f, 25.0f, false))
                        {
                            DoResetThreat();
                            me->AddThreat(player, 1.0f);
                            DoCast(player, SPELL_CHARGE);
                            break;
                        }
                    }
                }
                uiChargeTimer = 5000;
            }else uiChargeTimer -= uiDiff;

            //dosen't work at all
            if (uiShieldBreakerTimer <= uiDiff)
            {
                Vehicle* vehicle = me->GetVehicleKit();
                if (!vehicle)
                    return;

                if (Unit* pPassenger = vehicle->GetPassenger(SEAT_ID_0))
                {
                    Map::PlayerList const& players = me->GetMap()->GetPlayers();
                    if (me->GetMap()->IsDungeon() && !players.isEmpty())
                    {
                        for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
                        {
                            Player* player = itr->getSource();
                            if (player && !player->isGameMaster() && me->IsInRange(player, 10.0f, 30.0f, false))
                            {
                                pPassenger->CastSpell(player, SPELL_SHIELD_BREAKER, true);
                                break;
                            }
                        }
                    }
                }
                uiShieldBreakerTimer = 7000;
            }else uiShieldBreakerTimer -= uiDiff;

            DoMeleeAttackIfReady();
        }
开发者ID:Fuggi,项目名称:SkyFireEMU,代码行数:63,代码来源:boss_grand_champions.cpp


示例5: UpdateDrawObjs

void SSControlSurf::UpdateDrawObjs()
{
    SubSurface::UpdateDrawObjs();

    Vehicle* veh = VehicleMgr.GetVehicle();
    if ( !veh )
    {
        return;
    }
    Geom* geom = veh->FindGeom( m_CompID );
    if ( geom )
    {
        vector< VspSurf > surf_vec;
        geom->GetSurfVec( surf_vec );
        int ncopy = geom->GetNumSymmCopies();

        m_HingeDO.m_PntVec.clear();
        m_HingeDO.m_LineWidth = 2.0;
        m_HingeDO.m_Type = DrawObj::VSP_LINES;
        m_HingeDO.m_GeomID = m_ID + string( "_ss_hinge" );
        m_HingeDO.m_GeomChanged = true;

        m_ArrowDO.m_PntVec.clear();
        m_ArrowDO.m_Type = DrawObj::VSP_SHADED_TRIS;
        m_ArrowDO.m_GeomID = m_ID + string( "_ss_arrow" );
        m_ArrowDO.m_GeomChanged = true;

        for ( int i = 0; i < 4; i++ )
        {
            m_ArrowDO.m_MaterialInfo.Ambient[i] = 0.2;
            m_ArrowDO.m_MaterialInfo.Diffuse[i] = 0.1;
            m_ArrowDO.m_MaterialInfo.Specular[i] = 0.7;
            m_ArrowDO.m_MaterialInfo.Emission[i] = 0.0;
        }
        m_ArrowDO.m_MaterialInfo.Diffuse[3] = 0.5;
        m_ArrowDO.m_MaterialInfo.Shininess = 5.0;


        int isurf = m_MainSurfIndx();

        vector < int > symms = geom->GetSymmIndexs( isurf );
        assert( ncopy == symms.size() );

        int npt = m_UWStart.size();

        for ( int s = 0 ; s < ncopy ; s++ )
        {
            VspSurf* surf = &( surf_vec[ symms[ s ] ] );

            vec3d pst, pend;
            for ( int i = 0; i < npt; i++ )
            {
                pst = pst + surf->CompPnt01( m_UWStart[i].x(), m_UWStart[i].y() );
                pend = pend + surf->CompPnt01( m_UWEnd[i].x(), m_UWEnd[i].y() );
            }
            pst = pst / ( 1.0 * npt );
            pend = pend / ( 1.0 * npt );

            vec3d pmid = ( pst + pend ) * 0.5;

            vec3d dir = pend - pst;
            double len = dir.mag();
            dir.normalize();

            m_HingeDO.m_PntVec.push_back( pst );
            m_HingeDO.m_PntVec.push_back( pend );

            MakeCircleArrow( pmid, dir, 0.25, m_HingeDO, m_ArrowDO );
        }
        m_ArrowDO.m_NormVec = vector <vec3d> ( m_ArrowDO.m_PntVec.size() );
    }
}
开发者ID:cptdime,项目名称:OpenVSP,代码行数:72,代码来源:SubSurface.cpp


示例6: mouseDragged

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
 
    Vehicle v;
    v.setup(mouseX, mouseY);
    vehicles.push_back(v);
}
开发者ID:chopsuey5000,项目名称:nature_code_oF,代码行数:7,代码来源:testApp.cpp


示例7: CheckCaches

/**
 * Check the validity of some of the caches.
 * Especially in the sense of desyncs between
 * the cached value and what the value would
 * be when calculated from the 'base' data.
 */
static void CheckCaches()
{
	/* Return here so it is easy to add checks that are run
	 * always to aid testing of caches. */
	if (_debug_desync_level <= 1) return;

	/* Check the town caches. */
	SmallVector<TownCache, 4> old_town_caches;
	Town *t;
	FOR_ALL_TOWNS(t) {
		MemCpyT(old_town_caches.Append(), &t->cache);
	}

	extern void RebuildTownCaches();
	RebuildTownCaches();
	RebuildSubsidisedSourceAndDestinationCache();

	uint i = 0;
	FOR_ALL_TOWNS(t) {
		if (MemCmpT(old_town_caches.Get(i), &t->cache) != 0) {
			DEBUG(desync, 2, "town cache mismatch: town %i", (int)t->index);
		}
		i++;
	}

	/* Check company infrastructure cache. */
	SmallVector<CompanyInfrastructure, 4> old_infrastructure;
	Company *c;
	FOR_ALL_COMPANIES(c) MemCpyT(old_infrastructure.Append(), &c->infrastructure);

	extern void AfterLoadCompanyStats();
	AfterLoadCompanyStats();

	i = 0;
	FOR_ALL_COMPANIES(c) {
		if (MemCmpT(old_infrastructure.Get(i), &c->infrastructure) != 0) {
			DEBUG(desync, 2, "infrastructure cache mismatch: company %i", (int)c->index);
		}
		i++;
	}

	/* Strict checking of the road stop cache entries */
	const RoadStop *rs;
	FOR_ALL_ROADSTOPS(rs) {
		if (IsStandardRoadStopTile(rs->xy)) continue;

		assert(rs->GetEntry(DIAGDIR_NE) != rs->GetEntry(DIAGDIR_NW));
		rs->GetEntry(DIAGDIR_NE)->CheckIntegrity(rs);
		rs->GetEntry(DIAGDIR_NW)->CheckIntegrity(rs);
	}

	Vehicle *v;
	FOR_ALL_VEHICLES(v) {
		extern void FillNewGRFVehicleCache(const Vehicle *v);
		if (v != v->First() || v->vehstatus & VS_CRASHED || !v->IsPrimaryVehicle()) continue;

		uint length = 0;
		for (const Vehicle *u = v; u != NULL; u = u->Next()) length++;

		NewGRFCache        *grf_cache = CallocT<NewGRFCache>(length);
		VehicleCache       *veh_cache = CallocT<VehicleCache>(length);
		GroundVehicleCache *gro_cache = CallocT<GroundVehicleCache>(length);
		TrainCache         *tra_cache = CallocT<TrainCache>(length);

		length = 0;
		for (const Vehicle *u = v; u != NULL; u = u->Next()) {
			FillNewGRFVehicleCache(u);
			grf_cache[length] = u->grf_cache;
			veh_cache[length] = u->vcache;
			switch (u->type) {
				case VEH_TRAIN:
					gro_cache[length] = Train::From(u)->gcache;
					tra_cache[length] = Train::From(u)->tcache;
					break;
				case VEH_ROAD:
					gro_cache[length] = RoadVehicle::From(u)->gcache;
					break;
				default:
					break;
			}
			length++;
		}

		switch (v->type) {
			case VEH_TRAIN:    Train::From(v)->ConsistChanged(CCF_TRACK); break;
			case VEH_ROAD:     RoadVehUpdateCache(RoadVehicle::From(v)); break;
			case VEH_AIRCRAFT: UpdateAircraftCache(Aircraft::From(v));   break;
			case VEH_SHIP:     Ship::From(v)->UpdateCache();             break;
			default: break;
		}

		length = 0;
		for (const Vehicle *u = v; u != NULL; u = u->Next()) {
			FillNewGRFVehicleCache(u);
//.........这里部分代码省略.........
开发者ID:IchiroWang,项目名称:OpenTTD,代码行数:101,代码来源:openttd.cpp


示例8: followerNewState

void CFAPI::updateFollowerAcclr(int step, double time, Vehicle& veh, Vehicle predVeh) {

	// Followers controlled by car follow model.
	// Create a new vehicle state with same state as current vehicle.
	// Acclr for new state is calculated here. Position and velocity
	// will be calculated in future when time = currTime + reactionTime;
	Vehicle followerNewState(veh.getId(),
							veh.getPosX(),
							veh.getVel(),
							veh.getAcclr(),
							veh.getHdwayTime(),
							veh.hasSafetyDev(),
							veh.getSafetyDevStartTime());

	double newAcclr = 0.0;
	double newHdwayTime = 0.0;

	if((veh.hasSafetyDev()) &&
		(time >= veh.getSafetyDevStartTime()))
		{
		if(m_adjHdwayTime == HDWAY_SAFE)
		    {
			newAcclr = m_cfModel->getAcclrRespInNetSafe(time, veh, predVeh, newHdwayTime);
		    }
		else
			{
			newAcclr = m_cfModel->getAcclrRespInNetResume(time, veh, predVeh, newHdwayTime);
			}

		std::cout << "Recv safety message: Veh: " << veh.getId()
					<< " at time " << time << std::endl;
		}
	else
		{
		newAcclr = m_cfModel->getAcclrResp(time, veh, predVeh, newHdwayTime);
		}

	// Adjust for unrealistic acclr and decclr values
	if(newAcclr > ACCLR_LIMIT)
		{
		newAcclr = ACCLR_LIMIT;
		}
	if(newAcclr < DECCLR_LIMIT)
		{
		newAcclr = DECCLR_LIMIT;
		}
	std::cout << "Next Acclr: Veh " << veh.getId()
						<< " acclr " << newAcclr << std::endl;

	followerNewState.setAcclr(newAcclr);
	followerNewState.setHdwayTime(newHdwayTime);
	m_vehStateTable[step + m_factor].push_back(followerNewState);
}
开发者ID:Ur-Ideas-LabS,项目名称:Vehicle-Motion-Simulation,代码行数:53,代码来源:CFAPI.cpp


示例9: ParmChanged

//==== Parm Changed ====//
void LinkMgrSingleton::ParmChanged( const string& pid, bool start_flag  )
{
    //==== Find Parm Ptr ===//
    Parm* parm_ptr = ParmMgr.FindParm( pid );
    if ( !parm_ptr )
        return;

    //==== Check For Advanced Links ====//
    bool adv_link_flag = AdvLinkMgr.IsInputParm( pid );

    //==== Look for Reg Links  ====//
    vector < Link* > parm_link_vec;
    for ( int i = 0 ; i < ( int )m_LinkVec.size() ; i++ )
    {
        if ( m_LinkVec[i]->GetParmA() == pid )
        {
            parm_link_vec.push_back( m_LinkVec[i] );
        }
    }

    //==== Check Links ====//
    bool reg_link_flag = false;
    if ( parm_link_vec.size() )
    {
        reg_link_flag = true;
    }

    //==== Abort if No Links ====//
    if ( !adv_link_flag && !reg_link_flag )
        return;

    //==== Set Link Update Flag ====//
    parm_ptr->SetLinkUpdateFlag( true );
    m_UpdatedParmVec.push_back( parm_ptr->GetID() );

    //==== Update Linked Parms ====//
    for ( int i = 0 ; i < ( int )parm_link_vec.size() ; i++ )
    {
        Link* pl = parm_link_vec[i];
        Parm* pB = ParmMgr.FindParm( pl->GetParmB() );

        if ( pB && ! pB->GetLinkUpdateFlag() )       // Prevent Circular
        {
            double offset = 0.0;
            if ( pl->GetOffsetFlag() )
            {
                offset = pl->m_Offset();
            }
            double scale = 1.0;
            if ( pl->GetScaleFlag() )
            {
                scale = pl->m_Scale();
            }

            double val = parm_ptr->Get() * scale + offset;

            if ( pl->GetLowerLimitFlag() && val < pl->m_LowerLimit() )      // Constraints
            {
                val = pl->m_LowerLimit();
            }

            if ( pl->GetUpperLimitFlag() && val > pl->m_UpperLimit() )      // Constraints
            {
                val = pl->m_UpperLimit();
            }

            pB->SetFromLink( val );
        }
    }

    //==== Update Adv Link ===//
    if ( adv_link_flag )
    {
        AdvLinkMgr.UpdateLinks( pid );
    }

    //==== Clean Up ====/
    if ( start_flag )      
    {
        for ( int i = 0 ; i < ( int )m_UpdatedParmVec.size() ; i++ )
        {
            Parm* p = ParmMgr.FindParm( m_UpdatedParmVec[i] );
            if ( p )
            {
                p->SetLinkUpdateFlag( false );
            }
        }
        m_UpdatedParmVec.clear();

        Vehicle* veh = VehicleMgr.GetVehicle();
        if ( veh )
        {
            veh->ParmChanged( parm_ptr, Parm::SET );
        }
    }
}
开发者ID:sanbales,项目名称:OpenVSP,代码行数:97,代码来源:LinkMgr.cpp


示例10: GetDiscountRate

 virtual double GetDiscountRate(Vehicle& vehicle)
 {
     return vehicle.GetBaseDiscountRate();
 }
开发者ID:smallbruce,项目名称:CPlusPlus,代码行数:4,代码来源:main.cpp


示例11: option4

void option4()
{
    string inSSN;
    string choice;
    string test;
    string inData;
    Person testUpdatePerson;
    PersonFile * pPersonFile = new PersonFile;
    Person * pPerson = new Person;
    VehicleFile * pVehicleFile = new VehicleFile;
    Vehicle * pVehicle = new Vehicle;
    State * pState = new State;
    County * pCounty = new County;
    VMake * pVMake = new VMake;
    Color * pColor = new Color;
    VType * pVType = new VType;

    while(true)
    {

        PrintHeading4();
        getline(cin,inSSN);
        cin.sync();
        if(inSSN[0] == 'q' || inSSN[0] == 'Q') break;
        *pPerson = pPersonFile->SearchBySSN(inSSN);

        //Ensuring that the Record does not alrady exist
        if(pPerson->IsFound() == true || pPerson->IsDeleted())
        {
            cout << "\n\t\t\tRecord for SSN: " << SSNHyphens(inSSN) << " already exists." << endl;
            test = UserWait();
            if(test[0] == 'q' || test[0] =='Q')
                break;         
            
            continue;
        }
        //This Block only runs if the SSN was not found in the file
        //SetFound is run so the Person can be displayed as before they are written out
        pPerson->SetFound(true);
        pPerson->SetSSN(Trim(inSSN));

        while(true)
        {
            cout << "\n\n\t\tEnter new OLN: ";
            getline(cin, inData);
            cin.sync();
            testUpdatePerson = pPersonFile->SearchByOLN(inData);
             //IsDeleted is included because duplicate OLNs cause issues with SearchByOLN
            if(testUpdatePerson.IsFound() || testUpdatePerson.IsDeleted())
            {
                cout << "\n\t\tOLN Already Exists in File. Choose Different OLN." << endl;
                UserWait();
                system("clear");
                continue;
            }
            break;
        }

        pPerson->SetOLN(Trim(inData));

        cout << "\n\n\t\tEnter new Last Name     : ";
        getline(cin, inData);
        cin.sync();
        pPerson->SetLastName(Trim(inData));

        cout << "\n\n\t\tEnter new First Name    : ";
        getline(cin, inData);
        cin.sync();
        pPerson->SetFirstName(Trim(inData));

        cout << "\n\n\t\tEnter new Middle Initial: ";
        getline(cin, inData);
        cin.sync();
        pPerson->SetMI(Trim(inData));

        cout << "\n\n\t\tEnter new Street Address: ";
        getline(cin, inData);
        cin.sync();
        pPerson->SetStreet(Trim(inData));

        cout << "\n\n\t\tEnter new City          : ";
        getline(cin, inData);
        cin.sync();
        pPerson->SetCity(Trim(inData));

        system("clear");
        cout << "\n\t\tNow Displaying Codes for: State";
        pState->DisplayStates();
        cout << "\n\n\t\tEnter State Code        : ";
        getline(cin, inData);
        cin.sync();
        pPerson->SetStateCode(Trim(inData));

        //Only prompts for County if State is Alabama
        if(pPerson->GetStateCode() != "02")
        {
            pPerson->SetCountyCode("00");
        }
        else
        {
//.........这里部分代码省略.........
开发者ID:MaFoley,项目名称:CBHProject,代码行数:101,代码来源:opt4.cpp


示例12: if

void CfdMeshScreen::CallBack( Fl_Widget* w )
{
    bool update_flag = true;

    if ( w == m_CfdMeshUI->rigorLimitButton )
    {
        if ( m_CfdMeshUI->rigorLimitButton->value() )
        {
            CfdMeshMgr.GetGridDensityPtr()->SetRigorLimit( true );
        }
        else
        {
            CfdMeshMgr.GetGridDensityPtr()->SetRigorLimit( false );
        }
    }
    else if ( w == m_CfdMeshUI->farMeshButton )
    {
        if ( m_CfdMeshUI->farMeshButton->value() )
        {
            CfdMeshMgr.GetCfdSettingsPtr()->SetFarMeshFlag( true );
        }
        else
        {
            CfdMeshMgr.GetCfdSettingsPtr()->SetFarMeshFlag( false );
        }
    }
    else if ( w == m_CfdMeshUI->halfMeshButton )
    {
        if ( m_CfdMeshUI->halfMeshButton->value() )
        {
            CfdMeshMgr.GetCfdSettingsPtr()->SetHalfMeshFlag( true );
        }
        else
        {
            CfdMeshMgr.GetCfdSettingsPtr()->SetHalfMeshFlag( false );
        }
    }
    else if ( w == m_CfdMeshUI->finalMeshButton )
    {
        redirecter redir( std::cout, CfdMeshMgr.m_OutStream );
        CfdMeshMgr.GenerateMesh();

        // Hide all geoms.
        Vehicle* veh = m_ScreenMgr->GetVehiclePtr();
        veh->HideAll();
    }
    else if ( w == m_CfdMeshUI->addDefaultsButton )
    {
        CfdMeshMgr.AddDefaultSourcesCurrGeom();
    }

//  else if ( m_FarXScaleSlider->GuiChanged( w ) )
//  {
//      double val = m_FarXScaleSlider->GetVal();
//      bool change = false;
//
//      if ( CfdMeshMgr.GetFarAbsSizeFlag() )
//      {
//          CfdMeshMgr.SetFarAbsSizeFlag( false );
//          change = true;
//      }
//
//      CfdMeshMgr.SetFarXScale( val );
//      CfdMeshMgr.UpdateDomain();
//      char xstr[255];
//      sprintf( xstr, "%0.4f", CfdMeshMgr.GetFarLength() );
//      cfdMeshUI->farXScaleAbsInput->value(xstr);
//
//      if ( change )
//          CfdMeshMgr.SetFarAbsSizeFlag( true );
//
//      update_flag = false;
//  }
//  else if ( m_FarYScaleSlider->GuiChanged( w ) )
//  {
//      double val = m_FarYScaleSlider->GetVal();
//      bool change = false;
//
//      if ( CfdMeshMgr.GetFarAbsSizeFlag() )
//      {
//          CfdMeshMgr.SetFarAbsSizeFlag( false );
//          change = true;
//      }
//
//      CfdMeshMgr.SetFarYScale( val );
//      CfdMeshMgr.UpdateDomain();
//      char ystr[255];
//      sprintf( ystr, "%0.4f", CfdMeshMgr.GetFarWidth() );
//      cfdMeshUI->farYScaleAbsInput->value(ystr);
//
//      if ( change )
//          CfdMeshMgr.SetFarAbsSizeFlag( true );
//
//      update_flag = false;
//  }
//  else if ( m_FarZScaleSlider->GuiChanged( w ) )
//  {
//      double val = m_FarZScaleSlider->GetVal();
//      bool change = false;
//
//.........这里部分代码省略.........
开发者ID:Mr-Kumar-Abhishek,项目名称:OpenVSP,代码行数:101,代码来源:CfdMeshScreen.cpp


示例13: CmdSetCompanyColour

/**
 * Change the company's company-colour
 * @param tile unused
 * @param flags operation to perform
 * @param p1 bitstuffed:
 * p1 bits 0-7 scheme to set
 * p1 bits 8-9 set in use state or first/second colour
 * @param p2 new colour for vehicles, property, etc.
 * @param text unused
 * @return the cost of this operation or an error
 */
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
	Colours colour = Extract<Colours, 0, 4>(p2);
	LiveryScheme scheme = Extract<LiveryScheme, 0, 8>(p1);
	byte state = GB(p1, 8, 2);

	if (scheme >= LS_END || state >= 3 || colour == INVALID_COLOUR) return CMD_ERROR;

	Company *c = Company::Get(_current_company);

	/* Ensure no two companies have the same primary colour */
	if (scheme == LS_DEFAULT && state == 0) {
		const Company *cc;
		FOR_ALL_COMPANIES(cc) {
			if (cc != c && cc->colour == colour) return CMD_ERROR;
		}
	}

	if (flags & DC_EXEC) {
		switch (state) {
			case 0:
				c->livery[scheme].colour1 = colour;

				/* If setting the first colour of the default scheme, adjust the
				 * original and cached company colours too. */
				if (scheme == LS_DEFAULT) {
					_company_colours[_current_company] = colour;
					c->colour = colour;
					CompanyAdminUpdate(c);
				}
				break;

			case 1:
				c->livery[scheme].colour2 = colour;
				break;

			case 2:
				c->livery[scheme].in_use = colour != 0;

				/* Now handle setting the default scheme's in_use flag.
				 * This is different to the other schemes, as it signifies if any
				 * scheme is active at all. If this flag is not set, then no
				 * processing of vehicle types occurs at all, and only the default
				 * colours will be used. */

				/* If enabling a scheme, set the default scheme to be in use too */
				if (colour != 0) {
					c->livery[LS_DEFAULT].in_use = true;
					break;
				}

				/* Else loop through all schemes to see if any are left enabled.
				 * If not, disable the default scheme too. */
				c->livery[LS_DEFAULT].in_use = false;
				for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
					if (c->livery[scheme].in_use) {
						c->livery[LS_DEFAULT].in_use = true;
						break;
					}
				}
				break;

			default:
				break;
		}
		ResetVehicleColourMap();
		MarkWholeScreenDirty();

		/* All graph related to companies use the company colour. */
		InvalidateWindowData(WC_INCOME_GRAPH, 0);
		InvalidateWindowData(WC_OPERATING_PROFIT, 0);
		InvalidateWindowData(WC_DELIVERED_CARGO, 0);
		InvalidateWindowData(WC_PERFORMANCE_HISTORY, 0);
		InvalidateWindowData(WC_COMPANY_VALUE, 0);
		/* The smallmap owner view also stores the company colours. */
		BuildOwnerLegend();
		InvalidateWindowData(WC_SMALLMAP, 0, 1);

		/* Company colour data is indirectly cached. */
		Vehicle *v;
		FOR_ALL_VEHICLES(v) {
			if (v->owner == _current_company) v->InvalidateNewGRFCache();
		}

		extern void UpdateObjectColours(const Company *c);
		UpdateObjectColours(c);
	}
	return CommandCost();
}
开发者ID:habnabit,项目名称:openttd-cargodist,代码行数:100,代码来源:company_cmd.cpp


示例14: UpdateAI

        void UpdateAI(const uint32 diff)
        {
            if (!UpdateVictim())
                return;

            events.Update(diff);

            if (me->HasUnitState(UNIT_STAT_CASTING))
                return;
            
            if (events.GetTimer() > 15000 && !me->IsWithinMeleeRange(me->getVictim()))
                DoCastAOE(SPELL_PETRIFY_BREATH, true);
        
            if (!left && !right)
                DoCast(me, SPELL_STONE_SHOUT, true);

            switch(events.GetEvent())
            {
                case EVENT_NONE: break;
                case EVENT_SMASH:
                    if (left && right)
                    {
                        if (me->IsWithinMeleeRange(me->getVictim()))
                            DoCastVictim(SPELL_TWO_ARM_SMASH, true);
                    }
                    else if (left || right)
                    {
                        if (me->IsWithinMeleeRange(me->getVictim()))
                            DoCastVictim(SPELL_ONE_ARM_SMASH, true);
                    }
                    events.RescheduleEvent(EVENT_SMASH, 15000);
                    break;
                case EVENT_SWEEP:
                    if (left)
                        DoCastAOE(SPELL_ARM_SWEEP, true);
                    events.RescheduleEvent(EVENT_SWEEP, 15000);
                    break;
                case EVENT_GRIP:
                    if (right && instance)
                    {
                        if (Unit* RightArm = vehicle->GetPassenger(1))
                        {
                            me->MonsterTextEmote(EMOTE_STONE, 0, true);
                            DoScriptText(SAY_GRAB_PLAYER, me);
                            // Grip up to 3 players
                            for (int32 n = 0; n < RAID_MODE(1, 3); ++n)
                            {
                                if (Unit *pTarget = SelectTarget(SELECT_TARGET_RANDOM, 1, 40, true))
                                    GripTargetGUID[n] = pTarget->GetGUID();
                            }
                            RightArm->ToCreature()->AI()->DoAction(ACTION_GRIP);
                        }
                    }
                    events.RescheduleEvent(EVENT_GRIP, 40000);
                    break;
                case EVENT_SHOCKWAVE:
                    if (left)
                    {
                        DoScriptText(SAY_SHOCKWAVE, me);
                        DoCastAOE(SPELL_SHOCKWAVE, true);
                        DoCastAOE(SPELL_SHOCKWAVE_VISUAL, true);
                    }
                    events.RescheduleEvent(EVENT_SHOCKWAVE, urand(15000, 25000));
                    break;
                case EVENT_EYEBEAM:
                    if (Unit *pTarget = SelectTarget(SELECT_TARGET_FARTHEST, 0, 50, true))
                    {
                        if (Creature* EyeBeam = me->SummonCreature(NPC_EYEBEAM_1,pTarget->GetPositionX(),pTarget->GetPositionY()+3,pTarget->GetPositionZ(),0,TEMPSUMMON_TIMED_DESPAWN,10000))
                        {
                            EyeBeam->CastSpell(me, SPELL_EYEBEAM_VISUAL_1, true);
                            EyeBeam->AI()->AttackStart(pTarget);
                        }
                        if (Creature* EyeBeam = me->SummonCreature(NPC_EYEBEAM_2,pTarget->GetPositionX(),pTarget->GetPositionY()-3,pTarget->GetPositionZ(),0,TEMPSUMMON_TIMED_DESPAWN,10000))
                        {
                            EyeBeam->CastSpell(me, SPELL_EYEBEAM_VISUAL_2, true);
                            EyeBeam->AI()->AttackStart(pTarget);
                        }
                    }
                    events.RescheduleEvent(EVENT_EYEBEAM, 20000);
                    break;
                case EVENT_LEFT:
                    if (Unit* LeftArm = me->SummonCreature(NPC_LEFT_ARM, me->GetPositionX(), me->GetPositionY(), me->GetPositionZ(), me->GetOrientation()))
                    {
                        LeftArm->EnterVehicle(vehicle, 0);
                        DoCast(me, SPELL_ARM_RESPAWN, true);
                        me->MonsterTextEmote(EMOTE_LEFT, 0, true);
                        if (instance)
                            instance->DoStopTimedAchievement(ACHIEVEMENT_TIMED_TYPE_EVENT, ACHIEV_DISARMED_START_EVENT);
                    }
                    events.CancelEvent(EVENT_LEFT);
                    break;                
                case EVENT_RIGHT:
                    if (Unit* RightArm = me->SummonCreature(NPC_RIGHT_ARM, me->GetPositionX(), me->GetPositionY(), me->GetPositionZ(), me->GetOrientation()))
                    {
                        RightArm->EnterVehicle(vehicle, 1);
                        DoCast(me, SPELL_ARM_RESPAWN, true);
                        me->MonsterTextEmote(EMOTE_RIGHT, 0, true);
                        if (instance)
                            instance->DoStopTimedAchievement(ACHIEVEMENT_TIMED_TYPE_EVENT, ACHIEV_DISARMED_START_EVENT);
                    }
//.........这里部分代码省略.........
开发者ID:Barragan,项目名称:MadboxpcWOW-core-,代码行数:101,代码来源:boss_kologarn.cpp


示例15: painter

void GUI::paintEvent(QPaintEvent *event) {
    event->accept();
    //rysowanie pojazdu
    if(this->vehicles.size() == 0 || currentVehicle < 0 || currentVehicle >= vehicles.size()) return;

    QPainter painter(this);


    Vehicle v = this->vehicles[currentVehicle];
    double length = v.getLength();
    unsigned axles = v.getAxlesNumber();
    double positions[axles];
    for(unsigned i = 0; i < axles; i++) {
        positions[i] = v.getAxlePosition(i);
    }

    const double scale = 1000 / this->scale_length; //1000pix = 24m;

    QPoint vehicleStart, vehicleEnd;
    vehicleStart.setX(this->startx);
    vehicleEnd.setX(this->startx + length * scale);
    vehicleStart.setY(this->starty);
    vehicleEnd.setY(this->starty + this->v_height);

    QRect vehicle;
    vehicle.setTopLeft(vehicleStart);
    vehicle.setBottomRight(vehicleEnd);

    painter.drawRoundedRect(vehicle, 40, 10);
    painter.fillRect(vehicle, QColor(0, 0, 0, 70));


    for(unsigned i = 0; i < axles; i++) {
        //sprawdz warunek na podniesioną oś
        unsigned axle_offset_y = 0;
        if(axles == 5 && v.is5up() && i == 2) axle_offset_y = -5;// 3 os auta 5 os. z podniesioną osią
        QPoint center;
        center.setX(this->startx + scale * positions[i]);
        center.setY(this->starty + this->v_height + axle_offset_y);

        painter.setBrush(QWidget::palette().color(QWidget::backgroundRole()));
        painter.setPen(QWidget::palette().color(QWidget::backgroundRole()));
        painter.drawEllipse(center, this->wheel_size + 5, this->wheel_size + 5);
        painter.setPen(Qt::black);
        painter.setBrush(Qt::black);
        painter.drawEllipse(center, this->wheel_size, this->wheel_size);
        painter.setBrush(Qt::white);
        painter.drawEllipse(center, this->wheel_size - 5, this->wheel_size - 5);
    }

    const unsigned scale_offset = 100;
    QPoint scaleStart, scaleEnd;
    scaleStart.setX(this->startx);
    scaleStart.setY(this->starty + this->v_height + scale_offset);
    scaleEnd.setX(this->startx + scale * this->scale_length);
    scaleEnd.setY(this->starty + this->v_height + scale_offset);

    painter.drawLine(scaleStart, scaleEnd);

    //rysuj skale co 4m
    for(int pos = 0; pos <= this->scale_length; pos += 4) {
        QPoint scaleTop, scaleBottom, scaleCenter;

        scaleTop.setX(this->startx + pos * scale);
        scaleTop.setY(this->starty + this->v_height + scale_offset - 10);
        scaleBottom.setX(this->startx + pos * scale);
        scaleBottom.setY(this->starty + this->v_height + scale_offset + 10);
        scaleCenter.setX(this->startx + pos * scale);
        scaleCenter.setY(this->starty + this->v_height + scale_offset);

        painter.drawLine(scaleTop, scaleBottom);
        painter.drawText(scaleCenter, QString::number(pos) + QString("m"));
    }

    //rysuj wartości położenia dla osi
    //długość pojazdu
    QPoint vehicleLengthStart, vehicleLengthEnd;
    QPoint scaleTop, scaleBottom, scaleCenter;

    vehicleLengthStart.setX(this->startx);
    vehicleLengthEnd.setX(this->startx + length * scale);
    vehicleLengthStart.setY(this->starty + this->v_height + 70);
    vehicleLengthEnd.setY(this->starty + this->v_height + 70);

    painter.drawLine(vehicleLengthStart, vehicleLengthEnd);
    scaleCenter.setX((this->startx + length * scale + this->startx) / 2);
    scaleCenter.setY(this->starty + this->v_height + 70);

    painter.drawText(scaleCenter, QString().sprintf("%.2f", length) + QString("m"));

    //podzialka na początku i końcu
    scaleTop.setX(this->startx);
    scaleTop.setY(this->starty + this->v_height + 70 - 10);
    scaleBottom.setX(this->startx);
    scaleBottom.setY(this->starty + this->v_height + 70 + 10);
    painter.drawLine(scaleTop, scaleBottom);

    scaleTop.setX(this->startx + length * scale);
    scaleTop.setY(this->starty + this->v_height + 70 - 10);
    scaleBottom.setX(this->startx + length * scale);
//.........这里部分代码省略.........
开发者ID:wgml,项目名称:inzynier,代码行数:101,代码来源:gui.cpp


示例16: ReplaceChain

/**
 * Replace a whole vehicle chain
 * @param chain vehicle chain to let autoreplace/renew operator on
 * @param flags command flags
 * @param wagon_removal remove wagons when the resulting chain occupies more tiles than the old did
 * @param nothing_to_do is set to 'false' when something was done (only valid when not failed)
 * @return cost or error
 */
static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon_removal, bool *nothing_to_do)
{
	Vehicle *old_head = *chain;
	assert(old_head->IsPrimaryVehicle());

	CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0);

	if (old_head->type == VEH_TRAIN) {
		/* Store the length of the old vehicle chain, rounded up to whole tiles */
		uint16 old_total_length = CeilDiv(Train::From(old_head)->gcache.cached_total_length, TILE_SIZE) * TILE_SIZE;

		int num_units = 0; ///< Number of units in the chain
		for (Train *w = Train::From(old_head); w != NULL; w = w->GetNextUnit()) num_units++;

		Train **old_vehs = CallocT<Train *>(num_units); ///< Will store vehicles of the old chain in their order
		Train **new_vehs = CallocT<Train *>(num_units); ///< New vehicles corresponding to old_vehs or NULL if no replacement
		Money *new_costs = MallocT<Money>(num_units);   ///< Costs for buying and refitting the new vehicles

		/* Collect vehicles and build replacements
		 * Note: The replacement vehicles can only successfully build as long as the old vehicles are still in their chain */
		int i;
		Train *w;
		for (w = Train::From(old_head), i = 0; w != NULL; w = w->GetNextUnit(), i++) {
			assert(i < num_units);
			old_vehs[i] = w;

			CommandCost ret = BuildReplacementVehicle(old_vehs[i], (Vehicle**)&new_vehs[i], true);
			cost.AddCost(ret);
			if (cost.Failed()) break;

			new_costs[i] = ret.GetCost();
			if (new_vehs[i] != NULL) *nothing_to_do = false;
		}
		Train *new_head = (new_vehs[0] != NULL ? new_vehs[0] : old_vehs[0]);

		/* Note: When autoreplace has already failed here, old_vehs[] is not completely initialized. But it is also not needed. */
		if (cost.Succeeded()) {
			/* Separate the head, so we can start constructing the new chain */
			Train *second = Train::From(old_head)->GetNextUnit();
			if (second != NULL) cost.AddCost(CmdMoveVehicle(second, NULL, DC_EXEC | DC_AUTOREPLACE, true));

			assert(Train::From(new_head)->GetNextUnit() == NULL);

			/* Append engines to the new chain
			 * We do this from back to front, so that the head of the temporary vehicle chain does not change all the time.
			 * That way we also have less trouble when exceeding the unitnumber limit.
			 * OTOH the vehicle attach callback is more expensive this way :s */
			Train *last_engine = NULL; ///< Shall store the last engine unit after this step
			if (cost.Succeeded()) {
				for (int i = num_units - 1; i > 0; i--) {
					Train *append = (new_vehs[i] != NULL ? new_vehs[i] : old_vehs[i]);

					if (RailVehInfo(append->engine_type)->railveh_type == RAILVEH_WAGON) continue;

					if (new_vehs[i] != NULL) {
						/* Move the old engine to a separate row with DC_AUTOREPLACE. Else
						 * moving the wagon in front may fail later due to unitnumber limit.
						 * (We have to attach wagons without DC_AUTOREPLACE.) */
						CmdMoveVehicle(old_vehs[i], NULL, DC_EXEC | DC_AUTOREPLACE, false);
					}

					if (last_engine == NULL) last_engine = append;
					cost.AddCost(CmdMoveVehicle(append, new_head, DC_EXEC, false));
					if (cost.Failed()) break;
				}
				if (last_engine == NULL) last_engine = new_head;
			}

			/* When wagon removal is enabled and the new engines without any wagons are already longer than the old, we have to fail */
			if (cost.Succeeded() && wagon_removal && new_head->gcache.cached_total_length > old_total_length) cost = CommandCost(STR_ERROR_TRAIN_TOO_LONG_AFTER_REPLACEMENT);

			/* Append/insert wagons into the new vehicle chain
			 * We do this from back to front, so we can stop when wagon removal or maximum train length (i.e. from mammoth-train setting) is triggered.
			 */
			if (cost.Succeeded()) {
				for (int i = num_units - 1; i > 0; i--) {
					assert(last_engine != NULL);
					Vehicle *append = (new_vehs[i] != NULL ? new_vehs[i] : old_vehs[i]);

					if (RailVehInfo(append->engine_type)->railveh_type == RAILVEH_WAGON) {
						/* Insert wagon after 'last_engine' */
						CommandCost res = CmdMoveVehicle(append, last_engine, DC_EXEC, false);

						/* When we allow removal of wagons, either the move failing due
						 * to the train becoming too long, or the train becoming longer
						 * would move the vehicle to the empty vehicle chain. */
						if (wagon_removal && (res.Failed() ? res.GetErrorMessage() == STR_ERROR_TRAIN_TOO_LONG : new_head->gcache.cached_total_length > old_total_length)) {
							CmdMoveVehicle(append, NULL, DC_EXEC | DC_AUTOREPLACE, false);
							break;
						}

						cost.AddCost(res);
//.........这里部分代码省略.........
开发者ID:benjeffery,项目名称:openttd,代码行数:101,代码来源:autoreplace_cmd.cpp


示例17: d

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Velocity类代码示例发布时间:2022-05-31
下一篇:
C++ Vectors类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap