diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2016-03-14 07:34:08 -0400 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2016-03-14 07:34:08 -0400 |
commit | 569d23b5d4577fce1473a82ae7f8977205ff7f0f (patch) | |
tree | 6c07dd0389dad04c2b8ccd93068f173547b0bb8e /src | |
parent | 98e08cb7c2ae6c61192bac73a1fc7254224452be (diff) |
Faggot
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 90 | ||||
-rw-r--r-- | src/ui.cpp | 47 | ||||
-rw-r--r-- | src/world.cpp | 25 |
3 files changed, 100 insertions, 62 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index 8a10428..6d0f052 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -169,6 +169,7 @@ Merchant::Merchant(){ //sets all of the Merchant specific traits on object creat canMove = true; trade.reserve(100); + currTrade = 0; //tex = new Texturec(1,"assets/NPC.png"); //inv = new Inventory(NPC_INV_SIZE); @@ -433,50 +434,68 @@ void NPC::clearAIFunc(void){ } void NPC::interact(){ //have the npc's interact back to the player - int (*func)(NPC *); - loc.y += 5; - - canMove=false; - left = (player->loc.x < loc.x); - right = !left; - - if(aiFunc.size()){ - func=aiFunc.front(); + std::thread([this]{ + int (*func)(NPC *); + loc.y += 5; + + canMove=false; + left = (player->loc.x < loc.x); + right = !left; - if(!func(this)){ - if(aiFunc.size())aiFunc.erase(aiFunc.begin()); + if(aiFunc.size()){ + func=aiFunc.front(); + + if(!func(this)){ + if(aiFunc.size())aiFunc.erase(aiFunc.begin()); + } + }else{ + ui::dialogBox(name,NULL,false,randomDialog[randDialog]); } - }else{ - ui::dialogBox(name,NULL,false,randomDialog[randDialog]); - } - ui::waitForDialog(); - canMove=true; + ui::waitForDialog(); + canMove=true; + }).detach(); } void Merchant::interact(){ - ui::merchantBox(name, trade.back(), ":Accept:Good-Bye", false, "Welcome to Smithy\'s. Buy your sausages here you freaking meme lording screw-face"); - ui::waitForDialog(); - if(ui::dialogOptChosen == 1){ - std::cout << "Gimme ye' munny" << std::endl; - if(player->inv->takeItem(trade.back().item[1],trade.back().quantity[1]) >= 0) - player->inv->addItem(trade.back().item[0],trade.back().quantity[0]); - }else{ - std::cout << "See ye!" << std::endl; - } + std::thread([this]{ + ui::merchantBox(name, trade[currTrade], ":Accept:Good-Bye", false, "Welcome to Smithy\'s. Buy your sausages here you freaking meme lording screw-face"); + ui::waitForDialog(); + if(ui::dialogOptChosen == 1){ + std::cout << "Gimme ye' munny" << std::endl; + if(!(player->inv->takeItem(trade[currTrade].item[1],trade[currTrade].quantity[1]))) + player->inv->addItem(trade[currTrade].item[0],trade[currTrade].quantity[0]); + }else if(ui::dialogOptChosen == 2){ + std::cout << "See ye!" << std::endl; + }else if(ui::merchOptChosen == 1){ + if(currTrade != 0){ + currTrade--; + std::cout << "Last trade" << std::endl; + interact(); + } + }else if(ui::merchOptChosen == 2){ + if(currTrade < trade.size()){ + currTrade++; + std::cout << "Next trade" << std::endl; + interact(); + } + } + }).detach(); } void Object::interact(void){ - if(questObject && alive){ - ui::dialogBox( player->name, ":Yes:No", false, pickupDialog.c_str()); - ui::waitForDialog(); - if(ui::dialogOptChosen == 1){ - player->inv->addItem( iname, 1 ); + std::thread([this]{ + if(questObject && alive){ + ui::dialogBox( player->name, ":Yes:No", false, pickupDialog.c_str()); + ui::waitForDialog(); + if(ui::dialogOptChosen == 1){ + player->inv->addItem( iname, 1 ); + alive = false; + } + }else{ alive = false; + player->inv->addItem(iname, 1); } - }else{ - alive = false; - player->inv->addItem(iname, 1); - } + }).detach(); } void Entity:: @@ -601,7 +620,8 @@ void Mob::wander(int timeRun){ case MS_TRIGGER: if(player->loc.x + player->width / 2 > loc.x && player->loc.x + player->width / 2 < loc.x + width ) - hey(this); + std::thread([this]{hey(this);}).detach(); + //hey(this); break; case MS_PAGE: if(player->loc.x > loc.x - 100 && @@ -191,6 +191,7 @@ namespace ui { */ void setFontSize(unsigned int size){ + mtx.lock(); unsigned int i,j; unsigned char *buf; @@ -253,6 +254,7 @@ namespace ui { delete[] buf; //free(buf); } + mtx.unlock(); } /* @@ -569,6 +571,7 @@ namespace ui { }; dialogOptChosen = 0; + merchOptChosen = 0; memset(&dialogOptLoc, 0, sizeof(float) * 12); // handle options if desired @@ -607,8 +610,9 @@ namespace ui { void waitForDialog(void){ do{ - mainLoop(); - }while(ui::dialogBoxExists); + //std::thread(dialogAdvance); + //mainLoop(); + }while(dialogBoxExists); } void waitForCover(void){ do{ @@ -692,7 +696,7 @@ namespace ui { glVertex2f(x+1+(SCREEN_WIDTH/3),y+1); glVertex2f(x+1+(SCREEN_WIDTH/3),y-1-SCREEN_HEIGHT*.6); glVertex2f(x-1,y-1-SCREEN_HEIGHT*.6); - glVertex2f(x,y+1); + glVertex2f(x-1,y+1); glEnd(); glColor3ub(0,0,0); @@ -787,11 +791,11 @@ namespace ui { glColor3ub(255, 255, 255); glBegin(GL_LINE_STRIP); - glVertex2f(x-1 ,y+1); - glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y+1); - glVertex2f(x+1+SCREEN_WIDTH-HLINE*16,y-1-SCREEN_HEIGHT/4); - glVertex2f(x-1 ,y-1-SCREEN_HEIGHT/4); - glVertex2f(x ,y+1); + glVertex2i(x-1 ,y+1); + glVertex2i(x+1+SCREEN_WIDTH-HLINE*16,y+1); + glVertex2i(x+1+SCREEN_WIDTH-HLINE*16,y-1-SCREEN_HEIGHT/4); + glVertex2i(x-1 ,y-1-SCREEN_HEIGHT/4); + glVertex2i(x-1 ,y+1); glEnd(); glColor3ub(0,0,0); @@ -1203,27 +1207,40 @@ namespace ui { typeOutDone = true; return; } - for(i=0;i<dialogOptCount;i++){ if(mouse.x > dialogOptLoc[i][0] && mouse.x < dialogOptLoc[i][2] && mouse.y > dialogOptLoc[i][1] && mouse.y < dialogOptLoc[i][1] + 16 ){ // fontSize dialogOptChosen = i + 1; - goto DONE; + goto EXIT; + } + } + if(dialogMerchant){ + for(i=0;i<2;i++){ + if(((merchAOptLoc[i][0] < merchAOptLoc[i][2]) ? + (mouse.x > merchAOptLoc[i][0] && mouse.x < merchAOptLoc[i][2]) : + (mouse.x < merchAOptLoc[i][0] && mouse.x > merchAOptLoc[i][2])) && + mouse.y > merchAOptLoc[i][1] - 8 && mouse.y < merchAOptLoc[i][1] + 8){ // fontSize + merchOptChosen = i + 1; + goto EXIT; + } } } -DONE: - + + EXIT: + //if(!dialogMerchant)closeBox(); + dialogBoxExists = false; + dialogMerchant = false; + + //DONE: + // handle important text if(dialogImportant){ dialogImportant = false; setFontSize(16); } - - if(dialogMerchant) dialogMerchant = false; - dialogBoxExists = false; } void handleEvents(void){ diff --git a/src/world.cpp b/src/world.cpp index 5ce0b2d..8af9e6a 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1342,7 +1342,8 @@ loadWorldFromXMLNoSave( std::string path ) { float spawnx, randx; bool dialog,Indoor; - const char *ptr,*name; + const char *ptr; + std::string name; currentXML = (std::string)"xml/" + path; @@ -1364,18 +1365,18 @@ loadWorldFromXMLNoSave( std::string path ) { while(wxml){ name = wxml->Name(); - if(!strcmp(name,"link")){ + if(name == "link"){ if((ptr = wxml->Attribute("left"))) tmp->setToLeft(ptr); else if((ptr = wxml->Attribute("right"))) tmp->setToRight(ptr); else abort(); - }else if(!strcmp(name,"style")){ + }else if(name == "style"){ tmp->setStyle(wxml->StrAttribute("folder")); tmp->setBackground((WorldBGType)wxml->UnsignedAttribute("background")); tmp->setBGM(wxml->StrAttribute("bgm")); - }else if(!strcmp(name,"generation")){ + }else if(name == "generation"){ if(!strcmp(wxml->Attribute("type"),"Random")){ if(Indoor) ((IndoorWorld *)tmp)->generate(wxml->UnsignedAttribute("width")); @@ -1385,7 +1386,7 @@ loadWorldFromXMLNoSave( std::string path ) { } }else if(Indoor) abort(); - }else if(!strcmp(name,"mob")){ + }else if(name == "mob"){ unsigned int type; type = wxml->UnsignedAttribute("type"); if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR) @@ -1395,7 +1396,7 @@ loadWorldFromXMLNoSave( std::string path ) { if(wxml->QueryBoolAttribute("aggressive",&dialog) == XML_NO_ERROR) tmp->mob.back()->aggressive = dialog; - }else if(!strcmp(name,"npc")){ + }else if(name == "npc"){ const char *npcname; if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR) @@ -1415,7 +1416,7 @@ loadWorldFromXMLNoSave( std::string path ) { tmp->npc.back()->addAIFunc(commonAIFunc,false); else tmp->npc.back()->dialogIndex = 9999; - }else if(!strcmp(name,"structure")){ + }else if(name == "structure"){ tmp->addStructure((BUILD_SUB)wxml->UnsignedAttribute("type"), wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR ? getRand() % tmp->getTheWidth() / 2.0f : @@ -1423,7 +1424,7 @@ loadWorldFromXMLNoSave( std::string path ) { 100, wxml->StrAttribute("texture"), wxml->StrAttribute("inside")); - }else if(!strcmp(name,"trigger")){ + }else if(name == "trigger"){ tmp->addMob(MS_TRIGGER,wxml->FloatAttribute("x"),0,commonTriggerFunc); tmp->mob.back()->heyid = wxml->Attribute("id"); } @@ -1449,13 +1450,13 @@ loadWorldFromXMLNoSave( std::string path ) { * READS DATA ABOUT STRUCTURE CONTAINED IN VILLAGE */ - if(!strcmp(name,"structure")){ + if(name == "structure"){ tmp->addStructure((BUILD_SUB)vil->UnsignedAttribute("type"), vil->QueryFloatAttribute("x", &spawnx) != XML_NO_ERROR ? randx : spawnx, 100, vil->StrAttribute("texture"), vil->StrAttribute("inside")); - }else if(!strcmp(name, "stall")){ + }else if(name == "stall"){ if(!strcmp(vil->Attribute("type"),"market")){ std::cout << "Market" << std::endl; tmp->addStructure((BUILD_SUB)70, @@ -1467,8 +1468,6 @@ loadWorldFromXMLNoSave( std::string path ) { tmp->addMerchant(0,100); if(vil->FirstChildElement("buy")){ std::cout << "Buy" << std::endl; - //Trade goodMeme(1,"Dank MayMay",1,"Sword"); - //tmp->merchant.back()->trade.push_back(Trade()); }if(vil->FirstChildElement("sell")){ std::cout << "Sell" << std::endl; }if(vil->FirstChildElement("trade")){ @@ -1477,7 +1476,9 @@ loadWorldFromXMLNoSave( std::string path ) { vil->FirstChildElement("trade")->Attribute("item"), vil->FirstChildElement("trade")->IntAttribute("quantity1"), vil->FirstChildElement("trade")->Attribute("item1"))); + tmp->merchant.back()->trade.push_back(Trade(1,"Wood Sword", 420, "Dank MayMay")); } + std::cout << "new trade" << std::endl; strcpy(tmp->merchant.back()->name,"meme"); }else if(!strcmp(vil->Attribute("type"),"trader")){ |