hedgewars/uLandUtils.pas
branchtransitional_engine
changeset 15934 022ec6b916b7
parent 15933 33798b649d9c
child 15958 772a43d88e6b
equal deleted inserted replaced
15933:33798b649d9c 15934:022ec6b916b7
     1 unit uLandUtils;
     1 unit uLandUtils;
     2 interface
     2 interface
     3 uses SDLh;
     3 uses SDLh;
     4 
     4 
     5 procedure CreateTemplatedLand(featureSize: Longword; seed, dataPath, theme: shortstring);
     5 procedure GenerateTemplatedLand(featureSize: Longword; seed, templateType, dataPath: shortstring);
     6 procedure ResizeLand(width, height: LongWord);
     6 procedure ResizeLand(width, height: LongWord);
     7 procedure DisposeLand();
     7 procedure DisposeLand();
     8 procedure InitWorldEdges();
     8 procedure InitWorldEdges();
     9 
     9 
    10 function  LandGet(y, x: LongInt): Word;
    10 function  LandGet(y, x: LongInt): Word;
    21 uses uUtils, uConsts, uVariables, uTypes;
    21 uses uUtils, uConsts, uVariables, uTypes;
    22 
    22 
    23 const LibFutureName = 'hwengine_future';
    23 const LibFutureName = 'hwengine_future';
    24 
    24 
    25 function  create_empty_game_field(width, height: Longword): pointer; cdecl; external LibFutureName;
    25 function  create_empty_game_field(width, height: Longword): pointer; cdecl; external LibFutureName;
    26 procedure get_game_field_parameters(game_field: pointer; var width: LongInt; var height: LongInt); cdecl; external LibFutureName;
    26 procedure get_game_field_parameters(game_field: pointer; var width: LongInt; var height: LongInt; var play_width: LongInt; var play_height: LongInt); cdecl; external LibFutureName;
    27 procedure dispose_game_field(game_field: pointer); cdecl; external LibFutureName;
    27 procedure dispose_game_field(game_field: pointer); cdecl; external LibFutureName;
    28 
    28 
    29 function  land_get(game_field: pointer; x, y: LongInt): Word; cdecl; external LibFutureName;
    29 function  land_get(game_field: pointer; x, y: LongInt): Word; cdecl; external LibFutureName;
    30 procedure land_set(game_field: pointer; x, y: LongInt; value: Word); cdecl; external LibFutureName;
    30 procedure land_set(game_field: pointer; x, y: LongInt; value: Word); cdecl; external LibFutureName;
    31 function  land_row(game_field: pointer; row: LongInt): PWordArray; cdecl; external LibFutureName;
    31 function  land_row(game_field: pointer; row: LongInt): PWordArray; cdecl; external LibFutureName;
    33 
    33 
    34 function  land_pixel_get(game_field: pointer; x, y: LongInt): Longword; cdecl; external LibFutureName;
    34 function  land_pixel_get(game_field: pointer; x, y: LongInt): Longword; cdecl; external LibFutureName;
    35 procedure land_pixel_set(game_field: pointer; x, y: LongInt; value: Longword); cdecl; external LibFutureName;
    35 procedure land_pixel_set(game_field: pointer; x, y: LongInt; value: Longword); cdecl; external LibFutureName;
    36 function  land_pixel_row(game_field: pointer; row: LongInt): PLongwordArray; cdecl; external LibFutureName;
    36 function  land_pixel_row(game_field: pointer; row: LongInt): PLongwordArray; cdecl; external LibFutureName;
    37 
    37 
    38 function  generate_templated_game_field(feature_size: Longword; seed, data_path, theme_name: PChar): pointer; cdecl; external LibFutureName;
    38 function  generate_templated_game_field(feature_size: Longword; seed, template_type, data_path: PChar): pointer; cdecl; external LibFutureName;
       
    39 procedure apply_theme(game_field: pointer; data_path, theme_name: PChar); cdecl; external LibFutureName;
    39 
    40 
    40 var gameField: pointer;
    41 var gameField: pointer;
    41 
    42 
    42 function  LandGet(y, x: LongInt): Word;
    43 function  LandGet(y, x: LongInt): Word;
    43 begin
    44 begin
    72 function  LandPixelRow(row: LongInt): PLongwordArray;
    73 function  LandPixelRow(row: LongInt): PLongwordArray;
    73 begin
    74 begin
    74     LandPixelRow:= land_pixel_row(gameField, row)
    75     LandPixelRow:= land_pixel_row(gameField, row)
    75 end;
    76 end;
    76 
    77 
    77 procedure CreateTemplatedLand(featureSize: Longword; seed, dataPath, theme: shortstring);
    78 procedure GenerateTemplatedLand(featureSize: Longword; seed, templateType, dataPath: shortstring);
    78 begin
    79 begin
    79     seed[byte(seed[0]) + 1]:= #0;
    80     seed[byte(seed[0]) + 1]:= #0;
    80     theme[byte(theme[0]) + 1]:= #0;
    81     templateType[byte(templateType[0]) + 1]:= #0;
    81 
    82 
    82     gameField:= generate_templated_game_field(featureSize, @seed[1], Str2PChar(dataPath), @theme[1]);
    83     gameField:= generate_templated_game_field(featureSize, @seed[1], @templateType[1], Str2PChar(dataPath));
    83     get_game_field_parameters(gameField, LAND_WIDTH, LAND_HEIGHT);
    84     get_game_field_parameters(gameField, LAND_WIDTH, LAND_HEIGHT, playWidth, playHeight);
       
    85 
       
    86     MaxHedgehogs:= 32;
       
    87     hasGirders:= true;
       
    88 
       
    89     leftX:= (LAND_WIDTH - playWidth) div 2;
       
    90     rightX:= Pred(leftX + playWidth);
       
    91     topY:= LAND_HEIGHT - playHeight;
       
    92 
    84 
    93 
    85     // let's assume those are powers of two
    94     // let's assume those are powers of two
    86     LAND_WIDTH_MASK:= not(LAND_WIDTH-1);
    95     LAND_WIDTH_MASK:= not(LAND_WIDTH-1);
    87     LAND_HEIGHT_MASK:= not(LAND_HEIGHT-1);
    96     LAND_HEIGHT_MASK:= not(LAND_HEIGHT-1);
    88 
    97