Ejemplo n.º 1
0
    void Blueprint::adjacentCost( void* node, std::vector< micropather::StateCost > *neighbors )
    {
        int x, y;
        const int dx[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
        const int dy[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
        const float cost[8] = { 1.0f, 1.41f, 1.0f, 1.41f, 1.0f, 1.41f, 1.0f, 1.41f };

        nodeToXY( node, &x, &y );

        for( int i=0; i<8; ++i ) {
            int nx = x + dx[i];
            int ny = y + dy[i];

            int pass = passable( nx, ny );
            if ( pass > 0 ) {
                if ( pass == 1 )
                {
                    // Normal floor
                    micropather::StateCost nodeCost = { xYToNode( nx, ny ), cost[i] };
                    neighbors->push_back( nodeCost );
                }
                else
                {
                    // Normal floor
                    micropather::StateCost nodeCost = { xYToNode( nx, ny ), FLT_MAX };
                    neighbors->push_back( nodeCost );
                }
            }
        }
    }
Ejemplo n.º 2
0
	bool Problem::FindSuccessors(const ai::Search::State * const state_in, std::vector<ai::Search::ActionStatePair> &results_out) const
	{
		#if VERBOSE
			std::cout << "Problem::FindSuccessors()" << std::endl;
		#endif

		const State * pwstate_in = dynamic_cast<const State *>(state_in);

		for(ai::Scavenger::Location::Direction direction = ai::Scavenger::Location::NORTH; direction <= ai::Scavenger::Location::WEST; direction++)
		{
			Interface interface = model->getCell(pwstate_in->location).interface[direction];
			#if DEBUG
				std::cout << "From: " << pwstate_in <<" passable: " << interface << std::endl;
			#endif
			if(passable(interface))
			{
				State * next = pwstate_in->move(direction);
				next->charge = next->charge - pathCost(model, pwstate_in, direction);
				if(next->charge > 0)
				{
					results_out.push_back(
						ai::Search::ActionStatePair(
							next,
							new Action(getActionFromDirection(direction))
						)
					);
				}
			}
		}

		#if VERBOSE
			std::cout << "results_out.size() = " << results_out.size() << std::endl;
		#endif
		return true;
	}
Ejemplo n.º 3
0
 /*!
 Returns true if the tile is passable.
 */
 int Blueprint::passable( int nx, int ny )
 {
     int toRet=0;
     if (    nx >= 0 && nx < _mapWidth
             && ny >= 0 && ny < _mapHeigth )
     {
         QChar c = gMap.value(hash(ny,nx),' ');
         if ( c == ' ' )
         {
             toRet = 1;
         }
         else if ( c >= 'A' && c<='z' )
         {
             toRet = passable( c );
         }
     }
     return toRet;
 }
Ejemplo n.º 4
0
    /*!
    Sets player position
    */
    int Blueprint::setPos( int nx, int ny )
    {
        int result = 0;
        if ( passable( nx, ny ) == 1 )
        {
            float totalCost;

            result = _pather->Solve( xYToNode( _playerX, _playerY ), xYToNode( nx, ny ), &_path, &totalCost );

            if ( result == micropather::MicroPather::SOLVED ) {
                _playerX = nx;
                _playerY = ny;
            }
            qDebug()<< ( "Pather returned %d\n", result );

        }
        return result;
    }
Ejemplo n.º 5
0
void Character::mapCollisions() {
	// Up and down
	if(m_vy != 0) {
		if (!passable(m_x + m_hitboxX			 , m_y + m_hitboxY + m_vy			 )
		||  !passable(m_x + m_hitboxX + m_hitboxW, m_y + m_hitboxY + m_vy			 )
		||  !passable(m_x + m_hitboxX			 , m_y + m_hitboxY + m_vy + m_hitboxH)
		||  !passable(m_x + m_hitboxX + m_hitboxW, m_y + m_hitboxY + m_vy + m_hitboxH)) {
			/* Let player slide on tiles corners */
			// Top left
			if (!passable(m_x + m_hitboxX + m_hitboxW + 8, m_y + m_hitboxY + m_vy)
			&&	 passable(m_x + m_hitboxX				 , m_y + m_hitboxY + m_vy)) {
				m_vx = -1;
			}
			// Top right
			if (!passable(m_x + m_hitboxX - 8		 , m_y + m_hitboxY + m_vy)
			&&   passable(m_x + m_hitboxX + m_hitboxW, m_y + m_hitboxY + m_vy)) {
				m_vx = 1;
			}
			// Bottom left
			if (!passable(m_x + m_hitboxX + m_hitboxW + 8, m_y + m_hitboxY + m_hitboxH + m_vy)
			&&	 passable(m_x + m_hitboxX				 , m_y + m_hitboxY + m_hitboxH + m_vy)) {
				m_vx = -1;
			}
			// Bottom right
			if (!passable(m_x + m_hitboxX - 8		 , m_y + m_hitboxY + m_hitboxH + m_vy)
			&&   passable(m_x + m_hitboxX + m_hitboxW, m_y + m_hitboxY + m_hitboxH + m_vy)) {
				m_vx = 1;
			}
			
			// Reset vertical movement vector
			m_vy = 0;
			
			// Execute collision action
			collisionAction(NULL);
		}
	}
	
	// Left and right
	if(m_vx != 0) {
		if (!passable(m_x + m_hitboxX + m_vx			, m_y + m_hitboxY			 )
		||  !passable(m_x + m_hitboxX + m_vx + m_hitboxW, m_y + m_hitboxY			 )
		||  !passable(m_x + m_hitboxX + m_vx			, m_y + m_hitboxY + m_hitboxH)
		||  !passable(m_x + m_hitboxX + m_vx + m_hitboxW, m_y + m_hitboxY + m_hitboxH)) {
			/* Let player slide on tiles corners */
			// Top left
			if (!passable(m_x + m_hitboxX + m_vx, m_y + m_hitboxY + m_hitboxH + 0)
			&&	 passable(m_x + m_hitboxX + m_vx, m_y + m_hitboxY				 )) {
				m_vy = -1;
			}
			// Bottom left
			if (!passable(m_x + m_hitboxX + m_vx, m_y + m_hitboxY - 0		 )
			&&   passable(m_x + m_hitboxX + m_vx, m_y + m_hitboxY + m_hitboxH)) {
				m_vy = 1;
			}
			// Top right
			if (!passable(m_x + m_hitboxX + m_hitboxW + m_vx, m_y + m_hitboxY + m_hitboxH + 0)
			&&	 passable(m_x + m_hitboxX + m_hitboxW + m_vx, m_y + m_hitboxY				 )) {
				m_vy = -1;
			}
			// Bottom right
			if (!passable(m_x + m_hitboxX + m_hitboxW + m_vx, m_y + m_hitboxY - 0		 )
			&&   passable(m_x + m_hitboxX + m_hitboxW + m_vx, m_y + m_hitboxY + m_hitboxH)) {
				m_vy = 1;
			}
			
			// Reset horizontal movement vector
			m_vx = 0;
			
			// Execute collision action
			collisionAction(NULL);
		}
	}
}
Ejemplo n.º 6
0
bool Character::inNonPassableTile() {
	return(!passable(m_x + m_hitboxX + m_vx			   , m_y + m_hitboxY + m_vy			   )
		|| !passable(m_x + m_hitboxX + m_vx + m_hitboxW, m_y + m_hitboxY + m_vy			   )
		|| !passable(m_x + m_hitboxX + m_vx			   , m_y + m_hitboxY + m_vy + m_hitboxH)
		|| !passable(m_x + m_hitboxX + m_vx + m_hitboxW, m_y + m_hitboxY + m_vy + m_hitboxH));
}