-
Notifications
You must be signed in to change notification settings - Fork 1
/
Creature.cpp
149 lines (115 loc) · 4.41 KB
/
Creature.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// Created by KunstDerFuge on 1/23/18.
//
#include <iostream>
#include <vector>
#include <tgmath.h>
#include <SFML/Graphics/RectangleShape.hpp>
#include "Creature.h"
#include "Body.h"
#include "Player.h"
using namespace std;
float Creature::getWeight() {
return body->weight;
}
float Creature::getSize() {
return body->size;
}
Creature *Creature::generateRandom(int sizeClass, WorldMap* worldMap) {
float size;
int locomotion;
int composition;
list<string> tags;
switch (sizeClass) {
case SIZE_TINY:
size = randomSampleNormal(12, 2, 6, 20);
locomotion = randomChoiceFromWeights( {1, 3, 4, 3, 6, 6, 0, 1} ); // Weights for each respective type of locomotion
break;
case SIZE_SMALL:
size = randomSampleNormal(576, 144, 20, 864);
locomotion = randomChoiceFromWeights( {3, 4, 4, 3, 4, 6, 4, 1} );
break;
case SIZE_MEDIUM:
size = randomSampleNormal(1152, 144, 864, 1440);
locomotion = randomChoiceFromWeights( {4, 5, 2, 2, 2, 3, 1, 1} );
break;
case SIZE_LARGE:
size = randomSampleNormal(2592, 288, 1440, 4032);
locomotion = randomChoiceFromWeights( {3, 5, 1, 1, 2, 2, 1, 1} );
break;
case SIZE_COLOSSAL:
size = randomSampleNormal(14400, 432, 10000, 72000);
locomotion = randomChoiceFromWeights( {2, 2, 1, 1, 1, 1, 1, 1} );
break;
default:
cerr << "Unknown size class: " << sizeClass << endl;
throw;
}
auto randomX = randomFromXToY(-1000, 1000);
auto randomY = randomFromXToY(-1000, 1000);
auto* creature = new Creature(Point(randomX, randomY), worldMap);
list<BodyPart*> parts;
list<BodyRegion*> regions;
switch (locomotion) {
// flesh, gelatinous, mucousy, tough scales, slimy scales, chitin
case LOCOMOTION_BIPEDAL:
case LOCOMOTION_QUADRUPEDAL:
composition = randomChoiceFromWeights( {5, 0, 1, 2, 2, 1} );
break;
case LOCOMOTION_OCTOPEDAL:
composition = randomChoiceFromWeights( {1, 0, 0, 0, 0, 5} );
break;
case LOCOMOTION_SLITHERING:
composition = randomChoiceFromWeights( {2, 2, 5, 3, 4, 0} );
break;
case LOCOMOTION_GASTROPEDAL:
composition = randomChoiceFromWeights( {0, 1, 5, 1, 1, 0} );
break;
case LOCOMOTION_TENTACLE_CRAWLING:
composition = randomChoiceFromWeights( {0, 1, 4, 2, 3, 0} );
break;
case LOCOMOTION_FLYING:
composition = randomChoiceFromWeights( {3, 0, 2, 2, 2, 0} );
break;
case LOCOMOTION_PSYCHIC:
composition = randomChoiceFromWeights( {1, 1, 1, 1, 1, 1} );
break;
default:
cerr << "Unknown locomotion type: " << locomotion << endl;
throw;
}
//creature->body = new Body();
vector<string> sizeClassVect = {"Tiny", "Small", "Medium", "Large", "Colossal"};
vector<string> types = {"terrestrial", "snakelike", "amphibious", "fishy", "lizardlike", "snail", "crab", "blob"};
vector<string> locomotionVect = {"Bipedal", "Quadripedal", "Octopedal", "Slithering", "Gastropedal", "Tentacle crawling", "Flying", "Psychic"};
vector<string> compositionVect = {"Flesh", "Gelatinous", "Mucousy", "Tough scales", "Slimy scales", "Chitin"};
cout << "Size: " << size << " in^2" << endl;
cout << "Size class: " << sizeClassVect[sizeClass] << endl;
cout << "Locomotion: " << locomotionVect[locomotion] << endl;
cout << "Composition: " << compositionVect[composition] << endl;
cout << endl;
return nullptr;
//body = new Body(0, 0, 0);
}
void Creature::setBody(Body* body) {
this->body = body;
}
Creature::Creature(Point location, WorldMap* worldMap) : location(location), worldMap(worldMap) {
worldMap->addCreature(this);
}
Point Creature::getLocation() {
return location;
}
void Creature::render(sf::Texture* texture, VisibleMap* visibleMap, sf::RenderTexture& mapWindow) {
sf::RectangleShape tile;
tile.setPosition(visibleMap->getRenderCoord(location));
tile.setSize(sf::Vector2f(TILE_WIDTH, TILE_WIDTH));
tile.setTexture(texture);
mapWindow.draw(tile);
}
WorldMap *Creature::getWorldMap() {
return worldMap;
}
Point Creature::getAdjacentPoint(direction dir) {
return getAdjacentLocation(location, dir);
}