Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Ds::GetAllCreaturesByLevel(int MagiID, int **Creatures, int *numOfCreatures) {
- if (MagiID < 0) {
- if (creaturesByLevel.size() == 0) {
- *numOfCreatures = 0;
- *Creatures = NULL;
- return;
- }
- int size = creaturesByLevel.size();
- (*Creatures) = (int*) malloc(sizeof(int) * size);
- if (*Creatures == NULL) {
- throw bad_alloc();
- }
- Creature** tmpCreatures = creaturesByLevel.treeToArr();
- for (int i = 0; i < size; ++i) {
- (*Creatures)[size - 1 - i] = tmpCreatures[i]->ID();
- }
- delete[] tmpCreatures;
- *numOfCreatures = size;
- return;
- }
- Magi* magi = NULL;
- Magi tmpMagi = Magi(MagiID);
- if (Magis.find(&tmpMagi, &magi) == false) {
- throw DataDoesntExist();
- }
- int size = magi->numOfCreatures();
- if(!size) {
- *numOfCreatures = 0;
- *Creatures = NULL;
- return;
- }
- int* temp= (int*) malloc(sizeof(int) * size);
- (*Creatures) = temp;
- if (*Creatures == NULL) {
- throw bad_alloc();
- }
- magi->GetAllCreaturesByLevel(Creatures, numOfCreatures);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement