aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.cpp')
-rw-r--r--src/world.cpp69
1 files changed, 44 insertions, 25 deletions
diff --git a/src/world.cpp b/src/world.cpp
index baf3080..5893bfb 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -214,7 +214,7 @@ generate(unsigned int width)
// create slopes from the points that were just defined, populate the rest of the WorldData structure
- for(wditer = worldData.begin() + 1; wditer != worldData.end(); wditer++){
+ for(wditer = worldData.begin() + 1; wditer != worldData.end(); wditer++) {
if ((*wditer).groundHeight && wditer + GROUND_HILLINESS < worldData.end())
// wditer + GROUND_HILLINESS can go out of bounds (invalid read)
geninc = ((*(wditer + GROUND_HILLINESS)).groundHeight - (*wditer).groundHeight) / (float)GROUND_HILLINESS;
@@ -390,7 +390,6 @@ draw(Player *p)
l.loc.x = l.following->loc.x + SCREEN_WIDTH/2;
l.loc.y = l.following->loc.y;
}
-
if (l.flame) {
l.fireFlicker = .9+((rand()%2)/10.0f);
l.fireLoc.x = l.loc.x + (rand()%2-1)*3;
@@ -410,7 +409,7 @@ draw(Player *p)
GLfloat flameArray[64];
for (uint i = 0; i < light.size(); i++) {
- if(light[i].flame){
+ if (light[i].flame) {
pointArray[2 * i ] = light[i].fireLoc.x - offset.x;
pointArray[2 * i + 1] = light[i].fireLoc.y;
}else{
@@ -566,7 +565,7 @@ singleDetect(Entity *e)
// delete the entity
for (i = 0; i < entity.size(); i++) {
- if (entity[i] == e){
+ if (entity[i] == e) {
switch (e->type) {
case STRUCTURET:
killed = "structure";
@@ -1087,7 +1086,7 @@ goWorldRight(Player *p)
{
World *tmp;
- if(!toRight.empty() && p->loc.x + p->width > -worldStart - HLINE * 15) {
+ if (!toRight.empty() && p->loc.x + p->width > -worldStart - HLINE * 15) {
tmp = loadWorldFromPtr(currentWorldToRight);
p->loc.x = tmp->worldStart - HLINE * -15.0f;
@@ -1295,10 +1294,10 @@ bool isCurrentWorldIndoors(void) {
return !inside.empty();
}
-IndoorWorld::IndoorWorld(void){
+IndoorWorld::IndoorWorld(void) {
}
-IndoorWorld::~IndoorWorld(void){
+IndoorWorld::~IndoorWorld(void) {
delete bgTex;
deleteEntities();
@@ -1421,7 +1420,7 @@ draw(Player *p)
GLfloat flameArray[64];
for (i = 0; i < light.size(); i++) {
- if(light[i].flame){
+ if (light[i].flame) {
pointArray[2 * i ] = light[i].fireLoc.x - offset.x;
pointArray[2 * i + 1] = light[i].fireLoc.y;
}else{
@@ -1507,7 +1506,7 @@ draw(Player *p)
p->draw();
}
-Arena::Arena(World *leave,Player *p,Mob *m){
+Arena::Arena(World *leave,Player *p,Mob *m) {
generate(800);
addMob(MS_DOOR,100,100);
@@ -1522,11 +1521,11 @@ Arena::Arena(World *leave,Player *p,Mob *m){
battleNestLoc.push_back(p->loc);
}
-Arena::~Arena(void){
+Arena::~Arena(void) {
deleteEntities();
}
-World *Arena::exitArena(Player *p){
+World *Arena::exitArena(Player *p) {
World *tmp;
if (!mmob->alive &&
p->loc.x + p->width / 2 > mob[0]->loc.x &&
@@ -1571,7 +1570,7 @@ std::string getWorldWeatherStr(WorldWeather ww)
static bool loadedLeft = false;
static bool loadedRight = false;
-World *loadWorldFromXML(std::string path){
+World *loadWorldFromXML(std::string path) {
if (!currentXML.empty())
currentWorld->save();
@@ -1627,7 +1626,7 @@ loadWorldFromXMLNoSave(std::string path) {
}
// attempt to load an <IndoorWorld> tag
- else if((wxml = xml.FirstChildElement("IndoorWorld"))) {
+ else if ((wxml = xml.FirstChildElement("IndoorWorld"))) {
wxml = wxml->FirstChildElement();
vil = NULL;
tmp = new IndoorWorld();
@@ -1800,10 +1799,9 @@ loadWorldFromXMLNoSave(std::string path) {
vil = vil->FirstChildElement();
}
- while(vil){
+ while(vil) {
name = vil->Name();
randx = 0;
- //static BuySell bs;
/**
* READS DATA ABOUT STRUCTURE CONTAINED IN VILLAGE
@@ -1847,17 +1845,38 @@ loadWorldFromXMLNoSave(std::string path) {
while (sxml) {
tag = sxml->Name();
- if (tag == "buy") {
+ if (tag == "buy") { //converts price to the currencies determined in items.xml
// TODO
- } else if (tag == "sell") {
+ } else if (tag == "sell") { //converts price so the player can sell
// TODO
- } else if (tag == "trade") {
+ } else if (tag == "trade") { //doesn't have to convert anything, we just trade multiple items
tmp->merchant.back()->trade.push_back(Trade(sxml->IntAttribute("quantity"),
- sxml->StrAttribute("item"),
- sxml->IntAttribute("quantity1"),
- sxml->StrAttribute("item1")
- ));
- }
+ sxml->StrAttribute("item"),
+ sxml->IntAttribute("quantity1"),
+ sxml->StrAttribute("item1")));
+ } else if (tag == "text") { //this is what the merchant says
+ std::cout << "text" << std::endl;
+
+ XMLElement *txml = sxml->FirstChildElement();
+ std::string textOption;
+
+ while (txml) {
+ textOption = txml->Name();
+ const char* buf = txml->GetText();
+
+ if (textOption == "greet") { //when you talk to him
+ tmp->merchant.back()->text[0] = std::string(buf, strlen(buf));
+ tmp->merchant.back()->toSay = &tmp->merchant.back()->text[0];
+ } else if (textOption == "accept") { //when he accepts the trade
+ tmp->merchant.back()->text[1] = std::string(buf, strlen(buf));
+ } else if (textOption == "deny") { //when you don't have enough money
+ tmp->merchant.back()->text[2] = std::string(buf, strlen(buf));
+ } else if (textOption == "leave") { //when you leave the merchant
+ tmp->merchant.back()->text[3] = std::string(buf, strlen(buf));
+ }
+ txml = txml->NextSiblingElement();
+ }
+ }
sxml = sxml->NextSiblingElement();
}
@@ -1876,7 +1895,7 @@ loadWorldFromXMLNoSave(std::string path) {
}
std::ifstream dat (((std::string)currentXML + ".dat").c_str());
- if(dat.good()){
+ if (dat.good()) {
dat.close();
tmp->load();
}
@@ -1884,7 +1903,7 @@ loadWorldFromXMLNoSave(std::string path) {
return tmp;
}
-Village::Village(const char *meme, World *w){
+Village::Village(const char *meme, World *w) {
name = meme;
start.x = w->getTheWidth() / 2.0f;
end.x = -start.x;