Ejemplo n.º 1
0
int Scene_Common::req_enter_scene_outpost(const int64_t monster_role_id) {
    Move_Scene* scene = move_scene();
    if(!scene) {
        return 0;
    }
    Single_Scene* single_scene = dynamic_cast<Single_Scene*>(scene);
    if(!single_scene) {
        return 0;
    }
    Mover* mover = single_scene->find_mover_with_layer(0, monster_role_id);
    if(!mover || mover->monster_self() == NULL) {
        return 0;
    }
    // 没有收益的玩家不能进去
    if(scene->is_no_profit(role_id())) {
        return ERROR_FB_ENTER_TBAY_NO_PROFIT;
    }
    int target_scene_id = 0;
    int target_scene_time = 0;
    int target_scene_type = 0;
    mover->monster_self()->get_ex_param(target_scene_id, target_scene_time, target_scene_type);
    if(target_scene_id == 0) {
        return 0;
    }
    player_self()->inner_transmit(target_scene_id,0,monster_role_id);
    return 0;
}
Ejemplo n.º 2
0
//--------------------------------------------------------------
void ofApp::setup(){
    for(int i = 0; i<50; i++){
        Mover mInst;
        mInst.setup();
        mList.push_back(mInst);
    }
}
Ejemplo n.º 3
0
void Logistics::initializeLogData()
{
	LogisticsData::instance->removeMechsInForceGroup();

	LogisticsData::instance->init();
	Team* pTeam = Team::home;

	if ( pTeam )
	{
		for ( int i = pTeam->getRosterSize() - 1; i > -1; i-- )
		{
			Mover* pMover = (Mover*)pTeam->getMover( i );
			LogisticsPilot* pPilot = LogisticsData::instance->getPilot(pMover->getPilot()->getName());

			unsigned long base, highlight1, highlight2;
			((Mech3DAppearance*)pMover->getAppearance())->getPaintScheme( highlight1, 
				highlight2, base );
			
			
			if ( pMover->getObjectType()->getObjectTypeClass() == BATTLEMECH_TYPE )
			{
				LogisticsVariant* pVar = LogisticsData::instance->getVariant( ((BattleMech*)pMover)->variantName );
				LogisticsData::instance->addMechToInventory( 
					pVar, 1, pPilot,
					base, highlight1, highlight2 );
			}
		}
	}
}
Ejemplo n.º 4
0
Archivo: Grid.cpp Proyecto: t-s/astar
void Grid::printGrid(Mover mover)
{
	int i = 0;
	int j = 0;

	int curX = mover.getX();
	int curY = mover.getY();	

	std::cout << std::endl;

	for(i = 0; i < length; ++i)
	{
	
		for(j = 0; j < width; ++j)
		{
			
			if((curX == i) && (curY == j))
				std::cout << "|M| ";
			else if(cells[i][j].isGoal())
				std::cout << "|G| ";
			else if(cells[i][j].isBlockFunc() == true)
				std::cout << "||| ";
			else
				std::cout << "|" << cells[i][j].getData() << "| ";
		}

		std::cout << std::endl;
		std::cout << std::endl;

	}

}
Ejemplo n.º 5
0
const Vec2f Mover::attract( const Mover& m, const float g ) const
{
    auto force = location - m.getLocation();
    auto distance = force.lengthSquared();
    distance = ( distance < 25.0f ) ? 25.0f : ( ( distance > 625.0f ) ? 625.0 : distance );
    force.normalize();
    force *= g * mass * m.getMass() / ( distance );
    return force;
}
Ejemplo n.º 6
0
//static method
void* startThread(void* mover)
{
    Mover* m = reinterpret_cast<Mover*>(mover);
    assert(m);
    printf(" thread starting pid=%d  self=%lu\n", getpid(), pthread_self());
    m->start();
    sleep(200);
    printf(" thread finished\n");
    return 0;
}
Ejemplo n.º 7
0
//--------------------------------------------------------------
void ofApp::setup(){
    ofBackground(255);
    //    mover.setup(50, 500);
    
    for (int i=0; i<NUM; i++) {
        Mover mover;
        float x = ofRandomWidth();
        float y= ofRandomHeight();
        mover.setup(x, y);
        moverList.push_back(mover);
    }
}
Ejemplo n.º 8
0
//--------------------------------------------------------------
void ofApp::setup(){
    
    ofBackground(0);
    
    for (int y = 0; y < ofGetWidth(); y+=20) {
        for (int x = 0; x < ofGetWidth(); x+=20) {
            Mover mover;
            mover.setup(x, y, 0.5);
            moverList.push_back(mover);
        }
    }

}
Ejemplo n.º 9
0
void Single_Scene::outpost_notice_exit(const int64_t monster_role_id, bool clear_single){
	if(monster_role_id != 0){
		Mover* mover = this->find_mover_with_layer(0, monster_role_id);
		if(mover && mover->monster_self()){
			mover->exit_move_scene();
		}
	}
	if(clear_single){
		this->set_scene_status(Move_Scene::SCENE_RECOVER_STATUS);
		MSG_DEBUG("single scene recover outpost notice, scene id:%ld", this->scene_id());
		recover_time_ = Time_Value::zero;
	}
}
Ejemplo n.º 10
0
void RenderQueue::_pushRenderer(SceneNode * node)
{
	if (node->_getVisibleMask())
	{
		SceneNode::MoverVisitor vr = node->GetMovers();

		while (!vr.Endof())
		{
			Mover * m = *vr.Cursor();

			if (m->IsVisible())
				m->AddRenderQueue(this);

			++vr;
		}
	}
}
Ejemplo n.º 11
0
void listMotionTypes()
{
    #if __cplusplus <= 199711L
    static const int arr[] = {16,2,77,29};
    std::vector<int> int_vec (arr, arr + sizeof(arr) / sizeof(arr[0]) );
    static const MotionType mta[] = {SCOOP_TYPE_1, SCOOP_TYPE_2};
    std::vector<MotionType> template_arg_vec (mta, mta + sizeof(mta) / sizeof(mta[0]) );
    #else
    // NOTE: g++ -std=c++11   OR   clang++ -std=c++11
    std::vector <int> int_vec = {1, 2, 3, 4, 5};
    std::vector<MotionType> template_arg_vec = {SCOOP_TYPE_1, SCOOP_TYPE_2};
    #endif
    for (int j = FIRST_MotionType; j < NUM_MotionTypes; j++) {
        MotionType typer = template_arg_vec[j];
        printf("MotionType(%d)\n", typer);
        // const int tt = static_cast<int>(typer); // fails because value is not known at compile time
        // Mover<tt> mover;         // error: non-type template argument of type 'int' is not an integral constant expression
        Mover<SCOOP_TYPE_1> mover;
        mover.showMover();
    }
}
Ejemplo n.º 12
0
ofPoint Mover::computeEvadeSteering(const Mover &mover, const float maxPredictionTime) const {
    ofPoint offset = mover.pos - pos;
    float dist = offset.length();
    float dangerSpeed = mover.vel.length();
    if (dangerSpeed == 0.0f)
        dangerSpeed = 1.0f;
    float time = dist / dangerSpeed;
    if (time > maxPredictionTime)
        time = maxPredictionTime;
    ofPoint target = mover.predictFuturePosition(time);
    return computeFleeSteering(target);
}
Ejemplo n.º 13
0
ofVec2f Attractor::attract(Mover m){
    
    ofVec2f force = location - m.getLocation();   // Calculate direction of force
    float d = force.length();                              // Distance between objects
    d = ofClamp(d,5.0,25.0);

    force.normalize();                                  // Normalize vector (distance doesn't matter here, we just want this vector for direction)
    float strength = (G * mass * m.mass) / (d * d);      // Calculate gravitional force magnitude
    force *= strength;                                  // Get force vector --> magnitude * direction
    return force;

}
Ejemplo n.º 14
0
ofPoint Mover::computePursuitSteering(const Mover &mover, const float maxPredictionTime) const {
    ofPoint offset = mover.pos - pos;
    float dist = offset.length();
    float parallelness = vel.normalized().dot(mover.vel.normalized());
    float quaryForwardness = vel.normalized().dot(offset.normalized());
    float directTravelTime = vel.normalized().dot(offset.normalized());
    int f = intervalCompare(quaryForwardness, -0.707, 0.707);
    int p = intervalCompare(parallelness, -0.707, 0.707);
    float timeFactor = 0;
    switch (f) {
        case 1:
            switch (p) {
                case 1: // ahead, parallel
                    timeFactor = 4;
                    break;
                case 0: // ahead, perpendicular
                    timeFactor = 1.8;
                    break;
                case -1: // ahead, anti-parallel
                    timeFactor = 0.85;
                    break;
            }
            break;
        case 0:
            switch (p){
                case 1: // aside, parallel
                    timeFactor = 1;
                    break;
                case 0: // aside, perpendicular
                    timeFactor = 0.8;
                    break;
                case -1: // aside, anti-parallel
                    timeFactor = 4;
                    break;
            }
        case -1:
            switch (p){
                case 1: // behind, parallel
                    timeFactor = 0.5;
                    break;
                case 0: // behind, perpendicular
                    timeFactor = 2;
                    break;
                case -1: // behind, anti-parallel
                    timeFactor = 2;
                    break;
            }
    }
    float et = directTravelTime * timeFactor;
    float etl = (et > maxPredictionTime) ? maxPredictionTime : et;
    ofPoint target = mover.predictFuturePosition(etl);
    return computeSteering(target, false);
}
Ejemplo n.º 15
0
int Single_Scene::scene_pass_to_logic(void){
	if(is_scene_pass_ == false){
		if(is_scene_complete_){
			this->is_delay_show_ts_point_= true;
			this->reset_delay_show_ts_point_time();
		}
		return -1;
	}
	if(has_gain_rewards){
		return 0;
	}
	has_gain_rewards = true;
	MSG_20200080 msg;
	if(scene_config() && scene_config()->dungeon.first_layer_id != 0){
		msg.scene_id = scene_config()->dungeon.first_layer_id;
	}else{
		msg.scene_id = scene_id();
	}
	Mover *mover = this->find_mover_with_layer(0, role_id_);
	if (mover) {
		if(is_no_profit(mover->role_id())){// 没收益
			msg.result = 0;
			this->is_delay_show_ts_point_= true;
			this->reset_delay_show_ts_point_time();
		}else{// 有收益
			msg.result = 1;
			this->is_delay_show_ts_point_= true;
			if(has_scene_pass_box_ || scene_config()->type == FuBen_Scene_Type){
				this->ts_point_delay_time_ = Time_Value::gettimeofday() + Time_Value(12);
			}else{
				this->reset_delay_show_ts_point_time();
			}

		}
		OBJ_SEND_TO_LOGIC(msg, (*mover));
	}
	return 0;
}
Ejemplo n.º 16
0
void World::UpdateGeo(VisibleCullResult & result, Camera * cam)
{
    //notify update
    List<SceneNode *>::Iterator whr = result.nodes.Begin();
    List<SceneNode *>::Iterator end = result.nodes.End();

    while (whr != end)
    {
        SceneNode::MoverVisitor visitor = (*whr)->GetMovers();

        while (!visitor.Endof())
        {
            Mover * geo = *visitor.Cursor();
            geo->NotifyCamera(cam);
            ++visitor;
        }

        ++whr;
    }

    //update geometry
    whr = result.nodes.Begin();
    end = result.nodes.End();

    while (whr != end)
    {
        SceneNode::MoverVisitor visitor = (*whr)->GetMovers();

        while (!visitor.Endof())
        {
            Mover * geo = *visitor.Cursor();
            geo->UpdateGeometry();
            ++visitor;
        }

        ++whr;
    }
}
Ejemplo n.º 17
0
void ForceGroupBar::update( )
{
	bool bSelect = userInput->isLeftClick();
	bool bCommand = useLeftRightMouseProfile ? userInput->isRightClick() : userInput->isLeftClick();
	bool shiftDn = userInput->getKeyDown( KEY_LSHIFT ) ? true : false;
	bool bCamera = useLeftRightMouseProfile ? (userInput->isLeftDoubleClick()) : (userInput->isRightClick() && !userInput->isRightDrag());
	bool bForceGroup = useLeftRightMouseProfile ? (userInput->isLeftDoubleClick()) : userInput->isLeftDoubleClick();
	
	if ( bCamera )
		bSelect = 0;

	Stuff::Vector2DOf<long> screen;
	screen.x = userInput->getMouseX();
	screen.y = userInput->getMouseY();

	 if ( screen.x > FORCEGROUP_LEFT && screen.x < FORCEGROUP_LEFT + FORCEGROUP_WIDTH
		  && screen.y > FORCEGROUP_TOP )
	 {
		 if ( ControlGui::instance->isSelectingInfoObject() )
			userInput->setMouseCursor( mState_INFO );
		 else if ( ControlGui::instance->getRepair() )
			 userInput->setMouseCursor( mState_XREPAIR );
		 else if ( MissionInterfaceManager::instance()->hotKeyIsPressed( EJECT_COMMAND_INDEX ) )
			 userInput->setMouseCursor( mState_EJECT );
		 else
			userInput->setMouseCursor( mState_NORMAL );

		helpTextID = IDS_FORCEGROUP_BAR_DESC;
		helpTextHeaderID = IDS_FORCEGROUP_BAR;
	 }



	// unselect all if appropriate
	if ( bSelect && !shiftDn && inRegion(screen.x, screen.y) 
		&& !ControlGui::instance->isSelectingInfoObject() && (!ControlGui::instance->getRepair()
		&& !MissionInterfaceManager::instance()->hotKeyIsPressed( EJECT_COMMAND_INDEX )
		&& !ControlGui::instance->getGuard()
		|| useLeftRightMouseProfile) )
	{
		Team* pTeam = Team::home;
		for ( int i = 0; i < pTeam->rosterSize; ++i )
		{
			Mover* pMover = (Mover*)pTeam->getMover( i );
			if (pMover->getCommander()->getId() == Commander::home->getId())
			{
				pMover->setSelected( false );
			}
		}
	}

	
	// remove dead mechs
	for ( int t = 0; t < iconCount; ++t )
	{
		if ( (icons[t]->unit->isDestroyed() || icons[t]->unit->isDisabled()) && !icons[t]->unit->recoverBuddyWID )
		{
			if ( !icons[t]->isAnimatingDeath() )
				icons[t]->beginDeathAnimation();
			if ( icons[t]->deathAnimationOver() || icons[t]->unit->causeOfDeath == POWER_USED_UP )
			{
				delete icons[t];
				iconCount --;
				memmove( &icons[t], &icons[t] + 1, (iconCount - t) * sizeof (ForceGroupIcon*) );
				icons[iconCount] = 0;
			}
		}
	}

	qsort( icons, iconCount, sizeof( ForceGroupIcon* ), ForceGroupIcon::sort );

	for ( int i = 0; i < iconCount; i++ )
	{
		icons[i]->setLocationIndex( i );
	}
	

	for ( i = 0; i < iconCount; ++i )
	{
		if ( icons[i]->inRegion( screen.x, screen.y ) )
		{
			icons[i]->unit->setTargeted(true); 
			if ( ControlGui::instance->getRepair() )
			{
				if ( !MissionInterfaceManager::instance()->canRepair(icons[i]->unit ) )
				{
					userInput->setMouseCursor( mState_XREPAIR );
				
					// need to go back and unselect everything
					if ( bSelect  )
					{
						if ( !shiftDn )
						{
							Team* pTeam = Team::home;
							for ( int j = 0; j < pTeam->rosterSize; ++j )
							{
								Mover* pMover = (Mover*)pTeam->getMover( j );
								if (pMover->getCommander()->getId() == Commander::home->getId())
								{
									pMover->setSelected( false );
								}
							}
						}						
					}
				}
				else
				{
					userInput->setMouseCursor( mState_REPAIR );
				}
			}
			else if ( ControlGui::instance->getGuard() )
			{
				userInput->setMouseCursor( mState_GUARD );
			}
			else
			{
				ControlGui::instance->setRolloverHelpText( IDS_UNIT_SELECT_HELP );
			}

			if ( bSelect && !ControlGui::instance->infoButtonPressed() )
			{
				if ( !(ControlGui::instance->getRepair() && MissionInterfaceManager::instance()->canRepair(icons[i]->unit ) && !useLeftRightMouseProfile) )
					icons[i]->click( shiftDn ); 

				ControlGui::instance->setInfoWndMover( icons[i]->unit );	
			}

			if ( bCommand )
			{
				 if ( MissionInterfaceManager::instance()->hotKeyIsPressed( EJECT_COMMAND_INDEX ) )
				 {
					 MissionInterfaceManager::instance()->doEject( icons[i]->unit );
				 }
				 else if ( ControlGui::instance->getGuard() )
				 {
					 MissionInterfaceManager::instance()->doGuard( icons[i]->unit );
				 }
				 else if ( ControlGui::instance->getRepair() )
				 {
					 if ( MissionInterfaceManager::instance()->canRepair(icons[i]->unit ) )
						MissionInterfaceManager::instance()->doRepair( icons[i]->unit );
				 }
				 

				 else
					 ControlGui::instance->setInfoWndMover( icons[i]->unit );	
			}

			if ( bCamera )
			{
				icons[i]->rightClick();
			}

			if ( bForceGroup )
			{
				for( int j = 0; j < 10; ++j )
				{
					if ( icons[i]->unit->isInUnitGroup( j ) )
					{
						
						MissionInterfaceManager::selectForceGroup( j, true );

					}
				}				
			}
		
		}
		else
			icons[i]->unit->setTargeted( 0 );
		
		icons[i]->update();
		
	}

}
Ejemplo n.º 18
0
void SkeletalAnimation::CreateScene()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    
    scene_ = new Scene(context_);
    
    // Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
    // Also create a DebugRenderer component so that we can draw debug geometry
    scene_->CreateComponent<Octree>();
    scene_->CreateComponent<DebugRenderer>();
    
    // Create scene node & StaticModel component for showing a static plane
    Node* planeNode = scene_->CreateChild("Plane");
    planeNode->SetScale(Vector3(100.0f, 1.0f, 100.0f));
    StaticModel* planeObject = planeNode->CreateComponent<StaticModel>();
    planeObject->SetModel(cache->GetResource<Model>("Models/Plane.mdl"));
    planeObject->SetMaterial(cache->GetResource<Material>("Materials/StoneTiled.xml"));
    
    // Create a Zone component for ambient lighting & fog control
    Node* zoneNode = scene_->CreateChild("Zone");
    Zone* zone = zoneNode->CreateComponent<Zone>();
    zone->SetBoundingBox(BoundingBox(-1000.0f, 1000.0f));
    zone->SetAmbientColor(Color(0.15f, 0.15f, 0.15f));
    zone->SetFogColor(Color(0.5f, 0.5f, 0.7f));
    zone->SetFogStart(100.0f);
    zone->SetFogEnd(300.0f);
    
    // Create a directional light to the world. Enable cascaded shadows on it
    Node* lightNode = scene_->CreateChild("Directional light");
    lightNode->SetDirection(Vector3(0.6f, -1.0f, 0.8f));
    Light* light = lightNode->CreateComponent<Light>();
    light->SetLightType(LIGHT_DIRECTIONAL);
    light->SetCastShadows(true);
    light->SetShadowBias(BiasParameters(0.0001f, 0.5f));
    // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance
    light->SetShadowCascade(CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f));
    
    // Create animated models
    const unsigned NUM_MODELS = 100;
    const float MODEL_MOVE_SPEED = 2.0f;
    const float MODEL_ROTATE_SPEED = 100.0f;
    const BoundingBox bounds(Vector3(-47.0f, 0.0f, -47.0f), Vector3(47.0f, 0.0f, 47.0f));
    
    for (unsigned i = 0; i < NUM_MODELS; ++i)
    {
        Node* modelNode = scene_->CreateChild("Jack");
        modelNode->SetPosition(Vector3(Random(90.0f) - 45.0f, 0.0f, Random(90.0f) - 45.0f));
        modelNode->SetRotation(Quaternion(0.0f, Random(360.0f), 0.0f));
        AnimatedModel* modelObject = modelNode->CreateComponent<AnimatedModel>();
        modelObject->SetModel(cache->GetResource<Model>("Models/Jack.mdl"));
        modelObject->SetMaterial(cache->GetResource<Material>("Materials/Jack.xml"));
        modelObject->SetCastShadows(true);
        
        // Create an AnimationState for a walk animation. Its time position will need to be manually updated to advance the
        // animation, The alternative would be to use an AnimationController component which updates the animation automatically,
        // but we need to update the model's position manually in any case
        Animation* walkAnimation = cache->GetResource<Animation>("Models/Jack_Walk.ani");
        AnimationState* state = modelObject->AddAnimationState(walkAnimation);
        // Enable full blending weight and looping
        state->SetWeight(1.0f);
        state->SetLooped(true);
        
        // Create our custom Mover component that will move & animate the model during each frame's update
        Mover* mover = modelNode->CreateComponent<Mover>();
        mover->SetParameters(MODEL_MOVE_SPEED, MODEL_ROTATE_SPEED, bounds);
    }
    
    // Create the camera. Limit far clip distance to match the fog
    cameraNode_ = scene_->CreateChild("Camera");
    Camera* camera = cameraNode_->CreateComponent<Camera>();
    camera->SetFarClip(300.0f);
    
    // Set an initial position for the camera scene node above the plane
    cameraNode_->SetPosition(Vector3(0.0f, 5.0f, 0.0f));
}
void Ex15_VectorAccelRandomApp::draw()
{
    gl::clear( Color{ 0.111f, 0.111f, 0.111f } );
    ball.draw();
}
void Ex15_VectorAccelRandomApp::update()
{
    ball.update();
}
Ejemplo n.º 21
0
int Scene_Server_Request::process_20200050(int cid, role_id_t role_id, Scene_Player *player, Block_Buffer &buf) {
	JUDGE_PLAYER_NULL(player, role_id);

	// 战斗中,退出战斗
	if (player->is_in_battle()){
		player->exit_battle_scene(14);
		player->notify_gate_exit_battle(14);
	}

	Coord coord;
	Monitor_Unique_ID scene_muid;
	Create_Scene_Args scene_args;
	scene_muid.deserialize(buf);
	coord.deserialize(buf);
	scene_args.deserialize(buf);

	int src_scene_id = player->move_scene_id();

	{// tbay
		const Scene_Config* target_cfg = CONFIG_CACHE_SCENE->scene_config_cache(scene_muid.id);
		if(target_cfg){
			if(target_cfg->type == Tbay_Scene_Type){
				int64_t monster_role_id = scene_args.id;
				if(player->move_scene()){
					Mover* mover = player->move_scene()->find_mover_with_layer(0, monster_role_id);
					if(mover && mover->monster_self()){
						int target_id = 0;
						int target_time = 0;
						int target_type = 0;
						mover->monster_self()->get_ex_param(target_id, target_time, target_type);
						scene_args.type = target_type;
						scene_args.sub_sort = player->move_scene_id();
						scene_args.int_value = target_time;
					}
				}
			}
		}
	}

	player->set_rela_scene_id(scene_muid.id);
	player->gang_war_info().exit_ = true;

	player->exit_move_scene(false);

	player->set_scene_muid(scene_muid);
	player->set_create_scene_args(scene_args.type, scene_args.time, scene_args.id, scene_args.sort, scene_args.sub_sort, scene_args.int_value);
	player->set_grid_coord(coord.grid_coord().x, coord.grid_coord().y);
	player->set_pixel_coord(coord.pixel_coord().x, coord.pixel_coord().y);

	player->scene_init();

	Block_Buffer inner_buf;
	inner_buf.make_message(INNER_TRAN_SCENE_SAME_PRO);
	scene_muid.serialize(inner_buf);
	coord.serialize(inner_buf);
	inner_buf.finish_message();
	player->send_to_logic(inner_buf);

	player->notice_enter_scene();

	MSG_DEBUG("tran scene in same process , role:%ld, src:%d, des scene:%d", role_id, src_scene_id, player->move_scene_id());

	return 0;
}
void Example10App::mouseMove(MouseEvent event) {
    mMover->setTarget(event.getPos());
}
void Example7App::update()
{
    mMover->update();
    mMover->checkEdges();
}
Ejemplo n.º 24
0
void natureApp::draw()
{
    mover.display();
}
Ejemplo n.º 25
0
void natureApp::update()
{
    mover.update();
    mover.checkEdges();
  
}
Ejemplo n.º 26
0
void Ex21WindApp::update()
{
    ball.applyForce( wind );
    ball.applyForce( gravity );
    ball.update();
}
void Example7App::draw()
{
	gl::clear( Color( 1, 1, 1 ) );
    mMover->draw();
}
Ejemplo n.º 28
0
int _stdcall Logistics::beginMission(void*, int, void*[])
{

	if (MPlayer)
		MPlayer->setMode(MULTIPLAYER_MODE_LOADING);

	char commandersToLoad[MAX_MC_PLAYERS][3] = {{0, 0, 0}, {1, 1, 1}, {2, 2, 2}, {3, 3, 3}, {4, 4, 4}, {5, 5, 5}, {6, 6, 6}, {7, 7, 7}};
	long missionLoadType = LogisticsData::instance->skipLogistics() ? 
							MISSION_LOAD_SP_QUICKSTART : MISSION_LOAD_SP_LOGISTICS;
	if (MPlayer) {
		//---------------------------
		// Calc valid commanderIDs...
		long curCommanderID = 0;
		for (long CID = 0; CID < MAX_MC_PLAYERS; CID++) {
			MPlayer->availableCIDs[CID] = true;
			if (MPlayer->playerInfo[CID].player && (MPlayer->playerInfo[CID].commanderID > -1)) {
				if (CID != curCommanderID) {
					long oldCommanderID = CID;
					MPlayer->playerInfo[CID].commanderID = curCommanderID;
					memcpy(&MPlayer->playerInfo[curCommanderID], &MPlayer->playerInfo[CID], sizeof(MC2Player));
					MPlayer->playerInfo[CID].player = NULL;
					MPlayer->playerInfo[CID].commanderID = -1;
					for (long j = 0; j < MAX_MC_PLAYERS; j++)
						if (MPlayer->playerList[j].player == MPlayer->playerInfo[curCommanderID].player)
							MPlayer->playerList[j].commanderID = curCommanderID;
					if (oldCommanderID == MPlayer->commanderID)
						MPlayer->commanderID = curCommanderID;
				}
				MPlayer->availableCIDs[curCommanderID] = false;
				curCommanderID++;;
			}
		}
		//----------------------
		// Calc valid teamIDs...
		long curTeamID = 0;
		for (long teamID = 0; teamID < MAX_MC_PLAYERS; teamID++) {
			bool teamFound = false;
			for (long i = 0; i < MAX_MC_PLAYERS; i++)
				if (MPlayer->playerInfo[i].player && (MPlayer->playerInfo[i].team == teamID)) {
					MPlayer->playerInfo[i].team = curTeamID;
					teamFound = true;
				}
			if (teamFound)
				curTeamID++;
		}
		if (MPlayer->isHost()) {
			// Determine drop zone order here...
			char dropZoneList[8];
			char hqs[MAX_TEAMS];
			if (MPlayer->missionSettings.missionType == MISSION_TYPE_OTHER) {
				bool goodToLoad = mission->calcComplexDropZones((char*)(const char*)LogisticsData::instance->getCurrentMission(), dropZoneList);
				if (!goodToLoad)
					STOP(("Logisitics.beginMission: teams do not match up for complex mission"));
				for (long i = 0; i < MAX_TEAMS; i++)
					hqs[i] = i;
				}
			else
				MPlayer->calcDropZones(dropZoneList, hqs);
			if (MPlayer->missionSettings.quickStart)
				for (long i = 0; i < MAX_MC_PLAYERS; i++) {
					MPlayer->commandersToLoad[i][0] = (long)dropZoneList[i]; //MPlayer->playerInfo[i].commanderID;
					MPlayer->commandersToLoad[i][1] = (long)(dropZoneList[i] > -1) ? MPlayer->playerInfo[dropZoneList[i]].team : 0;
					MPlayer->commandersToLoad[i][2] = hqs[i];
				}
			else
				for (long i = 0; i < MAX_MC_PLAYERS; i++) {
					MPlayer->commandersToLoad[i][0] = dropZoneList[i]; //-1;
					MPlayer->commandersToLoad[i][1] = (dropZoneList[i] > -1) ? MPlayer->playerInfo[dropZoneList[i]].team : 0; //-1;
					MPlayer->commandersToLoad[i][2] = hqs[i];
				}
			MPlayer->sendMissionSetup(0, 0, NULL);
		}
		if (!MPlayer->waitTillStartLoading()) {
			// SERVER DROPPED
			return(0);
		}
		if (MPlayer->commandersToLoad[0][0] < -1)
			PAUSE(("Logistics.beginMission: bad commandersToLoad"));
		for (long i = 0; i < MAX_MC_PLAYERS; i++) {
			commandersToLoad[i][0] = MPlayer->commandersToLoad[i][0];
			commandersToLoad[i][1] = MPlayer->commandersToLoad[i][1];
			commandersToLoad[i][2] = MPlayer->commandersToLoad[i][2];
		}
		if (MPlayer->missionSettings.quickStart) {
			MultiPlayTeamId = MPlayer->playerInfo[MPlayer->commanderID].team;
			if (MultiPlayTeamId < 0)
				STOP(("Bad commanderID"));
			MultiPlayCommanderId = MPlayer->commanderID;
			if (MultiPlayCommanderId < 0)
				STOP(("Bad commanderID"));
			missionLoadType = MISSION_LOAD_MP_QUICKSTART;
			}
		else {
			MultiPlayTeamId = MPlayer->playerInfo[MPlayer->commanderID].team;
			MultiPlayCommanderId = MPlayer->commanderID;
			missionLoadType = MISSION_LOAD_MP_LOGISTICS;
		}
		long maxTeam = -1;
		for (i = 0; i < MAX_MC_PLAYERS; i++)
			if (MPlayer->playerInfo[i].team > maxTeam)
				maxTeam = MPlayer->playerInfo[i].team;
		MPlayer->numTeams = maxTeam + 1;
		}
	else if (missionLoadType == MISSION_LOAD_SP_LOGISTICS) {
		commandersToLoad[0][0] = -1;
		commandersToLoad[0][1] = -1;
		commandersToLoad[0][2] = -1;
	}
	else {
		commandersToLoad[0][0] = 0;
		commandersToLoad[0][1] = 0;
		commandersToLoad[0][2] = -1;
	}

	if (mission)
		mission->destroy();

	long numPlayers = 1;
	if ( MPlayer )
		MPlayer->getPlayers(numPlayers);
	long numMoversPerCommander[MAX_MC_PLAYERS] = {12, 12, 12, 9, 7, 6, 5, 4};
	Stuff::Vector3D dropZoneList[255]; // ubsurdly large, but sometimes we overrun this.
	long dropZoneID = 0;
	if (MPlayer) {
		//dropZoneID = MPlayer->commanderID;
		for (long i = 0; i < MAX_MC_PLAYERS; i++)
			if (commandersToLoad[i][0] == MPlayer->commanderID) {
				dropZoneID = i;
				break;
			}
		useUnlimitedAmmo = MPlayer->missionSettings.unlimitedAmmo;
	}

	mission->init((char*)(const char*)LogisticsData::instance->getCurrentMission(), missionLoadType, dropZoneID, dropZoneList, commandersToLoad, numMoversPerCommander[numPlayers - 1]);

	LogisticsData::instance->rpJustAdded = 0;

	if (MPlayer) {
		if (missionLoadType == MISSION_LOAD_MP_LOGISTICS) {
			EList< LogisticsMech*, LogisticsMech* > list;
			LogisticsData::instance->getForceGroup(list);

			long dropZoneIndex = 0;
			long numMechs = 0;
			for (EList< LogisticsMech*, LogisticsMech* >::EIterator iter = list.Begin(); !iter.IsDone(); iter++) {
				numMechs++;
				if ( !(*iter)->getPilot() )
					continue;
				CompressedMech mechData;
				mechData.lastMech = (list.Count() == numMechs);
				mechData.objNumber =  (*iter)->getFitID();
				mechData.commanderID = MPlayer->commanderID;
				mechData.baseColor = MPlayer->colors[MPlayer->playerInfo[MPlayer->commanderID].baseColor[BASECOLOR_TEAM]];
				mechData.highlightColor1 = MPlayer->colors[MPlayer->playerInfo[MPlayer->commanderID].stripeColor];
				mechData.highlightColor2 = MPlayer->colors[MPlayer->playerInfo[MPlayer->commanderID].stripeColor];
				strcpy(mechData.pilotFile, (*iter)->getPilot()->getFileName());
				strcpy(mechData.mechFile, (*iter)->getFileName());
				strcpy(mechData.variantName, (*iter)->getName());
				mechData.variantNum = (*iter)->getVariant()->getFileID();
				mechData.cBills = (*iter)->getVariant()->getCost();
				mechData.pos[0] = dropZoneList[dropZoneIndex].x;
				mechData.pos[1] = dropZoneList[dropZoneIndex++].y;
				mechData.designerMech = (*iter)->getVariant()->isDesignerMech();
				mechData.numComponents = (*iter)->getComponentCount();
				if (mechData.numComponents)	{
					long* componentList = (long*)systemHeap->Malloc(sizeof(long) * mechData.numComponents);
					long otherCount = mechData.numComponents;
					(*iter)->getComponents(otherCount, componentList);
					if (otherCount != mechData.numComponents)
						STOP(("Heidi's getComponentCount does not agree with count returned from getComponents"));
					for (long i = 0; i < mechData.numComponents; i++)
						mechData.components[i] = (unsigned char)componentList[i];
				}
				MPlayer->sendMissionSetup(0, 1, &mechData);
			}

			if (!MPlayer->waitTillMechDataReceived()) {
				// SERVER DROPPED
				mission->destroy();
				return(0);
			}
	
			ObjectManager->numMechs = 0;
			ObjectManager->numVehicles = 0;
			for (long i = 0; i < MAX_MC_PLAYERS; i++) {
				if (MPlayer->mechDataReceived[i]) {
					for (long j = 0; j < 12; j++) {
						if (MPlayer->mechData[i][j].objNumber > -1) {
							MoverInitData data;
							memset(&data, 0, sizeof(MoverInitData));
							data.objNumber = MPlayer->mechData[i][j].objNumber;
							data.rosterIndex = 255;
							data.controlType = 2;
							data.controlDataType = 1;
							data.position.x = MPlayer->mechData[i][j].pos[0];
							data.position.y = MPlayer->mechData[i][j].pos[1];
							data.position.z = 0.0;
							data.rotation = 0;
							data.teamID = MPlayer->playerInfo[MPlayer->mechData[i][j].commanderID].team;
							data.commanderID = MPlayer->mechData[i][j].commanderID;
							data.baseColor = MPlayer->mechData[i][j].baseColor;
							data.highlightColor1 = MPlayer->mechData[i][j].highlightColor1;
							data.highlightColor2 = MPlayer->mechData[i][j].highlightColor2;
							data.gestureID = 2;
							data.active = 1;
							data.exists = 1;
							data.capturable = 0;
							data.icon = 0;
							
							strcpy(data.pilotFileName, MPlayer->mechData[i][j].pilotFile);
							strcpy(data.brainFileName, "pbrain");
							strcpy(data.csvFileName, MPlayer->mechData[i][j].mechFile);
							data.numComponents = MPlayer->mechData[i][j].numComponents;
							for (long k = 0; k < MPlayer->mechData[i][j].numComponents; k++)
								data.components[k] = MPlayer->mechData[i][j].components[k];
							long moverHandle = mission->addMover(&data);
							if (moverHandle < 1)
								STOP(("Logistics.beginMission: unable to addMover"));
							MoverPtr mover = (MoverPtr)ObjectManager->get(moverHandle);
							if (!mover)
								STOP(("Logistics.beginMission: NULL mover"));
							if (mover->getObjectClass() != BATTLEMECH)
								STOP(("Logistics.beginMission: not a mech"));
							((BattleMech*)mover)->cBills = MPlayer->mechData[i][j].cBills;
							strcpy(((BattleMech*)mover)->variantName, MPlayer->mechData[i][j].variantName);
							data.variant = MPlayer->mechData[i][j].variantNum;
						}
					}
				}
			}
		}
		else // gotta update pilot availability
		{
			long count = 256;
			LogisticsPilot* pilots[256];
			LogisticsData::instance->getPilots( pilots, count );

			for ( int i = 0; i < count; i++ )
			{
				pilots[i]->setUsed(0);
			}

			Team* pTeam = Team::home;

			if ( pTeam )
			{
				for ( i = pTeam->getRosterSize() - 1; i > -1; i-- )
				{
					Mover* pMover = (Mover*)pTeam->getMover( i );
					if ( pMover && pMover->getCommander()->getId() == Commander::home->getId() )
					{
						LogisticsPilot* pPilot = LogisticsData::instance->getPilot( pMover->getPilot()->getName() );
						if ( pPilot )
							pPilot->setUsed( true );
					}
				}
			}
					

		}
		
		CompressedMech mechData;
		mechData.commanderID = MPlayer->commanderID;
		MPlayer->sendMissionSetup(0, 2, &mechData);
		if (!MPlayer->waitTillMissionLoaded()) {
			// SERVER DROPPED
			mission->destroy();
			return(0);
		}

		}
	else if (missionLoadType == MISSION_LOAD_SP_LOGISTICS) {
		EList< LogisticsMech*, LogisticsMech* > list;
		LogisticsData::instance->getForceGroup( list );

		float rotation = list.Count() ? 360.f/list.Count() : 0.f;

		MoverInitData data;
		memset( &data, 0, sizeof( data ) );
		data.rosterIndex = 255;
		data.controlType = 2;
		data.controlDataType = 1;
		data.position.Zero(); // need to get the drop zone location
		data.rotation = 0;
		data.teamID = Team::home->getId();
		data.commanderID = Team::home->getId();
		data.active = 1;
		data.exists = 1;
		data.capturable = 0;
		data.baseColor = prefs.baseColor;
		data.highlightColor1 = prefs.highlightColor;
		data.highlightColor2 = prefs.highlightColor;
		

		strcpy( data.pilotFileName, "pmw00031" );
		strcpy( data.brainFileName, "pbrain" );
	
		Stuff::Vector3D vector;
		vector.x = 0.f;
		vector.y = 1.f;
		vector.z = 0.f;
		Stuff::Vector3D scaled;
		for ( EList< LogisticsMech*, LogisticsMech* >::EIterator iter = list.Begin(); !iter.IsDone(); iter++) {
			scaled = vector;
			scaled *= 128.;
			data.position.Add(dropZoneList[0], scaled);
			//data.position = dropZoneList[dropZoneIndex++];
			data.objNumber = (*iter)->getFitID();
			strcpy( data.csvFileName, (*iter)->getFileName() );
			if ( !(*iter)->getPilot() )
				continue;
			strcpy( data.pilotFileName, (*iter)->getPilot()->getFileName() );
			data.overrideLoadedPilot = true;
			data.gunnerySkill = (*iter)->getPilot()->getGunnery();
			data.pilotingSkill = (*iter)->getPilot()->getPiloting();

			memcpy(data.specialtySkills,(*iter)->getPilot()->getSpecialtySkills(),sizeof(bool) * NUM_SPECIALTY_SKILLS);
			if ( !(*iter)->getVariant()->isDesignerMech())
			{		
				data.variant = 0;
				mission->addMover( &data, (*iter));
			}
			else
			{
				data.variant = (*iter)->getVariant()->getFileID();
				mission->addMover( &data );
			}
			Rotate( vector, rotation );
		}
	}

/*	if (MPlayer) {
		if (MPlayer->isHost())
			MPlayer->serverCID = MPlayer->commanderID;
		else {
			for (long i = 0; i < MAX_MC_PLAYERS; i++)
				if (MPlayer->serverPlayer && (MPlayer->playerList[i].player == MPlayer->serverPlayer))
					MPlayer->serverCID = MPlayer->playerList[i].commanderID;
			if (MPlayer->serverCID == -1)
				STOP(("Logistics.beginMission: bad serverCID"));
		}
	}
*/
	mission->missionInterface->initMechs();

	eye->activate();
	eye->update();
	mission->start();
	mission->update(); // force this, so we don't render first

	if (MPlayer) {
		CompressedMech mechData;
		mechData.commanderID = MPlayer->commanderID;
		MPlayer->sendMissionSetup(0, 4, &mechData);
		if (!MPlayer->waitTillMissionSetup()) {
			// SERVER DROPPED
				mission->destroy();
				return(0);
		}
		MPlayer->setMode(MULTIPLAYER_MODE_MISSION);
	}

	if (MPlayer && MPlayer->hostLeft) {
		mission->destroy();
		return(0);
	}

	return(1);
}
Ejemplo n.º 29
0
void Ex21WindApp::draw()
{
    gl::clear( Color( 0.111f, 0.111f, 0.111f ) );
    ball.draw();
}
Ejemplo n.º 30
0
void natureApp::setup()
{
    mover.setup(getWindowWidth(), getWindowHeight());
}