Open tdelc opened 5 years ago
would love to help out! but, I don't understand the requirement. could you explain what is "level" means to you? or, describe the entire feature?
also, did you check out the new location and waypoint features?
I give you an example : Ship is in sector V35C
But we can also say that the ship is in a larger yellow sector called X32C
Or in the green sector BLOC
Or in the red sector SROC
I want to describe a location with this designation : quadrant SROC - Sector BLOC - Area X32C - Section V35C
And so, I would like a function to get these four designation. For example : getSectorName(obj,level) with level could be equal to 1,2,3,4
Or something like this.
I am currently integrate your sector system in my fork, so I will test your next PR soon :)
I think it's really simple. just divide the location vector by 8 to the power of the level
getSectorName(position / 8)
should give you yellow sector
getSectorName(position / (8*8))
should give you green sector etc.
and the general form is getSectorName(position / std::pow(8, level))
warning : this code is straight from my head. maybe some small tweak is missing.
It was a good idea to ask you for that, I would tried a lot of hard code to do that...
Thanks a lot ! Not need for a new function so !
I had the chance to sleep on it, and I think i made a mistake. It would work only on positions close to 0,0.
The function should be getSectorName(Vector2i(position / std::pow(8, level)) * std::pow(8, level))
I tested the math briefly in javascript using this function:
function floorPositionToLevel(pos, lvl) {
let powerOfLevel = Math.pow(8, lvl);
return Math.floor(pos / powerOfLevel) * powerOfLevel;
}
console.log(floorPositionToLevel(5, 0)); //5
console.log(floorPositionToLevel(5, 1)); //0
console.log(floorPositionToLevel(5, 2)); //0
console.log(floorPositionToLevel(85, 0)); //85
console.log(floorPositionToLevel(85, 1)); //80
console.log(floorPositionToLevel(85, 2)); //64
console.log(floorPositionToLevel(85, 3)); //0
assuming the calculus of Vector2
has the same semantics for -
and /
(it should) and that casting Vector2f
to Vector2i
has same semantics as Math.floor
on number
in JS, it should work.
I would love to write the C++ code but we have no tests set up so i need a feature that uses it in order to test
How's it going? did it work?
I have a first try. I added a function for spaceobject : getSectorNameLevel
I tried to modify the getSectorName with a default parameter equal to 0, but I didn't suceed it.
What to you think ?
string SpaceObject::getSectorNameLevel(int level)
{
int factor = std::pow(8,level) * GameGlobalInfo::sector_size;
sf::Vector2f position = getPosition();
position.x = floorf(position.x / factor) * factor;
position.y = floorf(position.y / factor) * factor;
return ::getSectorName(position);
}
I seems like a more verbose way to do what I suggested (with the added GameGlobalInfo::sector_size
as part of the factor. good catch)
I bet ::getSectorName
doesn't compile though :)
I thought like you for ::getSectorName, but it works :) I don't understand why
Hi,
Really, I love, we love your system name sector. For Point Zero, that will be a huge enhancement. I want to ask you for a little PR for that. Could you please modify your getSectorName to include a level : blue, yellow, green and red ?
Example : getSectorName(obj,1) = A0C getSectorName(obj,2) = H0C getSectorName(obj,3) = BLOC getSectorName(obj,4) = SROC
I try it but I don't succeed it, I don't understand enough about division and modulo :)
Thanks it advance.