Changeset 274 for trunk/UPlayer.pas
- Timestamp:
- Feb 3, 2019, 8:32:20 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UPlayer.pas
r273 r274 28 28 procedure DisconnectFrom(Cell: TPlayerCell); 29 29 function GetAvialPower: Integer; 30 function GetAvialPowerForMove: Integer; 30 31 function GetAttackPower: Integer; 31 32 procedure LoadFromNode(Node: TDOMNode); … … 102 103 procedure CheckCounterMove(Move: TUnitMove); 103 104 procedure SetMode(AValue: TPlayerMode); 104 procedure RemoveEmptyUnitMoves;105 105 public 106 106 Id: Integer; … … 120 120 Moves: TUnitMoves; 121 121 Units: TUnits; 122 function IsAllowedMoveTarget(CellFrom, CellTo: TPlayerCell): Boolean; 122 123 procedure ReduceMovesPower; 123 124 procedure RemoveInvalidMoves; 124 125 procedure RemoveEmptyUnits; 126 procedure InitUnitMoves; 125 127 procedure UpdateRepeatMoves; 126 128 procedure UpdateEmptyCellsNeutral; … … 205 207 206 208 uses 207 UGame ;209 UGame, UGameSystem; 208 210 209 211 resourcestring … … 262 264 UnitMove: TUnitMove; 263 265 begin 264 if Assigned(MapCell.OneUnit) then Result := MapCell.OneUnit.Power 265 else Result := 0; 266 Result := 0; 267 if Assigned(MapCell.OneUnit) then 268 Result := MapCell.OneUnit.Power; 269 for UnitMove in MovesFrom do 270 Result := Result - UnitMove.CountOnce; 271 end; 272 273 function TPlayerCell.GetAvialPowerForMove: Integer; 274 var 275 UnitMove: TUnitMove; 276 begin 277 Result := 0; 278 if Assigned(MapCell.OneUnit) then 279 if MapCell.OneUnit.Moves > 0 then Result := MapCell.OneUnit.Power; 266 280 for UnitMove in MovesFrom do 267 281 Result := Result - UnitMove.CountOnce; … … 999 1013 // Inner move 1000 1014 CellTo.MapCell.OneUnit.Power := CellTo.MapCell.OneUnit.Power + UnitCount; 1015 Dec(CellTo.MapCell.OneUnit.Moves); 1001 1016 end else begin 1002 1017 AttackerPower := UnitCount; … … 1015 1030 // Defender wins with possible loses 1016 1031 CellTo.MapCell.OneUnit.Power := DefenderPower; 1032 CellTo.MapCell.OneUnit.Moves := CellFrom.MapCell.OneUnit.Moves - 1; 1017 1033 end else 1018 1034 raise Exception.Create(SUnfinishedBattle); … … 1020 1036 CellFrom.MapCell.OneUnit.Power := CellFrom.MapCell.OneUnit.Power - UnitCount; 1021 1037 end; 1038 1039 // Clean from cell from empty units 1040 if UnitMove.CellFrom.MapCell.OneUnit.Power = 0 then begin 1041 Units.Remove(UnitMove.CellFrom.MapCell.OneUnit); 1042 UnitMove.CellFrom.MapCell.OneUnit := nil; 1043 end; 1044 1045 // Remove empty move 1046 if (UnitMove.CellFrom.MapCell.Player = Self) and 1047 (UnitMove.CountOnce = 0) and (UnitMove.CountRepeat = 0) then 1048 Moves.Remove(UnitMove); 1022 1049 end; 1023 1050 1024 1051 procedure TPlayer.MoveAll; 1025 1052 var 1026 UnitMove: TUnitMove;1027 begin 1028 for UnitMove in Movesdo1029 with UnitMovedo1053 I: Integer; 1054 begin 1055 for I := Moves.Count - 1 downto 0 do 1056 with Moves[I] do 1030 1057 if CountOnce > 0 then begin 1031 1058 if CellFrom.MapCell.Player = Self then begin 1032 MoveUnit(UnitMove); 1033 end; 1034 end; 1035 1036 RemoveEmptyUnitMoves; 1059 MoveUnit(Moves[I]); 1060 end; 1061 end; 1037 1062 end; 1038 1063 … … 1077 1102 end; 1078 1103 1104 procedure TPlayer.InitUnitMoves; 1105 var 1106 I: Integer; 1107 begin 1108 for I := 0 to Units.Count - 1 do 1109 TUnit(Units[I]).Moves := TUnit(Units[I]).Kind.Moves; 1110 end; 1111 1079 1112 procedure TPlayer.ClearMovesFromCell(Cell: TPlayerCell); 1080 1113 var … … 1105 1138 1106 1139 if Assigned(Result) then begin 1140 // Update existing move 1107 1141 CountOnce := Result.CountOnce; 1108 1142 CountRepeat := Result.CountRepeat; … … 1111 1145 FOnMove(CellFrom, CellTo, CountOnce, CountRepeat, True, Confirm); 1112 1146 end else begin 1147 // Create new move 1113 1148 CountOnce := Power; 1114 1149 CountRepeat := 0; … … 1139 1174 Result := NewMove; 1140 1175 CheckCounterMove(NewMove); 1176 if TGame(Game).GameSystem.UnitsMoveImmediately then begin 1177 MoveUnit(NewMove); 1178 end; 1141 1179 end; 1142 1180 end; … … 1160 1198 end; 1161 1199 end; 1162 RemoveEmptyUnitMoves;1163 1200 end; 1164 1201 … … 1173 1210 MapCell.Player := nil; 1174 1211 end; 1175 end;1176 1177 procedure TPlayer.RemoveEmptyUnitMoves;1178 var1179 I: Integer;1180 begin1181 for I := Moves.Count - 1 downto 0 do1182 if (TUnitMove(Moves[I]).CellFrom.MapCell.Player = Self) and1183 (TUnitMove(Moves[I]).CountOnce = 0) and (TUnitMove(Moves[I]).CountRepeat = 0) then1184 Moves.Delete(I);1185 1212 end; 1186 1213 … … 1230 1257 end; 1231 1258 1259 function TPlayer.IsAllowedMoveTarget(CellFrom, CellTo: TPlayerCell): Boolean; 1260 var 1261 CellToHasOwnUnit: Boolean; 1262 UnitHasMoveEnergy: Boolean; 1263 begin 1264 CellToHasOwnUnit := Assigned(CellTo.MapCell.OneUnit) and 1265 (CellTo.MapCell.OneUnit.Player = Self) and (CellTo.MapCell.OneUnit.Power > 0); 1266 UnitHasMoveEnergy := Assigned(CellFrom.MapCell.OneUnit) and 1267 (CellFrom.MapCell.OneUnit.Moves > 0); 1268 Result := UnitHasMoveEnergy and 1269 TGame(Game).Map.IsCellsNeighbor(CellFrom.MapCell, CellTo.MapCell) 1270 and (TGame(Game).GameSystem.UnitsSplitMerge or 1271 (not TGame(Game).GameSystem.UnitsSplitMerge and not CellToHasOwnUnit)); 1272 end; 1273 1232 1274 procedure TPlayer.Grow; 1233 1275 var … … 1235 1277 Addition: Integer; 1236 1278 Dies: Integer; 1279 NewUnit: TUnit; 1237 1280 begin 1238 1281 with TGame(Game).Map do … … 1241 1284 if (Player = Self) and ((TGame(Game).GrowCells = gcPlayerAll) or 1242 1285 ((TGame(Game).GrowCells = gcPlayerCities) and (Terrain = ttCity))) then begin 1286 if not Assigned(OneUnit) then begin 1287 NewUnit := TGame(Game).Units.AddNew(TGame(Game).GameSystem.UnitKinds.First, 0); 1288 NewUnit.Player := Self; 1289 NewUnit.MapCell := TCell(Cells[I]); 1290 Units.Add(NewUnit); 1291 end; 1243 1292 if OneUnit.Power < MaxPower then begin 1244 1293 // Increase units count
Note:
See TracChangeset
for help on using the changeset viewer.