Skip to content

Commit b147252

Browse files
committed
rename explosions events to deaths
1 parent 6885fa6 commit b147252

File tree

9 files changed

+126
-97
lines changed

9 files changed

+126
-97
lines changed

.github/workflows/csharp.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: C#
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
11+
- name: install .NET SDK
12+
uses: actions/setup-dotnet@v4
13+
with:
14+
dotnet-version: '8.0.x'
15+
16+
- name: compile
17+
run: |
18+
mkdir temp_proj
19+
cd temp_proj
20+
dotnet new console --framework net8.0
21+
find ../ -name '*.cs' -not -path "../temp_proj/*" -exec cp {} . \; # copy source files
22+
dotnet add package System.Text.Json
23+
dotnet add package System.Memory
24+
dotnet build --configuration Release

c/uwapi/uwapi/modules/game.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern "C"
4747
UNNATURAL_ENTRY void uwUpdateCallback(bool stepping);
4848
#endif
4949

50-
// shooting callback
50+
// shootings callback
5151

5252
typedef struct UwShootingUnit
5353
{
@@ -61,39 +61,40 @@ extern "C"
6161
UwShootingUnit shooter;
6262
UwShootingUnit target;
6363
} UwShootingData;
64-
typedef struct UwShootingArray
64+
typedef struct UwShootingsArray
6565
{
6666
UNNATURAL_POINTER(const UwShootingData *) data;
6767
uint32 count;
68-
} UwShootingArray;
68+
} UwShootingsArray;
6969
#ifdef UNNATURAL_BOTS
70-
typedef void (*UwShootingCallbackType)(const UwShootingArray *data);
71-
UNNATURAL_API void uwSetShootingCallback(UwShootingCallbackType callback);
70+
typedef void (*UwShootingsCallbackType)(const UwShootingsArray *data);
71+
UNNATURAL_API void uwSetShootingsCallback(UwShootingsCallbackType callback);
7272
#endif
7373
#ifdef UNNATURAL_SCRIPTS
74-
UNNATURAL_ENTRY void uwShootingCallback(const UwShootingArray *data);
74+
UNNATURAL_ENTRY void uwShootingsCallback(const UwShootingsArray *data);
7575
#endif
7676

77-
// explosions callback
77+
// deaths callback
7878

79-
typedef struct UwExplosionData
79+
typedef struct UwDeathData
8080
{
8181
uint32 position;
8282
uint32 force;
8383
uint32 prototype;
8484
uint32 id; // beware, it is expired
85-
} UwExplosionData;
86-
typedef struct UwExplosionsArray
85+
bool explosion;
86+
} UwDeathData;
87+
typedef struct UwDeathsArray
8788
{
88-
UNNATURAL_POINTER(const UwExplosionData *) data;
89+
UNNATURAL_POINTER(const UwDeathData *) data;
8990
uint32 count;
90-
} UwExplosionsArray;
91+
} UwDeathsArray;
9192
#ifdef UNNATURAL_BOTS
92-
typedef void (*UwExplosionsCallbackType)(const UwExplosionsArray *data);
93-
UNNATURAL_API void uwSetExplosionsCallback(UwExplosionsCallbackType callback);
93+
typedef void (*UwDeathsCallbackType)(const UwDeathsArray *data);
94+
UNNATURAL_API void uwSetDeathsCallback(UwDeathsCallbackType callback);
9495
#endif
9596
#ifdef UNNATURAL_SCRIPTS
96-
UNNATURAL_ENTRY void uwExplosionsCallback(const UwExplosionsArray *data);
97+
UNNATURAL_ENTRY void uwDeathsCallback(const UwDeathsArray *data);
9798
#endif
9899

99100
// force eliminated callback

csharp/uwapi/events.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ namespace Unnatural
77
using GameStateEnum = Interop.UwGameStateEnum;
88
using MapStateEnum = Interop.UwMapStateEnum;
99
using ShootingData = Interop.UwShootingData;
10-
using ShootingArray = Interop.UwShootingArray;
11-
using ExplosionData = Interop.UwExplosionData;
12-
using ExplosionsArray = Interop.UwExplosionsArray;
10+
using ShootingsArray = Interop.UwShootingsArray;
11+
using DeathData = Interop.UwDeathData;
12+
using DeathsArray = Interop.UwDeathsArray;
1313
using ChatTargetFLags = Interop.UwChatTargetFlags;
1414

1515
public class ChatMessage
@@ -26,8 +26,8 @@ public static class Events
2626
public static event EventHandler<GameStateEnum> GameStateChanged;
2727
public static event EventHandler<MapStateEnum> MapStateChanged;
2828
public static event EventHandler<bool> Updating;
29-
public static event EventHandler<ShootingData[]> Shooting;
30-
public static event EventHandler<ExplosionData[]> Explosions;
29+
public static event EventHandler<ShootingData[]> Shootings;
30+
public static event EventHandler<DeathData[]> Deaths;
3131
public static event EventHandler<uint> ForceEliminated;
3232
public static event EventHandler<ChatMessage> ChatReceived;
3333

@@ -36,8 +36,8 @@ public static class Events
3636
static readonly Interop.UwGameStateCallbackType GameStateDelegate = new Interop.UwGameStateCallbackType(GameStateCallback);
3737
static readonly Interop.UwMapStateCallbackType MapStateDelegate = new Interop.UwMapStateCallbackType(MapStateCallback);
3838
static readonly Interop.UwUpdateCallbackType UpdateDelegate = new Interop.UwUpdateCallbackType(UpdateCallback);
39-
static readonly Interop.UwShootingCallbackType ShootingDelegate = new Interop.UwShootingCallbackType(ShootingCallback);
40-
static readonly Interop.UwExplosionsCallbackType ExplosionsDelegate = new Interop.UwExplosionsCallbackType(ExplosionsCallback);
39+
static readonly Interop.UwShootingsCallbackType ShootingsDelegate = new Interop.UwShootingsCallbackType(ShootingsCallback);
40+
static readonly Interop.UwDeathsCallbackType DeathsDelegate = new Interop.UwDeathsCallbackType(DeathsCallback);
4141
static readonly Interop.UwForceEliminatedCallbackType ForceEliminatedDelegate = new Interop.UwForceEliminatedCallbackType(ForceEliminatedCallback);
4242
static readonly Interop.UwChatCallbackType ChatDelegate = new Interop.UwChatCallbackType(ChatCallback);
4343

@@ -72,9 +72,9 @@ static void UpdateCallback(bool stepping)
7272
Updating(null, stepping);
7373
}
7474

75-
static void ShootingCallback(ref ShootingArray data)
75+
static void ShootingsCallback(ref ShootingsArray data)
7676
{
77-
if (Shooting == null)
77+
if (Shootings == null)
7878
return;
7979
ShootingData[] arr = new ShootingData[data.count];
8080
int size = Marshal.SizeOf(typeof(ShootingData));
@@ -83,21 +83,21 @@ static void ShootingCallback(ref ShootingArray data)
8383
IntPtr currentPtr = IntPtr.Add(data.data, i * size);
8484
arr[i] = Marshal.PtrToStructure<ShootingData>(currentPtr);
8585
}
86-
Shooting(null, arr);
86+
Shootings(null, arr);
8787
}
8888

89-
static void ExplosionsCallback(ref ExplosionsArray data)
89+
static void DeathsCallback(ref DeathsArray data)
9090
{
91-
if (Explosions == null)
91+
if (Deaths == null)
9292
return;
93-
ExplosionData[] arr = new ExplosionData[data.count];
94-
int size = Marshal.SizeOf(typeof(ExplosionData));
93+
DeathData[] arr = new DeathData[data.count];
94+
int size = Marshal.SizeOf(typeof(DeathData));
9595
for (int i = 0; i < data.count; i++)
9696
{
9797
IntPtr currentPtr = IntPtr.Add(data.data, i * size);
98-
arr[i] = Marshal.PtrToStructure<ExplosionData>(currentPtr);
98+
arr[i] = Marshal.PtrToStructure<DeathData>(currentPtr);
9999
}
100-
Explosions(null, arr);
100+
Deaths(null, arr);
101101
}
102102

103103
static void ForceEliminatedCallback(uint force)
@@ -130,8 +130,8 @@ static Events()
130130
Interop.uwSetGameStateCallback(GameStateDelegate);
131131
Interop.uwSetMapStateCallback(MapStateDelegate);
132132
Interop.uwSetUpdateCallback(UpdateDelegate);
133-
Interop.uwSetShootingCallback(ShootingDelegate);
134-
Interop.uwSetExplosionsCallback(ExplosionsDelegate);
133+
Interop.uwSetShootingsCallback(ShootingsDelegate);
134+
Interop.uwSetDeathsCallback(DeathsDelegate);
135135
Interop.uwSetForceEliminatedCallback(ForceEliminatedDelegate);
136136
Interop.uwSetChatCallback(ChatDelegate);
137137

csharp/uwapi/interop.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -742,39 +742,41 @@ public struct UwShootingData
742742
}
743743

744744
[StructLayout(LayoutKind.Sequential)]
745-
public struct UwShootingArray
745+
public struct UwShootingsArray
746746
{
747747
public IntPtr data;
748748
public uint count;
749749
}
750750

751751
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
752-
public delegate void UwShootingCallbackType(ref UwShootingArray data);
752+
public delegate void UwShootingsCallbackType(ref UwShootingsArray data);
753753

754754
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
755-
public static extern void uwSetShootingCallback(UwShootingCallbackType callback);
755+
public static extern void uwSetShootingsCallback(UwShootingsCallbackType callback);
756756

757757
[StructLayout(LayoutKind.Sequential)]
758-
public struct UwExplosionData
758+
public struct UwDeathData
759759
{
760760
public uint position;
761761
public uint force;
762762
public uint prototype;
763763
public uint id;
764+
[MarshalAs(UnmanagedType.I1)]
765+
public bool explosion;
764766
}
765767

766768
[StructLayout(LayoutKind.Sequential)]
767-
public struct UwExplosionsArray
769+
public struct UwDeathsArray
768770
{
769771
public IntPtr data;
770772
public uint count;
771773
}
772774

773775
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
774-
public delegate void UwExplosionsCallbackType(ref UwExplosionsArray data);
776+
public delegate void UwDeathsCallbackType(ref UwDeathsArray data);
775777

776778
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
777-
public static extern void uwSetExplosionsCallback(UwExplosionsCallbackType callback);
779+
public static extern void uwSetDeathsCallback(UwDeathsCallbackType callback);
778780

779781
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
780782
public delegate void UwForceEliminatedCallbackType(uint id);

python/uwapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
from .prototypes import uw_prototypes
1414
from .world import uw_world
1515

16-
__all__ = ["uw_admin","uw_commands","Entity","INVALID","uw_events","uw_game","UwapiLibrary","uw_map","uw_prototypes","uw_world","Severity","LogCallback","ConnectionState","MyPlayer","AssistConfig","PerformanceStatistics","OrderType","OrderPriority","Order","Orders","Ids","Priority","Ping","PathState","ForeignPolicy","ChatTarget","ProtoComponent","OwnerComponent","ControllerComponent","PositionComponent","UnitState","UnitComponent","LifeComponent","ManaComponent","MoveComponent","AimComponent","RecipeComponent","RecipeStatisticsComponent","LogisticsTimestampComponent","PriorityComponent","AmountComponent","AttachmentComponent","PingComponent","PlayerState","PlayerConnectionClass","PlayerComponent","PlayerAiConfigComponent","ForceState","ForceComponent","ForceDetailsComponent","ForeignPolicyComponent","DiplomacyProposalComponent","GameState","ShootingUnit","ShootingData","ShootingArray","ExplosionData","ExplosionsArray","TaskType","MapState","MapInfo","MapStartingPosition","MapStartingPositionsArray","Tile","Cluster","ClustersDistancesQuery","ClustersDistancesResult","PrototypeType","MyForceStatistics","UnitUpgrades","Overview","OverviewExtract","UnitPathfindingQuery","UnitPathfindingResult"]
16+
__all__ = ["uw_admin","uw_commands","Entity","INVALID","uw_events","uw_game","UwapiLibrary","uw_map","uw_prototypes","uw_world","Severity","LogCallback","ConnectionState","MyPlayer","AssistConfig","PerformanceStatistics","OrderType","OrderPriority","Order","Orders","Ids","Priority","Ping","PathState","ForeignPolicy","ChatTarget","ProtoComponent","OwnerComponent","ControllerComponent","PositionComponent","UnitState","UnitComponent","LifeComponent","ManaComponent","MoveComponent","AimComponent","RecipeComponent","RecipeStatisticsComponent","LogisticsTimestampComponent","PriorityComponent","AmountComponent","AttachmentComponent","PingComponent","PlayerState","PlayerConnectionClass","PlayerComponent","PlayerAiConfigComponent","ForceState","ForceComponent","ForceDetailsComponent","ForeignPolicyComponent","DiplomacyProposalComponent","GameState","ShootingUnit","ShootingData","ShootingsArray","DeathData","DeathsArray","TaskType","MapState","MapInfo","MapStartingPosition","MapStartingPositionsArray","Tile","Cluster","ClustersDistancesQuery","ClustersDistancesResult","PrototypeType","MyForceStatistics","UnitUpgrades","Overview","OverviewExtract","UnitPathfindingQuery","UnitPathfindingResult"]

python/uwapi/bots.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -462,30 +462,31 @@ typedef struct UwShootingData
462462
UwShootingUnit shooter;
463463
UwShootingUnit target;
464464
} UwShootingData;
465-
typedef struct UwShootingArray
465+
typedef struct UwShootingsArray
466466
{
467467
const UwShootingData *data;
468468
uint32 count;
469-
} UwShootingArray;
469+
} UwShootingsArray;
470470

471-
typedef void (*UwShootingCallbackType)(const UwShootingArray *data);
472-
void uwSetShootingCallback(UwShootingCallbackType callback);
471+
typedef void (*UwShootingsCallbackType)(const UwShootingsArray *data);
472+
void uwSetShootingsCallback(UwShootingsCallbackType callback);
473473

474-
typedef struct UwExplosionData
474+
typedef struct UwDeathData
475475
{
476476
uint32 position;
477477
uint32 force;
478478
uint32 prototype;
479479
uint32 id;
480-
} UwExplosionData;
481-
typedef struct UwExplosionsArray
480+
bool explosion;
481+
} UwDeathData;
482+
typedef struct UwDeathsArray
482483
{
483-
const UwExplosionData *data;
484+
const UwDeathData *data;
484485
uint32 count;
485-
} UwExplosionsArray;
486+
} UwDeathsArray;
486487

487-
typedef void (*UwExplosionsCallbackType)(const UwExplosionsArray *data);
488-
void uwSetExplosionsCallback(UwExplosionsCallbackType callback);
488+
typedef void (*UwDeathsCallbackType)(const UwDeathsArray *data);
489+
void uwSetDeathsCallback(UwDeathsCallbackType callback);
489490
typedef void (*UwForceEliminatedCallbackType)(uint32 id);
490491
void uwSetForceEliminatedCallback(UwForceEliminatedCallbackType callback);
491492
typedef void (*UwChatCallbackType)(const char *msg, uint32 sender, UwChatTargetFlags flags);

python/uwapi/events.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class Events:
88
_connection_state_listeners: List[Callable[[UwConnectionStateEnum], None]] = []
99
_game_state_listeners: List[Callable[[UwGameStateEnum], None]] = []
1010
_update_listeners: List[Callable[[bool], None]] = []
11-
_shooting_listeners: List[Callable[[UwShootingArray], None]] = []
12-
_explosions_listeners: List[Callable[[UwExplosionsArray], None]] = []
11+
_shootings_listeners: List[Callable[[UwShootingsArray], None]] = []
12+
_deaths_listeners: List[Callable[[UwDeathsArray], None]] = []
1313
_force_eliminated_listeners: List[Callable[[int], None]] = []
1414
_chat_listeners: List[Callable[[str, int, UwChatTargetFlags], None]] = []
1515
_map_state_listeners: List[Callable[[UwMapStateEnum], None]] = []
@@ -25,8 +25,8 @@ def initialize(self) -> None:
2525
uw_interop.uwSetConnectionStateCallback(self._connection_state_callback)
2626
uw_interop.uwSetGameStateCallback(self._game_state_callback)
2727
uw_interop.uwSetUpdateCallback(self._update_callback)
28-
uw_interop.uwSetShootingCallback(self._shooting_callback)
29-
uw_interop.uwSetExplosionsCallback(self._explosions_callback)
28+
uw_interop.uwSetShootingsCallback(self._shootings_callback)
29+
uw_interop.uwSetDeathsCallback(self._deaths_callback)
3030
uw_interop.uwSetForceEliminatedCallback(self._force_eliminated_callback)
3131
uw_interop.uwSetChatCallback(self._chat_callback)
3232
uw_interop.uwSetTaskCompletedCallback(self._task_completed_callback)
@@ -45,11 +45,11 @@ def on_game_state(self, listener: Callable[[UwGameStateEnum], None]) -> None:
4545
def on_update(self, listener: Callable[[bool], None]) -> None:
4646
self._update_listeners.append(listener)
4747

48-
def on_shooting(self, listener: Callable[[UwShootingArray], None]) -> None:
49-
self._shooting_listeners.append(listener)
48+
def on_shootings(self, listener: Callable[[UwShootingsArray], None]) -> None:
49+
self._shootings_listeners.append(listener)
5050

51-
def on_explosions(self, listener: Callable[[UwExplosionsArray], None]) -> None:
52-
self._explosions_listeners.append(listener)
51+
def on_deaths(self, listener: Callable[[UwDeathsArray], None]) -> None:
52+
self._deaths_listeners.append(listener)
5353

5454
def on_force_eliminated(self, listener: Callable[[int], None]) -> None:
5555
self._force_eliminated_listeners.append(listener)
@@ -78,12 +78,12 @@ def _update_callback(self, stepping: bool) -> None:
7878
for listener in self._update_listeners:
7979
listener(stepping)
8080

81-
def _shooting_callback(self, data: UwShootingArray) -> None:
82-
for listener in self._shooting_listeners:
81+
def _shootings_callback(self, data: UwShootingsArray) -> None:
82+
for listener in self._shootings_listeners:
8383
listener(data)
8484

85-
def _explosions_callback(self, data: UwExplosionsArray) -> None:
86-
for listener in self._explosions_listeners:
85+
def _deaths_callback(self, data: UwDeathsArray) -> None:
86+
for listener in self._deaths_listeners:
8787
listener(data)
8888

8989
def _force_eliminated_callback(self, force: int) -> None:

0 commit comments

Comments
 (0)