This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathnature.cpp
More file actions
76 lines (64 loc) · 2.02 KB
/
Copy pathnature.cpp
File metadata and controls
76 lines (64 loc) · 2.02 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
#include "nature.h"
#include "action.h"
/*! \file nature.cpp
\brief Plik zawierający metody z klasy Natura.
*/
nature *nature::jungl = 0;
nature *nature::jungle()
{
if (!jungl) jungl = new nature();
return jungl;
}
void nature::set(int day,bool anoon,int place)
{
daytime=day;
afternoon=anoon;
if(place!=2)
safe_place=place;
}
action* nature::random_nature_response()
{
int rand_max=0; //algorytm losowania z uwzglednieniem szansy wystapienia
for (vector<action>::iterator it = jungle_response.begin() ; it != jungle_response.end(); ++it)
{
rand_max+=(*it).get_action_chance_single(daytime-1);
}
int fate=rand() % rand_max;
int i;
int sum=0;
for (i = 0 ; i<= jungle_response.size(); i++)
{
sum+=jungle_response[i].get_action_chance_single(daytime-1);
if(sum>=rand_max-fate) break;
}
killer=jungle_response[i].get_action_name();
return &jungle_response[i];
}
longaction nature::get_longaction(action* last)
{
string _type; //pobieram sobie typ statniej akcji
_type=(*last).get_action_longterm_type();
vector<longaction*>longactionsOfSpecyficType;
for (vector<longaction>::iterator it = long_term_conditions.begin() ; it != long_term_conditions.end(); ++it)
{
if((*it).get_longaction_type()==_type)
longactionsOfSpecyficType.push_back(&(*it));
}
//algorytm losowania longakcji z uwzglednieniem szansy wystapienia pomiędzy innymi longakcjami teog samego typu
int rand_max=0;
for (vector<longaction*>::iterator it = longactionsOfSpecyficType.begin() ; it != longactionsOfSpecyficType.end(); ++it)
{
rand_max+=(*it)->get_action_chance_single(0);
}
int fate=rand() % rand_max;
int i;
int sum=0;
for (i = 0 ; i<= longactionsOfSpecyficType.size(); i++)
{
sum+=longactionsOfSpecyficType[i]->get_action_chance_single(0);
if(sum>=rand_max-fate) break;
}
longaction to_return=*longactionsOfSpecyficType[i];
longactionsOfSpecyficType.clear();
return to_return;
}