Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Cofined land sprays - normal placement edition

  • Loading branch information...
KoBeWi committed Apr 6, 2017
1 parent 5dc33d8 commit 0ae705807028fa02f5d798c902ae3eec367e1242
Showing with 79 additions and 5 deletions.
  1. +2 −0 hedgewars/uLand.pas
  2. +75 −5 hedgewars/uLandObjects.pas
  3. +2 −0 hedgewars/uVariables.pas
@@ -187,6 +187,8 @@ procedure ColorizeLand(Surface: PSDL_Surface);
y: LongInt; // stupid SDL 1.2 uses stupid SmallInt for y which limits us to 32767. But is even worse if LandTex is large, can overflow on 32767 map.
begin
tmpsurf:= LoadDataImage(ptCurrTheme, 'LandTex', ifCritical or ifIgnoreCaps);
cLandTexWidth:= tmpsurf^.w;
cLandTexHeight:= tmpsurf^.h;
r.y:= 0;
y:= 0;
while y < LAND_HEIGHT do
@@ -60,6 +60,8 @@ TSprayObject = record
Surf: PSDL_Surface;
Width, Height: Longword;
Maxcnt: Longword;
validAreas: array[0..Pred(MAXOBJECTRECTS)] of TSDL_Rect;
validAreaCount: Longword;
end;
TSprayObjects = record
Count: LongInt;
@@ -416,9 +418,10 @@ function TryPut(var Obj: TSprayObject; Surface: PSDL_Surface): boolean; overload
const MaxPointsIndex = 8095;
var x, y: Longword;
ar: array[0..MaxPointsIndex] of TPoint;
cnt, i: Longword;
cnt, i, randRect: Longword;
r: TSDL_Rect;
bRes: boolean;
tempd: Smallint;
begin
TryPut:= false;
cnt:= 0;
@@ -432,13 +435,33 @@ function TryPut(var Obj: TSprayObject; Surface: PSDL_Surface): boolean; overload
r.w:= Width;
r.h:= Height + 16;
repeat
y:= 8;
y:= 0;

if validAreaCount > 0 then
begin
randRect:= getRandom(validAreaCount);
tempd:= (validAreas[randRect].x + getrandom(validAreas[randRect].w+1) - (x mod cLandTexWidth));
if (tempd > 0) then
x:= x + (tempd - Round(Width/2))
else
x:= x + ((cLandTexWidth + tempd) - Round(Width/2));
end;

repeat
if CheckLand(r, x, y - 8, lfBasic)
if validAreaCount > 0 then
begin
tempd:= validAreas[randRect].y + getrandom(validAreas[randRect].h+1) - ((y+8) mod cLandTexHeight);
if (tempd > 0) then
y:= y + tempd - Round(Height/2)
else
y:= y + (cLandTexHeight + tempd) - Round(Height/2);
end;

if CheckLand(r, x, y, lfBasic)
and (not CheckIntersect(x, y, Width, Height)) then
begin
ar[cnt].x:= x;
ar[cnt].y:= y;
ar[cnt].y:= y + 8;
inc(cnt);
if cnt > MaxPointsIndex then // buffer is full, do not check the rest land
begin
@@ -706,7 +729,54 @@ procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSpra
Width:= Surf^.w;
Height:= Surf^.h;
Delete(s, 1, i);
Maxcnt:= StrToInt(Trim(s));

t:= 0;
for ii := 1 to Length(S) do
if S[ii] = ',' then
inc(t);

if (t < 3) then
Maxcnt:= StrToInt(Trim(s))
else
begin
i:= Pos(',', s);
Maxcnt:= StrToInt(Trim(Copy(s, 1, Pred(i))));
Delete(s, 1, i);
end;

while (t >= 4) do
begin
with validAreas[validAreaCount] do
begin
i:= Pos(',', s);
x:= StrToInt(Trim(Copy(s, 1, Pred(i))));
Delete(s, 1, i);

i:= Pos(',', s);
y:= StrToInt(Trim(Copy(s, 1, Pred(i))));
Delete(s, 1, i);

i:= Pos(',', s);
w:= StrToInt(Trim(Copy(s, 1, Pred(i))));
Delete(s, 1, i);

if t = 4 then
h:= StrToInt(Trim(s))
else
begin
i:= Pos(',', s);
h:= StrToInt(Trim(Copy(s, 1, Pred(i))));
Delete(s, 1, i)
end;
end;

inc(validAreaCount);
t:= 1;
for ii := 1 to Length(S) do
if S[ii] = ',' then
inc(t);

end;
end;
end
else if key = 'flakes' then
@@ -49,6 +49,8 @@ interface
cFlattenClouds : boolean;
cIce : boolean;
cSnow : boolean;
cLandTexWidth : longword;
cLandTexHeight : longword;

cAltDamage : boolean;
cReducedQuality : LongWord;

0 comments on commit 0ae7058

Please sign in to comment.
You can’t perform that action at this time.