-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerInfo.cpp
More file actions
executable file
·615 lines (583 loc) · 23 KB
/
Copy pathPlayerInfo.cpp
File metadata and controls
executable file
·615 lines (583 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
#include <iostream>
#include <map>
#include <vector>
#include <cassert>
#include <algorithm>
#include <sstream>
#include "PlayerInfo.hpp"
#include "GameState.hpp"
void PlayerInfo::make_default_player(const PlayerColors c)
{
score = 0;
color = c;
const unsigned num_planets_per_player = 5;
const unsigned default_ships_per_planet = 4;
planets.resize(num_planets_per_player);
for(unsigned i=0; i<planets.size(); i++)
{
for(unsigned ii=0; ii<default_ships_per_planet; ii++)
{
planets.planet_push_back(i,color);
}
}
alien_zapped = false;
used_flare_this_turn = false;
}
void PlayerInfo::dump_hand() const
{
std::string hand_info = get_hand();
std::cout << hand_info;
}
std::string PlayerInfo::get_hand() const
{
std::stringstream ret;
ret << "Hand for the " << to_string(color) << " player:\n";
ret << "[player_hand]\n";
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
ret << to_string(*i) << "\n";
}
ret << "\n";
return ret.str();
}
bool PlayerInfo::has_encounter_cards_in_hand() const
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(static_cast<unsigned>(*i) <= static_cast<unsigned>(CosmicCardType::Morph))
{
return true;
}
}
return false;
}
bool PlayerInfo::has_card(const CosmicCardType c) const
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == c)
{
return true;
}
}
return false;
}
//If the player doesn't have colonies on three of their own planets they they can't respond with an Alien power
//The alien is also disabled for the remainder of an encounter in which it was zapped
bool PlayerInfo::alien_enabled() const
{
if(alien_zapped)
{
return false;
}
unsigned num_home_colonies = 0;
for(unsigned planet=0; planet<planets.size(); planet++)
{
for(unsigned ship=0; ship<planets.planet_size(planet); ship++)
{
if(planets.get_ship(planet,ship) == color)
{
num_home_colonies++;
break;
}
}
}
if(num_home_colonies < 3)
{
std::stringstream msg;
msg << "The " << to_string(color) << " player cannot use their alien power because they do not control at least three of their home planets!\n";
game->get_server().broadcast_message(msg.str());
return false;
}
else
{
return true;
}
}
bool PlayerInfo::alien_revealed() const
{
return alien->get_revealed();
}
void PlayerInfo::discard_card_callback(const CosmicCardType c)
{
game->add_to_discard_pile(c);
bool card_found = false;
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == c)
{
card_found = true;
hand_erase(i);
break;
}
}
if(!card_found)
{
std::cerr << "Tried to erase " << to_string(c) << " from the " << to_string(color) << " player's hand, but couldn't find it!\n";
assert(0);
}
}
void PlayerInfo::add_card_zap_response(std::vector<GameEvent> &vret, const CosmicCardType c)
{
GameEvent ret = GameEvent(color,GameEventType::CardZap);
ret.callback_if_resolved = set_invalidate_next_callback_helper();
ret.callback_if_action_taken = [this,c] { this->discard_card_callback(c); };
vret.push_back(ret);
}
std::function<void()> PlayerInfo::set_invalidate_next_callback_helper() const
{
return [this] () { this->game->set_invalidate_next_callback(true); };
}
void PlayerInfo::can_respond(TurnPhase t, GameEvent g, std::vector<GameEvent> &vret)
{
if(alien->can_respond(current_role,t,g,color) && alien_enabled())
{
GameEvent ret = GameEvent(color,GameEventType::AlienPower);
ret.callback_if_resolved = alien->get_resolution_callback(game,color,ret,g);
ret.callback_if_action_taken = alien->get_callback_if_action_taken(game,color);
vret.push_back(ret);
}
if(g.event_type == GameEventType::AlienPower)
{
//We can respond if we have a CosmicZap
//If the zap resolves, the zapped alien is invalid until the next encounter
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::CosmicZap)
{
GameEvent ret = GameEvent(color,GameEventType::CosmicZap);
ret.callback_if_resolved = [this,g] () { this->game->set_invalidate_next_callback(true); this->game->zap_alien(g.player); };
const CosmicCardType c = *i;
ret.callback_if_action_taken = [this,c] { discard_card_callback(c); };
vret.push_back(ret);
}
}
}
else if(g.event_type == GameEventType::CosmicZap)
{
//We can respond if we have a CardZap
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::CardZap)
{
add_card_zap_response(vret,*i);
}
}
}
else if(g.event_type == GameEventType::CardZap)
{
//Counter wars!
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::CardZap)
{
add_card_zap_response(vret,*i);
}
}
}
else if(g.event_type == GameEventType::MobiusTubes)
{
//We can respond if we have a CardZap
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::CardZap)
{
add_card_zap_response(vret,*i);
}
}
}
else if(g.event_type == GameEventType::Plague)
{
//We can respond if we have a CardZap
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::CardZap)
{
add_card_zap_response(vret,*i);
}
//NOTE: More generally, we can respond with any card that can be played during the same phase as the plague (regroup)
//For now we sort of implicitly respect this rule but it would be better to use a more explicit approach that checks the phases
else if(*i == CosmicCardType::MobiusTubes) //Respond to the Plague with Mobius Tubes (to avoid discarding it, for instance)
{
GameEvent ret = GameEvent(color,GameEventType::MobiusTubes);
ret.callback_if_resolved = [this] () { this->game->free_all_ships_from_warp(); };
const CosmicCardType c = *i;
ret.callback_if_action_taken = [this,c] { discard_card_callback(c); };
vret.push_back(ret);
}
}
}
else if(g.event_type == GameEventType::ForceField)
{
//We can respond if we have a CardZap
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::CardZap)
{
add_card_zap_response(vret,*i);
}
}
}
else if(g.event_type == GameEventType::EmotionControl)
{
//We can respond if we have a CardZap
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::CardZap)
{
add_card_zap_response(vret,*i);
}
}
}
else if(g.event_type == GameEventType::Reinforcement2 || g.event_type == GameEventType::Reinforcement3 || g.event_type == GameEventType::Reinforcement5)
{
//We can respond with another reinforcement card, but only if we are a main player or ally
if(current_role != EncounterRole::None)
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::Reinforcement2)
{
GameEvent ret = GameEvent(color,GameEventType::Reinforcement2);
vret.push_back(ret);
GameEvent &ret_ref = vret.back();
const CosmicCardType c = *i;
ret_ref.callback_if_action_taken = [this,&ret_ref,c] { this->game->setup_reinforcements(ret_ref); discard_card_callback(c); };
ret_ref.callback_if_resolved = [this,&ret_ref] () { this->game->add_reinforcements(ret_ref,2); }; //This lambda needs to capture a reference to g because we want it to have access to the object altered by setup_reinforcements, which will occur later
}
else if(*i == CosmicCardType::Reinforcement3)
{
GameEvent ret = GameEvent(color,GameEventType::Reinforcement3);
vret.push_back(ret);
GameEvent &ret_ref = vret.back();
const CosmicCardType c = *i;
ret_ref.callback_if_action_taken = [this,&ret_ref,c] { this->game->setup_reinforcements(ret_ref); discard_card_callback(c); };
ret_ref.callback_if_resolved = [this,&ret_ref] () { this->game->add_reinforcements(ret_ref,3); }; //This lambda needs to capture a reference to g because we want it to have access to the object altered by setup_reinforcements, which will occur later
}
else if(*i == CosmicCardType::Reinforcement5)
{
GameEvent ret = GameEvent(color,GameEventType::Reinforcement5);
vret.push_back(ret);
GameEvent &ret_ref = vret.back();
const CosmicCardType c = *i;
ret_ref.callback_if_action_taken = [this,&ret_ref,c] { this->game->setup_reinforcements(ret_ref); discard_card_callback(c); };
ret_ref.callback_if_resolved = [this,&ret_ref] () { this->game->add_reinforcements(ret_ref,5); }; //This lambda needs to capture a reference to g because we want it to have access to the object altered by setup_reinforcements, which will occur later
}
}
}
}
else if(g.event_type == GameEventType::Quash)
{
//We can respond if we have a CardZap
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::CardZap)
{
add_card_zap_response(vret,*i);
}
}
}
else if(g.event_type == GameEventType::IonicGas)
{
//We can respond if we have a CardZap
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::CardZap)
{
add_card_zap_response(vret,*i);
}
}
}
else if(g.event_type == GameEventType::SuccessfulNegotiation) //Negotiation was successful, but hasn't resolved yet (can still be quashed)
{
//We can respond with a Quash
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::Quash)
{
GameEvent ret = GameEvent(color,GameEventType::Quash);
ret.callback_if_resolved = [this] () { this->game->get_deal_params().successful = false; };
const CosmicCardType c = *i;
ret.callback_if_action_taken = [this,c] { this->discard_card_callback(c); };
vret.push_back(ret);
}
}
}
else if(g.event_type == GameEventType::CosmicDeckShuffle)
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::Flare_TickTock && can_use_flare(*i,false,"Tick-Tock"))
{
GameEvent ret = GameEvent(color,GameEventType::Flare_TickTock_Wild);
ret.callback_if_resolved = [this] () { this->game->establish_colony_on_opponent_planet(this->color); };
const CosmicCardType c = *i; //Flares are only discarded when zapped
ret.callback_if_countered = [this,c] { this->discard_card_callback(c); };
ret.callback_if_action_taken = [this,c] () { this->game->cast_flare(this->color,c,false); };
vret.push_back(ret);
}
}
}
else if(g.event_type == GameEventType::SuccessfulDeal || g.event_type == GameEventType::EncounterWin) //For now these two events can only be responded to by the Tick-Tock flare; if that changes we'll need to handle them separately
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::Flare_TickTock && can_use_flare(*i,true,"Tick-Tock") && (current_role == EncounterRole::Offense || current_role == EncounterRole::Defense))
{
if((g.event_type == GameEventType::SuccessfulDeal && (game->get_offense() == color || game->get_defense() == color)) || (g.event_type == GameEventType::EncounterWin && g.player == color))
{
GameEvent ret = GameEvent(color,GameEventType::Flare_TickTock_Super);
ret.callback_if_resolved = [this] () { this->game->trade_ship_for_tick_tock_token(this->color); };
const CosmicCardType c = *i; //Flares are only discarded when zapped
ret.callback_if_countered = [this,c] { this->discard_card_callback(c); };
ret.callback_if_action_taken = [this,c] () { this->game->cast_flare(this->color,c,true); };
vret.push_back(ret);
}
}
}
}
else if(g.event_type == GameEventType::CastFlare)
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::Flare_Remora && g.player != color && can_use_flare(*i,false,"Remora"))
{
GameEvent ret = GameEvent(color,GameEventType::Flare_Remora_Wild);
ret.callback_if_resolved = [this] () {this->game->draw_cosmic_card(*this); };
const CosmicCardType c = *i;
ret.callback_if_countered = [this,c] () { this->discard_card_callback(c); };
ret.callback_if_action_taken = [this,c] () { this->game->cast_flare(this->color,c,false); };
vret.push_back(ret);
}
}
}
else if(g.event_type == GameEventType::NewColony)
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::Flare_Remora && g.player != color && can_use_flare(*i,true,"Remora"))
{
GameEvent ret = GameEvent(color,GameEventType::Flare_Remora_Super);
ret.callback_if_resolved = [this] () { this->game->resolve_defender_reward(this->color); };
const CosmicCardType c = *i;
ret.callback_if_countered = [this,c] { this->discard_card_callback(c); };
ret.callback_if_action_taken = [this,c] () { this->game->cast_flare(this->color,c,true); };
vret.push_back(ret);
}
}
}
else if(g.event_type == GameEventType::DefensiveEncounterLoss)
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::Flare_Spiff && current_role == EncounterRole::Defense && t == TurnPhase::Resolution && can_use_flare(*i,false,"Spiff"))
{
GameEvent ret = GameEvent(color,GameEventType::Flare_Spiff_Wild);
ret.callback_if_resolved = [this] () { this->game->resolve_spiff_wild_flare(); };
const CosmicCardType c = *i;
ret.callback_if_countered = [this,c] { this->discard_card_callback(c); };
ret.callback_if_action_taken = [this,c] () { this->game->cast_flare(this->color,c,false); };
vret.push_back(ret);
}
}
}
else if(g.event_type == GameEventType::CrashLandSuperTrigger)
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
//Technically this can't be used if the alien power was used, but since all that does is set a variable to true and since that's all this effect has as well, it doesn't matter if a player opts to do "both"
if(*i == CosmicCardType::Flare_Spiff && current_role == EncounterRole::Offense && t == TurnPhase::Resolution && can_use_flare(*i,true,"Spiff"))
{
GameEvent ret = GameEvent(color,GameEventType::Flare_Spiff_Super);
ret.callback_if_resolved = alien->get_resolution_callback(game,color,ret,g);
const CosmicCardType c = *i;
ret.callback_if_countered = [this,c] { this->discard_card_callback(c); };
ret.callback_if_action_taken = [this,c] () { this->game->cast_flare(this->color,c,true); };
vret.push_back(ret);
}
}
}
else if(g.event_type == GameEventType::Flare_Human_Super) //Needs special handling compared to other flares
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
//Card zapping the flare lets the alien power resolve if that choice was selected or it prevents the human from zapping themself
if(*i == CosmicCardType::CardZap)
{
GameEvent ret = GameEvent(color,GameEventType::CardZap);
ret.callback_if_resolved = [this,g] ()
{
this->game->set_invalidate_next_callback(true);
this->game->player_discard(g.player,to_cosmic_card_type(g.event_type));
assert(this->game->get_human_super_flare_choice() != -1 && "Need to card zap Human super flare but it was never cast!");
if(this->game->get_human_super_flare_choice() == 0)
{
//Resolve the Human's alien power instead of the alternate version from the super flare
this->game->get_alien_resolution_callback(g.player);
}
//Otherwise invalidating the next callback is sufficient, so we're done
};
const CosmicCardType c = *i;
ret.callback_if_action_taken = [this,c] { discard_card_callback(c); };
vret.push_back(ret);
}
//Sort of nonsensical in this case; if human chooses to zap himself then zapping him produces the same effect except he keeps the flare and if human chooses to add 8 zapping still lets him win
else if(*i == CosmicCardType::CosmicZap)
{
GameEvent ret = GameEvent(color,GameEventType::CosmicZap);
ret.callback_if_resolved = [this,g] () { this->game->set_invalidate_next_callback(true); this->game->zap_alien(g.player); this->game->human_encounter_win_condition(); };
const CosmicCardType c = *i;
ret.callback_if_action_taken = [this,c] { discard_card_callback(c); };
vret.push_back(ret);
}
}
}
else if(g.event_type == GameEventType::Flare_Trader_Super) //Needs special handling compared to other flares; this event really represents an alien power+flare
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
//Zap the flare so it gets discarded, the original alien power still resolves
if(*i == CosmicCardType::CardZap)
{
GameEvent ret = GameEvent(color,GameEventType::CardZap);
//We counter the existing event which was the alien power + super, but still need the base alien power to resolve so we do that as a resolution of the counter; a bit ghetto, but it should work
ret.callback_if_resolved = [this,g] () { this->game->set_invalidate_next_callback(true); this->game->player_discard(g.player,to_cosmic_card_type(g.event_type)); this->game->get_alien_resolution_callback(g.player); };
const CosmicCardType c = *i;
ret.callback_if_action_taken = [this,c] { this->discard_card_callback(c); };
vret.push_back(ret);
}
//Zap the alien power itself so nothing resolves but the Trader keeps the flare
else if(*i == CosmicCardType::CosmicZap)
{
GameEvent ret = GameEvent(color,GameEventType::CosmicZap);
ret.callback_if_resolved = [this,g] () { this->game->set_invalidate_next_callback(true); this->game->zap_alien(g.player); };
const CosmicCardType c = *i;
ret.callback_if_action_taken = [this,c] { discard_card_callback(c); };
vret.push_back(ret);
}
}
}
else if(g.event_type == GameEventType::Flare_Virus_Super)
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::CardZap)
{
//Flare is discarded but the base alien power resolves
GameEvent ret = GameEvent(color,GameEventType::CardZap);
ret.callback_if_resolved = [this,g] () { this->game->set_invalidate_next_callback(true); this->game->player_discard(g.player,to_cosmic_card_type(g.event_type)); this->game->get_alien_resolution_callback(g.player); };
const CosmicCardType c = *i;
ret.callback_if_action_taken = [this,c] { discard_card_callback(c); };
vret.push_back(ret);
}
else if(*i == CosmicCardType::CosmicZap)
{
//Nothing resolves but the flare is kept
GameEvent ret = GameEvent(color,GameEventType::CosmicZap);
ret.callback_if_resolved = [this,g] () { this->game->set_invalidate_next_callback(true); this->game->zap_alien(g.player); };
const CosmicCardType c = *i;
ret.callback_if_action_taken = [this,c] { discard_card_callback(c); };
vret.push_back(ret);
}
}
}
//Catchall for any flare; NOTE: We may need to change these nested if/else stmts to separate if stmts in case there are responses to flares that aren't card zaps
else if((static_cast<unsigned>(g.event_type) >= static_cast<unsigned>(GameEventType::Flare_TickTock_Wild)) && g.event_type != GameEventType::None)
{
for(auto i=hand.begin(),e=hand.end();i!=e;++i)
{
if(*i == CosmicCardType::CardZap)
{
//Can't use add_card_zap_response() here because it doesn't force the player to discard the flare -- in other uses the player will have already discarded the card being zapped on cast
GameEvent ret = GameEvent(color,GameEventType::CardZap);
ret.callback_if_resolved = [this,g] () { this->game->set_invalidate_next_callback(true); this->game->player_discard(g.player,to_cosmic_card_type(g.event_type)); }; //TODO: Can we safely call get_alien_resolution_callback here since it will be null for most aliens?
const CosmicCardType c = *i;
ret.callback_if_action_taken = [this,c] { discard_card_callback(c); };
vret.push_back(ret);
}
else if(*i == CosmicCardType::CosmicZap && is_super_flare(g.event_type))
{
GameEvent ret = GameEvent(color,GameEventType::CosmicZap);
ret.callback_if_resolved = [this,g] () { this->game->set_invalidate_next_callback(true); this->game->zap_alien(g.player); };
const CosmicCardType c = *i;
ret.callback_if_action_taken = [this,c] { discard_card_callback(c); };
vret.push_back(ret);
}
}
}
else if(g.event_type == GameEventType::DrawCard || g.event_type == GameEventType::RetrieveWarpShip || g.event_type == GameEventType::DefensiveEncounterWin || g.event_type == GameEventType::CrashLandTrigger || g.event_type == GameEventType::DestinyCardDrawn || g.event_type == GameEventType::DestinyWildDrawn)
{
//Nothing to do here, these events can only be responded to by Alien powers and that's already been taken care of
}
else
{
assert(0);
}
}
bool PlayerInfo::can_use_flare(const CosmicCardType flare, bool super, const std::string &alien_name) const
{
if(super)
{
//Super part of the flare: Can only be used by the alien on the card when that alien hasn't been zapped and that alien's power has not been lost
return alien->get_name().compare(alien_name) == 0 && alien_enabled() && !used_flare_this_turn && !game->check_for_used_flare(flare);
}
else
{
//Wild part of the flare: Can be used by aliens that aren't the name of the alien on the card or by the alien on the card when that alien's power is disabled or zapped
return (alien->get_name().compare(alien_name) != 0 || !alien_enabled()) && !used_flare_this_turn && !game->check_for_used_flare(flare);
}
}
GameEvent PlayerInfo::can_use_alien_with_empty_stack(const TurnPhase t) const
{
if(alien->check_for_game_event(current_role,t) && alien_enabled())
{
//Warpish also needs to have revealed an attack card; ideally this check would be within check_for_game_event but we don't yet pass that information
bool event_valid = false;
if(alien->get_name().compare("Warpish") == 0)
{
if((game->get_offense() == color && is_attack_card(game->get_offensive_encounter_card())) || (game->get_defense() == color && is_attack_card(game->get_defensive_encounter_card())))
{
event_valid = true;
}
}
else
{
event_valid = true;
}
if(event_valid)
{
GameEvent ret = GameEvent(color,GameEventType::AlienPower);
GameEvent bogus = GameEvent(PlayerColors::Invalid,GameEventType::None); //Some Aliens need to know which GameEvent they're responding to in order to take the correct action (Remora). In this case, there is no event to respond to
ret.callback_if_resolved = alien->get_resolution_callback(game,color,ret,bogus);
ret.callback_if_countered = alien->get_callback_if_countered(game,color);
ret.callback_if_action_taken = alien->get_callback_if_action_taken(game,color);
return ret;
}
}
return GameEvent(color,GameEventType::None);
}
const std::string PlayerInfo::get_alien_desc() const
{
return alien->get_desc();
}
void PlayerInfo::update_client_hand() const
{
game->send_player_hand(color);
game->broadcast_player_hand_size(color);
}
void PlayerInfo::hand_push_back(const CosmicCardType c)
{
hand.push_back(c);
update_client_hand();
}
void PlayerInfo::hand_clear()
{
hand.clear();
update_client_hand();
}
void PlayerInfo::set_game_state(GameState *g)
{
game = g;
std::function<void()> callback = [this] () { this->game->update_planets(); };
planets.set_server_callback(callback);
}