void DBNetworkIF::Climb (DBObjRecord *cellRec,DBInt level) { DBInt dir, maxCell = 0, maxDir = 0, cells, maxOrder = 1, orderNo = 0; DBFloat maxLength = -DBHugeVal; DBObjRecord *fromCell; TravelFLD->Int (cellRec,level); for (dir = 0;dir < 8;++dir) if ((fromCell = FromCell (cellRec,0x01 << dir)) != (DBObjRecord *) NULL) { Climb (fromCell,level + 1); cells = BasinCellsFLD->Int (fromCell); BasinCellsFLD->Int (cellRec,BasinCellsFLD->Int (cellRec) + cells); SubbasinAreaFLD->Float (cellRec,SubbasinAreaFLD->Float (cellRec) + SubbasinAreaFLD->Float (fromCell)); if (cells > maxCell) { maxCell = cells; maxDir = 0x01 << dir; } else if ((cells == maxCell) && (maxLength < SubbasinLengthFLD->Float (fromCell))) { maxLength = SubbasinLengthFLD->Float (fromCell); maxDir = 0x01 << dir; } if (OrderFLD->Int (fromCell) == maxOrder) { orderNo++; continue; } if (OrderFLD->Int (fromCell) > maxOrder) { maxOrder = OrderFLD->Int (fromCell); orderNo = 1; } } OrderFLD->Int (cellRec,maxOrder + (orderNo > 1 ? 1 : 0)); if (maxDir != 0) { fromCell = FromCell (cellRec,maxDir); SubbasinLengthFLD->Float (cellRec,SubbasinLengthFLD->Float (cellRec) + SubbasinLengthFLD->Float (fromCell)); UpCellPosFLD->Position (cellRec,UpCellPosFLD->Position (fromCell)); } }
DBInt DBNetworkIF::Build () { DBInt i, j, row, col, basin, dir, projection = DataPTR->Projection (); DBCoordinate coord0, coord1; char nameStr [DBStringLength]; DBPosition pos; DBObjRecord *cellRec, *toCell, *fromCell, *basinRec, *symbolRec; _DBnetIF = this; for (j = 0;j < BasinTable->ItemNum ();++j) { basinRec = BasinTable->Item (j); if (((cellRec = Cell (MouthPosFLD->Position (basinRec))) == (DBObjRecord *) NULL) || (ToCell (cellRec) != (DBObjRecord *) NULL)) { BasinTable->Delete (basinRec); j--; } } for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); DBPause (i * 10 / CellNum ()); if (Cell (CellPosition (cellRec)) == (DBObjRecord *) NULL) continue; else if (ToCell (ToCell (cellRec)) == cellRec) ToCellFLD->Int (cellRec,DBNull); } DBPause (10); for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); DBPause (10 + i * 10 / CellNum ()); pos = CellPosition (cellRec); if (((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] == DBFault) { CellTable->Delete (cellRec); --i; } else { cellRec->Flags (DBObjectFlagLocked,DBClear); FromCellFLD->Int (cellRec,DBNull); OrderFLD->Int (cellRec,1); BasinFLD->Int (cellRec,DBFault); BasinCellsFLD->Int (cellRec,1); TravelFLD->Int (cellRec,0); UpCellPosFLD->Position (cellRec,pos); CellAreaFLD->Float (cellRec,DBMathRectangleArea (projection,Center (cellRec) - CellSize () / 2,Center (cellRec) + CellSize () / 2)); coord0 = Center (cellRec); coord1 = Center (cellRec) + Delta (cellRec); CellLengthFLD->Float (cellRec,DBMathCoordinateDistance (DataPTR->Projection (),coord0,coord1)); SubbasinLengthFLD->Float (cellRec,CellLength (cellRec)); SubbasinAreaFLD->Float (cellRec,CellAreaFLD->Float (cellRec)); } } for (j = 0;j < BasinTable->ItemNum ();++j) { basinRec = BasinTable->Item (j); cellRec = Cell (MouthPosFLD->Position (basinRec)); if ((cellRec == (DBObjRecord *) NULL) || ((cellRec->Flags () & DBObjectFlagLocked) == DBObjectFlagLocked)) { BasinTable->Delete (basinRec); j--; } else cellRec->Flags (DBObjectFlagLocked,DBSet); } DBPause (20); for (row = 0;row < RowNum ();row++) for (col = 0;col < ColNum ();col++) ((DBInt *) DataRec->Data ()) [row * ColNum () + col] = DBFault; for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); cellRec->Flags (DBObjectFlagLocked,DBClear); DBPause (20 + i * 10 / CellNum ()); pos = CellPosition (cellRec); if (((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] != DBFault) { CellTable->Delete (cellRec); --i; } else ((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] = cellRec->RowID (); } DBPause (30); for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); if ((toCell = ToCell (cellRec)) != (DBObjRecord *) NULL) FromCellFLD->Int (toCell,FromCellFLD->Int (toCell) | _DBNetworkOppositeDirection (ToCellFLD->Int (cellRec))); } for (i = 0;i < CellNum ();++i) { DBPause (30 + i * 10 / CellNum ()); cellRec = CellTable->Item (i); if (ToCell (cellRec) == (DBObjRecord *) NULL) Climb (cellRec,0); } DBPause (40); CellTable->ItemSort (_DBGNetworkCellCompare); for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); DBPause (35 + i * 10/ CellNum ()); pos = CellPosition (cellRec); ((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] = cellRec->RowID (); } DBPause (50); basin = 0; for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); DBPause (50 + i * 20 / CellNum ()); if (ToCell (cellRec) == (DBObjRecord *) NULL) { SetBasin (cellRec,basin + 1); basinRec = (DBObjRecord *) NULL; for (j = 0;j < BasinTable->ItemNum ();++j) { if (((basin - j) >= 0) && ((basin - j) < BasinTable->ItemNum ()) && (cellRec == MouthCell (basinRec = BasinTable->Item (basin - j)))) break; if (((basin + j) < BasinTable->ItemNum ()) && (cellRec == MouthCell (basinRec = BasinTable->Item (basin + j)))) break; basinRec = (DBObjRecord *) NULL; } if (basinRec == (DBObjRecord *) NULL) { basinRec = BasinTable->Add ("GHAASBasin"); MouthPosFLD->Position (basinRec,CellPosition (cellRec)); } basinRec->ListPos (basin++); } } DBPause (70); CellTable->ItemSort (_DBGNetworkCellCompare); BasinTable->ItemSort (); for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); DBPause (70 + i * 10 / CellNum ()); pos = CellPosition (cellRec); ((DBInt *) DataRec->Data ()) [pos.Row * ColNum () + pos.Col] = cellRec->RowID (); sprintf (nameStr,"GHAASCell:%d",cellRec->RowID () + 1); cellRec->Name (nameStr); } DBPause (80); SymbolTable->DeleteAll (); symbolRec = SymbolTable->Add ("Network Symbol"); SymbolIDFLD->Int (symbolRec,1); ForegroundFLD->Int (symbolRec,1); BackgroundFLD->Int (symbolRec,0); for (j = 0;j < BasinTable->ItemNum ();++j) { basinRec = BasinTable->Item (j); if ((strncmp (basinRec->Name (),"GHAASBasin",strlen ("GHAASBasin")) == 0) || (strlen (basinRec->Name ()) < 1)) { sprintf (nameStr,"GHAASBasin%d",basinRec->RowID () + 1); basinRec->Name (nameStr); } ColorFLD->Int (basinRec,DBFault); BasinOrderFLD->Int (basinRec,CellOrder (MouthCell (basinRec))); BasinAreaFLD->Float (basinRec,CellBasinArea (MouthCell (basinRec))); BasinLengthFLD->Float (basinRec,CellBasinLength (MouthCell (basinRec))); SymbolFLD->Record (basinRec,symbolRec); } basin = DBFault; for (i = 0;i < CellNum ();++i) { cellRec = CellTable->Item (i); if ((basinRec = Basin (cellRec)) == (DBObjRecord *) NULL) { CMmsgPrint (CMmsgAppError,"BasinID: %d CellID:%d",BasinFLD->Int (cellRec),cellRec->RowID ()); continue; } if (basin != basinRec->RowID ()) { basin = basinRec->RowID (); DBPause (80 + basin * 20 / BasinNum ()); ColorFLD->Int (basinRec,7); toCell = cellRec; } for (dir = 0;dir < 8;dir += 2) { if ((fromCell = FromCell (cellRec,0x01 << dir,false)) == (DBObjRecord *) NULL) continue; if (basinRec == Basin (fromCell)) continue; if (ColorFLD->Int (basinRec) == ColorFLD->Int (Basin (fromCell))) { ColorFLD->Int (basinRec,ColorFLD->Int (basinRec) + 1); cellRec = MouthCell (basinRec); i = cellRec->RowID () - 1; } } } DBPause (100); if (DistToMouth ()) SetDistToMouth (); if (DistToOcean ()) SetDistToOcean (); if (Magnitude ()) SetMagnitude (); return (DBSuccess); }
void Climber_Class::AutoClimb(int state) { bool climb; bool reach; bool pushOut; bool safety; bool release; switch(state) { case AUTO_CLIMB_STATE_1: //brings the towers stationary hooks all the way up //The towers need to be reset, but only once /*if(firstReach) { ResetTowers(); firstReach = false; }*/ if(startCC) { ResetTowers(); startCC = false; } inState = ReachDistance(LEVEL_1A_REACH_POS); break; case AUTO_CLIMB_STATE_2: //pushes the candy cane out inState = (bool)candyCane->PushOut(); //The startCC boolean only allows the CC functions to be called once per state startCC = true; break; case AUTO_CLIMB_STATE_3: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Grab the pole if(startCC) { candyCane->StartGrab(LEVEL_1_GRAB_POS); //This line makes the CC only grab once startCC = false; } //If we're done grabbing, inState will be false and we can go to the next state otherwise it will be true inState = (bool)candyCane->Grab(); break; case AUTO_CLIMB_STATE_4: //climb until arms grab the horizontal bar //If we're still climbing inState is set to true, otherwise it is set to false inState = (bool)ClimbDistance(LEVEL_1A_CLIMB_POS); //Tell the CC it can move in the next state startCC = true; break; case AUTO_CLIMB_STATE_5: //Release the CC if(startCC) { //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); candyCane->StartRelease(); startCC = false; release = true; climb = true; } //If we're done releasing, inState will be set to false so we can go to the next state, otherwise it will be true release = (bool)candyCane->Release(); climb = (bool)Climb(); if(!climb && !release) { inState = false; } break; /*case AUTO_CLIMB_STATE_6: //Climb until the hooks transition //Check to see if we're still climbing inState = (bool)Climb(); break;*/ case AUTO_CLIMB_STATE_6: //Reach until the CC is clear if(startCC) { reach = true; pushOut = true; startCC = false; bringOutCC = true; } //Check to see if we're still reaching reach = (bool)ReachDistance(LEVEL_2A_REACH_POS); //Once the towers reached a certain distance, push out the CC if((leftTower->GetDistance() >= DISTANCE_FOR_EXTENDEING_CC) && bringOutCC) { candyCane->StartSafety(LEVEL_2A_SAFETY_POS); bringOutCC = false; } pushOut = candyCane->Safety(); //If we're not reaching or pushing out, we're not in the state anymore if(!reach && !pushOut) { inState = false; } /*//Check to see if we're still reaching inState = (bool)ReachDistance(LEVEL_2A_REACH_POS); //Tell the CC it can move in the next state startCC = true;*/ break; //Level 2 /*case AUTO_CLIMB_STATE_7: //CC safety position if(startCC) { candyCane->StartSafety(LEVEL_2A_SAFETY_POS); //This line makes the CC go into the safety position only once startCC = false; } inState = (bool)candyCane->Safety(); break;*/ case AUTO_CLIMB_STATE_7: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Bring in the CC so the servo turns if(startCC) { candyCane->StartLeanIn(LEVEL_2A_SAFETY_LEAN_POS); startCC = false; } inState = (bool)candyCane->LeanIn(); break; case AUTO_CLIMB_STATE_8: //Reach until the CC grabs the vertical bar //Check to see if we're still reaching inState = (bool)ReachDistance(LEVEL_2B_REACH_POS); //Tell the CC it can move in the next state startCC = true; break; case AUTO_CLIMB_STATE_9: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Lean a little bit if(startCC) { candyCane->StartLeanIn(LEVEL_2A_LEAN_POS); startCC = false; } //Check to see if we're still leaning in inState = (bool)candyCane->LeanIn(); break; case AUTO_CLIMB_STATE_10: //Reach all the way //Check to see if we're still reaching inState = (bool)Reach(); startCC = true; break; case AUTO_CLIMB_STATE_11: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Lean in until the arms touch the horizontal bars if(startCC) { candyCane->StartLeanIn(LEVEL_2B_LEAN_POS); startCC = false; } //Check to see if we're still leaning in inState = (bool)candyCane->LeanIn(); break; case AUTO_CLIMB_STATE_12: //climb until the arms grab the horizontal bars //Check to see if we're still climbing inState = (bool)ClimbDistance(LEVEL_2A_CLIMB_POS); startCC = true; break; /*case AUTO_CLIMB_STATE_14: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //CC safety if(startCC) { candyCane->StartSafety(LEVEL_2B_SAFETY); startCC = false; } //Check to see if we're still safetying inState = (bool)candyCane->Safety(); break;*/ case AUTO_CLIMB_STATE_13: //Release the CC if(startCC) { //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); candyCane->StartRelease(); startCC = false; climb = true; release = true; } //Climb until the hooks transition //Check to see if we're still climbing climb = (bool)Climb(); release = (bool)candyCane->Release(); if(!climb && !release) { inState = false; } break; /*case AUTO_CLIMB_STATE_16: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Release the CC if(startCC) { candyCane->StartRelease(); startCC = false; } //Check to see if we're still releasing inState = (bool)candyCane->Release(); break;*/ //Level 3 case AUTO_CLIMB_STATE_14: //Reach until the CC is clear if(startCC) { reach = true; pushOut = true; bringOutCC = true; startCC = false; } //Check to see if we're still reaching reach = (bool)ReachDistance(LEVEL_3A_REACH_POS); //Once the towers reached a certain distance, push out the CC if((leftTower->GetDistance() >= DISTANCE_FOR_EXTENDEING_CC) && bringOutCC) { candyCane->StartSafety(LEVEL_3A_SAFETY_POS); bringOutCC = false; } pushOut = candyCane->Safety(); //If we're not reaching or pushing out, we're not in the state anymore if(!reach && !pushOut) { inState = false; } /*//Check to see if we're still reaching inState = (bool)ReachDistance(LEVEL_3A_REACH_POS); startCC = true;*/ break; /*case AUTO_CLIMB_STATE_16: //CC safety if(startCC) { candyCane->StartSafety(LEVEL_3A_SAFETY_POS); startCC = false; } //Check to see if we're still safetying inState = (bool)candyCane->Safety(); break;*/ case AUTO_CLIMB_STATE_15: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Bring in the CC so the servo turns if(startCC) { candyCane->StartLeanIn(LEVEL_3A_SAFETY_LEAN_POS); startCC = false; } inState = (bool)candyCane->LeanIn(); break; case AUTO_CLIMB_STATE_16: //Reach until the CC grabs the verticle bar //Check to see if we're still reaching inState = (bool)ReachDistance(LEVEL_3B_REACH_POS); startCC = true; break; case AUTO_CLIMB_STATE_17: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Lean in if(startCC) { candyCane->StartLeanIn(LEVEL_3A_LEAN_POS); startCC = false; } //Check to see if we're still leaning in inState = (bool)candyCane->LeanIn(); break; case AUTO_CLIMB_STATE_18: //Reach all the way //Check to see if we're still reaching inState = (bool)Reach(); startCC = true; break; case AUTO_CLIMB_STATE_19: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Lean in until the arms hit the horizontal bar if(startCC) { candyCane->StartLeanIn(LEVEL_3B_LEAN_POS); startCC = false; } //Check to see if we're still leaning in inState = (bool)candyCane->LeanIn(); break; case AUTO_CLIMB_STATE_20: //climb until the arms grab the horizontal bars //Check to see if we're still climbing inState = (bool)ClimbDistance(LEVEL_3A_CLIMB_POS); startCC = true; break; case AUTO_CLIMB_STATE_21: //CC safety if(startCC) { //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); candyCane->StartSafety(LEVEL_3B_SAFETY_POS); startCC = false; safety = true; climb = true; } //Check to see if we're still safetying safety = (bool)candyCane->Safety(); climb = (bool)ClimbDistance(LEVEL_3B_CLIMB_POS); if(!safety && !climb) { inState = false; } break; /*case AUTO_CLIMB_STATE_27: //Climb until we want to stop and win ////Check to see if we're still climbing inState = (bool)ClimbDistance(LEVEL_3B_CLIMB_POS); break;*/ } /*grabbing = (bool)candyCane->Grab(); safetying = (bool)candyCane->Safety(); releasing = (bool)candyCane->Release(); leaningIn = (bool)candyCane->LeanIn();*/ }