Heroes of Might and Magic Community
visiting hero! Register | Today's Posts | Games | Search! | FAQ/Rules | AvatarList | MemberList | Profile


Age of Heroes Headlines:  
5 Oct 2016: Heroes VII development comes to an end.. - read more
6 Aug 2016: Troubled Heroes VII Expansion Release - read more
26 Apr 2016: Heroes VII XPack - Trial by Fire - Coming out in June! - read more
17 Apr 2016: Global Alternative Creatures MOD for H7 after 1.8 Patch! - read more
7 Mar 2016: Romero launches a Piano Sonata Album Kickstarter! - read more
19 Feb 2016: Heroes 5.5 RC6, Heroes VII patch 1.7 are out! - read more
13 Jan 2016: Horn of the Abyss 1.4 Available for Download! - read more
17 Dec 2015: Heroes 5.5 update, 1.6 out for H7 - read more
23 Nov 2015: H7 1.4 & 1.5 patches Released - read more
31 Oct 2015: First H7 patches are out, End of DoC development - read more
5 Oct 2016: Heroes VII development comes to an end.. - read more
[X] Remove Ads
LOGIN:     Username:     Password:         [ Register ]
HOMM1: info forum | HOMM2: info forum | HOMM3: info mods forum | HOMM4: info CTG forum | HOMM5: info mods forum | MMH6: wiki forum | MMH7: wiki forum
Heroes Community > Library of Enlightenment > Thread: Tribute to Strategists
Thread: Tribute to Strategists This thread is 20 pages long: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 · «PREV / NEXT»
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted December 15, 2014 10:38 PM
Edited by AlexSpl at 22:40, 15 Dec 2014.

Can you write an ERM script that will show the value of R4, provided a, b, c, and d are integers?

1. R1 = a*x + b*y + c*z + d
2. R2 = R1 / 65536 (integer division here!)
3. R3 = R2 mod 32768
4. R4 = R3 mod 100

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
kicferk
kicferk


Known Hero
posted December 15, 2014 10:40 PM

I think if you use e variables the game will recognize it. That's what floating point is for in the first place. v variables on the other hand seem like integer ones to me, so they are forced to be integers by game You will need to use a bit different commands, but all in all very similar.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted December 15, 2014 10:44 PM
Edited by AlexSpl at 22:46, 15 Dec 2014.

Or, using '%' symbol for a remainder:

1. R1 = a*x + b*y + c*z + d
2. R2 = R1 / 65536 (integer division here!)
3. R3 = R2 % 32768
4. R4 = R3 % 100

Where

a = 196143423
b = 928924629
c = 348991063
d = 2148842073

x, y, z - coordinates

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Salamandre
Salamandre


Admirable
Omnipresent Hero
Wog refugee
posted December 15, 2014 10:46 PM
Edited by Salamandre at 22:47, 15 Dec 2014.

What means:

R2 mod 32768

remainder?

@Edit: ok, give me a moment
____________
Era II mods and utilities

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Salamandre
Salamandre


Admirable
Omnipresent Hero
Wog refugee
posted December 15, 2014 10:53 PM
Edited by Salamandre at 22:58, 15 Dec 2014.

The script:

!?CM0;
;get active hero position (x:y:z  14/18/0)
!!OW:A-1/?y1;
!!HEy1:P?y2/?y3/?y4;
;R1 = a*x + b*y + c*z + d
!!VRy5:S196143423*y2;
!!VRy6:S928924629*y3;
!!VRy7:S348991063*y4;
!!VRv2:Sy5+y6+y7+2148842073;
;R2 = R1 / 65536 (integer division here!)
!!VRv3:Sv2:65536;
;R3 = R2 % 32768
!!VRv4:Sv3%32768;
;R4 = R3 % 100
!!VRv5:Sv4%100;
!!IF:M^%V5^;

I got R4=46.
____________
Era II mods and utilities

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted December 15, 2014 10:57 PM

Well done. Now compare this number to 50.

R4 < 50 means you will see an upgraded stack, otherwise not.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Salamandre
Salamandre


Admirable
Omnipresent Hero
Wog refugee
posted December 15, 2014 11:00 PM
Edited by Salamandre at 23:02, 15 Dec 2014.

I got R4=-25 if I move hero to other location. Is this possible or some error in my maths?

When you say:
;R2 = R1 / 65536 (integer division here!)
!!VRv3:Sv2:65536;

This is division, right? v2 divided by 65536, ok?
____________
Era II mods and utilities

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted December 15, 2014 11:02 PM

You should use only unsigned integers.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
kicferk
kicferk


Known Hero
posted December 15, 2014 11:02 PM

I bet you get an overflow here: !!VRv2:Sy5+y6+y7+2148842073;
Try dividing each of parts by 65k individually, keeping it in y-variables.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Salamandre
Salamandre


Admirable
Omnipresent Hero
Wog refugee
posted December 15, 2014 11:04 PM
Edited by Salamandre at 23:05, 15 Dec 2014.

Well yes the max range of integers is 2147483647 in erm.  How do I avoid that, divide each result by 65536?
____________
Era II mods and utilities

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted December 15, 2014 11:05 PM

Overflow is needed here. You cannot divide each part.

See this:
(1 + 2 + 3) / 6 = 1
1/6 + 2/6 + 3/6 = 0 + 0 + 0 = 0


 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
AlexSpl
AlexSpl


Responsible
Supreme Hero
posted December 15, 2014 11:07 PM

Quote:
Well yes the max range of integers is 2147483647 in erm

I should think about a workaround. Give me some time

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Salamandre
Salamandre


Admirable
Omnipresent Hero
Wog refugee
posted December 15, 2014 11:08 PM

The problem is here, I need to rewrite it to get accurate result:

R1 = a*x + b*y + c*z + d

If I write this as it is in erm, we get

a*x+b, now the result will be multiplied by y, then add c then the result multiply by z and so on. So I need to divide the operation in valid parts.
____________
Era II mods and utilities

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
kicferk
kicferk


Known Hero
posted December 15, 2014 11:09 PM

Ok, so to deal with that you can do the following:
If you get a negative result after dividing by 65536 you make the number equal to 65536 + the result and carry on. I think it should return a correct result in the end

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Salamandre
Salamandre


Admirable
Omnipresent Hero
Wog refugee
posted December 15, 2014 11:12 PM

To add a negative integer to 65536 if negative result?
____________
Era II mods and utilities

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
kicferk
kicferk


Known Hero
posted December 15, 2014 11:14 PM
Edited by kicferk at 23:24, 15 Dec 2014.

Ok, it seems in this particular setup what I wrote will work. Normally you would need to adjust to the remainder of max number+1 divided by divisor, but in this case it is 0, so you can do what I wrote and it should work.

It exploits the fact that the remainder may have two types - positive and negative, and that adding the divisor to the negative remainder gives you positive one. And in this case it also exploits the fact that remainder of division of 2147483648 by 65536 is 0.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Salamandre
Salamandre


Admirable
Omnipresent Hero
Wog refugee
posted December 15, 2014 11:24 PM
Edited by Salamandre at 23:24, 15 Dec 2014.

kicferk said:
Ok, so to deal with that you can do the following:
If you get a negative result after dividing by 65536 you make the number equal to 65536 + the result and carry on. I think it should return a correct result in the end


I don't have a clue of what to do
How changing a negative integer to 65536 will keep the thing accurate
Give me please an example based on that erm I wrote.
____________
Era II mods and utilities

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
kicferk
kicferk


Known Hero
posted December 15, 2014 11:28 PM

Take the example that gave you negative result.
v2 got negative and so did v3. But v3 is the remainder, so by what I wrote in "edit", you can get a positive integer with the same meaning if you add 65536 to it.

The reason it works is because of the way overflow is taken care of. after 2147483647 you get -2147483648, and then it goes normally(I think the range should be -2147483648 to + 2147483647)

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Salamandre
Salamandre


Admirable
Omnipresent Hero
Wog refugee
posted December 15, 2014 11:32 PM
Edited by Salamandre at 23:32, 15 Dec 2014.

ok, this is modified to add 65536 each time a result is negative, except for R4, right?:

!?CM0;
!!OW:A-1/?y1;
!!HEy1:P?y2/?y3/?y4;

;R1 = a*x + b*y + c*z + d
!!VRy5:S196143423*y2;
!!VRy6:S928924629*y3;
!!VRy7:S348991063*y4;
!!VRv2:Sy5+y6+y7+2148842073;

;R2 = R1 / 65536 (integer division here!)
!!VRv3:Sv2:65536;
!!VRv3&v3<0:+65536;

;R3 = R2 % 32768
!!VRv4:Sv3%32768;
!!VRv4&v4<0:+65536;

;R4 = R3 % 100
!!VRv5:Sv4%100;
!!IF:M^%V5^;

Now I will test about upgraded/non upgraded stacks, within this script.

____________
Era II mods and utilities

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
kicferk
kicferk


Known Hero
posted December 15, 2014 11:36 PM

!!VRv4&v4<0:+65536;
This line is unnecessary, and is unlikely to ever being triggered. If it is ever triggered it should be
!!VRv4&v4<0:+32768;
because to get v4 you divided by 32768. And it will never occur, because there is no way the result would go negative after you took care of v3 being negative

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Jump To: « Prev Thread . . . Next Thread » This thread is 20 pages long: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 · «PREV / NEXT»
Post New Poll    Post New Topic    Post New Reply

Page compiled in 0.2770 seconds