• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Sight range underground

Sherice

Sky&Wind
Joined
Jan 20, 2012
Messages
183
Reaction score
7
Location
Sweden
I noticed that when you're underground, you can only see 2 floors down/up. Where can I change this / how?
I found this:
Code:
bool Creature::canSee(const Position& myPos, const Position& pos, uint32_t viewRangeX, uint32_t viewRangeY)
{
    if(myPos.z <= 7)
    {
        //we are on ground level or above (7 -> 0)
        //view is from 7 -> 0
        if(pos.z > 7)
            return false;
    }
    else if(myPos.z >= 8)
    {
        //we are underground (8 -> 15)
        //view is +/- 2 from the floor we stand on
        if(std::abs(myPos.z - pos.z) > 2)
            return false;
    }

    int32_t offsetz = myPos.z - pos.z;
    return (((uint32_t)pos.x >= myPos.x - viewRangeX + offsetz) && ((uint32_t)pos.x <= myPos.x + viewRangeX + offsetz) &&
        ((uint32_t)pos.y >= myPos.y - viewRangeY + offsetz) && ((uint32_t)pos.y <= myPos.y + viewRangeY + offsetz));
}
in creature.cpp.

I tried changing > 2 to > 4, but it didn't do any difference (which means what I did is probably totally wrong :p).
 
[cpp]else if(myPos.z >= 8)
{
//we are underground (8 -> 15)
if(pos.z > 7)
return true;
}[/cpp]

Maybe this is not the best solution.
 
This is look function.

[cpp]bool Game::playerLookAt(uint32_t playerId, const Position& pos, uint16_t spriteId, int16_t stackpos)
{
Player* player = getPlayerByID(playerId);
if(!player || player->isRemoved())
return false;

Thing* thing = internalGetThing(player, pos, stackpos, spriteId, STACKPOS_LOOK);
if(!thing)
{
player->sendCancelMessage(RET_NOTPOSSIBLE);
return false;
}

Position thingPos = pos;
if(pos.x == 0xFFFF)
thingPos = thing->getPosition();

if(!player->canSee(thingPos))
{
player->sendCancelMessage(RET_NOTPOSSIBLE);
return false;
}

Position playerPos = player->getPosition();
int32_t lookDistance = -1;
if(thing != player)
{
lookDistance = std::max(std::abs(playerPos.x - thingPos.x), std::abs(playerPos.y - thingPos.y));
if(playerPos.z != thingPos.z)
lookDistance = lookDistance + 9 + 6;
}

bool deny = false;
CreatureEventList lookEvents = player->getCreatureEvents(CREATURE_EVENT_LOOK);
for(CreatureEventList::iterator it = lookEvents.begin(); it != lookEvents.end(); ++it)
{
if(!(*it)->executeLook(player, thing, thingPos, stackpos, lookDistance))
deny = true;
}

if(deny)
return false;

std::stringstream ss;
ss << "You see " << thing->getDescription(lookDistance);[/cpp]

This function calls:
[cpp]bool Player::canSee(const Position& pos) const
{
if(client)
return client->canSee(pos);

return false;
}[/cpp]

Which calls:
[cpp]bool ProtocolGame::canSee(uint16_t x, uint16_t y, uint16_t z) const
{
const Position& myPos = player->getPosition();
if(myPos.z <= 7)
{
//we are on ground level or above (7 -> 0), view is from 7 -> 0
if(z > 7)
return false;
}
else if(myPos.z >= 8 && std::abs(myPos.z - z) > 2) //we are underground (8 -> 15), view is +/- 2 from the floor we stand on
return false;

//negative offset means that the action taken place is on a lower floor than ourself
int32_t offsetz = myPos.z - z;
return ((x >= myPos.x - 8 + offsetz) && (x <= myPos.x + 9 + offsetz) &&
(y >= myPos.y - 6 + offsetz) && (y <= myPos.y + 7 + offsetz));
}[/cpp]

Try changing:
else if(myPos.z >= 8 && std::abs(myPos.z - z) > 2) //we are underground (8 -> 15), view is +/- 2 from the floor we stand on
return false;

To:
else if(myPos.z >= 8 && z >= 8) //we are underground (8 -> 15), view is +/- 2 from the floor we stand on
return true;
 
Back
Top Bottom