Skip to content

Commit 8159280

Browse files
committed
pause and cutscene (wip)
1 parent 48154d4 commit 8159280

File tree

11 files changed

+105
-43
lines changed

11 files changed

+105
-43
lines changed

c/uwapi/uwapi/modules/botsAdmin.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,23 @@ extern "C"
1010

1111
#ifdef UNNATURAL_BOTS
1212

13+
typedef struct UwPlayerAiConfigComponent UwPlayerAiConfigComponent;
14+
1315
UNNATURAL_API uint64 uwGetLobbyId(void);
1416
UNNATURAL_API uint64 uwGetUserId(void);
1517
UNNATURAL_API uint16 uwGetServerPort(void);
1618
UNNATURAL_API void uwAdminSetMapSelection(const char *path);
17-
UNNATURAL_API void uwAdminStartGame(void);
18-
UNNATURAL_API void uwAdminTerminateGame(void);
1919
UNNATURAL_API void uwAdminSetGameSpeed(float speed);
2020
UNNATURAL_API void uwAdminSetWeatherSpeed(float speed, float offset);
21+
UNNATURAL_API void uwAdminStartGame(void);
22+
UNNATURAL_API void uwAdminTerminateGame(void);
23+
UNNATURAL_API void uwAdminPauseGame(bool pause);
24+
UNNATURAL_API void uwAdminSkipCutscene(void);
2125
UNNATURAL_API void uwAdminAddAi(void);
2226
UNNATURAL_API void uwAdminKickPlayer(uint32 playerId);
2327
UNNATURAL_API void uwAdminPlayerSetAdmin(uint32 playerId, bool admin);
2428
UNNATURAL_API void uwAdminPlayerSetName(uint32 playerId, const char *name);
29+
UNNATURAL_API void uwAdminPlayerAiConfig(uint32 playerId, const UwPlayerAiConfigComponent *config);
2530
UNNATURAL_API void uwAdminPlayerJoinForce(uint32 playerId, uint32 forceId);
2631
UNNATURAL_API void uwAdminForceJoinTeam(uint32 forceId, uint32 team);
2732
UNNATURAL_API void uwAdminForceSetColor(uint32 forceId, float r, float g, float b);

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 = 36;
37+
static const uint32 UW_VERSION = 37;
3838
static const uint32 UW_GameTicksPerSecond = 20;
3939

4040
typedef struct UwIds

c/uwapi/uwapi/modules/components.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ extern "C"
140140
typedef enum UwPlayerStateFlags
141141
{
142142
UwPlayerStateFlags_None = 0,
143-
UwPlayerStateFlags_Loaded = 1 << 0,
144-
UwPlayerStateFlags_Pause = 1 << 1,
145-
UwPlayerStateFlags_Disconnected = 1 << 2,
146-
UwPlayerStateFlags_Admin = 1 << 3,
143+
UwPlayerStateFlags_Disconnected = 1 << 0,
144+
UwPlayerStateFlags_Admin = 1 << 1,
145+
UwPlayerStateFlags_Loaded = 1 << 2,
146+
UwPlayerStateFlags_Pause = 1 << 3,
147+
UwPlayerStateFlags_SkipCutscene = 1 << 4,
147148
} UwPlayerStateFlags;
148149
typedef enum UwPlayerConnectionClassEnum
149150
{
@@ -168,19 +169,19 @@ extern "C"
168169

169170
typedef struct UwPlayerAiConfigComponent
170171
{
171-
float dumbness;
172+
float difficulty;
172173
float aggressive; // army is frequently attacking, or mostly just defends
173-
float stretched; // army is spread into many small groups, or mostly concentrated
174+
float stretching; // army is spread into many small groups, or mostly concentrated
174175
float expansive; // takes many bases, or turtles on few
175176
} UwPlayerAiConfigComponent;
176177
UNNATURAL_API bool uwFetchPlayerAiConfigComponent(UwEntityPtr entity, UwPlayerAiConfigComponent *data);
177178

178179
typedef enum UwForceStateFlags
179180
{
180181
UwForceStateFlags_None = 0,
181-
UwForceStateFlags_Winner = 1 << 0,
182-
UwForceStateFlags_Defeated = 1 << 1,
183-
UwForceStateFlags_Disconnected = 1 << 2,
182+
UwForceStateFlags_Disconnected = 1 << 0,
183+
UwForceStateFlags_Winner = 1 << 1,
184+
UwForceStateFlags_Defeated = 1 << 2,
184185
} UwForceStateFlags;
185186
typedef struct UwForceComponent
186187
{

c/uwapi/uwapi/modules/game.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ extern "C"
2121
UwGameStateEnum_Preparation = 2,
2222
UwGameStateEnum_Game = 3,
2323
UwGameStateEnum_Finish = 4,
24+
UwGameStateEnum_Paused = 5,
25+
UwGameStateEnum_CutscenePaused = 6,
26+
UwGameStateEnum_CutsceneRunning = 7,
2427
} UwGameStateEnum;
2528
#ifdef UNNATURAL_BOTS
2629
typedef void (*UwGameStateCallbackType)(UwGameStateEnum state);

csharp/uwapi/admin.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace Unnatural
22
{
33
using ChatTargetFLags = Interop.UwChatTargetFlags;
44
using PingEnum = Interop.UwPingEnum;
5+
using PlayerAiConfig = Interop.UwPlayerAiConfigComponent;
56

67
public static class Admin
78
{
@@ -25,6 +26,16 @@ public static void SetMapSelection(string path)
2526
Interop.uwAdminSetMapSelection(path);
2627
}
2728

29+
public static void SetGameSpeed(float speed)
30+
{
31+
Interop.uwAdminSetGameSpeed(speed);
32+
}
33+
34+
public static void SetWeatherSpeed(float speed, float offset)
35+
{
36+
Interop.uwAdminSetWeatherSpeed(speed, offset);
37+
}
38+
2839
public static void StartGame()
2940
{
3041
Interop.uwAdminStartGame();
@@ -35,14 +46,14 @@ public static void TerminateGame()
3546
Interop.uwAdminTerminateGame();
3647
}
3748

38-
public static void SetGameSpeed(float speed)
49+
public static void PauseGame(bool pause)
3950
{
40-
Interop.uwAdminSetGameSpeed(speed);
51+
Interop.uwAdminPauseGame(pause);
4152
}
4253

43-
public static void SetWeatherSpeed(float speed, float offset)
54+
public static void SkipCutscene()
4455
{
45-
Interop.uwAdminSetWeatherSpeed(speed, offset);
56+
Interop.uwAdminSkipCutscene();
4657
}
4758

4859
public static void AddAi()
@@ -65,6 +76,11 @@ public static void PlayerSetName(uint playerId, string name)
6576
Interop.uwAdminPlayerSetName(playerId, name);
6677
}
6778

79+
public static void PlayerAiConfig(uint playerId, PlayerAiConfig config)
80+
{
81+
Interop.uwAdminPlayerAiConfig(playerId, ref config);
82+
}
83+
6884
public static void PlayerJoinForce(uint playerId, uint forceId)
6985
{
7086
Interop.uwAdminPlayerJoinForce(playerId, forceId);

csharp/uwapi/interop.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,23 @@ public static class Interop
2929
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
3030
public static extern void uwAdminSetMapSelection([MarshalAs(UnmanagedType.LPStr)] string path);
3131

32+
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
33+
public static extern void uwAdminSetGameSpeed(float speed);
34+
35+
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
36+
public static extern void uwAdminSetWeatherSpeed(float speed, float offset);
37+
3238
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
3339
public static extern void uwAdminStartGame();
3440

3541
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
3642
public static extern void uwAdminTerminateGame();
3743

3844
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
39-
public static extern void uwAdminSetGameSpeed(float speed);
45+
public static extern void uwAdminPauseGame([MarshalAs(UnmanagedType.I1)] bool pause);
4046

4147
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
42-
public static extern void uwAdminSetWeatherSpeed(float speed, float offset);
48+
public static extern void uwAdminSkipCutscene();
4349

4450
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
4551
public static extern void uwAdminAddAi();
@@ -53,6 +59,9 @@ public static class Interop
5359
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
5460
public static extern void uwAdminPlayerSetName(uint playerId, [MarshalAs(UnmanagedType.LPStr)] string name);
5561

62+
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
63+
public static extern void uwAdminPlayerAiConfig(uint playerId, ref UwPlayerAiConfigComponent config);
64+
5665
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
5766
public static extern void uwAdminPlayerJoinForce(uint playerId, uint forceId);
5867

@@ -305,7 +314,7 @@ public static extern void uwCommandPlaceConstruction(uint constructionProto, uin
305314
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl)]
306315
public static extern void uwCommandSelfDestruct(uint entityId);
307316

308-
public const uint UW_VERSION = 36;
317+
public const uint UW_VERSION = 37;
309318
public const uint UW_GameTicksPerSecond = 20;
310319
[StructLayout(LayoutKind.Sequential)]
311320
public struct UwIds
@@ -570,10 +579,11 @@ public struct UwPingComponent
570579
public enum UwPlayerStateFlags
571580
{
572581
None = 0,
573-
Loaded = 1 << 0,
574-
Pause = 1 << 1,
575-
Disconnected = 1 << 2,
576-
Admin = 1 << 3,
582+
Disconnected = 1 << 0,
583+
Admin = 1 << 1,
584+
Loaded = 1 << 2,
585+
Pause = 1 << 3,
586+
SkipCutscene = 1 << 4,
577587
}
578588

579589
public enum UwPlayerConnectionClassEnum
@@ -606,9 +616,9 @@ public struct UwPlayerComponent
606616
[StructLayout(LayoutKind.Sequential)]
607617
public struct UwPlayerAiConfigComponent
608618
{
609-
public float dumbness;
619+
public float difficulty;
610620
public float aggressive;
611-
public float stretched;
621+
public float stretching;
612622
public float expansive;
613623
}
614624

@@ -620,9 +630,9 @@ public struct UwPlayerAiConfigComponent
620630
public enum UwForceStateFlags
621631
{
622632
None = 0,
623-
Winner = 1 << 0,
624-
Defeated = 1 << 1,
625-
Disconnected = 1 << 2,
633+
Disconnected = 1 << 0,
634+
Winner = 1 << 1,
635+
Defeated = 1 << 2,
626636
}
627637

628638
[StructLayout(LayoutKind.Sequential)]
@@ -688,6 +698,9 @@ public enum UwGameStateEnum
688698
Preparation = 2,
689699
Game = 3,
690700
Finish = 4,
701+
Paused = 5,
702+
CutscenePaused = 6,
703+
CutsceneRunning = 7,
691704
}
692705

693706
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]

python/uwapi/uw/bots.h

Lines changed: 21 additions & 12 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 = 36;
12+
static const uint32 UW_VERSION = 37;
1313
static const uint32 UW_GameTicksPerSecond = 20;
1414

1515
typedef struct UwIds
@@ -71,18 +71,23 @@ typedef enum UwChatTargetFlags
7171
UwChatTargetFlags_Everyone = UwChatTargetFlags_Players | UwChatTargetFlags_Observer | UwChatTargetFlags_Admin,
7272
} UwChatTargetFlags;
7373

74+
typedef struct UwPlayerAiConfigComponent UwPlayerAiConfigComponent;
75+
7476
uint64 uwGetLobbyId(void);
7577
uint64 uwGetUserId(void);
7678
uint16 uwGetServerPort(void);
7779
void uwAdminSetMapSelection(const char *path);
78-
void uwAdminStartGame(void);
79-
void uwAdminTerminateGame(void);
8080
void uwAdminSetGameSpeed(float speed);
8181
void uwAdminSetWeatherSpeed(float speed, float offset);
82+
void uwAdminStartGame(void);
83+
void uwAdminTerminateGame(void);
84+
void uwAdminPauseGame(bool pause);
85+
void uwAdminSkipCutscene(void);
8286
void uwAdminAddAi(void);
8387
void uwAdminKickPlayer(uint32 playerId);
8488
void uwAdminPlayerSetAdmin(uint32 playerId, bool admin);
8589
void uwAdminPlayerSetName(uint32 playerId, const char *name);
90+
void uwAdminPlayerAiConfig(uint32 playerId, const UwPlayerAiConfigComponent *config);
8691
void uwAdminPlayerJoinForce(uint32 playerId, uint32 forceId);
8792
void uwAdminForceJoinTeam(uint32 forceId, uint32 team);
8893
void uwAdminForceSetColor(uint32 forceId, float r, float g, float b);
@@ -342,10 +347,11 @@ bool uwFetchPingComponent(UwEntityPtr entity, UwPingComponent *data);
342347
typedef enum UwPlayerStateFlags
343348
{
344349
UwPlayerStateFlags_None = 0,
345-
UwPlayerStateFlags_Loaded = 1 << 0,
346-
UwPlayerStateFlags_Pause = 1 << 1,
347-
UwPlayerStateFlags_Disconnected = 1 << 2,
348-
UwPlayerStateFlags_Admin = 1 << 3,
350+
UwPlayerStateFlags_Disconnected = 1 << 0,
351+
UwPlayerStateFlags_Admin = 1 << 1,
352+
UwPlayerStateFlags_Loaded = 1 << 2,
353+
UwPlayerStateFlags_Pause = 1 << 3,
354+
UwPlayerStateFlags_SkipCutscene = 1 << 4,
349355
} UwPlayerStateFlags;
350356
typedef enum UwPlayerConnectionClassEnum
351357
{
@@ -370,19 +376,19 @@ bool uwFetchPlayerComponent(UwEntityPtr entity, UwPlayerComponent *data);
370376

371377
typedef struct UwPlayerAiConfigComponent
372378
{
373-
float dumbness;
379+
float difficulty;
374380
float aggressive;
375-
float stretched;
381+
float stretching;
376382
float expansive;
377383
} UwPlayerAiConfigComponent;
378384
bool uwFetchPlayerAiConfigComponent(UwEntityPtr entity, UwPlayerAiConfigComponent *data);
379385

380386
typedef enum UwForceStateFlags
381387
{
382388
UwForceStateFlags_None = 0,
383-
UwForceStateFlags_Winner = 1 << 0,
384-
UwForceStateFlags_Defeated = 1 << 1,
385-
UwForceStateFlags_Disconnected = 1 << 2,
389+
UwForceStateFlags_Disconnected = 1 << 0,
390+
UwForceStateFlags_Winner = 1 << 1,
391+
UwForceStateFlags_Defeated = 1 << 2,
386392
} UwForceStateFlags;
387393
typedef struct UwForceComponent
388394
{
@@ -427,6 +433,9 @@ typedef enum UwGameStateEnum
427433
UwGameStateEnum_Preparation = 2,
428434
UwGameStateEnum_Game = 3,
429435
UwGameStateEnum_Finish = 4,
436+
UwGameStateEnum_Paused = 5,
437+
UwGameStateEnum_CutscenePaused = 6,
438+
UwGameStateEnum_CutsceneRunning = 7,
430439
} UwGameStateEnum;
431440

432441
typedef void (*UwGameStateCallbackType)(UwGameStateEnum state);

sphinx/source/bots/performance.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Performance
22
===========
33
Some hints on improving performance.
44

5-
Distribute work over multiple ticks
5+
Distribute Work Over Multiple Ticks
66
-----------------------------------
77
Most events in the game take some time: shooting, moving, building, processing, etc.
88
Therefore, it is generally unnecessary to keep updating everything all the time.

sphinx/source/bots/programOverview.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Initialization
1010
^^^^^^^^^^^^^^
1111

1212
- You need to change current working directory to the ``bin`` directory in the game installation.
13-
Without it, the game will be unable to load maps and assets, even if it might load the shared library.
13+
Without it, the game will be unable to load maps and assets (even if it might happen to load the shared library).
1414

1515
.. warning::
16-
Do *not* change current working directory once configured.
16+
Do *not* change current working directory from now on.
1717

1818
- Next, you load the shared library.
1919

sphinx/source/concepts/players.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ Observers
1313
^^^^^^^^^
1414
A player that is not associated with any force is an observer.
1515

16+
Admin
17+
^^^^^
18+
Admin player has full control over the game:
19+
20+
- starts the game,
21+
- chooses map,
22+
- can add/remove ai players or kick real players,
23+
- can change game settings, ai settings, etc.
24+
25+
Typically, the player that hosts the game will become the admin.
26+
However, in some cases, such as tournaments, it is possible that the host and admin are separate.
27+
1628
Forces
1729
------
1830
Forces represent the actual armies in the world.

0 commit comments

Comments
 (0)