Page 1 of 1

Bug in dynamic scripting

PostPosted: 22 Feb 2017, 19:21
by Toxic
Hi,

I have a problem in my script when I want to create trees. Command Actions.MapTileObjectSet(X,Y,TREE_NUMBER); (for example Actions.MapTileObjectSet(10,10,88);) gives me nice small tree seedlings. The problem is that it will never grow up + if I create big trees, woodcutters are not able to cut it down :? . Can you help me solve this problem?

(tested for objects: Tree:=[88,89,90,92,93,94,95,97,98,99,100,102,103,104,105,107,108,109,110,149,150,151,153,154,155,157,158,159,160,162,163,164,165,167,168,169,170];)

Re: Bug in dynamic scripting

PostPosted: 23 Feb 2017, 17:49
by Rey
Andreus (scripts developer), said, that this bug is not possible to fix in current version (r6720), but it was already fixed and will come with next release version

Re: Bug in dynamic scripting

PostPosted: 24 Feb 2017, 14:52
by Toxic
Thank you. I suppose that you will not be able to tell me when this update will be released, am I right?

Re: Bug in dynamic scripting

PostPosted: 24 Feb 2017, 17:59
by Rey
In the future, for sure. Just wait for updates :)

Re: Bug in dynamic scripting

PostPosted: 25 Feb 2017, 00:32
by Ben
A remarkable political answer from our dear Rey!

Re: Bug in dynamic scripting

PostPosted: 25 Feb 2017, 05:17
by Rey
Sorry, but I can say no more for now ... :wink:
But let's hope for the best.
There is still a hope with us :D

Re: Bug in dynamic scripting

PostPosted: 25 Feb 2017, 19:58
by Toxic
I have another (it is not so important). Make this script in new (empty) map:
  Code:
procedure OnHousePlanRemoved(aPlayer, aX, aY, aType: Integer); begin Actions.log('Removed: X='+intToStr(aX)+' Y='+intToStr(aY)); end; procedure OnHousePlanPlaced(aPlayer, aX, aY, aType: Integer); begin Actions.log('Placed: X='+intToStr(aX)+' Y='+intToStr(aY)); end;
This bug appears if you place schoolhouse plan and then immediately remove it. When you check .LOG file you will see that coordination X is different for event OnHousePlanRemoved (+-1 dependent on the building). This happens also when you choose the exactly same tile for placing and removing (i.e. building entrance).

Here are differences (index of array = house type from Lookups):
  Code:
FixConstant := [-1,0,-1,-1,0,0,-1,1,-1,0,-1,-1,0,-1,0,-1,1,0,0,-1,-1,-1,0,0,1,0,0,-1,1,1];

Re: Bug in dynamic scripting

PostPosted: 25 Feb 2017, 23:05
by Rey
Thanks, we didn't noticed that bug before.
It comes not because of entrance offsets for different houses, but because in OnHousePlanRemoved coordinates of tile, where player click to remove house, were used. So. f.e. if you place school plan on 5,5, then click on 4,3 - top left corner of house, then you will get 4,3 in OnHousePlanRemoved.
Fixed here https://github.com/Kromster80/kam_remake/pull/298, thanks!

Re: Bug in dynamic scripting

PostPosted: 26 Feb 2017, 07:53
by Toxic
... where player click to remove house, were used.
I know and I have not problem with it.
So. f.e. if you place school plan on 5,5, then click on 4,3 - top left corner of house, then you will get 4,3 in OnHousePlanRemoved.
This is wrong. Check my script - you will not get 4,3 but 3,3! This is why I wrote my post because X coordinates are changing +-1 in depent on building. To sum up each specific building after demolition returns you different X coordinates.

Re: Bug in dynamic scripting

PostPosted: 26 Feb 2017, 11:22
by Rey
Yes I understand. But if we show real house position(entrance actually, not position), instead of where user click on the map, then this issue will be resolved automatically.
So finally in new version when you place any house plan and then remove this house plan, same coordinates are logged with your script code.
For all houses there are 2 coordinates - one is house position, smth like house center, and other is house entrance, which has +-1 offset with house position for some houses. These 2 commands above both use entrance coordinates now.

Re: Bug in dynamic scripting

PostPosted: 26 Feb 2017, 17:55
by Ben
To expand on Rey's answer:
It may seem weird that some houses "center" is not where the door is. I agree that is very odd, but it's important to keep the game this way to keep compatibility with original mission files for Knights and Merchants, TSK/TPR. Why they didn't just set all houses to have a center at the door, I really don't know, but it's a legacy that the Remake appropriately continues.

Re: Bug in dynamic scripting

PostPosted: 26 Feb 2017, 18:16
by Krom
Original KaM did not set the houses center on the door likely due to memory and CPU considerations. Each house is described by 4x4 matrix (element = tile usage). So to allow for 4 tile wide houses with door at any place it would have need a 7x4 matrix. This is much larger. So instead offsets were used.