CivOne
CivOne copied to clipboard
Unit 'flash'
- Unit A attempts to attack city B
- attack succeeds
- Unit A is temporarily drawn over city B
- Unit A is then drawn in its original, correct location
The problem seems to be in line 173 of GameMap.cs which draws movement of unit:
this.AddLayer(unitPicture, dx + movement.X, dy + movement.Y);
Every time you move a unit this line is called 17 times (basically 16 +1 times, where 16 is the width of a tile). I believe that it should be called just 16 times and not 17 times. This means that disabling the 17-th call solves this issue.
An ugly workaround seems to do the job:
if (!(Math.Abs(movement.X) == 16 || Math.Abs(movement.Y) == 16)) this.AddLayer(unitPicture, dx + movement.X, dy + movement.Y);
However a more elegant way would be to change line 34 in MoveUnit.cs:
if (_step <= 15)
But this doesn't seem to work, even though the drawing code is in this case called just 16 times.
Any thaughts?
I think you're on to something here.
If you add a Console.Writeline()
statement showing the values of movement.X,Y to GameMap.cs just before line 173, you can see that the bitmap is drawn 16 times: for values (0,0),(2,2),etc through (16,16).
I had the best results with this version of MoveUnit.cs, Step()
:
protected override bool Step()
{
X = (RelX * _step);
Y = (RelY * _step);
_step += STEP_SIZE;
if (_step <= 16)
return true;
EndTask();
return true;
}
With the above change, the drawing happens for (0,0),(1,1),etc through (15,15).
Unfortunately, this change doesn't seem to eliminate the extra draw all the time. I think it is happening less frequently with the change but not all the time. I think it would be useful to understand when else the unit in question is being drawn.
If you add a Console.Writeline() statement showing the values of movement.X,Y to GameMap.cs just before line 173, you can see that the bitmap is drawn 16 times: for values (0,0),(2,2),etc through (16,16).
Any idea why it skips (1,1)? Was it intentional on SWY's behalf?
It's strange that doing the "ugly workaround" I mentioned in my previous post seems to do the job, but I have no idea why.
Any idea why it skips (1,1)? Was it intentional on SWY's behalf? Logic error. _step is initialized to 1, then incremented first, so first draw is for 2. By doing the increment later, the first draw is for 1.
I thought about initializing _step to 0, but that caused something else to go wrong, but I've forgotten what already ...
It's strange that doing the "ugly workaround" I mentioned in my previous post seems to do the job, but I have no idea why.
I'm going to have to re-visit your workaround because my change doesn't seem to solve every instance. I still get the attacker drawing over the target occasionally.