Corner Check

Corner check (major home systems); support/discussion/questions

Moderator: thunderchero

Post Reply
User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Corner Check

Post by Gowron » Sun Jun 21, 2009 1:25 pm

After the random generation of coordinates for the starting systems of major empires, subroutine 4B2F20 takes these coordinates and tests if one of the empires starts in a corner of the map. Such a set of coordinates would then be rejected.

For each corner, the coordinates are tested against two adjacent edges. For example, if a location is both at the left edge of the map and at the top edge of the map, then it is a corner.

Here's the code for the different corners. Note that the 2nd coordinate appears to be scaled.
Initial data:
eax == (coordinate1)
ecx == (coordinate2)
esi == 1 for small maps
esi == 2 for medium and large maps
dword[esp] == (length of long edge of the map) - (esi)
ebp == 5 x (length of short edge of the map) - (esi)

Code: Select all

---------
:004B2F88 39F1                    cmp ecx, esi             // 1st corner
:004B2F8A 7D04                    jge 004B2F90
:004B2F8C 39F0                    cmp eax, esi
:004B2F8E 7C3B                    jl 004B2FCB              // reject coordinates
---------
:004B2F90 39F1                    cmp ecx, esi             // 2nd corner
:004B2F92 7D05                    jge 004B2F99
:004B2F94 3B0424                  cmp eax, dword[esp]
:004B2F97 7D32                    jge 004B2FCB             // reject coordinates
---------
:004B2F99 39E9                    cmp ecx, ebp             // 3rd corner
:004B2F9B 7C04                    jl 004B2FA1
:004B2F9D 39F0                    cmp eax, esi
:004B2F9F 7C2A                    jl 004B2FCB              // reject coordinates
---------
:004B2FA1 39E9                    cmp ecx, ebp             // 4th corner
:004B2FA3 7C05                    jl 004B2FAA              // ACCEPT coordinates
:004B2FA5 3B0424                  cmp eax, dword[esp]
:004B2FA8 7D21                    jge 004B2FCB             // reject coordinates
---------
Note that some locations which are not corners can also be rejected.

Also, the code of the subroutine which calls sub_4B2F20 suggests that if this test fails a hundred times, it is not performed again. This would mean that it IS possible (albeit very improbable) to start in a corner in vanilla BotF.
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.

User avatar
jigalypuff
Past Administrator
Past Administrator
Posts: 238
Joined: Sat Apr 26, 2008 2:00 am

Post by jigalypuff » Sun Jun 21, 2009 2:58 pm

I have started in a corner a fair few times :) usually in a random galaxy.

User avatar
Gowron
Code Master
Code Master
Posts: 304
Joined: Sat Apr 26, 2008 2:00 am
Location: 50° N, 11° E

Post by Gowron » Tue Jun 23, 2009 2:15 pm

jigalypuff wrote:I have started in a corner a fair few times :) usually in a random galaxy.
I don't remember starting directly in a corner in any game/test. And it's been a few games ;)
But maybe I didn't notice ^^
Spocks-cuddly-tribble wrote:A really nice find :), but I'm a bit confused here.:?

1.) Are we talking about coordinates for home systems only, or additional starting systems as well?

2.) I still didn't catch the gal-size differentation. Does this mean large/med also reject the bordering coordinates of the corners?


And would it be much complicated to alter the code in order to avoid edge coordinates instead of corners? I ask because of an possible increasing of additional starting systems beyond the limit of 5. :)
1. This only applies to major empire home systems.

2. Yep, but only in two directions, as it seems. This is because the 2nd coordinates are multiplied by 5, but the parameter (esi) is not.


And yes, increasing the possible amount of additional starting systems was the main point behind this :)

The corner tests can be changed to edge tests by removing one half of them (since they already consist of two edge tests each). For example, you can change

Code: Select all

--------- 
:004B2F88 39F1                    cmp ecx, esi             // 1st corner 
:004B2F8A 7D04                    jge 004B2F90 
:004B2F8C 39F0                    cmp eax, esi 
:004B2F8E 7C3B                    jl 004B2FCB              // reject coordinates 
---------
to

Code: Select all

--------- 
:004B2F88 90                      nop
:004B2F89 90                      nop
:004B2F8A 90                      nop
:004B2F8B 90                      nop
:004B2F8C 39F0                    cmp eax, esi             // 1st edge
:004B2F8E 7C3B                    jl 004B2FCB              // reject coordinates 
---------
EDIT:

For a copy & paste hex code see:
viewtopic.php?p=24351&sid=531b7dcca9449 ... 866#p24351
A discovery consists in seeing something everybody has seen and at the same time thinking something nobody has thought yet.

Post Reply

Return to “Corner check (major home systems)”

Who is online

Users browsing this forum: No registered users