-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCreature_Manager.cpp
More file actions
69 lines (56 loc) · 1.15 KB
/
Creature_Manager.cpp
File metadata and controls
69 lines (56 loc) · 1.15 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
#pragma once
#ifndef WORLDSIM_CREATURE_MANAGER_CPP
#define WORLDSIM_CREATURE_MANAGER_CPP
/* WorldSim: Creature_Manager
#include "Creature_Manager.cpp"
Implementation of Creature_Manager.hpp
*/
#include "Creature_Species.hpp"
#include "Creature_Manager.hpp"
Creature_Manager::Creature_Manager()
{
totalSpawnWeight=0;
rng.seed(SEEDER);
}
void Creature_Manager::generate (const int amount /*=1*/)
{
int currentPoints=1000;
for (int i=0; i<amount; ++i)
{
vSpecies.push(creatureGenerator.get(currentPoints));
totalSpawnWeight+=currentPoints;
currentPoints/=2;
}
}
// return a random flora from the weighted lists
Creature_Species* Creature_Manager::get()
{
return 0;
vSpecies.clear();
std::cout<<"vspecies size: "<<vSpecies.size()<<"\n";
return 0;
if (vSpecies.size() == 0 )
{
return 0;
}
if ( vSpecies.size() == 1 )
{
return vSpecies(0);
}
int floraSlot=0;
if (totalSpawnWeight>0)
{
floraSlot = rng.rand32(totalSpawnWeight-1);
}
int currentWeighting = 0;
for (int i=0; i<vSpecies.size(); ++i)
{
currentWeighting+=vSpecies(i)->spawnWeight;
if ( currentWeighting >= floraSlot )
{
return vSpecies(i);
}
}
return 0;
}
#endif