Ejemplo n.º 1
0
	DrawableSprite::DrawableSprite() : Sprite ( Coord(), Coord ( 1, 1 ), 0, 1 )
	{
		//ctor
	}
Ejemplo n.º 2
0
	Coord Widget::toLocal( const Coord& coord ) const
	{
		Coord c = globalPos();
		return Coord( coord.x - c.x, coord.y - c.y );
	}
Ejemplo n.º 3
0
	void Menubar::_render( GfxDevice * pDevice, const Rect& _canvas, const Rect& _window, const Rect& _clip )
	{
		Widget::_render(pDevice,_canvas,_window,_clip);
	
		// Take backgrounds content borders into account
	
		Rect	window;
		Rect	clip;
	
		if( m_pSkin )
		{
			window = m_pSkin->contentRect( _canvas, m_state );
			clip.intersection( window, _clip );
		}
		else
		{
			window = _canvas;
			clip = _clip;
		}
	
		// Go throught the MenuBarItems and print their text and render their rectangles.
	
		MenuBarItem * pI = m_items.first();
		uint32_t posX = window.x;
	
		Pen pen;
	
	
		TextAttr	attr;
		TextTool::addPropAttributes( attr, Base::getDefaultTextprop(), StateEnum::Normal);
		TextTool::addPropAttributes( attr, m_pTextProp, StateEnum::Normal);
	
		pen.setAttributes( attr );
		pen.setClipRect( clip );
		pen.setDevice( pDevice );
	
		uint32_t printPosY = window.y + ( window.h - pen.getLineHeight() )/2 + pen.getBaseline();
	
		uint32_t itemNb = 1;
		while( pI )
		{
			if( pI->isVisible() )
			{
				State	state = StateEnum::Disabled;
				if( m_state.isEnabled() && pI->m_bEnabled )
				{
					state = StateEnum::Normal;
	
					if( itemNb == m_selectedItem )
						state = StateEnum::Pressed;
					else if( itemNb == m_markedItem )
						state = StateEnum::Hovered;
				}
	
				Border b = _getEntryBorder();
	
	//			ColorsetPtr pTextColors;
				
	//			if( m_pSkin )
	//				pTextColors = m_pSkin->TextColors();
	
				if( m_pEntrySkin )
				{
					Rect	dest( posX, window.y, pI->m_width + b.width(), window.h );
					m_pEntrySkin->render( pDevice, dest, state, clip );
	
	//				pTextColors = m_pEntrySkin->TextColors();
				}
	
				pen.setPos( Coord(posX + b.left, printPosY) );
	
				TextAttr	attr;
				TextTool::addPropAttributes( attr, Base::getDefaultTextprop(), state );
	//			TextTool::setAttrColor( attr, pTextColors, mode );
				TextTool::addPropAttributes( attr, m_pTextProp, state );
				pen.setAttributes( attr );
	
				pDevice->printLine( pen, attr, pI->m_pText );
	
				posX += pI->m_width + b.width();
			}
			itemNb++;
			pI = pI->next();
		}
	}
Ejemplo n.º 4
0
/**
 * Applique l'opérateur modulo sur les deux coordonnées.
 */
Coord Coord::operator%(const int n) const
{
	return Coord(this->x % n, this->y % n);
}
Ejemplo n.º 5
0
/**
    This function returns the size of the specified item.
    \param ItemID   the id of the item (e.g. Structure_HeavyFactory)
    \return a Coord containg the size (e.g. (3,2) ). Returns (0,0) on error.
*/
Coord getStructureSize(int itemID) {

	switch(itemID) {
		case Structure_Barracks:			return Coord(2,2); break;
		case Structure_ConstructionYard:	return Coord(2,2); break;
		case Structure_GunTurret: 			return Coord(1,1); break;
		case Structure_HeavyFactory: 		return Coord(3,2); break;
		case Structure_HighTechFactory:		return Coord(3,2); break;
		case Structure_IX:					return Coord(2,2); break;
		case Structure_LightFactory:		return Coord(2,2); break;
		case Structure_Palace:				return Coord(3,3); break;
		case Structure_Radar:				return Coord(2,2); break;
		case Structure_Refinery:			return Coord(3,2); break;
		case Structure_RepairYard:			return Coord(3,2); break;
		case Structure_RocketTurret:		return Coord(1,1); break;
		case Structure_Silo:				return Coord(2,2); break;
		case Structure_StarPort:			return Coord(3,3); break;
		case Structure_Slab1:				return Coord(1,1); break;
		case Structure_Slab4:				return Coord(2,2); break;
		case Structure_Wall:				return Coord(1,1); break;
		case Structure_WindTrap:			return Coord(2,2); break;
		case Structure_WOR:					return Coord(2,2); break;
		default:							return Coord(0,0); break;
	}

	return Coord(0,0);
}
Ejemplo n.º 6
0
/**
 * Soustrait deux coordonnées.
 */
Coord Coord::operator-(const Coord& c) const
{
	return Coord(this->x - c.x, this->y - c.y);
}
Ejemplo n.º 7
0
/**
 * Divise une coordonnée par une valeur entière.
 */
Coord Coord::operator/(const int n) const
{
	return Coord(this->x / n, this->y / n);
}
Ejemplo n.º 8
0
Coord operator-(Coord coord1,Coord coord2){
	return Coord(coord1.x()-coord2.x(),coord1.y()-coord2.y(),coord1.z()-coord2.z(),coord1.ex()-coord2.ex(),coord1.ey()-coord2.ey(),coord1.ez()-coord2.ez());
}
Ejemplo n.º 9
0
Coord operator*(float value,Coord coord2){
	return Coord(coord2.x()*value,coord2.y()*value,coord2.z()*value,coord2.ex()*value,coord2.ey()*value,coord2.ez()*value);
}
Ejemplo n.º 10
0
 Apple() {
   _value = 10;
   _type = NORMAL_APPLE;
   _pos = Coord(0, 0);
 }
Ejemplo n.º 11
0
void GlAxisBoxPlot::draw(float lod,Camera* camera) {

  float rotationAngle = axis->getRotationAngle();

  if (rotationAngle != 0) {
    glPushMatrix();
    glRotatef(rotationAngle, 0.0f, 0.0f, 1.0f);
  }

  bottomOutlierCoord = axis->getBottomOutlierCoord();
  firstQuartileCoord = axis->getFirstQuartileCoord();
  medianCoord = axis->getMedianCoord();
  thirdQuartileCoord = axis->getThirdQuartileCoord();
  topOutlierCoord = axis->getTopOutlierCoord();

  Coord interQuartileRangeBoxCoords[4];

  if (axis->hasAscendingOrder()) {
    boundingBox.expand(Coord(bottomOutlierCoord.getX() - boxWidth / 2.0f, bottomOutlierCoord.getY(), 0.0f));
    boundingBox.expand(Coord(topOutlierCoord.getX() + boxWidth / 2.0f, topOutlierCoord.getY(), 0.0f));

    interQuartileRangeBoxCoords[0] = Coord(thirdQuartileCoord.getX() - boxWidth / 2.0f, thirdQuartileCoord.getY(), 0.0f);
    interQuartileRangeBoxCoords[1] = Coord(thirdQuartileCoord.getX() + boxWidth / 2.0f, thirdQuartileCoord.getY(), 0.0f);
    interQuartileRangeBoxCoords[2] = Coord(firstQuartileCoord.getX() + boxWidth / 2.0f, firstQuartileCoord.getY(), 0.0f);
    interQuartileRangeBoxCoords[3] = Coord(firstQuartileCoord.getX() - boxWidth / 2.0f, firstQuartileCoord.getY(), 0.0f);
  }
  else {
    boundingBox.expand(Coord(topOutlierCoord.getX() - boxWidth / 2.0f, topOutlierCoord.getY(), 0.0f));
    boundingBox.expand(Coord(bottomOutlierCoord.getX() + boxWidth / 2.0f, bottomOutlierCoord.getY(), 0.0f));

    interQuartileRangeBoxCoords[0] = Coord(firstQuartileCoord.getX() - boxWidth / 2.0f, firstQuartileCoord.getY(), 0.0f);
    interQuartileRangeBoxCoords[1] = Coord(firstQuartileCoord.getX() + boxWidth / 2.0f, firstQuartileCoord.getY(), 0.0f);
    interQuartileRangeBoxCoords[2] = Coord(thirdQuartileCoord.getX() + boxWidth / 2.0f, thirdQuartileCoord.getY(), 0.0f);
    interQuartileRangeBoxCoords[3] = Coord(thirdQuartileCoord.getX() - boxWidth / 2.0f, thirdQuartileCoord.getY(), 0.0f);
  }

  GlQuad interQuartileRangeBox(interQuartileRangeBoxCoords[0], interQuartileRangeBoxCoords[1],
                               interQuartileRangeBoxCoords[2], interQuartileRangeBoxCoords[3], fillColor);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA,GL_SRC_COLOR);
  glEnable(GL_LIGHTING);
  interQuartileRangeBox.draw(lod, camera);
  glDisable(GL_BLEND);
  glDisable(GL_LIGHTING);

  glEnable(GL_BLEND);
  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  GlLines::glDrawLine(interQuartileRangeBoxCoords[0], interQuartileRangeBoxCoords[1], 2, GlLines::TLP_PLAIN, outlineColor, outlineColor);
  GlLines::glDrawLine(interQuartileRangeBoxCoords[1], interQuartileRangeBoxCoords[2], 2, GlLines::TLP_PLAIN, outlineColor, outlineColor);
  GlLines::glDrawLine(interQuartileRangeBoxCoords[2], interQuartileRangeBoxCoords[3], 2, GlLines::TLP_PLAIN, outlineColor, outlineColor);
  GlLines::glDrawLine(interQuartileRangeBoxCoords[3], interQuartileRangeBoxCoords[0], 2, GlLines::TLP_PLAIN, outlineColor, outlineColor);

  GlLines::glDrawLine(bottomOutlierCoord + Coord(-(boxWidth / 2.0f), 0.0f, 0.0f), bottomOutlierCoord + Coord(boxWidth / 2.0f, 0.0f, 0.0f), 2, GlLines::TLP_PLAIN, outlineColor, outlineColor);
  GlLines::glDrawLine(medianCoord + Coord(-(boxWidth / 2.0f), 0.0f, 0.0f), medianCoord + Coord(boxWidth / 2.0f, 0.0f, 0.0f), 2, GlLines::TLP_PLAIN, outlineColor, outlineColor);
  GlLines::glDrawLine(topOutlierCoord + Coord(-(boxWidth / 2.0f), 0.0f, 0.0f), topOutlierCoord + Coord(boxWidth / 2.0f, 0.0f, 0.0f), 2, GlLines::TLP_PLAIN, outlineColor, outlineColor);

  GlLines::glDrawLine(bottomOutlierCoord, firstQuartileCoord, 2, GlLines::TLP_DASHED, outlineColor, outlineColor);
  GlLines::glDrawLine(thirdQuartileCoord, topOutlierCoord, 2, GlLines::TLP_DASHED, outlineColor, outlineColor);
  glDisable(GL_BLEND);

  drawLabel(bottomOutlierCoord, axis->getBottomOutlierStringValue(),camera);
  drawLabel(firstQuartileCoord, axis->getFirstQuartileStringValue(),camera);
  drawLabel(medianCoord, axis->getMedianStringValue(),camera);
  drawLabel(thirdQuartileCoord, axis->getThirdQuartileStringValue(),camera);
  drawLabel(topOutlierCoord, axis->getTopOutlierStringValue(),camera);

  if (highlightRangeLowBound != NULL && highlightRangeHighBound != NULL) {
    Coord highlightBoxCoords[4] = { Coord(highlightRangeHighBound->getX() - boxWidth / 2.0f, highlightRangeHighBound->getY(), 0.0f),
                                    Coord(highlightRangeHighBound->getX() + boxWidth / 2.0f, highlightRangeHighBound->getY(), 0.0f),
                                    Coord(highlightRangeLowBound->getX() + boxWidth / 2.0f, highlightRangeLowBound->getY(), 0.0f),
                                    Coord(highlightRangeLowBound->getX() - boxWidth / 2.0f, highlightRangeLowBound->getY(), 0.0f)
                                  };
    Color outlineColorTranslucent(outlineColor);
    outlineColorTranslucent.setA(10);
    GlQuad highlightBox(highlightBoxCoords[0], highlightBoxCoords[1], highlightBoxCoords[2], highlightBoxCoords[3], outlineColorTranslucent);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA,GL_SRC_COLOR);
    glEnable(GL_LIGHTING);
    highlightBox.draw(lod, camera);
    glDisable(GL_BLEND);
    glDisable(GL_LIGHTING);
    highlightRangeLowBound = NULL;
    highlightRangeHighBound = NULL;
  }

  if (rotationAngle != 0.0f) {
    glPopMatrix();
  }
}
Ejemplo n.º 12
0
static inline
Coord __compute_up(unit_t NX, unit_t NY)
{
    return Coord(NX,__half_NY(NY)-1);
}
Ejemplo n.º 13
0
static inline
Coord __compute_lo(unit_t NY)
{
    return Coord(0,-__half_NY(NY) );
}
Ejemplo n.º 14
0
 inline Coord latlonInverse(const QPointF& point) const
 {
     return Coord(point.x()/*/EQUATORIALMETERPERDEGREE*/, point.y()/*/EQUATORIALMETERPERDEGREE*/);
 }
Ejemplo n.º 15
0
 virtual void SetUp() {
     ModuleNodePointer module = Utility::getPointer(new RectangularModuleFactory("module1"));
     module->addShape(Utility::getPointer(new RectangularShape("0", Coord(1, 1, 1))));
     module->addShape(Utility::getPointer(new RectangularShape("1", Coord(1, 1, 2))));
     graph->add(module);
 }
Ejemplo n.º 16
0
Coord operator/(Coord coord1,float value){
	return Coord(coord1.x()/value,coord1.y()/value,coord1.z()/value,coord1.ex()/value,coord1.ey()/value,coord1.ez()/value);
}
Ejemplo n.º 17
0
/**
 * Additionne deux coordonnées.
 */
Coord Coord::operator+(const Coord& c) const
{
	return Coord(this->x + c.x, this->y + c.y);
}
Ejemplo n.º 18
0
Coord operator/(float value,Coord coord2){
	return Coord(value/coord2.x(),value/coord2.y(),value/coord2.z(),value/coord2.ex(),value/coord2.ey(),value/coord2.ez());
}
Ejemplo n.º 19
0
/**
 * Multiplie une coordonnée par une valeur entière.
 */
Coord Coord::operator*(const int n) const
{
	return Coord(this->x * n, this->y * n);
}
Ejemplo n.º 20
0
Coord Coord::operator+( const Coord& src ) const
{
	return Coord( this->x + src.x, this->y + src.y, this->z + src.z, this->map );
}
Ejemplo n.º 21
0
/**
 * Applique l'opérateur modulo entre les coordonnées correspondantes.
 */
Coord Coord::operator%(const Coord& c) const
{
	return Coord(this->x % c.x, this->y % c.y);
}
Ejemplo n.º 22
0
Coord Coord::operator-( const Coord& src ) const
{
	return Coord( this->x - src.x, this->y - src.y, this->z - src.z, this->map );
}
Ejemplo n.º 23
0
// かならず、listCharacterが先に呼ばれてロードされていることが前提。
// load失敗していたらNOTLOADエラー返す
void KServer::recv_login( const char *characterName )
{
    if( !m_authenticationSuccess )return;
    
    m_lastFunction = FUNCTION_LOGIN;
    m_usingPCName = std::string( characterName );

    db_proto::PlayerCharacter *dbpc = getDBPC();
    if(!dbpc){
        send_loginResult( FAIL,0);
        std::cerr << "character not found:" << characterName << std::endl;
        return;
    }

    Floor *f = World::getFloor( dbpc->floorID );
    if(!f || Coord( dbpc->x, dbpc->y ).insideFloor() == false ){
        send_loginResult( FAIL,0);
        std::cerr << "invalid location:" << dbpc->floorID << "," << dbpc->x << "," << dbpc->y << std::endl;
        return;
    }

    // このサーバの担当領域か?
    Coord logoutCoord = Coord(dbpc->x,dbpc->y);
    if( !Zone::inThisZone( dbpc->floorID, logoutCoord) ){
        // 領域外でも、1タイル分だけ外れているなら、位置を修正してログインさせる。
        // 厳密に1タイルではなくもうちょっとマージンが広くても良い。
        Coord c0 = logoutCoord.translate(1,0);
        Coord c1 = logoutCoord.translate(0,1);
        Coord c2 = logoutCoord.translate(0,-1);
        Coord c3 = logoutCoord.translate(-1,0);
        
        bool b0 = Zone::inThisZone( dbpc->floorID, c0 );
        bool b1 = Zone::inThisZone( dbpc->floorID, c1 );
        bool b2 = Zone::inThisZone( dbpc->floorID, c2 );
        bool b3 = Zone::inThisZone( dbpc->floorID, c3 );

        if( b0 ){ dbpc->x = c0.x; dbpc->y = c0.y; }
        if( b1 ){ dbpc->x = c1.x; dbpc->y = c1.y; }
        if( b2 ){ dbpc->x = c2.x; dbpc->y = c2.y; }
        if( b3 ){ dbpc->x = c3.x; dbpc->y = c3.y; }        

        bool resolved = b0 || b1 || b2 || b3;
        if( !resolved ){
            send_loginResult( FAIL, 0 );
            std::cerr << "location is not in this zone." << std::endl;
            return;
        }
    }


    // キャラクターを生成して存在するようにする
    m_pc = World::allocPlayerCharacter( World::getFloor(dbpc->floorID),
                                        Coord( dbpc->x, dbpc->y ),
                                        this );
    assert(m_pc);

    m_pc->stat = CharStat( dbpc->hp, dbpc->maxhp, dbpc->level, dbpc->exp );

    // 最終的に結果送信
    send_loginResult( SUCCESS, m_pc->id );
    m_loginSuccess = true;
            
    m_pc->notify( k_proto::FUNCTION_MOVENOTIFY );
            
    // アイテム、スキル、クエストをロードする(遅延して後で読み込まれる)
    g_dbcli->send_get_CharacterItem_by_characterID( uID,  dbpc->id );
    g_dbcli->send_get_CharacterSkill_by_characterID( uID,  dbpc->id );

    // DEBUG: 敵つくる
    if( dbpc->exp == 0 ){
        int cnt =0 ;
        while(true){
            if( World::allocEnemy( m_pc->floor,
                                   m_pc->coord.translate( -5 + ( random() %11 ),
                                                          -5 + ( random() %11 ) ),
                                   MOVABLE_GOBLIN ) ){
                cnt++;
                if(cnt==10)break;
            }
        }
    }
    
    return;
}
Ejemplo n.º 24
0
int StateLobby::OnSelectCharacter (IPacket &packet)
{
    std::string name = packet.Read();

    if (!packet.EndOfStream())
        return MSG_ERROR_SIZE;

    World *world = m_server->GetWorld();

    player_iterator i = FindCharacterIndex(name);

    if ( i != m_player_list.end() )
    {
        boost::shared_ptr<Player> player = *i;

        if (!player)
            return MSG_ERROR;

        DB::MASTERY::Select mselect;
        MasteryTree tree = mselect(m_server->DBConnection(),player->ID(),player->level(),player->race());

        player->set_mastery_tree(tree);

        DB::SKILL::Select sselect;
        std::set<uint32_t> skill_list = sselect(m_server->DBConnection(),player->ID());

        player->set_skill_list(skill_list);

        boost::shared_ptr<Storage> ml = player->get_storage(STORAGE_MAIN);

        DB::ITEM::Select iobj;
        std::vector<Item::extended_type> item_list = iobj(m_server->DBConnection(),player->ID(),STORAGE_MAIN);

        for (std::vector<Item::extended_type>::const_iterator i = item_list.begin(); i != item_list.end(); ++i)
        {
            try
            {
                ml->InsertItem(world->GetItemFactory()->Create(i->id,*i));
            }
            catch (Exception::InvalidItemID &error)
            {
                syslog(LOG_INFO,"Lobby::LoadCharacters() - Error while cloning item with ID = %i",i->id);
            }
        }

        DB::JOB::Select jb_sl_query;
        Job job = jb_sl_query(m_server->DBConnection(),player->ID());

        player->set_job(job);

        boost::shared_ptr<OPacket> pkt(new OPacket);
        srv_pkt::RequestIngame(pkt);
        m_connection->Send(pkt);

        DB::PLAYER::State st_query;
        st_query(m_server->DBConnection(),player->ID(),true);

        pkt.reset(new OPacket);

        srv_pkt::InitScreen(pkt);
        m_connection->Send(pkt);

        DB::HOTKEY::Select hotkey_query;
        player->m_Hotkeys = hotkey_query(m_server->DBConnection(),player->ID());

        DB::BLOCK::Select block_query;
        player->m_BlockList = block_query(m_server->DBConnection(),player->ID());

        DB::PLAYER::Autopot autopot_query;
        player->m_Autopot = autopot_query(m_server->DBConnection(),player->ID());

        if (player->IsDead())
        {
            player->resurrect(false,false,0,false);

            Teleport tlp = m_server->GetWorld()->FindTeleport(player->get_return_point());

            if (!tlp.ID)
            {
                syslog(LOG_INFO,"Invalid Return Point - %i",player->get_return_point());
                return MSG_ERROR;
            }

            player->set_position(Coord(tlp.x,tlp.y,tlp.z,tlp.Zone));
        }

        pkt.reset(new OPacket);

        srv_pkt::PlayerInfo(pkt,player,static_cast<srv::Connection*>(m_connection)->AccountID());
        m_connection->Send(pkt);

        pkt.reset(new OPacket);

        srv_pkt::EndScreen(pkt);
        m_connection->Send(pkt);

        pkt.reset(new OPacket);

        srv_pkt::PlayerID(pkt,player);
        m_connection->Send(pkt);

        /// ADD SKILL PASSIVES

        boost::shared_ptr<Skill> skill;
        for (std::set<uint32_t>::const_iterator it = skill_list.begin(); it != skill_list.end(); ++it)
        {
            skill = m_server->GetWorld()->GetSkillManager()->find(*it);

            if (skill && skill->type() == SKT_PASSIVE)
            {
                Buff buff;
                buff.passive = true;
                buff.persistent = true;
                buff.Level = skill->level();
                buff.GroupID = skill->group_id();
                buff.Effects = skill->buff_list();

                buff.ReqShield = skill->require_shield();
                buff.ReqDevil = skill->require_devil();
                buff.ReqWeapon = skill->required_weapons();

                if (player->is_buff_stackable(buff))
                {
                    player->RemoveLesserBuffs(buff);
                    player->insert_buff(buff);
                }
            }
        }

        m_connection->SetState(srv::STATE_GAME);
        static_cast<srv::Connection*>(m_connection)->SetPlayer(player);
    }
    else
        return MSG_ERROR_ARG;

    return MSG_SUCCESS;
}
Ejemplo n.º 25
0
void WelcomeScreen::removeButton(int x, int y)
{
    Button* button = m_buttons.take(Coord(x, y));
    delete button;
    update();
}
Ejemplo n.º 26
0
std::vector<Coord> AStar( std::vector< std::vector< int > > grid, Point start, Point end )
{

	//The current 'focal' point.
	Point *cur;

	//The open and closed lists.
	std::vector< Point* > closed;
	std::vector< Point* > open;

	//Start by adding the starting position to the list.
	open.push_back( &start );

	//Just so it knows whether or not to try and reconstruct a path.
	bool error = true;

	while( open.size() > 0 )
	{

		//The current point is the first entry in the open list.
		cur = open.at(0);

		if( cur->getPos() == end.getPos() )
		{

			error = false;
			break;

		}

		//Add in all the neighbors of the current point.
		for( int y = -1; y <= 1; y++ )
		{

			for( int x = -1; x <= 1; x++ )
			{

				int curX = cur->getPos().x+x;
				int curY = cur->getPos().y+y;

				int movCost = 10;

				//If it is a diagonal, make it cost 14 instead of 10.
				if( (y == -1 && x == -1)||
					(y ==  1 && x == -1)||
					(y == -1 && x ==  1)||
					(y ==  1 && x ==  1))
				{

					movCost = 14;
					//continue;

				}

				Coord temp( curX, curY );
				bool make = true;

				//If it is outside the range of the map, continue.
				if( curY >= grid.size() || 
					curX >= grid.size() )
				{

					continue;
				}

				/*

				These two loops are to check whether or not the point's neighbors already exist.
				This feels really sloppy to me. Please tell me if there is a better way.

				*/
				for( int i = 0; i < open.size(); i++ )
				{

					if( temp == open.at(i)->getPos() )
					{

						make = false;
						break;

					}

				}

				for( int i = 0; i < closed.size(); i++ )
				{

					if( temp == closed.at(i)->getPos() )
					{

						make = false;
						break;

					}

				}

				//If the point in the map is a zero, then it is a wall. Continue.
				if( (grid.at(temp.x).at(temp.y) == 0 ) ||
					( temp.x<0 || temp.y < 0 ) )
				{

					continue;

				}

				//If it is allowed to make a new point, it adds it to the open list.
				if( make )
				{

					int gScore = cur->getCost();
					int hScore = manhattan( end.getPos(), Coord( curX, curY ) );
					int tileCost = grid[curX][curY];
					int fScore = gScore+hScore+tileCost+movCost;

					open.push_back( new Point( curX, curY, fScore, cur ) );

				}
		
			}

		}

		//It then pushes back the current into the closed set as well as erasing it from the open set.
		closed.push_back( cur );
		open.erase( open.begin() );

		//Heapsort works, guranteed. Not sure if it's a stable sort, though. From what I can tell that shouldn't matter, though.
		open = heapsort( open );

	}

	std::vector<Coord> path;

	if( error )
	{

		return path;

	}

	//Reconstruct a path by tracing through the parents.
	while( cur->getParent() != nullptr )
	{

		path.push_back( cur->getPos() );
		cur = cur->getParent();
		
	}

	path.push_back( cur->getPos() );

	return path;

}
Ejemplo n.º 27
0
void Action_Wander::execute()
{
	m_npc->fight( 0 );

	// If the next wandertype hasn't come yet.
	if ( m_npc->nextMoveTime() > Server::instance()->time() )
	{
		return;
	}

	m_npc->setNextMoveTime();

	if ( m_npc->wanderType() == enHalt )
	{
		return;
	}

	switch ( m_npc->wanderType() )
	{
		case enWanderSpawnregion:
		{
			// Only try to walk if we're not already out of the spawnregion
			// Otherwise fall trough to enFreely
			cSpawnRegion* region = m_npc->spawnregion();

			if ( region && region->isValidSpot( m_npc->pos() ) )
			{
				// Calculate the field we're facing.
				unsigned char dir = m_npc->direction();

				// There is a 5% chance of changing the direction
				if ( !RandomNum( 0, 19 ) )
				{
					dir = RandomNum( 0, 7 );
				}

				Coord newpos = Movement::instance()->calcCoordFromDir( dir, m_npc->pos() );

				// Calculate a new direction.
				if ( !region->isValidSpot( newpos ) )
				{
					unsigned char newdir = RandomNum( 0, 7 );
					// Make sure we're not trying to walk in the same
					// direction or the directions directly beneath if we met the border of a
					// spawnregion. But we don't want to turn around exactly either. (Looks
					// to mechanically)
					while ( newdir == dir || newdir == ( ( dir == 0 ) ? 7 : dir - 1 ) || newdir == ( ( dir == 7 ) ? 0 : dir + 1 ) )
					{
						newdir += RandomNum( 0, 1 ) ? -1 : 1;
					}
					dir = newdir;

					newpos = Movement::instance()->calcCoordFromDir( dir, m_npc->pos() ); // Recalculate the new one

					// See if it's still invalid
					if ( !region->isValidSpot( newpos ) )
					{
						return;
					}
				}

				// Change our current heading first.
				if ( m_npc->direction() != dir )
				{
					Movement::instance()->Walking( m_npc, dir, 0xFF );
				}

				// Walk in the same direction or if the direction has changed simply turn around.
				// If there's a obstacle, change the direction slightly to see if we can get
				// around it.
				if ( !Movement::instance()->Walking( m_npc, dir, 0xFF ) )
				{
					signed char newdir = dir;
					newdir += RandomNum( 0, 1 ) ? -1 : 1;
					if ( newdir < 0 )
					{
						newdir = 7;
					}
					else if ( newdir > 7 )
					{
						newdir = 0;
					}

					Movement::instance()->Walking( m_npc, newdir, 0xFF );
				}
				break;
			}
		}

		case enFreely:
		{
			Q_UINT8 dir = m_npc->direction();
			if ( RandomNum( 0, 100 ) < 20 )
				dir = RandomNum( 0, 7 );

			Movement::instance()->Walking( m_npc, dir, 0xFF );
			break;
		}

		case enRectangle:
		{
			// get any point out of the rectangle and calculate the direction to it
			Q_UINT16 rndx = RandomNum( m_npc->wanderX1(), m_npc->wanderX2() );
			Q_UINT16 rndy = RandomNum( m_npc->wanderY1(), m_npc->wanderY2() );

			Q_UINT8 dir = m_npc->pos().direction( Coord( rndx, rndy ) );
			Movement::instance()->Walking( m_npc, dir, 0xFF );
			break;
		}

		case enCircle:
		{
			Coord pos = m_npc->pos();
			pos.x = m_npc->wanderX1();
			pos.y = m_npc->wanderY1();
			// get any point within the circle and calculate the direction to it
			// first a random distance which can be max. the length of the radius
			float rnddist = ( float ) RandomNum( 1, m_npc->wanderRadius() );
			// now get a point on this circle around the m_npc
			float rndphi = ( float ) RandomNum( 0, 100 ) / 100.0f * 2.0f * 3.14159265358979323846f;
			pos.x = pos.x + ( Q_INT16 ) floor( cos( rndphi ) * rnddist );
			pos.y = pos.y + ( Q_INT16 ) floor( sin( rndphi ) * rnddist );

			Q_UINT8 dir = m_npc->pos().direction( pos );

			if ( m_npc->direction() != dir )
			{
				Movement::instance()->Walking( m_npc, dir, 0xFF );
			}

			Movement::instance()->Walking( m_npc, dir, 0xFF );
			break;
		}

		case enFollowTarget:
		{
			if ( Config::instance()->pathfind4Follow() )
			{
				P_CHAR pTarget = m_npc->wanderFollowTarget();
				if ( pTarget )
				{
					if ( m_npc->dist( pTarget ) < 4 )
					{
						movePath( pTarget->pos() );
					}
					else
					{
						moveTo( pTarget->pos() );
					}
				}
			}
			else
			{
				P_CHAR pTarget = m_npc->wanderFollowTarget();
				if ( pTarget )
				{
					moveTo( pTarget->pos() );
				}
			}
			break;
		}

		case enDestination:
		{
			if ( m_npc->pos().distance( m_npc->wanderDestination() ) < 6 )
			{
				movePath( m_npc->wanderDestination() );
			}
			else
			{
				moveTo( m_npc->wanderDestination() );
			}
			break;
		}

		default:
			break;
	}
	return;
}
Ejemplo n.º 28
0
// |----------------------------------------------------------------------------|
// |							   Initialize									|
// |----------------------------------------------------------------------------|
bool Player::Initialize() {
    GameObject::Initialize();

	// Set up ship
	Graphic* graphic = new Graphic;
    graphic->SetTint(1.0f,1.0f,1.0f,1.0f);
    graphic->SetShader("Texture");
    graphic->SetShader("Light");
	graphic->SetTexture("shiptexture");
    graphic->SetModel("ship");
    graphic->SetScale(Coord(0.01f,0.01f,0.01f));
	graphic->SetReflectiveness(0.95f);
    graphic->Initialize();
    m_ship = new GameObject;
    m_ship->Initialize();
	m_ship->SetGraphic(graphic);
    m_ship->SetPosition(Coord(0.0f,0.0f,0.0f));
    m_ship->SetOrientation(Coord(0.0f,0.0f,0.0f));

    // Set up left thruster
    m_leftThruster = new ParticleSystem;
    m_leftThruster->Initialize();
    graphic = new Billboard;
    graphic->SetShader("Texture");
    graphic->SetTexture("fireball");
    graphic->SetAlphaBlend(true);
    graphic->SetScale(Coord(0.003f,0.003f,0.003f));
    graphic->Initialize();
    m_leftThruster->SetGraphic(graphic);
    m_leftThruster->SetPosition(Coord(-0.6f,0.0f,-0.7f));
    m_leftThruster->SetParticleVelocity(Coord(0.0f,0.0f,-2.0f));
    m_leftThruster->SetParticleVelocityVariation(Coord(0.5f,0.5f,0.5f));
    m_leftThruster->SetParticleSpawnFrequency(0.01f);
    m_leftThruster->SetParticleDeviation(Coord(0.0f,0.0f,0.0f));
    m_leftThruster->SetParticleLifetime(0.5f);
    m_leftThruster->SetParticleFadeout(0.2f);
    m_leftThruster->SetMaxParticles(100);
    m_leftThruster->SetTint(0.8f,0.9f,1.0f);
    m_leftThruster->SetTintVar(0.2f,0.2f,0.2f);

    // Set up right thruster
    m_rightThruster = new ParticleSystem;
    m_rightThruster->Initialize();
    graphic = new Billboard;
    graphic->SetShader("Texture");
    graphic->SetTexture("fireball");
    graphic->SetAlphaBlend(true);
    graphic->SetScale(Coord(0.003f,0.003f,0.003f));
    graphic->Initialize();
    m_rightThruster->SetGraphic(graphic);
    m_rightThruster->SetPosition(Coord(0.6f,0.0f,-0.7f));
    m_rightThruster->SetParticleVelocity(Coord(0.0f,0.0f,-2.0f));
    m_rightThruster->SetParticleVelocityVariation(Coord(0.5f,0.5f,0.5f));
    m_rightThruster->SetParticleSpawnFrequency(0.001f);
    m_rightThruster->SetParticleDeviation(Coord(0.0f,0.0f,0.0f));
    m_rightThruster->SetParticleLifetime(0.5f);
    m_rightThruster->SetParticleFadeout(0.2f);
    m_rightThruster->SetMaxParticles(100);
    m_rightThruster->SetTint(0.8f,0.9f,1.0f);
    m_rightThruster->SetTintVar(0.2f,0.2f,0.2f);



	DebugLog ("Player: object initialized.");
	return true;
}
Ejemplo n.º 29
0
Coord MacPrinterCanvas::width() const {
	return Coord(hres_)/float(lpx_)*72.;
}
Ejemplo n.º 30
0
	Coord shift( const Move & move ) const {
		return Coord( this->x + move.dx, this->y + move.dy );
	}