Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

Commit

Permalink
Buildable buildings
Browse files Browse the repository at this point in the history
  • Loading branch information
switchboy committed Apr 28, 2020
1 parent eeb0fc8 commit 357f687
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 68 deletions.
3 changes: 3 additions & 0 deletions include/actors.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class actors
void renderPath();
void setCommonGoalTrue();
void setGatheringRecource(bool flag);
void setIsBuildingTrue();
bool canTargetBeReached();
void checkCollision(int newCellId);
nearestBuildingTile findNearestDropOffPoint(int Resource);
Expand All @@ -71,6 +72,7 @@ class actors
void startGatheringAnimation();
void animateWalkingToResource();
void gatherResource();
void buildBuilding();
void unloadAndReturnToGathering();
void cleanUp();
int getMeleeDMG();
Expand Down Expand Up @@ -127,6 +129,7 @@ class actors
bool noPathPossible;
bool routeNeedsPath;
bool initialized;
bool isBuilding;
int mapArray[MAP_HEIGHT*MAP_WIDTH];
nearestBuildingTile dropOffTile;
std::list<routeCell> route;
Expand Down
1 change: 1 addition & 0 deletions include/buildings.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class buildings
int getTeam();
bool getCompleted();
void setCompleted();
void addBuildingPoint();

private:
int buildingId;
Expand Down
19 changes: 10 additions & 9 deletions include/gametext.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
#include <list>


struct gameMessage{
struct gameMessage
{
std::string message;
int color;
float timeAdded;
};

class gametext
{
public:
gametext();
void addNewMessage(std::string message, int color);
void drawMessages();
void throwOutOldMessages();
virtual ~gametext();
public:
gametext();
void addNewMessage(std::string message, int color);
void drawMessages();
void throwOutOldMessages();
virtual ~gametext();

private:
std::list<gameMessage> listOfMessages;
private:
std::list<gameMessage> listOfMessages;
};

extern gametext gameText;
Expand Down
2 changes: 0 additions & 2 deletions isometric.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<Add directory="D:/Programming/SFML-2.5.1/lib" />
</Linker>
<Unit filename="include/actors.h" />
<Unit filename="include/animation.h" />
<Unit filename="include/buildings.h" />
<Unit filename="include/button.h" />
<Unit filename="include/gamestate.h" />
Expand All @@ -66,7 +65,6 @@
<Unit filename="main.cpp" />
<Unit filename="main.h" />
<Unit filename="src/actors.cpp" />
<Unit filename="src/animation.cpp" />
<Unit filename="src/buildings.cpp" />
<Unit filename="src/button.cpp" />
<Unit filename="src/gamestate.cpp" />
Expand Down
17 changes: 9 additions & 8 deletions isometric.depend
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
<list>
<sstream>

1588018508 source:d:\programming\isometric\src\gamestate.cpp
1588085166 source:d:\programming\isometric\src\gamestate.cpp
"gamestate.h"
"buildings.h"
"objects.h"
Expand All @@ -475,12 +475,13 @@
"gamestate.h"
"globals.h"

1588017416 source:d:\programming\isometric\src\buildings.cpp
1588079549 source:d:\programming\isometric\src\buildings.cpp
"buildings.h"
"gamestate.h"
"player.h"
"gametext.h"

1587998944 d:\programming\isometric\include\buildings.h
1588067771 d:\programming\isometric\include\buildings.h
<vector>
<list>

Expand All @@ -495,7 +496,7 @@

1584720289 d:\programming\isometric\globals.h

1587980070 source:d:\programming\isometric\src\actors.cpp
1588069823 source:d:\programming\isometric\src\actors.cpp
"actors.h"
"objects.h"
"player.h"
Expand All @@ -505,7 +506,7 @@
<string>
"globalfunctions.h"

1587979795 d:\programming\isometric\include\actors.h
1588066515 d:\programming\isometric\include\actors.h
<cmath>
<list>
"gamestate.h"
Expand All @@ -527,7 +528,7 @@
1587977934 d:\programming\isometric\include\button.h
<SFML/Graphics.hpp>

1587984943 source:d:\programming\isometric\src\button.cpp
1588067443 source:d:\programming\isometric\src\button.cpp
"button.h"
"gamestate.h"
<iostream>
Expand All @@ -536,11 +537,11 @@
"gametext.h"
"actors.h"

1587933231 source:d:\programming\isometric\src\gametext.cpp
1588067443 source:d:\programming\isometric\src\gametext.cpp
"gametext.h"
"gamestate.h"

1587932871 d:\programming\isometric\include\gametext.h
1588067443 d:\programming\isometric\include\gametext.h
<string>
<list>

68 changes: 39 additions & 29 deletions isometric.layout
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,89 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="src\actors.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<File name="include\actors.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="13276" topLine="333" />
<Cursor1 position="1046" topLine="15" />
</Cursor>
</File>
<File name="src\gamestate.cpp" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="include\globalfunctions.h" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="56241" topLine="2" />
<Cursor1 position="866" topLine="0" />
</Cursor>
</File>
<File name="src\globalfunctions.cpp" open="1" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="include\buildings.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="928" topLine="0" />
<Cursor1 position="1191" topLine="10" />
</Cursor>
</File>
<File name="include\actors.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="include\objects.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="3162" topLine="84" />
<Cursor1 position="439" topLine="0" />
</Cursor>
</File>
<File name="include\globalfunctions.h" open="1" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="866" topLine="0" />
<Cursor1 position="299" topLine="0" />
</Cursor>
</File>
<File name="main.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\button.cpp" open="1" top="0" tabpos="15" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="299" topLine="0" />
<Cursor1 position="3221" topLine="119" />
</Cursor>
</File>
<File name="include\buildings.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\globalfunctions.cpp" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="628" topLine="0" />
<Cursor1 position="928" topLine="0" />
</Cursor>
</File>
<File name="include\objects.h" open="1" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="include\button.h" open="1" top="0" tabpos="14" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="439" topLine="0" />
<Cursor1 position="351" topLine="0" />
</Cursor>
</File>
<File name="src\buildings.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\buildings.cpp" open="1" top="1" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2646" topLine="98" />
<Cursor1 position="4170" topLine="127" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2007" topLine="64" />
</Cursor>
</File>
<File name="src\player.cpp" open="1" top="0" tabpos="15" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\gametext.cpp" open="1" top="0" tabpos="16" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1690" topLine="64" />
<Cursor1 position="865" topLine="3" />
</Cursor>
</File>
<File name="include\animation.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\objects.cpp" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
<Cursor1 position="1283" topLine="0" />
</Cursor>
</File>
<File name="src\animation.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\actors.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
<Cursor1 position="65446" topLine="1701" />
</Cursor>
</File>
<File name="src\objects.cpp" open="1" top="0" tabpos="12" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<File name="src\gamestate.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1283" topLine="0" />
<Cursor1 position="9132" topLine="255" />
</Cursor>
</File>
<File name="include\gamestate.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\player.cpp" open="1" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2869" topLine="30" />
<Cursor1 position="1690" topLine="64" />
</Cursor>
</File>
<File name="include\gamestate.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1257" topLine="12" />
</Cursor>
</File>
<File name="include\gametext.h" open="1" top="0" tabpos="17" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
54 changes: 53 additions & 1 deletion src/actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ actors::actors(int type, int actorX, int actorY, int actorTeam, int actorId)
this->timeStartedWalkingToRecource = 0.0f;
this->goalNeedsUpdate = false;
this->routeNeedsPath = false;
this->isBuilding = false;
this->busyWalking = false;
this->pathFound = false;
this->isAtRecource = false;
Expand Down Expand Up @@ -563,7 +564,7 @@ void actors::update()
int wantedOrientation = actorOrientation(this->actorCords[0], this->actorCords[1], this->route.back().positionX, this->route.back().positionY);
if(wantedOrientation == this->orientation)
{
if(this->isGatheringRecources && this->route.size() == 1)
if((this->isGatheringRecources || this->isBuilding) && this->route.size() == 1)
{
this->pathFound = false;
this->commonGoal = false;
Expand Down Expand Up @@ -711,6 +712,25 @@ void actors::update()
}
}
}
else if(this->isBuilding && (!this->busyWalking)&& this->route.empty()){
//villager is aangekomen bij te bouwen gebouw en kan na verplaatst te zijn gaan bouwen!
if(this->isAtRecource)
{
this->buildBuilding();
} else if(this->timeStartedWalkingToRecource == 0.0f)
{
this->timeStartedWalkingToRecource = currentGame.elapsedTime;
}
else if(currentGame.elapsedTime - this->timeStartedWalkingToRecource < 0.5f)
{
this->animateWalkingToResource();
}
else
{
this->startGatheringAnimation();
}
}

if(this->commonGoal && !this->pathFound && this->retries < 6 && currentGame.elapsedTime-this->timeLastAttempt > 1)
{
this->routeNeedsPath = true;
Expand Down Expand Up @@ -1088,6 +1108,7 @@ void actors::unloadAndReturnToGathering()
void actors::setGatheringRecource(bool flag)
{
this->isGatheringRecources = flag;
this->isBuilding = false;
if(flag)
{
this->ResourceBeingGatherd = listOfObjects[currentGame.objectLocationList[this->actorGoal[0]][this->actorGoal[1]]].getTypeOfResource();
Expand Down Expand Up @@ -1748,6 +1769,37 @@ void actors:: drawActor()
}


void actors::buildBuilding(){
if(currentGame.occupiedByBuildingList[this->gatheringResourcesAt[0]][this->gatheringResourcesAt[1]] != -1)
{
if(!listOfBuildings[currentGame.occupiedByBuildingList[this->gatheringResourcesAt[0]][this->gatheringResourcesAt[1]]].getCompleted())
{
if(currentGame.elapsedTime - this->timeStartedGatheringRecource > 2)
{
listOfBuildings[currentGame.occupiedByBuildingList[this->gatheringResourcesAt[0]][this->gatheringResourcesAt[1]]].addBuildingPoint();
this->timeStartedGatheringRecource = currentGame.elapsedTime;
}
} else {
//Het gebouw is af!
this->isAtRecource = false;
this->isBuilding = false;
}
}
else
{
//Building not here!
this->isAtRecource = false;
this->isBuilding = false;
}
}

void actors::setIsBuildingTrue(){
this->isBuilding = true;
this->isGatheringRecources = false;
this->ResourceBeingGatherd = 1;
this->gatheringResourcesAt[0] = this->actorGoal[0];
this->gatheringResourcesAt[1] = this->actorGoal[1];
}
void actors::renderPath()
{
std::list<routeCell>::iterator it;
Expand Down
Loading

0 comments on commit 357f687

Please sign in to comment.