Skip to content

Commit

Permalink
refactor: continue work on move startCombat to Nim
Browse files Browse the repository at this point in the history
FossilOrigin-Name: f3ecc68dea0d639048fe0084e7f9ee1f8c1f8e1d0cf99b9f5b3337bfcd2fc567
  • Loading branch information
thindil committed Jul 26, 2023
1 parent d391381 commit 7cdab21
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nim/src/combat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,15 @@ type
loot: cint
perception: cint
guns: array[10, array[3, cint]]
name: cstring

proc getAdaEnemy(adaEnemy: var AdaEnemyData) {.raises: [], tags: [], exportc.} =
adaEnemy.accuracy = enemy.accuracy.cint
adaEnemy.combatAi = enemy.combatAi.ord.cint
adaEnemy.evasion = enemy.evasion.cint
adaEnemy.loot = enemy.loot.cint
adaEnemy.perception = enemy.perception.cint
adaEnemy.name = enemyName.cstring
for index, gun in enemy.guns:
adaEnemy.guns[index] = [gun[1].cint, gun[2].cint, gun[3].cint]
if enemy.guns.len < 10:
Expand Down
40 changes: 40 additions & 0 deletions src/combat.adb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

with Ada.Strings;
with Ada.Strings.Fixed;
with Interfaces.C.Strings;
with GNAT.String_Split;
with Crew; use Crew;
with Messages; use Messages;
Expand Down Expand Up @@ -70,6 +71,7 @@ package body Combat is

function Start_Combat
(Enemy_Index: Positive; New_Combat: Boolean := True) return Boolean is
use Interfaces.C.Strings;
use Trades;
use Tiny_String;

Expand All @@ -78,13 +80,51 @@ package body Combat is
Enemy_Guns: Guns_Container.Vector;
--## rule on IMPROPER_INITIALIZATION
Shooting_Speed: Integer := 0;
type Nim_Guns is array(0 .. 9, 0 .. 2) of Integer;
type Nim_Enemy_Record is record
Accuracy: Natural := 0;
Combat_Ai: Integer := 0;
Evasion: Natural := 0;
Loot: Natural := 0;
Perception: Natural := 0;
Guns: Nim_Guns;
Name: chars_ptr;
end record;
Nim_Enemy: Nim_Enemy_Record;
Result: Integer;
function Start_Ada_Combat
(E_Index, N_Combat: Integer) return Integer with
Import => True,
Convention => C,
External_Name => "startAdaCombat";
procedure Get_Ada_Enemy
(Nim_Enemy: out Nim_Enemy_Record) with
Import => True,
Convention => C,
External_Name => "getAdaEnemy";
begin
Enemy_Ship_Index := Enemy_Index;
Faction_Name :=
Get_Faction(Index => Get_Proto_Ship(Proto_Index => Enemy_Index).Owner)
.Name;
Harpoon_Duration := 0;
Boarding_Orders.Clear;
Enemy.Distance := 10_000;
Enemy.Harpoon_Duration := 0;
Result := Start_Ada_Combat(E_Index => Enemy_Index, N_Combat => (if New_Combat then 1 else 0));
Get_Ada_Enemy(Nim_Enemy => Nim_Enemy);
Enemy.Accuracy := Nim_Enemy.Accuracy;
Enemy.Combat_Ai := Ship_Combat_Ai'Val(Nim_Enemy.Combat_Ai);
Enemy.Evasion := Nim_Enemy.Evasion;
Enemy.Loot := Nim_Enemy.Loot;
Enemy.Perception := Nim_Enemy.Perception;
End_Combat := False;
Enemy_Name := To_Bounded_String(Source => Value(Item => Nim_Enemy.Name));
Messages_Starts := Get_Last_Message_Index + 1;
Get_Ship_From_Nim(Ship => Enemy.Ship);
if Result = 1 then
return True;
end if;
Enemy_Ship :=
Create_Ship
(Proto_Index => Enemy_Index, Name => Null_Bounded_String,
Expand Down

0 comments on commit 7cdab21

Please sign in to comment.