353
354
* \return true/allow on low congestion-risk.
355
356
bool Flag::has_capacity_for_ware(WareInstance& ware) const {
356
358
bool test = false;
357
359
if (get_position().hash() == test_coords_hash) {
358
log("NOCOM has_capacity_for_ware (%d, %d) %s - this\n", get_position().x, get_position().y, ware.descr().name().c_str());
361
if (abs(get_position().x - test_coords.x) <= 1 && abs(get_position().y - test_coords.y) <= 1) {
362
log("NOCOM has_capacity_for_ware (%d, %d) %s - very near flag\n", get_position().x, get_position().y, ware.descr().name().c_str());
365
/*else if (get_position().x == test_coords.x - 2 || get_position().x == test_coords.x + 2 || get_position().y == test_coords.y - 2 || get_position().y == test_coords.y + 2) {
366
log("NOCOM has_capacity_for_ware (%d, %d) %s - near flag\n", get_position().x, get_position().y, ware.descr().name().c_str());
360
log("NOCOM *************** Flag::has_capacity_for_ware (%d, %d) %s - this\n", get_position().x, get_position().y, ware.descr().name().c_str());
363
if (abs(get_position().x - test_coords.x) <= 1 && abs(get_position().y - test_coords.y) <= 0) {
364
log("NOCOM *************** Flag::has_capacity_for_ware (%d, %d) %s - very near flag\n", get_position().x, get_position().y, ware.descr().name().c_str());
367
if (abs(get_position().x - test_coords.x) <= 2 && abs(get_position().y - test_coords.y) <= 0) {
368
log("NOCOM *************** Flag::has_capacity_for_ware (%d, %d) %s - near flag\n", get_position().x, get_position().y, ware.descr().name().c_str());
373
const bool test = get_position().hash() == target_flag_coords.hash();
375
log("NOCOM *************** Flag::has_capacity_for_ware (%d, %d) %s\n", get_position().x, get_position().y, ware.descr().name().c_str());
370
378
// NOCOM check this
371
379
// avoid iteration for the easy cases
372
380
if (ware_filled_ < ware_capacity_ - 2) {
373
if (test) log("NOCOM ware_filled_ < ware_capacity_ - 2 true\n");
381
if (test) log("NOCOM HAS CAPACITY ware_filled_ < ware_capacity_ - 2 true\n");
374
382
return true; // more than two free slots, allow
376
384
if (ware_filled_ >= ware_capacity_) {
377
if (test) log("NOCOM ware_filled_ >= ware_capacity_ false\n");
385
if (test) log("NOCOM NO CAPACITY ware_filled_ >= ware_capacity_ false\n");
378
386
return false; // all slots filled, no room
381
389
DescriptionIndex const descr_index = ware.descr_index();
382
390
for (int i = 0; i < ware_filled_; ++i) {
383
391
if (wares_[i].ware->descr_index() == descr_index) {
384
if (test) log("NOCOM already there - false\n");
392
if (test) log("NOCOM NO CAPACITY already there - false\n");
385
393
return false; // ware of this type already present, leave room for other types
388
if (test) log("NOCOM end - true\n");
396
if (test) log("NOCOM end - HAS CAPACITY\n");
389
397
return true; // ware of this type not present, allow
394
402
* has_capacity_for_ware() also checks ware's type to prevent congestion.
396
404
bool Flag::has_capacity() const {
397
if (get_position().hash() == test_coords_hash) {
398
log("NOCOM **** Flag::has_capacity (%d, %d)\n", get_position().x, get_position().y);
405
if (get_position().hash() == target_flag_coords.hash()) {
406
log("NOCOM *************** Flag::has_capacity (%d, %d)\n", get_position().x, get_position().y);
400
408
return (ware_filled_ < ware_capacity_);
484
492
Flag::PendingWare* Flag::get_ware_for_flag(Flag& destflag, bool const pending_only) {
485
493
bool test = false;
486
494
if (get_position().hash() == test_coords_hash) {
487
log("NOCOM get_ware_for_flag (%d, %d) -> (%d, %d) - this\n", get_position().x, get_position().y, destflag.get_position().x, destflag.get_position().y);
495
log("NOCOM ######################### get_ware_for_flag (%d, %d) -> (%d, %d) - this\n", get_position().x, get_position().y, destflag.get_position().x, destflag.get_position().y);
490
498
if (destflag.get_position().hash() == test_coords_hash) {
491
log("NOCOM get_ware_for_flag (%d, %d) -> (%d, %d) - other\n", destflag.get_position().x, destflag.get_position().y, get_position().x, get_position().y);
499
log("NOCOM ######################### get_ware_for_flag (%d, %d) -> (%d, %d) - other\n", destflag.get_position().x, destflag.get_position().y, get_position().x, get_position().y);
494
502
// NOCOM test this
495
if (test) log("NOCOM ware_filled_: %d\n", ware_filled_);
503
if (test) log("NOCOM +++ ware_filled_: %d\n", ware_filled_);
496
504
for (int32_t i = 0; i < ware_filled_; ++i) {
497
505
PendingWare* pw = &wares_[i];
499
507
log("NOCOM testing ware: %s\n", pw->ware->descr().name().c_str());
500
508
log("NOCOM !pending_only ? %s\n", !pending_only ? "true" : "false");
501
509
log("NOCOM pw->pending ? %s\n", pw->pending ? "true" : "false");
510
//pw->nextstep.get(get_owner()->egbase())->
502
511
log("NOCOM pw->nextstep == &destflag ? %s\n", pw->nextstep == &destflag ? "true" : "false");
512
if (pw->nextstep != nullptr) {
513
Coords dest_position(pw->nextstep.get(get_owner()->egbase())->get_positions(get_owner()->egbase())[0]);
514
log("NOCOM pw->nextstep position: (%d, %d)\n", dest_position.x, dest_position.y);
516
// NOCOM nextstep is empty where we should have a destination
517
log("NOCOM pw->nextstep is empty\n");
503
519
log("NOCOM destflag.allow_ware_from_flag(*pw->ware, *this) ? %s\n", destflag.allow_ware_from_flag(*pw->ware, *this) ? "true" : "false");
505
521
if ((!pending_only || pw->pending) && pw->nextstep == &destflag &&
528
// We didn't find anything with priority, so let's schedule a ware for the next round if there is one
529
if (current_wares() > 0 && destflag.current_wares() < 6) {
530
PendingWare* pw = &wares_[0];
531
if (pw->nextstep == nullptr) {
532
upcast(Game, game, &get_owner()->egbase());
533
init_ware(*game, *pw->ware, *pw);
534
pw->ware->update(*game);
512
538
if (test) log("NOCOM no ware found\n");
820
846
void Flag::call_carrier(Game& game, WareInstance& ware, PlayerImmovable* const nextstep) {
821
847
last_update_ = game.get_gametime();
822
848
if (get_position().hash() == test_coords_hash) {
823
log("NOCOM call_carrier - this\n");
849
log("NOCOM **** call_carrier - this\n");
851
if (nextstep != nullptr) {
852
Coords dest_position(nextstep->get(get_owner()->egbase())->get_positions(get_owner()->egbase())[0]);
853
log("NOCOM nextstep position: (%d, %d)", dest_position.x, dest_position.y);
855
// NOCOM nextstep is empty where we should have a destination
856
log("NOCOM nextstep is empty\n");
825
860
PendingWare* pi = nullptr;
1151
1187
const int gametime = game.get_gametime();
1152
1188
if (gametime > last_update_ + kTriggerPotentiallyFrozenFlagInterval) {
1153
1189
if (ware_filled_ > 0) {
1154
molog("%d: Potentially frozen flag for Player %d at (%d, %d) - %d wares\n", static_cast<int>(gametime / 1000), static_cast<unsigned int>(owner().player_number()), get_position().x, get_position().y, ware_filled_);
1191
log("%d: Potentially frozen flag for Player %d at (%d, %d) - %d wares\n", static_cast<int>(gametime / 1000), static_cast<unsigned int>(owner().player_number()), get_position().x, get_position().y, ware_filled_);
1155
1193
++freeze_counter_;
1157
1195
last_update_ = gametime;
1159
1197
freeze_counter_ = 0;
1161
if (freeze_counter_ > 2) {
1162
if ( ware_filled_ > 0) {
1163
log("%d: Unfreezing flag for Player %d at (%d, %d) - %d wares\n", static_cast<int>(gametime / 1000), static_cast<unsigned int>(owner().player_number()), get_position().x, get_position().y, ware_filled_);
1199
if (freeze_counter_ > 1) {
1200
if (ware_filled_ > 0) {
1202
log("%d: Unfreezing flag for Player %d at (%d, %d) - %d wares\n", static_cast<int>(gametime / 1000), static_cast<unsigned int>(owner().player_number()), get_position().x, get_position().y, ware_filled_);
1164
1204
for (int32_t i = 0; i < ware_filled_; ++i) {
1165
1205
init_ware(game, *wares_[i].ware, wares_[i]);
1166
1206
wares_[i].ware->update(game);