Changeset 294 for trunk/UBuilding.pas


Ignore:
Timestamp:
Mar 29, 2019, 8:40:42 AM (6 years ago)
Author:
chronos
Message:
  • Modified: Change terrain type ttCity to map cell building with special type stCity.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UBuilding.pas

    r290 r294  
    99
    1010type
     11  TBuildingSpecialType = (stNone, stCity);
    1112
    1213  { TBuildingKind }
     
    1415  TBuildingKind = class(TItem)
    1516    Cost: Integer;
     17    SpecialType: TBuildingSpecialType;
    1618    class function GetFields: TItemFields; override;
    1719    procedure GetValue(Index: Integer; out Value); override;
     
    2527  TBuildingKinds = class(TItemList)
    2628    class function GetItemClass: TItemClass; override;
     29    function FindBySpecialType(SpecialType: TBuildingSpecialType): TItem;
    2730  end;
    2831
    29   TBuilding = class
     32  { TBuilding }
     33
     34  TBuilding = class(TItem)
     35  private
     36    FMapCell: TObject;
     37    procedure SetMapCell(AValue: TObject);
     38  public
    3039    Kind: TBuildingKind;
     40    property MapCell: TObject read FMapCell write SetMapCell; // TMapCell;
     41  end;
     42
     43  { TBuildings }
     44
     45  TBuildings = class(TItemList)
     46    Game: TObject; // TGame;
     47    class function GetItemClass: TItemClass; override;
    3148  end;
    3249
     
    3451  SBuildingKind = 'Building';
    3552  SCost = 'Cost';
     53  SSpecialType = 'Special type';
    3654
    3755
    3856implementation
     57
     58uses
     59  UMap;
     60
     61{ TBuildings }
     62
     63class function TBuildings.GetItemClass: TItemClass;
     64begin
     65  Result := TBuilding;
     66end;
     67
     68{ TBuilding }
     69
     70procedure TBuilding.SetMapCell(AValue: TObject);
     71var
     72  OldValue: TCell;
     73begin
     74  if FMapCell = AValue then Exit;
     75  OldValue := TCell(FMapCell);
     76  FMapCell := nil;
     77  if Assigned(OldValue) then TCell(OldValue).Building := nil;
     78  FMapCell := AValue;
     79  if Assigned(FMapCell) then TCell(FMapCell).Building := Self;
     80end;
    3981
    4082{ TBuildingKind }
     
    4486  Result := inherited;
    4587  Result.AddField(2, 'Cost', SCost, dtInteger);
     88  Result.AddField(3, 'SpecialType', SSpecialType, dtInteger);
    4689end;
    4790
     
    5093  if Index = 1 then string(Value) := Name
    5194  else if Index = 2 then Integer(Value) := Cost
     95  else if Index = 3 then TBuildingSpecialType(Value) := SpecialType
    5296  else raise Exception.Create('Unsupported value index ' + IntToStr(Index));
    5397end;
     
    57101  if Index = 1 then Name := string(Value)
    58102  else if Index = 2 then Cost := Integer(Value)
     103  else if Index = 3 then SpecialType := TBuildingSpecialType(Value)
    59104  else raise Exception.Create('Unsupported value index ' + IntToStr(Index));
    60105end;
     
    77122end;
    78123
     124function TBuildingKinds.FindBySpecialType(SpecialType: TBuildingSpecialType
     125  ): TItem;
     126var
     127  I: Integer;
     128begin
     129  I := 0;
     130  while (I < Count) and (TBuildingKind(Items[I]).SpecialType <> SpecialType) do Inc(I);
     131  if I < Count then Result := Items[I]
     132    else Result := nil;
     133end;
     134
    79135end.
    80136
Note: See TracChangeset for help on using the changeset viewer.