00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Agent_space.h"
00021 #include "Pixel.h"
00022 #include "ThreadManager.h"
00023 #include "Scheduler.h"
00024 #include "Manager_base.h"
00025
00026 Agent_space::Agent_space(ThreadManager* MTHREAD_h, Manager_base* manager_h): Agent_base(MTHREAD_h, manager_h){
00027 homePlot = NULL;
00028 }
00029
00030 Agent_space::Agent_space(ThreadManager* MTHREAD_h, int uniqueID_h, Manager_base* manager_h): Agent_base(MTHREAD_h, uniqueID_h, manager_h){
00031 if(MTHREAD->RD->getBoolSetting("agentsView")){
00032 MTHREAD->treeViewerAddAgentProperty(agentUniqueID, "owned land");
00033 MTHREAD->treeViewerAddAgentProperty(agentUniqueID, "rented land");
00034 }
00035 homePlot = NULL;
00036 }
00037
00038 Agent_space::~Agent_space(){
00039
00040 }
00041
00042 int
00043 Agent_space::uncompletePlotDotation (int landCode_h, int ptype){
00044 map<int, double>::iterator p;
00045 int freePlots=0;
00046 int alreadyOwnedPlots =0;
00047 int alreadyRentedPlots =0;
00048
00049
00050 if (ptype==PLOTS_ALL || ptype ==PLOTS_OWNED){
00051 for (uint i=0;i<ownedPlots.size();i++){
00052 if (ownedPlots.at(i)->getDoubleValue("landUse") == landCode_h) alreadyOwnedPlots++;
00053 }
00054 p = initialOwnedPlots.find(landCode_h);
00055 if(p != initialOwnedPlots.end()){
00056 int initialOwned = (int) p->second;
00057 freePlots += initialOwned - alreadyOwnedPlots;
00058 }
00059 }
00060
00061 if (ptype==PLOTS_ALL || ptype == PLOTS_RENTED){
00062 for (uint i=0;i<rentedPlots.size();i++){
00063 if (rentedPlots.at(i)->getDoubleValue("landUse") == landCode_h) alreadyRentedPlots++;
00064 }
00065 p = initialRentedPlots.find(landCode_h);
00066 if(p != initialRentedPlots.end()){
00067 int initialRented = (int) p->second;
00068 freePlots += initialRented - alreadyRentedPlots;
00069 }
00070 }
00071 return freePlots;
00072 }
00073
00078 vector <Pixel *>
00079 Agent_space::getPlots(int ptype, int landCode_h){
00080 vector <Pixel *> toReturn;
00081 switch (ptype) {
00082 case PLOTS_ALL:
00083 merge(ownedPlots.begin(), ownedPlots.end(), rentedPlots.begin(), rentedPlots.end(), back_inserter(toReturn));
00084 break;
00085 case PLOTS_OWNED:
00086 toReturn = ownedPlots;
00087 break;
00088 case PLOTS_RENTED:
00089 toReturn = rentedPlots;
00090 break;
00091 default:
00092 msgOut(MSG_ERROR, "You have called Agent_space::getPlots(int ptype) with an invalid parameter. All plots have been returned.");
00093 merge(ownedPlots.begin(), ownedPlots.end(), rentedPlots.begin(), rentedPlots.end(), back_inserter(toReturn));
00094 }
00095 if(landCode_h == 0){return toReturn;}
00096 else{
00097 vector <Pixel *> toReturn2;
00098 for(uint i=0;i<toReturn.size();i++){
00099 if(toReturn.at(i)->getDoubleValue("landUse") == landCode_h){
00100 toReturn2.push_back(toReturn.at(i));
00101 }
00102 }
00103 return toReturn2;
00104 }
00105
00106 }
00107
00112 int
00113 Agent_space::getNPlots(int ptype, int landCode_h){
00114
00115 if(landCode_h == 0){
00116 switch (ptype) {
00117 case PLOTS_ALL:
00118 return ownedPlots.size()+rentedPlots.size();
00119 case PLOTS_OWNED:
00120 return ownedPlots.size();
00121 case PLOTS_RENTED:
00122 return rentedPlots.size();
00123 default:
00124 msgOut(MSG_ERROR, "You have called Agent_space::getNPlots(int ptype) with an invalid parameter. Count of all plots has been returned.");
00125 return ownedPlots.size()+rentedPlots.size();
00126 }
00127 }
00128 else{
00129 vector <Pixel* > plots = getPlots(ptype, landCode_h);
00130 return plots.size();
00131 }
00132 }
00133
00134 int
00135 Agent_space::countMyObjects(){
00136 int counter = myObjects.size();
00137 for (uint i=0; i<ownedPlots.size();i++){
00138 counter += ownedPlots.at(i)->countMyObjects();
00139 }
00140 return counter;
00141 }
00142
00143 double
00144 Agent_space::getDistance(const Pixel* px1){
00145 return MTHREAD->GIS->getDistance(px1, homePlot);
00146 }
00147
00148 void
00149 Agent_space::payInitialYearCosts(){
00150 sunkCostsPaid = 0;
00151
00152 for (uint i=0;i<rentedPlots.size();i++){
00153 sunkCostsPaid += rentedPlots[i]->getRentalCosts();
00154 }
00155 pay (sunkCostsPaid,false);
00156
00157 }
00158
00164 void
00165 Agent_space::freeLand(){
00166
00167 for(uint i=0;i<rentedPlots.size();i++){
00168 rentedPlots[i]->destroyRentalContract();
00169 }
00170 rentedPlots.clear();
00171 for(uint i=0;i<ownedPlots.size();i++){
00172 ownedPlots[i]->setOwner(0);
00173 }
00174
00175 }