Ejemplo n.º 1
0
bool Enemy::initwithGame(Layer* gameLayer)
{
	if (!Node::init())
		return false;

	_gameLayer = gameLayer;
	_maxHp = 40;
	_currentHp = _maxHp;
	_walkingspeed = 5.0f;

	_ptrSprite = Sprite::create("images/enemy.png");
	this->addChild(_ptrSprite);

	
	MainGame* layer = static_cast<MainGame*>(_gameLayer);
	unsigned int count = layer->getWayPoints().size();
	WayPoint* wayPoint = static_cast<WayPoint*>(layer->getWayPoints().at(count - 1));
	_destinationWayPoint = wayPoint->getNextWayPoint();
	_spritePosition = wayPoint->getWayPosition();
	_ptrSprite->setPosition(_spritePosition);

	_gameLayer->addChild(this);

	scheduleUpdate();

	return true;
}
Ejemplo n.º 2
0
void StartScene::addHome()
{
    DataModel *m = DataModel::getModel();
    Home* home = NormalHome::home();
    WayPoint* wp = *(m->waypoints.end()-1);
    home->setPosition(wp->getPosition());
    m->home = home;
    this->addChild(home,1);
}
Ejemplo n.º 3
0
long GetFlightTime(Flight element)
{
    WayPoint wp;
    if(!element)
        return(0);

    wp=element->GetCurrentUnitWP();
    if(wp)
        return(wp->GetWPDepartureTime());
    return(0);
}
void ClientGameObjectManagerAddon::do_CREATE_WAYPOINT(PE::Events::Event *pEvt)
{
	PEINFO("GameObjectManagerAddon::do_CREATE_WAYPOINT()\n");

	assert(pEvt->isInstanceOf<Event_CREATE_WAYPOINT>());

	Event_CREATE_WAYPOINT *pTrueEvent = (Event_CREATE_WAYPOINT*)(pEvt);

	PE::Handle hWayPoint("WayPoint", sizeof(WayPoint));
	WayPoint *pWayPoint = new(hWayPoint) WayPoint(*m_pContext, m_arena, hWayPoint, pTrueEvent);
	pWayPoint->addDefaultComponents();

	addComponent(hWayPoint);
}
void Entity::FollowRoute()
{
	AppDebugAssert(m_routeId != -1);
	Route *route = g_app->m_location->m_levelFile->GetRoute(m_routeId);
    
    if( g_app->Multiplayer() ) route = g_app->m_location->m_routingSystem.GetRoute( m_routeId );

	if(!route)
    {
        m_routeId = -1;
        return;
    }

	if (m_routeWayPointId == -1)
	{
		m_routeWayPointId = 0;
	}

    WayPoint *waypoint = route->m_wayPoints.GetData(m_routeWayPointId);
    if( !waypoint )
    {
        m_routeId = -1;
        return;
    }

    SetWaypoint ( waypoint->GetPos() );
	Vector3 targetVect = waypoint->GetPos() - m_pos;

	m_spawnPoint = waypoint->GetPos();

    if (waypoint->m_type != WayPoint::TypeBuilding &&
        targetVect.Mag() < m_routeTriggerDistance )
	{

		m_routeWayPointId++;
		if (m_routeWayPointId >= route->m_wayPoints.Size())
		{
			m_routeWayPointId = -1;
			m_routeId = -1;
		}
	}

    //
    // If its a building instead of a 3D pos, this unit will never
    // get to the next waypoint.  A new unit is created when the unit
    // enters the teleport, and taht new unit will automatically
    // continue towards the next waypoint instead.
    //
}
Ejemplo n.º 6
0
void HelloWorld::FollowPath(CCNode* sender) {
    
	Creeps *creep = (Creeps *)sender;
	
	WayPoint * waypoint =creep->getNextWaypoint();
    if(waypoint==NULL){
        return;
    }
//	int moveDuration = creep->getMoveDuration();
    int moveDuration = creep->moveDurScale();
	CCMoveTo *actionMove =CCMoveTo::create(moveDuration,waypoint->getPosition());
	CCCallFuncN* actionMoveDone =CCCallFuncN::create(this,callfuncN_selector(HelloWorld::FollowPath));
	creep->stopAllActions();
    creep->runAction(CCSequence::create(actionMove, actionMoveDone, NULL));
}
Ejemplo n.º 7
0
void MissionUpdateTime(Flight element,C_Mission *mission)
{
    _TCHAR buffer[80];

    mission->Refresh();
    WayPoint wp = element->GetFirstUnitWP();
    if (wp) { // JPO CTD fix
        GetTimeString(wp->GetWPDepartureTime(),buffer);
        mission->SetTakeOff(buffer);
        mission->SetTakeOffTime(wp->GetWPDepartureTime());
    }
    else
        mission->SetTakeOff(_T("Unknown"));
    mission->Refresh();
}
Ejemplo n.º 8
0
void StartScene::addWayPoint()
{
    DataModel *m = DataModel::getModel();
    auto objects = this->_tileMap->objectGroupNamed("Objects");
    WayPoint *wp = NULL;
    std::string stringWithFormat = "Waypoint";
    int wayPointCounter = 0;
    ValueMap wayPoint;
    wayPoint = objects->objectNamed(stringWithFormat + to_string(wayPointCounter));
    while (wayPoint.begin() != wayPoint.end())
    {
        int x = wayPoint.at("x").asInt();
        int y = wayPoint.at("y").asInt();
        wp = WayPoint::create();
        wp->setPosition(ccp(x, y));
        m->waypoints.pushBack(wp);
        wayPointCounter++;
        wayPoint = objects->objectNamed(stringWithFormat + to_string(wayPointCounter));
    }
    wp =NULL;
}
Ejemplo n.º 9
0
void HelloWorld::addWaypoint() {
	DataModel *m = DataModel::getModel();
	
	CCTMXObjectGroup *objects =_tileMap->objectGroupNamed("Objects");
	WayPoint *wp = NULL;
	
	int spawnPointCounter = 0;
	CCDictionary *spawnPoint;
	while ((spawnPoint =objects ->objectNamed(CCString::createWithFormat("Waypoint%d", spawnPointCounter)->getCString()))) {
		int x = spawnPoint->valueForKey("x")->intValue();
		int y = spawnPoint->valueForKey("y")->intValue();
		
		wp =(WayPoint *)WayPoint::create();
		wp->setPosition(ccp(x, y));
		m->getWaypoints()->addObject(wp);
		spawnPointCounter++;
	}
	
//	NSAssert([m->getWaypoints()->count()] > 0, @"Waypoint objects missing");
	wp = NULL;
}
Ejemplo n.º 10
0
WayPoint ResetCurrentWP (TaskForce tf)
{
    WayPoint	w;
    GridIndex	x,y,ux,uy;

    w = tf->GetCurrentUnitWP();
    while (w && w->GetWPDepartureTime() < Camp_GetCurrentTime())
    {
        if (w->GetWPFlags())				// Make sure we actually get here, it's important
        {
            w->GetWPLocation(&x,&y);
            tf->GetLocation(&ux,&uy);
            if (DistSqu(x,y,ux,uy) > 2.0F)
                return w;
            if (DoWPAction(tf,w))
                return tf->GetCurrentUnitWP();
        }
        w = w->GetNextWP();
        tf->SetCurrentUnitWP(w);
    }
    return w;
}
Ejemplo n.º 11
0
// Unit within operation area, needs to take it's Waypoint's action
// This currently is only called if this waypoint has a flag set
WayPoint DoWPAction (TaskForce tf, WayPoint w)
{
    WayPoint	cw;

    if (!w || !tf)
        return NULL;

    // Check Actions
    /*	int action = w->GetWPAction();
    	switch (action)
    	{
    	case WP_NOTHING:
    	default:
    	break;
    	}
     */

    // Check Flags
    if (w->GetWPFlags() & WPF_REPEAT)
    {
        // Check if we've been here long enough
        if (Camp_GetCurrentTime() > w->GetWPDepartureTime())
        {
            // If so, go on to the next wp (adjust their times from now)
            tf->AdjustWayPoints();
        }
        else
        {
            // If not, restore previous WP and readjust times
            cw = w->GetPrevWP();
            tf->SetCurrentUnitWP(cw);
            tf->AdjustWayPoints();
            return cw;
        }
    }

    return NULL;
}
Ejemplo n.º 12
0
void HelloWorld::ResumePath(CCNode* sender) {
    Creeps *creep = (Creeps *)sender;
    
    WayPoint * cWaypoint = creep->getCurrentWaypoint();//destination
    WayPoint * lWaypoint = creep->getLastWaypoint();//startpoint
    
    float waypointDist = fabsf(cWaypoint->getPosition().x - lWaypoint->getPosition().x);
    float creepDist = fabsf(cWaypoint->getPosition().x - creep->getPosition().x);
    float distFraction = creepDist / waypointDist;
//    float moveDuration = creep->getMoveDuration() * distFraction; //Time it takes to go from one way point to another * the fraction of how far is left to
    float durScale = creep->moveDurScale();
    float moveDuration = durScale * distFraction;
//    go (meaning it will move at the correct speed)
    

    CCMoveTo* actionMove = CCMoveTo::create(moveDuration,cWaypoint->getPosition());
    CCCallFuncN* actionMoveDone = CCCallFuncN::create(this,callfuncN_selector(HelloWorld::FollowPath));
	creep->stopAllActions();
	creep->runAction(CCSequence::create(actionMove, actionMoveDone, NULL));
}
Ejemplo n.º 13
0
void DogfightClass::ApplySettingsToFlight (Flight flight)
{
	float				x,y,z;
	WayPoint			w;
	int					p,i,cid=0;
	CampaignTime		ttc = FloatToInt32(startRange / 1500.0F) * CampaignSeconds;	// find time to convergence in campaign time
	
	x = startX + DFOffsetX[flight->GetTeam()]*startRange*0.5F;
	y = startY + DFOffsetY[flight->GetTeam()]*startRange*0.5F;
	
	while (calltable[flight->GetTeam()][cid] != flight->callsign_id)
	{
		cid++;
	}

	z = startAltitude - 500.0F * cid - 2500.0F * (flight->callsign_num-1);
	flight->SimSetLocation(x,y,z);
	
	if (FalconLocalGame && FalconLocalGame->IsLocal())
	{
		CampEnterCriticalSection();
		flight->DisposeWayPoints();
		
		// Start waypoint
		w = flight->AddUnitWP (0, 0, 0, 0, startTime, 0, WP_CA);
		w->SetLocation(x,y,startAltitude);
		flight->SetCurrentUnitWP(w);
		
		// Center waypoint
		w = flight->AddUnitWP (0, 0, 0, 0, startTime + ttc, 0, WP_CA);
		w->SetLocation(startX,startY,startAltitude);
		
		// Repeat waypoint
		w = flight->AddUnitWP (0, 0, 0, 0, startTime + ttc, 3*CampaignHours, WP_CA);
		w->SetLocation(x,y,startAltitude);
		w->SetWPFlags(WPF_REPEAT);
		
		// Load weapons
		flight->RemoveLoadout();
		flight->UseFuel(1);
		flight->LoadWeapons(NULL, DefaultDamageMods, Air, numRadarMissiles, WEAP_FORCE_ON_ONE, WEAP_RADAR); 
		flight->LoadWeapons(NULL, DefaultDamageMods, Air, numAllAspectMissiles, WEAP_FORCE_ON_ONE, WEAP_HEATSEEKER); 
		flight->LoadWeapons(NULL, DefaultDamageMods, Air, numRearAspectMissiles, WEAP_FORCE_ON_ONE, WEAP_HEATSEEKER | WEAP_REAR_ASPECT); 

		if (flags & DF_ECM_AVAIL)
		{
			flight->LoadWeapons(NULL, DefaultDamageMods, Air, 1, WEAP_ECM, 0); 
		}

		// Load the gun (for guns only case)
		flight->LoadWeapons(NULL, DefaultDamageMods, Air, 2, WEAP_GUN, 0); 
		CampLeaveCriticalSection();
	}

	flight->SetUnitLastMove (startTime);
	flight->SetFalcFlag(FEC_REGENERATING);
	
	// Check if there are any players in this flight
	for (i=0,p=0; i<PILOTS_PER_FLIGHT; i++){
		if (flight->player_slots[i] != NO_PILOT){
			p++;
		}
	}
	
	// Set our player flag appropriately
	if (p){
		flight->SetFalcFlag(FEC_PLAYERONLY);
		flight->SetFinal(0);
	}
	else {
		flight->UnSetFalcFlag(FEC_PLAYERONLY);
		flight->SetFinal(1);
	}
	
	flight->SetMoving(1);
	flight->SetNoAbort (1);
	flight->SetCurrentWaypoint (2);
	flight->SetUnitMission(AMIS_SWEEP);
	
	MonoPrint ("Apply Settings To Flight %08x %f %f %f\n", flight, x, y, z);
}
Ejemplo n.º 14
0
void StartScene::FollowPath(Node *sender)
{
    DataModel *m = DataModel::getModel();
    Creep* creep = (Creep *)sender;
    WayPoint* curWaypoint = creep->getCurrentWaypoint();
    WayPoint* waypoint = creep->getNextWaypoint();
    if (waypoint!=nullptr) {
        Point moveVector = waypoint->getPosition()-curWaypoint->getPosition();
        float angle = ccpToAngle(moveVector);
        float cocosAngle = CC_RADIANS_TO_DEGREES(angle);
//        std::ostringstream text("angle = ");
//        text<<std::to_string(cocosAngle)<<" curPoint("<<std::to_string(curWaypoint->getPosition().x)<<","<<std::to_string(curWaypoint->getPosition().y)<<") nextPoint("<<std::to_string(waypoint->getPosition().x)<<","<<std::to_string(waypoint->getPosition().y)<<")";
//        log(text.str().c_str());
        if (cocosAngle==0) {
            if (creep->inverse) {
                cocosAngle += 180;
                creep->lifeBar->setPosition(creep->sprite->getPosition().x, creep->sprite->getPosition().y-60);
            } else
                creep->lifeBar->setPosition(creep->sprite->getPosition().x, creep->sprite->getPosition().y+60);
            creep->emptyLifeBar->setPosition(creep->lifeBar->getPosition());
        } else if(cocosAngle==180) {
            if (creep->inverse) {
                cocosAngle += 180;
                creep->lifeBar->setPosition(creep->sprite->getPosition().x, creep->sprite->getPosition().y+60);
            } else
                creep->lifeBar->setPosition(creep->sprite->getPosition().x, creep->sprite->getPosition().y-60);
            creep->emptyLifeBar->setPosition(creep->lifeBar->getPosition());
        } else {
            if (!creep->inverse)
                cocosAngle += 180;
        }
        sender->setRotation(cocosAngle);
        int moveDuration = creep->moveDuration;
        auto actionMove = MoveTo::create(moveDuration, waypoint->getPosition());
        auto actionMoveDone = CallFuncN::create(this, callfuncN_selector(StartScene::FollowPath));
        creep->stopAllActions();
//        creep->lifeBar->stopAllActions();
        creep->runAction(Sequence::create(actionMove, actionMoveDone, NULL));
//        creep->lifeBar->runAction(Sequence::create(lifeBarActionMove, NULL));
    } else {
        m->home->homeHP--;
        life->setText(to_string(m->home->homeHP));
        CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("blast.wav");
        m->targets.eraseObject(creep);
        this->removeChild(creep);
        CCParticleSystem* particleSystem = CCParticleExplosion::create();
        particleSystem->setTexture(CCTextureCache::sharedTextureCache()->addImage("bullet2.png"));
        particleSystem->setPosition(creep->getPosition());
        particleSystem->setScale(0.15);
        particleSystem->setLife(1);
        this->addChild(particleSystem);
        if (m->home->homeHP<=0) {
            m->home->removeAllChildren();
            m->home->sprite = Sprite::create("destroy.png");
            m->home->sprite->setScale(0.7);
            m->home->addChild(m->home->sprite,0);
            Size visibleSize = Director::getInstance()->getVisibleSize();
            Point origin = Director::getInstance()->getVisibleOrigin();
            auto losePic = Sprite::create("over.png");
            losePic->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
            this->addChild(losePic,3);
            widget = dynamic_cast<Layout*>(cocostudio::GUIReader::getInstance()->widgetFromJsonFile("OverUi_1/LoseUi_1.json"));
            widget->setPosition(Point(visibleSize.width/2 + origin.x -widget->getContentSize().width/2, visibleSize.height/2 + origin.y - widget->getContentSize().height/2));
            this->addChild(widget,2);
            auto restartButton = dynamic_cast<Button*>(widget->getChildByName("RestartBTN"));
            auto mainMenuButton = dynamic_cast<Button*>(widget->getChildByName("MainMenuBTN"));
            restartButton->addTouchEventListener(this, toucheventselector(StartScene::restartEvent));
            mainMenuButton->addTouchEventListener(this, toucheventselector(StartScene::mainMenuEvent));
            this->cleanup();
        } else {
            std::string home = to_string(m->home->homeHP) + ".png";
            m->home->removeAllChildren();
            m->home->sprite = Sprite::create(home);
            m->home->sprite->setScale(0.7);
            m->home->addChild(m->home->sprite,0);
        }
    }
}
Ejemplo n.º 15
0
void StartScene::addTarget()
{
    DataModel *m = DataModel::getModel();
    Wave *wave = this->getCurrentWave();
    if(wave==nullptr)
        this->cleanup();
    if (wave->totalCreeps <= 0)
    {
        if (m->targets.size()==0)
            getNextWave();
        return;
    }
    wave->totalCreeps--;
    Creep *target = NULL;

    /*
     int random = rand()%3;
     if (random == 0)
     {
     target = FastGrayCreep::creep(m->waypoints.size());
     }
     else  if(random == 1)
     {
     target = StrongGreenCreep::creep(m->waypoints.size());
     }
     else
     {
     target = MonsterYellowCreep::creep(m->waypoints.size());
     }
     */


    target = Creep::createWithType(wave->creeptype,m->waypoints.size(),true);
    WayPoint *waypoint = target->getCurrentWaypoint();
    target->setPosition(waypoint->getPosition());
    waypoint = target->getNextWaypoint();
    auto lifeBar = CCProgressTimer::create(CCSprite::create("loginbg.png"));
    lifeBar->setType(kCCProgressTimerTypeBar);
    lifeBar->setPercentage(100.0f);
    lifeBar->setBarChangeRate(ccp(1, 0));//水平方向
    lifeBar->setMidpoint(ccp(0,0));//设置起始点为左下方
    lifeBar->setPosition(target->sprite->getPosition().x, target->sprite->getPosition().y+60);
    lifeBar->setScaleY(0.6);
    lifeBar->setScaleX(0.3);
    target->addChild(lifeBar,1);
    target->lifeBar = lifeBar;
    auto emptyLifeBar = Sprite::create("login_dbg.png");
    emptyLifeBar->setScaleX(0.3);
    emptyLifeBar->setScaleY(0.3);
    emptyLifeBar->setPosition(lifeBar->getPosition());
    target->addChild(emptyLifeBar,0);
    target->emptyLifeBar = emptyLifeBar;
    this->addChild(target, 1);
    int moveDuration = target->moveDuration;
    auto actionMove = CCMoveTo::create(moveDuration, waypoint->getPosition());
    auto lifeBarActionMove = MoveTo::create(moveDuration, ccp(waypoint->getPosition().x,waypoint->getPosition().y+25));
    auto actionMoveDone = CallFuncN::create(this, callfuncN_selector(StartScene::FollowPath));
    target->runAction(CCSequence::create(actionMove, actionMoveDone, NULL));
//    lifeBar->runAction(CCSequence::create(lifeBarActionMove, NULL));
    target->tag = 1;
    m->targets.pushBack(target);
}
Ejemplo n.º 16
0
int TaskForceClass::MoveUnit (CampaignTime time)
{
    GridIndex x = 0, y = 0;
    GridIndex nx = 0, ny = 0;
    GridIndex ox = 0, oy = 0;
    WayPoint w = NULL, ow = NULL;
    Objective o = NULL;
    int	moving = 1;
    CampaignHeading	h = 0;

    // RV - Biker
    // Naval units now have three modes:
    // (a) Sit still in harbor
    // (b) Do a 20 km track (repeating waypoints)
    // (c) Followy WPs

    GetLocation(&x,&y);

    w = ResetCurrentWP(this);

    FindNearestUnit(x, y, NULL);

    // Check for mode a
    o = FindNearestObjective(x, y, NULL, 1);

    // RV - Biker - If we are in port and have no WPs do nothing
    if (o && o->GetType() == TYPE_PORT && !w) {
        return TRUE;
    }

    // If not in port and no WPs... create a repeating path 20 km north and back
    if (!w)	{
        DisposeWayPoints();

        w = AddUnitWP(x, y, 0, 60,	TheCampaign.CurrentTime + (rand()%15), 0, 0);
        w->SetWPFlags(WPF_REPEAT);

        // This should prevent naval units to run into ground
        if (GetCover(x, y+20) == Water) {
            w = AddUnitWP(x, y+20, 0, 60, TheCampaign.CurrentTime + (15+(rand()%15))*CampaignMinutes, 0, 0);
        }
        else {
            w = AddUnitWP(x, y, 0, 60, TheCampaign.CurrentTime + 15*CampaignMinutes, 0, 0);
        }
        w->SetWPFlags(WPF_REPEAT);

        w = AddUnitWP(x, y, 0, 60, TheCampaign.CurrentTime + (30+(rand()%15))*CampaignMinutes, 0xffffffff, 0);
        w->SetWPFlags(WPF_REPEAT);

        SetCurrentWaypoint (1);
        w = GetCurrentUnitWP();
    }

    w->GetWPLocation(&nx, &ny);

    // RV - Biker - Wait for departure
    if (Camp_GetCurrentTime() < w->GetWPDepartureTime()) {
        SetUnitLastMove(Camp_GetCurrentTime());
        return 0;
    }

    // Move, if we're not at destination
    if (x!=nx || y!=ny)
    {
        if (w)
            ow = w->GetPrevWP();
        if (ow)
            ow->GetWPLocation(&ox, &oy);
        else
            GetLocation(&ox, &oy);

        while (moving) {
            h = DirectionTo(ox, oy, nx, ny, x, y);
            if (h > 7) {
                moving = 0;
                h = Here;
            }
            // This is kinda hacky - basically, limit change in direction to 45 deg per move
            if (h > last_direction) {
                if (h - last_direction < 5)
                    h = (last_direction+1) & 0x07;
                else
                    h = (last_direction+7) & 0x07;
            }

            else if (h < last_direction) {
                if (last_direction - h < 5)
                    h = (last_direction+7) & 0x07;
                else
                    h = (last_direction+1) & 0x07;
            }

            //this moves the unit
            if (ChangeUnitLocation(h) > 0) {
                last_direction = h;
            }
            else {
                moving = 0;
            }

            // Now do combat
            if (GetCombatTime() > CombatTime()) {
                DoCombat();
            }
        }
    }
    return 0;
}
Ejemplo n.º 17
0
void HelloWorld::addTarget() {
    
	DataModel *m = DataModel::getModel();
	Wave * wave = getCurrentWave();
    int tc=wave->getRedCreeps();
    int gn=wave->getGreenCreeps();
	if (tc <= 0&&gn<=0) {
		return; //[self getNextWave];
	}
	
//	wave->setTotalCreeps(--tc);
	
    Creeps *target = NULL;
//    if ((arc4random() % 2) == 0) {
//        target = FastRedCreep::creep();
//    } else {
//        target = StrongGreenCreep::creep();
//    }
	int random=CCRANDOM_0_1()*100;
    if ((random % 2) == 0) {
        if (wave->getRedCreeps()>0) {
           target =Creeps::create(ENERMY_NAME[0].c_str(),0,Info::getInfo()->creepInfo->value[0]);
            wave->setRedCreeps(--tc);
        }
        else if (wave->getGreenCreeps()>0){
           target = Creeps::create(ENERMY_NAME[1].c_str(),1,Info::getInfo()->creepInfo->value[1]);
            wave->setGreenCreeps(--gn);
            // NSLog(@"no more red");
        }
    }
    else {
        if (wave->getGreenCreeps()>0) {
          target = Creeps::create(ENERMY_NAME[1].c_str(),1,Info::getInfo()->creepInfo->value[1]);
            wave->setGreenCreeps(--gn);
        }
        else if (wave->getRedCreeps()>0){
            target = Creeps::create(ENERMY_NAME[0].c_str(),0,Info::getInfo()->creepInfo->value[0]);
            wave->setRedCreeps(--tc);
            //NSLog(@"no more green");
        }
        
    }
	WayPoint *waypoint = target->getCurrentWaypoint();
	target->setPosition( waypoint->getPosition());
	waypoint = target->getNextWaypoint();
	target->setVisible(true);
	addChild(target,1);
    
    target->setHealthBar(CCProgressTimer::create(CCSprite::create("health_bar_red.png")));
    target->getHealthBar()->setType(kCCProgressTimerTypeBar);
    target->getHealthBar()->setPercentage(100);
    target->getHealthBar()->setScale(0.1);
    target->getHealthBar()->setPosition(ccp(target->getPosition().x,(target->getPosition().y+20)));
    addChild(target->getHealthBar(),3);
    
	int moveDuration = target->getMoveDuration();
	CCMoveTo* actionMove = CCMoveTo::create(moveDuration,waypoint->getPosition());
	CCCallFuncN* actionMoveDone =CCCallFuncN::create(this,callfuncN_selector(HelloWorld::FollowPath));
	target->runAction(CCSequence::create(actionMove, actionMoveDone, NULL));
	
	// Add to targets array
	target->setTag(1);
	m->getTargets()->addObject(target);
	
}
Ejemplo n.º 18
0
int TaskForceClass::GetVehicleDeagData (SimInitDataClass *simdata, int remote)
{
    static CampEntity		ent;
    static int				round;
    int						dist, i, ptIndexAt;

    // Reinitialize static vars upon query of first vehicle
    if (simdata->vehicleInUnit < 0)
    {
        simdata->vehicleInUnit = 0;
        ent = NULL;

        if (!remote)
        {
            // Used only in port
            round = 0;
            simdata->ptIndex = GetDeaggregationPoint(0, &ent);
            if (simdata->ptIndex) {
                // Yuck!  The first call returns only the list index, NOT a real point index.
                // To ensure we have at least one set of points we have to actually query for them
                // then reset again...
                simdata->ptIndex = GetDeaggregationPoint(0, &ent);
                if (simdata->ptIndex)
                    simdata->ptIndex = GetDeaggregationPoint(0, &ent);
                ent = NULL;
                GetDeaggregationPoint(0, &ent);
            }

            // Used only at sea
            WayPoint			w;
            w = GetCurrentUnitWP();
            if (w)
            {
                // Find heading to next waypoint
                GridIndex	ux,uy,wx,wy;
                GetLocation(&ux,&uy);
                w->GetWPLocation(&wx,&wy);
                simdata->heading = AngleTo(ux,uy,wx,wy);
            }
        }
    }
    else
    {
        simdata->vehicleInUnit++;
    }

    if (!remote)
    {
        if (simdata->ptIndex) {
            // In port
            float	dx, dy;

            // Find the center point and direction point for this ship
            simdata->ptIndex = GetDeaggregationPoint(simdata->campSlot, &ent);
            ptIndexAt        = GetDeaggregationPoint(simdata->campSlot, &ent);

            if (!ptIndexAt)
            {
                ShiAssert( !simdata->ptIndex );	// We should always have an even number of points

                // Reuse the old points, but with an offset
                ent = NULL;
                GetDeaggregationPoint(simdata->campSlot, &ent);		// Reset
                simdata->ptIndex = GetDeaggregationPoint(simdata->campSlot, &ent);
                ptIndexAt        = GetDeaggregationPoint(simdata->campSlot, &ent);
                round++;
            }
            ShiAssert( ptIndexAt );		// We must have at least two points (center and toward)
            TranslatePointData(ent, simdata->ptIndex, &simdata->x, &simdata->y);

            // Face toward the "at" point
            dx = PtDataTable[ptIndexAt].yOffset - PtDataTable[simdata->ptIndex].yOffset; // KCK NOTE: axis' are reversed
            dy = PtDataTable[ptIndexAt].xOffset - PtDataTable[simdata->ptIndex].xOffset; // KCK NOTE: axis' are reversed
            simdata->heading = (float)atan2(dx,dy);

            // If we reused a point, shift our center point along the at vector
            simdata->x += dx * round;
            simdata->y += dy * round;
        } else {
            // At sea
            dist = (simdata->vehicleInUnit - 1) >> 2;
            switch ( (simdata->vehicleInUnit - 1) & 0x3 )
            {
            case 0:
                simdata->x = XPos() - 1500.0f - 1500.0f * dist;
                simdata->y = YPos() - 1500.0f - 1500.0f * dist;
                break;
            case 1:
                simdata->x = XPos() + 1500.0f + 1500.0f * dist;
                simdata->y = YPos() - 1500.0f - 1500.0f * dist;
                break;
            case 2:
                simdata->x = XPos() + 1500.0f + 1500.0f * dist;
                simdata->y = YPos() + 1500.0f + 1500.0f * dist;
                break;
            case 3:
            default:
                simdata->x = XPos() - 1500.0f - 1500.0f * dist;
                simdata->y = YPos() + 1500.0f + 1500.0f * dist;
                break;
            }
        }
    }

    // We're always at sea level
    simdata->z = 0.0f;

    // Determine skill (Sim only uses it for anti-air stuff right now, so bow to expedience
    simdata->skill = ((TeamInfo[GetOwner()]->airDefenseExperience - 60) / 10) + rand()%3 - 1;
    //	simdata->skill = ((TeamInfo[GetOwner()]->navalExperience - 60) / 10) + rand()%3 - 1;

    // Clamp it to legal sim side values
    if (simdata->skill > 4)
        simdata->skill = 4;
    if (simdata->skill < 0)
        simdata->skill = 0;

    // Weapon loadout
    for (i=0; i<HARDPOINT_MAX; i++)
    {
        simdata->weapon[i] = GetUnitWeaponId(i,simdata->campSlot);
        if (simdata->weapon[i])
            simdata->weapons[i] = GetUnitWeaponCount(i,simdata->campSlot);
        else
            simdata->weapons[i] = 0;
    }

    simdata->playerSlot = NO_PILOT;
    simdata->waypointList = CloneWPToList(GetFirstUnitWP(),NULL);

    return  MOTION_GND_AI;
}
Ejemplo n.º 19
0
C_Mission *MakeMissionItem(C_TreeList *tree,Flight element)
{
    C_Mission *mission;
    C_Window *win;
    _TCHAR buffer[200];
    TREELIST *item;
    int	ent_mission;
    Package package;
    WayPoint wp;

    if(!element->Final())
        return(NULL);

    if(TheCampaign.Flags & CAMP_TACTICAL)
    {
        if (element->GetOwner () != FalconLocalSession->GetTeam ())
        {
            return NULL;
        }
    }
    else
    {
        if(element->GetUnitSquadronID() != FalconLocalSession->GetPlayerSquadronID())
            return(NULL);
    }

    if(!tree || !element || !element->GetUnitParent())
        return(NULL);

    // Create new record
    mission=new C_Mission;
    if(!mission)
        return(NULL);

    win=tree->GetParent();
    if(!win)
        return(NULL);

    mission->Setup(element->GetCampID(),0); // ID=element->CampID;
    mission->SetFont(win->Font_);
    mission->SetClient(tree->GetClient());
    mission->SetW(win->ClientArea_[tree->GetClient()].right - win->ClientArea_[tree->GetClient()].left);
    mission->SetH(gFontList->GetHeight(tree->GetFont()));
    // Set takeoff time string
    wp = element->GetFirstUnitWP();
    if (wp) { // JPO CTD fix
        GetTimeString(wp->GetWPDepartureTime(),buffer);
        mission->SetTakeOff(static_cast<short>(tree->GetUserNumber(C_STATE_0)),0,buffer);
        mission->SetTakeOffTime(wp->GetWPDepartureTime());
    }

    // Set Mission Type
    ent_mission = element->GetUnitMission();
    if (ent_mission == AMIS_ALERT)
        ent_mission = AMIS_INTERCEPT;
    mission->SetMission(static_cast<short>(tree->GetUserNumber(C_STATE_1)),0,MissStr[ent_mission]);
    mission->SetMissionID(static_cast<short>(element->GetUnitMission()));

    // Set Package (campID of package)
    _stprintf(buffer,"%1d",element->GetUnitParent()->GetCampID());
    mission->SetPackage(static_cast<short>(tree->GetUserNumber(C_STATE_2)),0,buffer);
    mission->SetPackageID(element->GetUnitParent()->GetCampID());

    // Set Mission Status String
    mission->SetStatusID(GetFlightStatusID(element));
    mission->SetStatus(static_cast<short>(tree->GetUserNumber(C_STATE_3)),0,gStringMgr->GetString(FlightStatusID[mission->GetStatusID()]));

    // Set Mission Priority String
    package = element->GetUnitPackage();
    buffer[1]=0;
    // KCK: It seemed more logical to get the priority from the flight, not the package's request
    // PJW: Why Kevin you are sooo f*****g wrong... and ASK when making changes butt f**k
//	buffer[0]=(255 - element->GetUnitPriority()) / 51 + _T('A');
    buffer[0]=static_cast<char>((255 - package->GetMissionRequest()->priority) / 51 + _T('A'));
    mission->SetPriority(static_cast<short>(tree->GetUserNumber(C_STATE_4)),0,buffer);
    mission->SetPriorityID(static_cast<short>(255 - package->GetMissionRequest()->priority));

    // Set a callback incase someone actually wants to see this mission
//	if (TheCampaign.Flags & CAMP_TACTICAL)
//	{
//		mission->SetCallback (TacMissionSelectCB);
//	}
//	else
//	{
    mission->SetCallback(MissionSelectCB);
//	}

    // Tack on the VU_ID
    mission->SetVUID(element->Id());
    mission->SetUserNumber(C_STATE_0,element->GetTeam());
    mission->SetUserNumber(C_STATE_1,wp ? wp->GetWPDepartureTime() : 0);
    mission->SetUserNumber(C_STATE_2,1000 - element->GetUnitPriority()); // Priority
    mission->SetUserNumber(C_STATE_3,element->GetUnitMission());

    if (!element->Final() || element->GetUnitMission() == AMIS_ALERT)
    {
        mission->SetFlagBitOn(C_BIT_INVISIBLE);
    }

    // Add to tree
    item=tree->CreateItem(element->GetCampID(),C_TYPE_ITEM,mission);
    mission->SetOwner(item);
    if(tree->AddItem(tree->GetRoot(),item))
        return(mission);
    mission->Cleanup();
    delete mission;
    delete item;
    return(NULL);
}
Ejemplo n.º 20
0
const bool WayPoint::operator== (const WayPoint& comp) {
	return (x == comp.getX() && y == comp.getY());
}