void verif_maps_crees() { int i; /* On verifie que les 3 premiers inodes sont a 1 et tous les autres à 0 */ for (i = 0; i < NB_INODES; i = i + 1) { if (i < 3) assert(info_map(inodes, i) == 1); else assert(info_map(inodes, i) == 0); } /* On verifie que tous les blocs sont à 0 */ for (i = 0; i < BLOCS_RESTANTS; i = i + 1) { assert(info_map(blocs,i) == 0); } /* Cas limites : demande d'états incorrects */ assert(info_map(inodes, -1) == -1); assert(info_map(blocs, -1) == -1); assert(info_map(inodes, NB_INODES) == -1); assert(info_map(blocs, BLOCS_RESTANTS) == -1); }
void StorageSystem::issue_jobs() { auto storeloc = info_map.begin(); for (auto it = global_set<item::Item>::begin(); it != global_set<item::Item>::end(); ++it) { // We only store items not currently being used. if ((*it)->locked) { continue; } // We only store food. if (!(*it)->parent->has<Foodstuff>()) { continue; } // Is this item currently in a stockpile? auto pt = (*it)->pos(); if (info_map(pt.as_point()) != nullptr) { continue; } // Do we already have a job for this item? auto jptr = std::lower_bound(jobs.begin(), jobs.end(), *it, [](const jobs_t::value_type& l, item::Item* item) -> bool { return l.first < item; }); if (jptr != jobs.end() && jptr->first == *it) { continue; } // Find a free space to store it for(;;) { if (storeloc == info_map.end()) { return; } if (*storeloc != nullptr && *storeloc != this) { break; } ++storeloc; } // We will only reach here if: // * the item is unlocked // * the item is food // * the item is not in a stockpile // * we do not have a job for the item // * we have found a free stockpile space point dest = info_map.pointof(storeloc); auto jb = make_storage_job({ city, dest.first, dest.second }, *it); job::JobList::getJoblist().add_job(jb); jobs.emplace_back(*it, jb); ++storeloc; } }
/// Creates (effectively) a bitmap of the storage situation ///@todo Use the job list to clear out any in-progress destinations void StorageSystem::build_info_map() { info_map.resize(city->getXSize(), city->getYSize()); info_map.clear(); for (auto e : ents) { auto storage = e->assert_get<Storage>(); // For the moment, we only support storage rooms auto room = e->assert_get<Room>(); for (auto y = room->r.y; y < room->r.y + room->r.h; ++y) { for (auto x = room->r.x; x < room->r.x + room->r.w; ++x) { if (city->ent(x, y).empty()) { info_map(x, y) = storage; } else { // Quick hack. info_map(x, y) = this; } } } } }
void modifier_maps() { int i; superbloc_s *ptr = recup_ptr_superbloc(); /* Modification des blocs : tout a 1*/ for (i = 0; i < BLOCS_RESTANTS; i++) { //modifier_map(blocs, i, 1); // modifier map ne décremente pas !! recuperer_id(blocs); } assert(ptr->nb_blocs_libres == 0); /* Modification des inodes */ for (i = 0; i < NB_INODES; i++) { //modifier_map(inodes, i, 1); recuperer_id(inodes); } assert(ptr->nb_inodes_libres == 0); /* Verification que tout est à 1*/ for (i = 0; i < BLOCS_RESTANTS; i++) assert(info_map(blocs, i) == 1); for (i = 0; i < NB_INODES; i++) assert(info_map(inodes, i) == 1); /* Plus de place disponible */ assert(recuperer_id(inodes) == -1); assert(recuperer_id(blocs) == -1); assert(ptr->nb_blocs_libres == 0); assert(ptr->nb_inodes_libres == 0); /* Quelques modif */ /* Liberation */ liberer_id(inodes, 214); liberer_id(inodes, 18); assert(ptr->nb_inodes_libres == 2); liberer_id(blocs, 5); liberer_id(blocs, 850); assert(ptr->nb_blocs_libres == 2); /* Verification que les bits ont bien ete mis à 0 */ assert(info_map(inodes, 18) == 0); assert(info_map(inodes, 214) == 0); assert(info_map(blocs, 5) == 0); assert(info_map(blocs, 850) == 0); /* Recuperation des id : on recupere bien ce qu'on a libéré */ assert(recuperer_id(inodes) == 18); assert(recuperer_id(inodes) == 214); assert(recuperer_id(blocs) == 5); assert(recuperer_id(blocs) == 850); /* Verification que les bits ont bien ete REMIS à 1 */ assert(info_map(inodes, 18) == 1); assert(info_map(inodes, 214) == 1); assert(info_map(blocs, 5) == 1); assert(info_map(blocs, 850) == 1); }