• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Return-To-The-Roots / s25client / 12496581356

25 Dec 2024 09:11PM UTC coverage: 50.231% (+0.006%) from 50.225%
12496581356

Pull #1681

github

web-flow
Merge 7a15afd70 into 17844c810
Pull Request #1681: Add support for campaign status

77 of 143 new or added lines in 10 files covered. (53.85%)

3 existing lines in 3 files now uncovered.

22376 of 44546 relevant lines covered (50.23%)

35690.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.71
/libs/s25main/lua/LuaInterfaceGame.cpp
1
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "LuaInterfaceGame.h"
6
#include "EventManager.h"
7
#include "Game.h"
8
#include "Settings.h"
9
#include "WindowManager.h"
10
#include "ai/AIInterface.h"
11
#include "ai/AIPlayer.h"
12
#include "ingameWindows/iwMissionStatement.h"
13
#include "lua/LuaHelpers.h"
14
#include "lua/LuaPlayer.h"
15
#include "lua/LuaWorld.h"
16
#include "network/GameClient.h"
17
#include "postSystem/PostMsg.h"
18
#include "world/GameWorld.h"
19
#include "gameTypes/Resource.h"
20
#include "s25util/Serializer.h"
21
#include "s25util/strAlgos.h"
22

23
LuaInterfaceGame::LuaInterfaceGame(Game& gameInstance, ILocalGameState& localGameState)
27✔
24
    : LuaInterfaceGameBase(localGameState), localGameState(localGameState), gw(gameInstance.world_), game(gameInstance)
27✔
25
{
26
#pragma region ConstDefs
27
#define ADD_LUA_CONST(name) lua["BLD_" + s25util::toUpper(#name)] = BuildingType::name
28
    ADD_LUA_CONST(Headquarters);
27✔
29
    ADD_LUA_CONST(Barracks);
27✔
30
    ADD_LUA_CONST(Guardhouse);
27✔
31
    ADD_LUA_CONST(Watchtower);
27✔
32
    ADD_LUA_CONST(Fortress);
27✔
33
    ADD_LUA_CONST(GraniteMine);
27✔
34
    ADD_LUA_CONST(CoalMine);
27✔
35
    ADD_LUA_CONST(IronMine);
27✔
36
    ADD_LUA_CONST(GoldMine);
27✔
37
    ADD_LUA_CONST(LookoutTower);
27✔
38
    ADD_LUA_CONST(Catapult);
27✔
39
    ADD_LUA_CONST(Woodcutter);
27✔
40
    ADD_LUA_CONST(Fishery);
27✔
41
    ADD_LUA_CONST(Quarry);
27✔
42
    ADD_LUA_CONST(Forester);
27✔
43
    ADD_LUA_CONST(Slaughterhouse);
27✔
44
    ADD_LUA_CONST(Hunter);
27✔
45
    ADD_LUA_CONST(Brewery);
27✔
46
    ADD_LUA_CONST(Armory);
27✔
47
    ADD_LUA_CONST(Metalworks);
27✔
48
    ADD_LUA_CONST(Ironsmelter);
27✔
49
    ADD_LUA_CONST(Charburner);
27✔
50
    ADD_LUA_CONST(PigFarm);
27✔
51
    ADD_LUA_CONST(Storehouse);
27✔
52
    ADD_LUA_CONST(Mill);
27✔
53
    ADD_LUA_CONST(Bakery);
27✔
54
    ADD_LUA_CONST(Sawmill);
27✔
55
    ADD_LUA_CONST(Mint);
27✔
56
    ADD_LUA_CONST(Well);
27✔
57
    ADD_LUA_CONST(Shipyard);
27✔
58
    ADD_LUA_CONST(Farm);
27✔
59
    ADD_LUA_CONST(DonkeyBreeder);
27✔
60
    ADD_LUA_CONST(HarborBuilding);
27✔
61
    ADD_LUA_CONST(Vineyard);
27✔
62
    ADD_LUA_CONST(Winery);
27✔
63
    ADD_LUA_CONST(Temple);
27✔
64
#undef ADD_LUA_CONST
65

66
#define ADD_LUA_CONST(name) lua["JOB_" + s25util::toUpper(#name)] = Job::name
67
    ADD_LUA_CONST(Helper);
27✔
68
    ADD_LUA_CONST(Woodcutter);
27✔
69
    ADD_LUA_CONST(Fisher);
27✔
70
    ADD_LUA_CONST(Forester);
27✔
71
    ADD_LUA_CONST(Carpenter);
27✔
72
    ADD_LUA_CONST(Stonemason);
27✔
73
    ADD_LUA_CONST(Hunter);
27✔
74
    ADD_LUA_CONST(Farmer);
27✔
75
    ADD_LUA_CONST(Miller);
27✔
76
    ADD_LUA_CONST(Baker);
27✔
77
    ADD_LUA_CONST(Butcher);
27✔
78
    ADD_LUA_CONST(Miner);
27✔
79
    ADD_LUA_CONST(Brewer);
27✔
80
    ADD_LUA_CONST(PigBreeder);
27✔
81
    ADD_LUA_CONST(DonkeyBreeder);
27✔
82
    ADD_LUA_CONST(IronFounder);
27✔
83
    ADD_LUA_CONST(Minter);
27✔
84
    ADD_LUA_CONST(Metalworker);
27✔
85
    ADD_LUA_CONST(Armorer);
27✔
86
    ADD_LUA_CONST(Builder);
27✔
87
    ADD_LUA_CONST(Planer);
27✔
88
    ADD_LUA_CONST(Private);
27✔
89
    ADD_LUA_CONST(PrivateFirstClass);
27✔
90
    ADD_LUA_CONST(Sergeant);
27✔
91
    ADD_LUA_CONST(Officer);
27✔
92
    ADD_LUA_CONST(General);
27✔
93
    ADD_LUA_CONST(Geologist);
27✔
94
    ADD_LUA_CONST(Shipwright);
27✔
95
    ADD_LUA_CONST(Scout);
27✔
96
    ADD_LUA_CONST(PackDonkey);
27✔
97
    ADD_LUA_CONST(BoatCarrier);
27✔
98
    ADD_LUA_CONST(CharBurner);
27✔
99
    ADD_LUA_CONST(Winegrower);
27✔
100
    ADD_LUA_CONST(Vintner);
27✔
101
    ADD_LUA_CONST(TempleServant);
27✔
102
#undef ADD_LUA_CONST
103

104
#define ADD_LUA_CONST(name) lua["STAT_" + s25util::toUpper(#name)] = StatisticType::name
105
    ADD_LUA_CONST(Country);
27✔
106
    ADD_LUA_CONST(Buildings);
27✔
107
    ADD_LUA_CONST(Inhabitants);
27✔
108
    ADD_LUA_CONST(Merchandise);
27✔
109
    ADD_LUA_CONST(Military);
27✔
110
    ADD_LUA_CONST(Gold);
27✔
111
    ADD_LUA_CONST(Productivity);
27✔
112
    ADD_LUA_CONST(Vanquished);
27✔
113
    ADD_LUA_CONST(Tournament);
27✔
114
#undef ADD_LUA_CONST
115

116
#define ADD_LUA_CONST(name) lua["GD_" + s25util::toUpper(#name)] = GoodType::name
117
    ADD_LUA_CONST(Beer);
27✔
118
    ADD_LUA_CONST(Tongs);
27✔
119
    ADD_LUA_CONST(Hammer);
27✔
120
    ADD_LUA_CONST(Axe);
27✔
121
    ADD_LUA_CONST(Saw);
27✔
122
    ADD_LUA_CONST(PickAxe);
27✔
123
    ADD_LUA_CONST(Shovel);
27✔
124
    ADD_LUA_CONST(Crucible);
27✔
125
    ADD_LUA_CONST(RodAndLine);
27✔
126
    ADD_LUA_CONST(Scythe);
27✔
127
    ADD_LUA_CONST(Water);
27✔
128
    ADD_LUA_CONST(Cleaver);
27✔
129
    ADD_LUA_CONST(Rollingpin);
27✔
130
    ADD_LUA_CONST(Bow);
27✔
131
    ADD_LUA_CONST(Boat);
27✔
132
    ADD_LUA_CONST(Sword);
27✔
133
    ADD_LUA_CONST(Iron);
27✔
134
    ADD_LUA_CONST(Flour);
27✔
135
    ADD_LUA_CONST(Fish);
27✔
136
    ADD_LUA_CONST(Bread);
27✔
137
    lua["GD_SHIELD"] = GoodType::ShieldRomans;
27✔
138
    ADD_LUA_CONST(Wood);
27✔
139
    ADD_LUA_CONST(Boards);
27✔
140
    ADD_LUA_CONST(Stones);
27✔
141
    ADD_LUA_CONST(Grain);
27✔
142
    ADD_LUA_CONST(Coins);
27✔
143
    ADD_LUA_CONST(Gold);
27✔
144
    ADD_LUA_CONST(IronOre);
27✔
145
    ADD_LUA_CONST(Coal);
27✔
146
    ADD_LUA_CONST(Meat);
27✔
147
    ADD_LUA_CONST(Ham);
27✔
148
    ADD_LUA_CONST(Grapes);
27✔
149
    ADD_LUA_CONST(Wine);
27✔
150
#undef ADD_LUA_CONST
151

152
#define ADD_LUA_CONST(name) lua["RES_" + s25util::toUpper(#name)] = ResourceType::name
153
    ADD_LUA_CONST(Iron);
27✔
154
    ADD_LUA_CONST(Gold);
27✔
155
    ADD_LUA_CONST(Coal);
27✔
156
    ADD_LUA_CONST(Granite);
27✔
157
    ADD_LUA_CONST(Water);
27✔
158
#undef ADD_LUA_CONST
159

160
#define ADD_LUA_CONST(name) lua[#name] = name
161
    lua["NON_AGGRESSION_PACT"] = PactType::NonAgressionPact;
27✔
162
    lua["TREATY_OF_ALLIANCE"] = PactType::TreatyOfAlliance;
27✔
163
    // infinite pact duration, see GamePlayer::GetRemainingPactTime
164
    ADD_LUA_CONST(DURATION_INFINITE);
27✔
165
#undef ADD_LUA_CONST
166

167
#define ADD_LUA_CONST(name) lua[#name] = iwMissionStatement::name
168
    ADD_LUA_CONST(IM_NONE);
27✔
169
    ADD_LUA_CONST(IM_SWORDSMAN);
27✔
170
    ADD_LUA_CONST(IM_READER);
27✔
171
    ADD_LUA_CONST(IM_RIDER);
27✔
172
    ADD_LUA_CONST(IM_AVATAR1);
27✔
173
    ADD_LUA_CONST(IM_AVATAR2);
27✔
174
    ADD_LUA_CONST(IM_AVATAR3);
27✔
175
    ADD_LUA_CONST(IM_AVATAR4);
27✔
176
    ADD_LUA_CONST(IM_AVATAR5);
27✔
177
    ADD_LUA_CONST(IM_AVATAR6);
27✔
178
    ADD_LUA_CONST(IM_AVATAR7);
27✔
179
    ADD_LUA_CONST(IM_AVATAR8);
27✔
180
    ADD_LUA_CONST(IM_AVATAR9);
27✔
181
    ADD_LUA_CONST(IM_AVATAR10);
27✔
182
    ADD_LUA_CONST(IM_AVATAR11);
27✔
183
    ADD_LUA_CONST(IM_AVATAR12);
27✔
184

185
#undef ADD_LUA_CONST
186
#pragma endregion ConstDefs
187

188
    Register(lua);
27✔
189
    LuaPlayer::Register(lua);
27✔
190
    LuaWorld::Register(lua);
27✔
191

192
    lua["rttr"] = this;
27✔
193
}
27✔
194

195
LuaInterfaceGame::~LuaInterfaceGame() = default;
54✔
196

197
KAGUYA_MEMBER_FUNCTION_OVERLOADS(SetMissionGoalWrapper, LuaInterfaceGame, SetMissionGoal, 1, 2)
60✔
198

199
void LuaInterfaceGame::Register(kaguya::State& state)
27✔
200
{
201
    state["RTTRGame"].setClass(
27✔
202
      kaguya::UserdataMetatable<LuaInterfaceGame, LuaInterfaceGameBase>()
54✔
203
        .addFunction("ClearResources", &LuaInterfaceGame::ClearResources)
27✔
204
        .addFunction("GetGF", &LuaInterfaceGame::GetGF)
27✔
205
        .addFunction("FormatNumGFs", &LuaInterfaceGame::FormatNumGFs)
27✔
206
        .addFunction("GetGameFrame", &LuaInterfaceGame::GetGF)
27✔
207
        .addFunction("GetNumPlayers", &LuaInterfaceGame::GetNumPlayers)
27✔
208
        .addFunction("Chat", &LuaInterfaceGame::Chat)
27✔
209
        .addOverloadedFunctions("MissionStatement", &LuaInterfaceGame::MissionStatement,
210
                                &LuaInterfaceGame::MissionStatement2, &LuaInterfaceGame::MissionStatement3)
27✔
211
        .addFunction("SetMissionGoal", SetMissionGoalWrapper())
54✔
212
        .addFunction("PostMessage", &LuaInterfaceGame::PostMessageLua)
27✔
213
        .addFunction("PostMessageWithLocation", &LuaInterfaceGame::PostMessageWithLocation)
27✔
214
        .addFunction("EnableCampaignChapter", &LuaInterfaceGame::EnableCampaignChapter)
27✔
215
        .addFunction("SetCampaignChapterCompleted", &LuaInterfaceGame::SetCampaignChapterCompleted)
27✔
216
        .addFunction("SetCampaignCompleted", &LuaInterfaceGame::SetCampaignCompleted)
27✔
217
        .addFunction("GetPlayer", &LuaInterfaceGame::GetPlayer)
27✔
218
        .addFunction("GetWorld", &LuaInterfaceGame::GetWorld)
27✔
219
        // Old name
220
        .addFunction("GetPlayerCount", &LuaInterfaceGame::GetNumPlayers));
27✔
221
    state["RTTR_Serializer"].setClass(kaguya::UserdataMetatable<Serializer>()
54✔
222
                                        .addFunction("PushInt", &Serializer::PushSignedInt)
27✔
223
                                        .addFunction("PopInt", &Serializer::PopSignedInt)
27✔
224
                                        .addFunction("PushBool", &Serializer::PushBool)
27✔
225
                                        .addFunction("PopBool", &Serializer::PopBool)
27✔
226
                                        .addFunction("PushString", &Serializer::PushString)
27✔
227
                                        .addFunction("PopString", &Serializer::PopString));
27✔
228
}
27✔
229

230
bool LuaInterfaceGame::Serialize(Serializer& luaSaveState)
7✔
231
{
232
    kaguya::LuaRef save = lua["onSave"];
14✔
233
    if(save.type() == LUA_TFUNCTION)
7✔
234
    {
235
        clearErrorOccured();
4✔
236
        if(save.call<bool>(kaguya::standard::ref(luaSaveState)) && !hasErrorOccurred())
4✔
237
            return true;
1✔
238
        else
239
        {
240
            luaSaveState.Clear();
2✔
241
            return false;
2✔
242
        }
243
    } else
244
        return true;
3✔
245
}
246

247
bool LuaInterfaceGame::Deserialize(Serializer& luaSaveState)
5✔
248
{
249
    kaguya::LuaRef load = lua["onLoad"];
10✔
250
    if(load.type() == LUA_TFUNCTION)
5✔
251
    {
252
        clearErrorOccured();
3✔
253
        return load.call<bool>(kaguya::standard::ref(luaSaveState)) && !hasErrorOccurred();
3✔
254
    } else
255
        return true;
2✔
256
}
257

258
void LuaInterfaceGame::ClearResources()
1✔
259
{
260
    for(unsigned p = 0; p < gw.GetNumPlayers(); p++)
4✔
261
        GetPlayer(p).ClearResources();
3✔
262
}
1✔
263

264
unsigned LuaInterfaceGame::GetGF() const
2✔
265
{
266
    return gw.GetEvMgr().GetCurrentGF();
2✔
267
}
268

269
std::string LuaInterfaceGame::FormatNumGFs(unsigned numGFs) const
1✔
270
{
271
    return localGameState.FormatGFTime(numGFs);
1✔
272
}
273

274
unsigned LuaInterfaceGame::GetNumPlayers() const
1✔
275
{
276
    return gw.GetNumPlayers();
1✔
277
}
278

279
void LuaInterfaceGame::Chat(int playerIdx, const std::string& msg)
3✔
280
{
281
    if(playerIdx >= 0 && localGameState.GetPlayerId() != unsigned(playerIdx))
3✔
282
        return;
1✔
283

284
    localGameState.SystemChat(msg);
2✔
285
}
286

287
void LuaInterfaceGame::MissionStatement(int playerIdx, const std::string& title, const std::string& msg)
4✔
288
{
289
    MissionStatement2(playerIdx, title, msg, iwMissionStatement::IM_SWORDSMAN);
4✔
290
}
4✔
291

292
void LuaInterfaceGame::MissionStatement2(int playerIdx, const std::string& title, const std::string& msg,
7✔
293
                                         unsigned imgIdx)
294
{
295
    MissionStatement3(playerIdx, title, msg, imgIdx, true);
7✔
296
}
7✔
297

298
void LuaInterfaceGame::MissionStatement3(int playerIdx, const std::string& title, const std::string& msg,
7✔
299
                                         unsigned imgIdx, bool pause)
300
{
301
    if(playerIdx >= 0 && localGameState.GetPlayerId() != unsigned(playerIdx))
7✔
302
        return;
2✔
303

304
    WINDOWMANAGER.Show(std::make_unique<iwMissionStatement>(_(title), msg, gw.IsSinglePlayer() && pause,
15✔
305
                                                            iwMissionStatement::HelpImage(imgIdx)));
15✔
306
}
307

308
void LuaInterfaceGame::SetMissionGoal(int playerIdx, const std::string& newGoal)
6✔
309
{
310
    gw.GetPostMgr().SetMissionGoal(playerIdx, newGoal);
6✔
311
}
6✔
312

313
// Must not be PostMessage as this is a windows define :(
314
void LuaInterfaceGame::PostMessageLua(int playerIdx, const std::string& msg)
3✔
315
{
316
    lua::assertTrue(playerIdx >= 0, "Invalid player idx");
5✔
317
    gw.GetPostMgr().SendMsg(static_cast<unsigned>(playerIdx),
4✔
318
                            std::make_unique<PostMsg>(gw.GetEvMgr().GetCurrentGF(), msg, PostCategory::General));
4✔
319
}
2✔
320

321
void LuaInterfaceGame::PostMessageWithLocation(int playerIdx, const std::string& msg, int x, int y)
1✔
322
{
323
    lua::assertTrue(playerIdx >= 0, "Invalid player idx");
1✔
324
    gw.GetPostMgr().SendMsg(static_cast<unsigned>(playerIdx),
2✔
325
                            std::make_unique<PostMsg>(gw.GetEvMgr().GetCurrentGF(), msg, PostCategory::General,
2✔
326
                                                      gw.MakeMapPoint(Position(x, y))));
1✔
327
}
1✔
328

329
void LuaInterfaceGame::EnableCampaignChapter(const CampaignID& campaignUid, ChapterID chapter)
2✔
330
{
331
    SETTINGS.campaigns.enableChapter(campaignUid, chapter);
2✔
332
}
2✔
333

334
void LuaInterfaceGame::SetCampaignChapterCompleted(const CampaignID& campaignUid, ChapterID chapter)
2✔
335
{
336
    SETTINGS.campaigns.setChapterCompleted(campaignUid, chapter);
2✔
337
}
2✔
338

NEW
339
void LuaInterfaceGame::SetCampaignCompleted(const CampaignID& campaignUid)
×
340
{
NEW
341
    SETTINGS.campaigns.setCampaignCompleted(campaignUid);
×
NEW
342
}
×
343

344
LuaPlayer LuaInterfaceGame::GetPlayer(int playerIdx)
21✔
345
{
346
    lua::assertTrue(playerIdx >= 0 && static_cast<unsigned>(playerIdx) < gw.GetNumPlayers(), "Invalid player idx");
23✔
347
    return LuaPlayer(game, gw.GetPlayer(static_cast<unsigned>(playerIdx)));
19✔
348
}
349

350
LuaWorld LuaInterfaceGame::GetWorld()
10✔
351
{
352
    return LuaWorld(gw);
10✔
353
}
354

355
void LuaInterfaceGame::EventExplored(unsigned player, const MapPoint pt, unsigned char owner)
12,171✔
356
{
357
    kaguya::LuaRef onExplored = lua["onExplored"];
24,342✔
358
    if(onExplored.type() == LUA_TFUNCTION)
12,171✔
359
    {
360
        if(owner == 0)
938✔
361
        {
362
            // No owner? Pass nil value to Lua.
363
            onExplored.call<void>(player, pt.x, pt.y, kaguya::NilValue());
347✔
364
        } else
365
        {
366
            // Adapt owner to be comparable with the player index
367
            onExplored.call<void>(player, pt.x, pt.y, owner - 1);
591✔
368
        }
369
    }
370
}
12,171✔
371

372
void LuaInterfaceGame::EventOccupied(unsigned player, const MapPoint pt)
7,047✔
373
{
374
    kaguya::LuaRef onOccupied = lua["onOccupied"];
14,094✔
375
    if(onOccupied.type() == LUA_TFUNCTION)
7,047✔
376
        onOccupied.call<void>(player, pt.x, pt.y);
542✔
377
}
7,047✔
378

379
void LuaInterfaceGame::EventAttack(unsigned char attackerPlayerId, unsigned char defenderPlayerId,
2✔
380
                                   unsigned attackerCount)
381
{
382
    kaguya::LuaRef onAttack = lua["onAttack"];
4✔
383
    if(onAttack.type() == LUA_TFUNCTION)
2✔
384
        onAttack.call<void>(attackerPlayerId, defenderPlayerId, attackerCount);
1✔
385
}
2✔
386

387
void LuaInterfaceGame::EventStart(bool isFirstStart)
3✔
388
{
389
    kaguya::LuaRef onStart = lua["onStart"];
6✔
390
    if(onStart.type() == LUA_TFUNCTION)
3✔
391
        onStart.call<void>(isFirstStart);
2✔
392
}
3✔
393

NEW
394
void LuaInterfaceGame::EventHumanWinner()
×
395
{
NEW
396
    kaguya::LuaRef onStart = lua["onHumanWinner"];
×
NEW
397
    if(onStart.type() == LUA_TFUNCTION)
×
NEW
398
        onStart.call<void>();
×
NEW
399
}
×
400

401
void LuaInterfaceGame::EventGameFrame(unsigned nr)
3✔
402
{
403
    kaguya::LuaRef onGameFrame = lua["onGameFrame"];
6✔
404
    if(onGameFrame.type() == LUA_TFUNCTION)
3✔
405
        onGameFrame.call<void>(nr);
2✔
406
}
3✔
407

408
void LuaInterfaceGame::EventResourceFound(unsigned char player, const MapPoint pt, ResourceType type,
6✔
409
                                          unsigned char quantity)
410
{
411
    kaguya::LuaRef onResourceFound = lua["onResourceFound"];
12✔
412
    if(onResourceFound.type() == LUA_TFUNCTION)
6✔
413
        onResourceFound.call<void>(player, pt.x, pt.y, type, quantity);
5✔
414
}
6✔
415

416
bool LuaInterfaceGame::EventCancelPactRequest(PactType pt, unsigned char canceledByPlayerId,
1✔
417
                                              unsigned char targetPlayerId)
418
{
419
    kaguya::LuaRef onPactCancel = lua["onCancelPactRequest"];
2✔
420
    if(onPactCancel.type() == LUA_TFUNCTION)
1✔
421
        return onPactCancel.call<bool>(pt, canceledByPlayerId, targetPlayerId);
1✔
422
    return true; // always accept pact cancel if there is no handler
×
423
}
424

425
void LuaInterfaceGame::EventSuggestPact(const PactType pt, unsigned char suggestedByPlayerId,
2✔
426
                                        unsigned char targetPlayerId, const unsigned duration)
427
{
428
    AIPlayer* ai = game.GetAIPlayer(targetPlayerId);
2✔
429
    if(ai != nullptr)
2✔
430
    {
431
        kaguya::LuaRef onPactCancel = lua["onSuggestPact"];
4✔
432
        if(onPactCancel.type() == LUA_TFUNCTION)
2✔
433
        {
434
            AIInterface& aii = ai->getAIInterface();
2✔
435
            auto luaResult = onPactCancel.call<bool>(pt, suggestedByPlayerId, targetPlayerId, duration);
2✔
436
            if(luaResult)
2✔
437
                aii.AcceptPact(gw.GetEvMgr().GetCurrentGF(), pt, suggestedByPlayerId);
2✔
438
            else
439
                aii.CancelPact(pt, suggestedByPlayerId);
×
440
        }
441
    }
442
}
2✔
443

444
void LuaInterfaceGame::EventPactCanceled(const PactType pt, unsigned char canceledByPlayerId,
2✔
445
                                         unsigned char targetPlayerId)
446
{
447
    kaguya::LuaRef onPactCanceled = lua["onPactCanceled"];
4✔
448
    if(onPactCanceled.type() == LUA_TFUNCTION)
2✔
449
    {
450
        onPactCanceled.call<void>(pt, canceledByPlayerId, targetPlayerId);
2✔
451
    }
452
}
2✔
453

454
void LuaInterfaceGame::EventPactCreated(const PactType pt, unsigned char suggestedByPlayerId,
3✔
455
                                        unsigned char targetPlayerId, const unsigned duration)
456
{
457
    kaguya::LuaRef onPactCreated = lua["onPactCreated"];
6✔
458
    if(onPactCreated.type() == LUA_TFUNCTION)
3✔
459
    {
460
        onPactCreated.call<void>(pt, suggestedByPlayerId, targetPlayerId, duration);
3✔
461
    }
462
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc