Skip to content

Commit 2233997

Browse files
committed
remove deaths events
1 parent b147252 commit 2233997

File tree

9 files changed

+48
-199
lines changed

9 files changed

+48
-199
lines changed

c/uwapi/uwapi/modules/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern "C"
3434
typedef uint64_t uint64;
3535
typedef int64_t sint64;
3636

37-
static const uint32 UW_VERSION = 39;
37+
static const uint32 UW_VERSION = 40;
3838
static const uint32 UW_GameTicksPerSecond = 20;
3939

4040
typedef struct UwIds

c/uwapi/uwapi/modules/game.h

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,16 @@ extern "C"
4949

5050
// shootings callback
5151

52-
typedef struct UwShootingUnit
52+
typedef enum UwShootingEventEnum
5353
{
54-
uint32 position;
55-
uint32 force;
56-
uint32 prototype;
57-
uint32 id; // beware, it may have expired
58-
} UwShootingUnit;
59-
typedef struct UwShootingData
60-
{
61-
UwShootingUnit shooter;
62-
UwShootingUnit target;
63-
} UwShootingData;
54+
UwShootingEventEnum_None = 0,
55+
UwShootingEventEnum_Shooting = 1,
56+
UwShootingEventEnum_Death = 2,
57+
UwShootingEventEnum_Explosion = 3,
58+
} UwShootingEventEnum;
6459
typedef struct UwShootingsArray
6560
{
66-
UNNATURAL_POINTER(const UwShootingData *) data;
61+
UNNATURAL_POINTER(const uint32 *) data;
6762
uint32 count;
6863
} UwShootingsArray;
6964
#ifdef UNNATURAL_BOTS
@@ -74,29 +69,6 @@ extern "C"
7469
UNNATURAL_ENTRY void uwShootingsCallback(const UwShootingsArray *data);
7570
#endif
7671

77-
// deaths callback
78-
79-
typedef struct UwDeathData
80-
{
81-
uint32 position;
82-
uint32 force;
83-
uint32 prototype;
84-
uint32 id; // beware, it is expired
85-
bool explosion;
86-
} UwDeathData;
87-
typedef struct UwDeathsArray
88-
{
89-
UNNATURAL_POINTER(const UwDeathData *) data;
90-
uint32 count;
91-
} UwDeathsArray;
92-
#ifdef UNNATURAL_BOTS
93-
typedef void (*UwDeathsCallbackType)(const UwDeathsArray *data);
94-
UNNATURAL_API void uwSetDeathsCallback(UwDeathsCallbackType callback);
95-
#endif
96-
#ifdef UNNATURAL_SCRIPTS
97-
UNNATURAL_ENTRY void uwDeathsCallback(const UwDeathsArray *data);
98-
#endif
99-
10072
// force eliminated callback
10173

10274
#ifdef UNNATURAL_BOTS

c/uwapi/uwapi/scripts.hpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef unnatural_uwapi_scripts_hpp_zhgfa8g4
22
#define unnatural_uwapi_scripts_hpp_zhgfa8g4
33

4-
#include <vector>
54
#include <cstring> // memcpy
5+
#include <vector>
66

77
#include "scripts.h"
88

@@ -18,7 +18,7 @@ namespace uw
1818
}
1919

2020
template<class S>
21-
requires(requires { S::data; })
21+
requires(requires { S::data; })
2222
auto makeVector(const S *src)
2323
{
2424
return makeVector(src->data, src->count);
@@ -35,6 +35,19 @@ namespace uw
3535
uwAllEntities(&ids);
3636
return makeVector(ids);
3737
}
38+
39+
inline auto shootingControlData(uint32 id)
40+
{
41+
struct ShootingControlData
42+
{
43+
UwShootingEventEnum type;
44+
uint16 count;
45+
};
46+
47+
uint16_t high = static_cast<uint16_t>(id >> 16);
48+
uint16_t low = static_cast<uint16_t>(id & 0xFFFF);
49+
return ShootingControlData{ (UwShootingEventEnum)high, low };
50+
}
3851
}
3952

4053
#endif // unnatural_uwapi_scripts_hpp_zhgfa8g4

csharp/uwapi/events.cs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ namespace Unnatural
66
using ConnectionStateEnum = Interop.UwConnectionStateEnum;
77
using GameStateEnum = Interop.UwGameStateEnum;
88
using MapStateEnum = Interop.UwMapStateEnum;
9-
using ShootingData = Interop.UwShootingData;
109
using ShootingsArray = Interop.UwShootingsArray;
11-
using DeathData = Interop.UwDeathData;
12-
using DeathsArray = Interop.UwDeathsArray;
1310
using ChatTargetFLags = Interop.UwChatTargetFlags;
1411

1512
public class ChatMessage
@@ -26,8 +23,6 @@ public static class Events
2623
public static event EventHandler<GameStateEnum> GameStateChanged;
2724
public static event EventHandler<MapStateEnum> MapStateChanged;
2825
public static event EventHandler<bool> Updating;
29-
public static event EventHandler<ShootingData[]> Shootings;
30-
public static event EventHandler<DeathData[]> Deaths;
3126
public static event EventHandler<uint> ForceEliminated;
3227
public static event EventHandler<ChatMessage> ChatReceived;
3328

@@ -37,7 +32,6 @@ public static class Events
3732
static readonly Interop.UwMapStateCallbackType MapStateDelegate = new Interop.UwMapStateCallbackType(MapStateCallback);
3833
static readonly Interop.UwUpdateCallbackType UpdateDelegate = new Interop.UwUpdateCallbackType(UpdateCallback);
3934
static readonly Interop.UwShootingsCallbackType ShootingsDelegate = new Interop.UwShootingsCallbackType(ShootingsCallback);
40-
static readonly Interop.UwDeathsCallbackType DeathsDelegate = new Interop.UwDeathsCallbackType(DeathsCallback);
4135
static readonly Interop.UwForceEliminatedCallbackType ForceEliminatedDelegate = new Interop.UwForceEliminatedCallbackType(ForceEliminatedCallback);
4236
static readonly Interop.UwChatCallbackType ChatDelegate = new Interop.UwChatCallbackType(ChatCallback);
4337

@@ -74,30 +68,7 @@ static void UpdateCallback(bool stepping)
7468

7569
static void ShootingsCallback(ref ShootingsArray data)
7670
{
77-
if (Shootings == null)
78-
return;
79-
ShootingData[] arr = new ShootingData[data.count];
80-
int size = Marshal.SizeOf(typeof(ShootingData));
81-
for (int i = 0; i < data.count; i++)
82-
{
83-
IntPtr currentPtr = IntPtr.Add(data.data, i * size);
84-
arr[i] = Marshal.PtrToStructure<ShootingData>(currentPtr);
85-
}
86-
Shootings(null, arr);
87-
}
88-
89-
static void DeathsCallback(ref DeathsArray data)
90-
{
91-
if (Deaths == null)
92-
return;
93-
DeathData[] arr = new DeathData[data.count];
94-
int size = Marshal.SizeOf(typeof(DeathData));
95-
for (int i = 0; i < data.count; i++)
96-
{
97-
IntPtr currentPtr = IntPtr.Add(data.data, i * size);
98-
arr[i] = Marshal.PtrToStructure<DeathData>(currentPtr);
99-
}
100-
Deaths(null, arr);
71+
// todo decode shooting
10172
}
10273

10374
static void ForceEliminatedCallback(uint force)
@@ -131,7 +102,6 @@ static Events()
131102
Interop.uwSetMapStateCallback(MapStateDelegate);
132103
Interop.uwSetUpdateCallback(UpdateDelegate);
133104
Interop.uwSetShootingsCallback(ShootingsDelegate);
134-
Interop.uwSetDeathsCallback(DeathsDelegate);
135105
Interop.uwSetForceEliminatedCallback(ForceEliminatedDelegate);
136106
Interop.uwSetChatCallback(ChatDelegate);
137107

csharp/uwapi/interop.cs

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public static extern void uwCommandPlaceConstruction(uint constructionProto, uin
317317
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
318318
public static extern void uwCommandSelfDestruct(uint entityId);
319319

320-
public const uint UW_VERSION = 39;
320+
public const uint UW_VERSION = 40;
321321
public const uint UW_GameTicksPerSecond = 20;
322322
[StructLayout(LayoutKind.Sequential)]
323323
public struct UwIds
@@ -725,20 +725,12 @@ public enum UwGameStateEnum
725725
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
726726
public static extern void uwSetUpdateCallback(UwUpdateCallbackType callback);
727727

728-
[StructLayout(LayoutKind.Sequential)]
729-
public struct UwShootingUnit
730-
{
731-
public uint position;
732-
public uint force;
733-
public uint prototype;
734-
public uint id;
735-
}
736-
737-
[StructLayout(LayoutKind.Sequential)]
738-
public struct UwShootingData
728+
public enum UwShootingEventEnum
739729
{
740-
public UwShootingUnit shooter;
741-
public UwShootingUnit target;
730+
None = 0,
731+
Shooting = 1,
732+
Death = 2,
733+
Explosion = 3,
742734
}
743735

744736
[StructLayout(LayoutKind.Sequential)]
@@ -754,30 +746,6 @@ public struct UwShootingsArray
754746
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
755747
public static extern void uwSetShootingsCallback(UwShootingsCallbackType callback);
756748

757-
[StructLayout(LayoutKind.Sequential)]
758-
public struct UwDeathData
759-
{
760-
public uint position;
761-
public uint force;
762-
public uint prototype;
763-
public uint id;
764-
[MarshalAs(UnmanagedType.I1)]
765-
public bool explosion;
766-
}
767-
768-
[StructLayout(LayoutKind.Sequential)]
769-
public struct UwDeathsArray
770-
{
771-
public IntPtr data;
772-
public uint count;
773-
}
774-
775-
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
776-
public delegate void UwDeathsCallbackType(ref UwDeathsArray data);
777-
778-
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
779-
public static extern void uwSetDeathsCallback(UwDeathsCallbackType callback);
780-
781749
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
782750
public delegate void UwForceEliminatedCallbackType(uint id);
783751

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","ShootingsArray","DeathData","DeathsArray","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","ShootingEvent","ShootingsArray","TaskType","MapState","MapInfo","MapStartingPosition","MapStartingPositionsArray","Tile","Cluster","ClustersDistancesQuery","ClustersDistancesResult","PrototypeType","MyForceStatistics","UnitUpgrades","Overview","OverviewExtract","UnitPathfindingQuery","UnitPathfindingResult"]

python/uwapi/bots.h

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ typedef int32_t sint32;
99
typedef uint64_t uint64;
1010
typedef int64_t sint64;
1111

12-
static const uint32 UW_VERSION = 39;
12+
static const uint32 UW_VERSION = 40;
1313
static const uint32 UW_GameTicksPerSecond = 20;
1414

1515
typedef struct UwIds
@@ -450,43 +450,21 @@ uint32 uwGameTick(void);
450450
typedef void (*UwUpdateCallbackType)(bool stepping);
451451
void uwSetUpdateCallback(UwUpdateCallbackType callback);
452452

453-
typedef struct UwShootingUnit
453+
typedef enum UwShootingEventEnum
454454
{
455-
uint32 position;
456-
uint32 force;
457-
uint32 prototype;
458-
uint32 id;
459-
} UwShootingUnit;
460-
typedef struct UwShootingData
461-
{
462-
UwShootingUnit shooter;
463-
UwShootingUnit target;
464-
} UwShootingData;
455+
UwShootingEventEnum_None = 0,
456+
UwShootingEventEnum_Shooting = 1,
457+
UwShootingEventEnum_Death = 2,
458+
UwShootingEventEnum_Explosion = 3,
459+
} UwShootingEventEnum;
465460
typedef struct UwShootingsArray
466461
{
467-
const UwShootingData *data;
462+
const uint32 *data;
468463
uint32 count;
469464
} UwShootingsArray;
470465

471466
typedef void (*UwShootingsCallbackType)(const UwShootingsArray *data);
472467
void uwSetShootingsCallback(UwShootingsCallbackType callback);
473-
474-
typedef struct UwDeathData
475-
{
476-
uint32 position;
477-
uint32 force;
478-
uint32 prototype;
479-
uint32 id;
480-
bool explosion;
481-
} UwDeathData;
482-
typedef struct UwDeathsArray
483-
{
484-
const UwDeathData *data;
485-
uint32 count;
486-
} UwDeathsArray;
487-
488-
typedef void (*UwDeathsCallbackType)(const UwDeathsArray *data);
489-
void uwSetDeathsCallback(UwDeathsCallbackType callback);
490468
typedef void (*UwForceEliminatedCallbackType)(uint32 id);
491469
void uwSetForceEliminatedCallback(UwForceEliminatedCallbackType callback);
492470
typedef void (*UwChatCallbackType)(const char *msg, uint32 sender, UwChatTargetFlags flags);

python/uwapi/events.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class Events:
99
_game_state_listeners: List[Callable[[UwGameStateEnum], None]] = []
1010
_update_listeners: List[Callable[[bool], None]] = []
1111
_shootings_listeners: List[Callable[[UwShootingsArray], None]] = []
12-
_deaths_listeners: List[Callable[[UwDeathsArray], None]] = []
1312
_force_eliminated_listeners: List[Callable[[int], None]] = []
1413
_chat_listeners: List[Callable[[str, int, UwChatTargetFlags], None]] = []
1514
_map_state_listeners: List[Callable[[UwMapStateEnum], None]] = []
@@ -26,7 +25,6 @@ def initialize(self) -> None:
2625
uw_interop.uwSetGameStateCallback(self._game_state_callback)
2726
uw_interop.uwSetUpdateCallback(self._update_callback)
2827
uw_interop.uwSetShootingsCallback(self._shootings_callback)
29-
uw_interop.uwSetDeathsCallback(self._deaths_callback)
3028
uw_interop.uwSetForceEliminatedCallback(self._force_eliminated_callback)
3129
uw_interop.uwSetChatCallback(self._chat_callback)
3230
uw_interop.uwSetTaskCompletedCallback(self._task_completed_callback)
@@ -48,9 +46,6 @@ def on_update(self, listener: Callable[[bool], None]) -> None:
4846
def on_shootings(self, listener: Callable[[UwShootingsArray], None]) -> None:
4947
self._shootings_listeners.append(listener)
5048

51-
def on_deaths(self, listener: Callable[[UwDeathsArray], None]) -> None:
52-
self._deaths_listeners.append(listener)
53-
5449
def on_force_eliminated(self, listener: Callable[[int], None]) -> None:
5550
self._force_eliminated_listeners.append(listener)
5651

@@ -82,10 +77,6 @@ def _shootings_callback(self, data: UwShootingsArray) -> None:
8277
for listener in self._shootings_listeners:
8378
listener(data)
8479

85-
def _deaths_callback(self, data: UwDeathsArray) -> None:
86-
for listener in self._deaths_listeners:
87-
listener(data)
88-
8980
def _force_eliminated_callback(self, force: int) -> None:
9081
for listener in self._force_eliminated_listeners:
9182
listener(force)

0 commit comments

Comments
 (0)