//--------------------------------------------------------------------------- #pragma hdrstop #include "MoveInd.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- // Functions concerned with animal movement StochasticLib1 sto1move(SEED); ofstream pathfile ("paths.csv"); bool write_paths = WRITE_PATHS; #if VCL void draw_path(double,double,int); bool write_indpath = WRITE_INDPATH; #endif bool write_headers = 1; int moveInd(Animal* pAnimal, Toadscape* pLand, locn start, int startpatch, int parameterset, char* ctrlID, int maxsteps) { // start - location of starting cell (x,y) int step = 0; // step number int dest = -1; // set to target number when target destination reached int success = 0; locn curr,newloc; //to hold current and new locations bool inbounds = 1; // to indicate if move goes beyond bounds of array int xmax,ymax,target; Square* sq; movedata move; // distance and cost of current move double path_cost = 0.0; // total cost of path taken if (write_paths && write_headers) { pathfile<<"Landscape,PRMethod,PR,DP,MemSize,Ind,StartPatch" <<",Success,Steps,PathCost,Target,FinalX,FinalY"; pathfile<get_location(); // get boundaries of landscape xmax = pLand->get_bounds().x; ymax = pLand->get_bounds().y; // record identity of starting patch startpatch = pLand->locate_square(curr.x,curr.y)->get_target(); #if VCL ofstream indpath ("path.txt"); if (write_indpath) { indpath<<"id,step,x,y"<get_id()<<",0,"<<(double)curr.x+0.5<<","<<(double)curr.y+0.5< (9*WINDOW)) recruit = 1; // window is open move = pAnimal->nbrmove(pLand,step); if (move.dist < 0.0) { // indicates an error in nbrmove() dest = -9999; inbounds = 0; } newloc = pAnimal->get_location(); path_cost += move.cost; if (newloc.x<0 || newloc.x>=xmax || newloc.y<0 || newloc.y>=ymax ) { // move has taken individual out of bounds dest = -99; inbounds = 0; } #if VCL // draw the move drawpixel(pLand,newloc.x,newloc.y,recruit); // note that co-ordinates need to be transformed for display in GIS if (write_indpath) indpath<get_id()<<","<locate_square(newloc.x,newloc.y); if (sq == 0) { // moved into 'no data' area dest = -9; inbounds = 0; } else { if (recruit) { target = sq->get_target(); if (target > 0) { // animal is within a buffer area if (target > 10) { // animal is within a target site success = 1; dest = target / 10; } else { // set the site within the buffer to be the goal if (pAnimal->get_goaltype() == 0) { pAnimal->set_goal(1,STARTLOCN[target-1][0],STARTLOCN[target-1][1]); } } } } else { // switch off goal-seeking behaviour if set if (pAnimal->get_goaltype() > 0) { pAnimal->set_goal(0,0,0); } } } } step++; } // end of while loop if (write_paths) { pathfile<get_id()<<","<get_prmethod() <<","<get_pr()<<","<get_dp()<<","<get_memsize() <<","<get_id()<<","<