void Move::changeBoard(Board& other) const { p = getPiece(other); c = getCell(other); b = &other; }

Cell* operator()(VectorDi const& index, VectorDi const& indexShift) { return getCell(index + indexShift); }

Cell* operator()(VectorDi const& index) { return getCell(index); }

Vector AiLocation::getPosition_p ( CellProperty const * relativeCell ) const { Vector pos_p = getPosition_p(); return CollisionUtils::transformToCell(getCell(),pos_p,relativeCell); }

bool AiLocation::isInWorldCell ( void ) const { return isValid() && ( (getCell() == NULL) || (getCell() == CellProperty::getWorldCellProperty()) ); }

void cRocketTurret::think() { int iMyIndex = -1; for (int i = 0; i < MAX_STRUCTURES; i++) { if (structure[i] == this) { iMyIndex = i; break; } } // this should not happen, but just in case if (iMyIndex < 0) { return; } if (player[getOwner()].bEnoughPower() == false) { return; // do not fire a thing now } // turning & shooting if (iTargetID > -1) { if (unit[iTargetID].isValid()) { // first make sure we face okay! int iCellX = iCellGiveX(getCell()); int iCellY = iCellGiveY(getCell()); int iTargetX = iCellGiveX(unit[iTargetID].iCell); int iTargetY = iCellGiveY(unit[iTargetID].iCell); int d = fDegrees(iCellX, iCellY, iTargetX, iTargetY); int f = face_angle(d); // get the angle // set facing iShouldHeadFacing = f; if (iShouldHeadFacing == iHeadFacing || (unit[iTargetID].iType == ORNITHOPTER)) { TIMER_fire++; int iDistance = 9999; int iSlowDown = 250; if (getType() == RTURRET) iSlowDown = 450; if (unit[iTargetID].isValid()) { // calculate distance iDistance = ABS_length(iCellX, iCellY, iTargetX, iTargetY); if (iDistance > structures[getType()].sight) iTargetID = -1; } else iTargetID = -1; if (iTargetID < 0) return; if (TIMER_fire > iSlowDown) { int iTargetCell = unit[iTargetID].iCell; int iBullet = BULLET_TURRET; if (getType() == RTURRET && iDistance > 3) iBullet = ROCKET_RTURRET; else { int iShootX = (iDrawX() + 16) + (mapCamera->getX() * 32); int iShootY = (iDrawY() + 16) + (mapCamera->getY() * 32); int bmp_head = convert_angle(iHeadFacing); PARTICLE_CREATE(iShootX, iShootY, OBJECT_TANKSHOOT, -1, bmp_head); } int iBull = create_bullet(iBullet, getCell(), iTargetCell, -1, iMyIndex); if (unit[iTargetID].iType == ORNITHOPTER) { // it is a homing missile! bullet[iBull].iHoming = iTargetID; bullet[iBull].TIMER_homing = 200; } TIMER_fire = 0; } } else { TIMER_turn++; int iSlowDown = 200; if (TIMER_turn > iSlowDown) { TIMER_turn = 0; int d = 1; int toleft = (iHeadFacing + 8) - iShouldHeadFacing; if (toleft > 7) toleft -= 8; int toright = abs(toleft - 8); if (toright == toleft) d = -1 + (rnd(2)); if (toleft > toright) d = 1; if (toright > toleft) d = -1; iHeadFacing += d; if (iHeadFacing < 0) iHeadFacing = 7; if (iHeadFacing > 7) iHeadFacing = 0; } // turning } } else iTargetID = -1; } // think like base class cAbstractStructure::think(); }

int main(){ int in_game=0; int turnPre=0; int mode=-1; /*range 1-3*/ int diff=-1; /*range 0-3, 0 if pvp*/ int timer=-1; /*range 0, 5, 10, 20*/ int side=-1; /*range '0' for white, '1' for black*/ int all41 = -1; /* range 0-5 depending on piece */ char confirm='n'; /*range 'n', 'y'*/ char modeS[26]; char diffS[26]; char timerS[26]; board *board = createNewGame(); int timer1 = 0; int timer2 = 0; int timer3 = 0; int timer4 = 0; int timer5 = 0; int altcounter = 1; do{ /*game setup*/ printf("\nChess v1.0 by nøl / C Gets Degrees\n\n"); while (mode < 1){ printf("Please select game mode:\n"); printf("1. Player versus Player\n"); printf("2. Player versus Computer\n"); printf("3. Computer versus Computer\n\n"); scanf("%d", &mode); switch(mode){ case 1: printf("Player versus Player selected\n"); break; case 2: printf("Player versus Computer selected\n\n"); printf("Choose a side: White(0) or Black(1)?\n"); scanf("%d", &side); switch(side){ case 0: printf("White selected\n"); break; case 1: printf("Black selected\n"); break; default: printe(selection); side = -1; break; } break; case 3: printf("Computer versus Computer selected\n"); break; default: printe(selection); mode = -1; break; } } while (all41 < 0){ printf("\nPlease select game type. All-for-One mode creates all pieces of the same type!\n"); printf("0. Standard Chess\n"); printf("1. All-for-Pawn\n"); printf("2. All-for-Knight\n"); printf("3. All-for-Queen\n"); printf("4. All-for-Rook\n"); printf("5. All-for-Bishop\n"); scanf("%d", &all41); switch(all41){ case 0: printf("Standard chess selected\n"); break; case 1: printf("All-for-Pawn selected\n"); break; case 2: printf("All-for-Knight selected\n"); break; case 3: printf("All-for-Queen selected\n"); break; case 4: printf("All-for-Rook selected\n"); break; case 5: printf("All-for-Bishop selected\n"); break; default: printe(selection); all41 = -1; break; } } while (diff < 0){ if (mode == 1){ diff = 0; break; } printf("\nPlease select computer difficulty:\n"); printf("1. Easy\n"); printf("2. Medium\n"); printf("3. Hard\n\n"); scanf("%d", &diff); switch(diff){ case 1: printf("Easy selected\n"); break; case 2: printf("Medium selected\n"); break; case 3: printf("Hard selected\n"); break; default: printe(selection); diff = -1; break; } } while (timer < 0){ printf("\nPlease select game timer length:\n"); printf("0. No limit\n"); printf("5. 5 minutes\n"); printf("10. 10 minutes\n"); printf("20. 20 minutes\n\n"); scanf("%d", &timer); switch(timer){ case 0: printf("No limit selected\n"); timer = 0; break; case 5: printf("5 minutes selected\n"); timer1 = timer*60; timer3 = timer*60; break; case 10: printf("10 minutes selected\n"); timer1 = timer*60; timer3 = timer*60; break; case 20: printf("20 minutes selected\n"); timer1 = timer*60; timer3 = timer*60; break; default: printe(selection); timer1 = 0; timer3 = 0; timer = -1; break; } } /*CREATE STRINGS FOR SELECTIONS*/ switch(mode){ case 1: strcpy(modeS, "Player versus Player"); break; case 2: strcpy(modeS, "Player versus Computer"); break; case 3: strcpy(modeS, "Computer versus Computer"); break; } switch(diff){ case 0: strcpy(diffS, ""); break; case 1: strcpy(diffS, "\nDifficulty: Easy"); break; case 2: strcpy(diffS, "\nDifficulty: Medium"); break; case 3: strcpy(diffS, "\nDifficulty: Hard"); break; } switch(timer){ case 0: strcpy(timerS, "No time limit"); break; case 5: strcpy(timerS, "5 minutes"); break; case 10: strcpy(timerS, "10 minutes"); break; case 20: strcpy(timerS, "20 minutes"); break; } /*CONFIRM SELECTIONS*/ printf("\n\nPlease confirm selections: [y/n]\n\n"); printf("Mode: %s", modeS); printf("%s", diffS); printf("\nTimer: %s\n\n", timerS); scanf(" %c", &confirm); if (confirm == 'y' || confirm == 'Y'){ in_game = 1; fgetc(stdin); /* absorb the /n produced by the last scanf */ createMoveLog(); } else if (confirm == 'n' || confirm == 'N'){ mode = -1; side = -1; diff = -1; timer = -1; all41 = -1; } else{ printe(selection); } int aiTeam1, aiTeam2; if(mode == 2){ /* Inverts input value 0 -> 1, 1 -> 0, other input will cause assertion failure */ aiTeam1 = oppTeam(side); /* oppTeam function comes from ai.c. Reads an int, returns an int. */ } if(mode == 3){ /* Default for CPU vs CPU */ aiTeam1 = 0; aiTeam2 = 1; } while(in_game){ /* if side = 1, player is black */ if (timer != 0){ /* set up timer */ if (altcounter % 2 != 0){ timer5 = timer4 - timer2; timer1 = timer1 - timer5; altcounter = altcounter+1; } else{ timer5 = timer4 - timer2; timer3 = timer3 - timer5; altcounter = altcounter+1; } if (timer1 <= 0){ printf("\nWhite has run out of time!\n"); exit(0); } if (timer3 <= 0){ printf("\nBlack has run out of time!\n"); exit(0); } } int alpha; cell *tmp1; switch(all41){ case 0: break; case 1: for(alpha = 0; alpha <64; alpha++){ tmp1 = getCell(alpha, board); if (tmp1->piece != NULL && tmp1->piece->type != king){ tmp1->piece->type = pawn; updatePrintPiece(tmp1); } } break; case 2: for(alpha = 0; alpha <64; alpha++){ tmp1 = getCell(alpha, board); if (tmp1->piece != NULL && tmp1->piece->type != king){ tmp1->piece->type = knight; updatePrintPiece(tmp1); } } break; case 3: for(alpha = 0; alpha <64; alpha++){ tmp1 = getCell(alpha, board); if (tmp1->piece != NULL && tmp1->piece->type != king){ tmp1->piece->type = queen; updatePrintPiece(tmp1); } } break; case 4: for(alpha = 0; alpha <64; alpha++){ tmp1 = getCell(alpha, board); if (tmp1->piece != NULL && tmp1->piece->type != king){ tmp1->piece->type = rook; updatePrintPiece(tmp1); } } break; case 5: for(alpha = 0; alpha <64; alpha++){ tmp1 = getCell(alpha, board); if (tmp1->piece != NULL && tmp1->piece->type != king){ tmp1->piece->type = bishop; updatePrintPiece(tmp1); } } break; } turnPre = board->turn; timer2 = (int) time(NULL); updateGameDisplay(board); /* display the entire board only when its a new turn */ while (turnPre == board->turn){ cell *temp; switch(mode){ case 1: /* PvP */ updateMessage(board); /*board->turn++;*/ break; case 2: /* P vs AI */ if(board->turn%2 == aiTeam1){ /* AI's turn */ printMessage(board->turn); if (board->turn == 0){ temp = getCell(12, board); movePiece(temp->piece, getCell(20, board)); temp = NULL; } else if (board->turn == 1){ temp = getCell(52, board); movePiece(temp->piece, getCell(44, board)); } else if (board->turn == 2){ temp = getCell(3, board); movePiece(temp->piece, getCell(21, board)); } else if (board->turn == 3){ temp = getCell(59, board); movePiece(temp->piece, getCell(45, board)); } else if (board->turn == 4){ temp = getCell(5, board); movePiece(temp->piece, getCell(26, board)); } else if (board->turn == 5){ temp = getCell(61, board); movePiece(temp->piece, getCell(34, board)); } else if (board->turn == 6){ temp = getCell(21, board); movePiece(temp->piece, getCell(53, board)); } else if (board->turn == 7){ temp = getCell(45, board); movePiece(temp->piece, getCell(13, board)); } else{ aiMove(diff, aiTeam1, board); } } else{ /* player's turn */ updateMessage(board); /*board->turn++;*/ } break; case 3: /* AI vs AI*/ if(board->turn%2 == 0){ /* White's turn */ /* aiTeam1 goes */ printMessage(board->turn); aiMove(diff, aiTeam1, board); /*board->turn++;*/ } else{ /* Black's turn */ /* aiTeam2 goes */ printMessage(board->turn); aiMove(diff, aiTeam2, board); /*board->turn++;*/ } break; } /* Exits loop when turn is finished */ } timer4 = (int) time(NULL); if (timer != 0 && board->turn > 1){ printf("DEBUG: Current time: %d\n", timer4); printf("DEBUG: Current time: %d\n", timer2); printf("Time remaining for Player 1: %d seconds.\n", timer1); printf("Time remaining for Player 2: %d seconds.\n", timer3); } } } while(!in_game); return 0; }

// Rework faceOnlySet samples. // Take two consecutive samples void Foam::midPointAndFaceSet::genSamples() { // Generate midpoints and add to face points List<point> newSamplePoints(3*size()); labelList newSampleCells(3*size()); labelList newSampleFaces(3*size()); labelList newSampleSegments(3*size()); scalarList newSampleCurveDist(3*size()); label newSampleI = 0; label sampleI = 0; while(true && size()>0) { // sampleI is start of segment // Add sampleI newSamplePoints[newSampleI] = operator[](sampleI); newSampleCells[newSampleI] = cells_[sampleI]; newSampleFaces[newSampleI] = faces_[sampleI]; newSampleSegments[newSampleI] = segments_[sampleI]; newSampleCurveDist[newSampleI] = curveDist_[sampleI]; newSampleI++; while ( (sampleI < size() - 1) && (segments_[sampleI] == segments_[sampleI+1]) ) { // Add mid point const point mid = 0.5*(operator[](sampleI) + operator[](sampleI+1)); label cell1 = getCell(faces_[sampleI], mid); label cell2 = getCell(faces_[sampleI+1], mid); if (cell1 != cell2) { FatalErrorIn("midPointAndFaceSet::genSamples()") << " sampleI:" << sampleI << " newSampleI:" << newSampleI << " pts[sampleI]:" << operator[](sampleI) << " face[sampleI]:" << faces_[sampleI] << " pts[sampleI+1]:" << operator[](sampleI+1) << " face[sampleI+1]:" << faces_[sampleI+1] << " cell1:" << cell1 << " cell2:" << cell2 << abort(FatalError); } newSamplePoints[newSampleI] = mid; newSampleCells[newSampleI] = cell1; newSampleFaces[newSampleI] = -1; newSampleSegments[newSampleI] = segments_[sampleI]; newSampleCurveDist[newSampleI] = mag(newSamplePoints[newSampleI] - start()); newSampleI++; // Add sampleI+1 newSamplePoints[newSampleI] = operator[](sampleI+1); newSampleCells[newSampleI] = cells_[sampleI+1]; newSampleFaces[newSampleI] = faces_[sampleI+1]; newSampleSegments[newSampleI] = segments_[sampleI+1]; newSampleCurveDist[newSampleI] = mag(newSamplePoints[newSampleI] - start()); newSampleI++; sampleI++; } if (sampleI == size() - 1) { break; } sampleI++; } newSamplePoints.setSize(newSampleI); newSampleCells.setSize(newSampleI); newSampleFaces.setSize(newSampleI); newSampleSegments.setSize(newSampleI); newSampleCurveDist.setSize(newSampleI); setSamples ( newSamplePoints, newSampleCells, newSampleFaces, newSampleSegments, newSampleCurveDist ); }

void cRocketTurret::think_guard() { // no power = no defense if (player[getOwner()].bEnoughPower() == false) { return; } TIMER_guard++; if (TIMER_guard > 10) { int iCellX = iCellGiveX(getCell()); int iCellY = iCellGiveY(getCell()); int iDistance = 9999; // closest distance int iAir = -1; // aircraft (prioritized!) int iWorm = -1; // worm lowest priority int iDanger = -1; // danger id (unit to attack) iTargetID = -1; // no target // scan area for units for (int i = 0; i < MAX_UNITS; i++) { // is valid if (unit[i].isValid()) { bool bAlly = player[getOwner()].iTeam == player[unit[i].iPlayer].iTeam; // not ours and its visible if (unit[i].iPlayer != getOwner() && mapUtils->isCellVisibleForPlayerId(getOwner(), unit[i].iCell) && bAlly == false) { int distance = ABS_length(iCellX, iCellY, iCellGiveX(unit[i].iCell), iCellGiveY(unit[i].iCell)); // when worm or ornithopter is in range, they are not limited to the iDistance (closest // unit) range. if (distance <= structures[getType()].sight) { if (unit[i].iType == ORNITHOPTER) { iAir = i; } else if (unit[i].iType == SANDWORM) { iWorm = i; } } // when distance < closest range so far, this one is the most dangerous. if (distance <= structures[getType()].sight && distance < iDistance) { // ATTACK iDistance = distance; iDanger = i; } } } } // set target if (iAir > -1) { iTargetID = iAir; } else if (iDanger > -1) { iTargetID = iDanger; } else if (iWorm > -1) { iTargetID = iWorm; // else pick worm } TIMER_guard = 0 - rnd(20); // redo } }

long Concentration::getCell(int x, int y) { return getCell(linearPos(x, y)); }

bool ExpressionCell::_compute() { if (this->computed) return this->error ? false : true; if (data[0]!='=') { this->error = true; this->computed = true; this->data = "#parce_expr_error"; return false; } enum {EQUAL='=', PLUS='+', MINUS='-', MULTIPLICATION='*', DIVISION='\\'} signState=EQUAL; int leftValue = 0; int rightArgBegin = 1; for (unsigned int i=1; i<data.size()+1; i++) { if ( (i == data.size()-1) || isSign(data[i]) ) { int rightValue = 0; string rightArg = data.substr(rightArgBegin, i-1); if (isNumberString(rightArg)) rightValue = atoi(rightArg.c_str()); else if (isCellString(rightArg)) { pair<int, int> cellCoord = parseCellCoordinate(rightArg); Cell *cell = getCell(cellCoord.first, cellCoord.second); // if cell not found or cell can't be computed => error if (cell == NULL || !cell->compute() || !cell->isNumber()) { this->error = true; this->computed = true; this->data = "#incorrect_cell_"+rightArg; return false; } rightValue = cell->getNumber(); } // Compute operation switch (signState) { case EQUAL: leftValue = rightValue; break; case PLUS: leftValue += rightValue; break; case MINUS: leftValue -= rightValue; break; case MULTIPLICATION: leftValue *= rightValue; break; case DIVISION: if (rightValue == 0) { this->error = true; this->computed = true; this->data = "#division_by_zero"; return false; } leftValue /= rightValue; break; } } if ( i == data.size()-1 ) break; // set next sing if (data[i] == '+') signState = PLUS; if (data[i] == '-') signState = MINUS; if (data[i] == '*') signState = MULTIPLICATION; if (data[i] == '/') signState = DIVISION; } this->error = false; this->computed = true; this->data = std::to_string(leftValue); this->data_int = leftValue; return true; }

Cell* Path::getLastCell() { return getCell(length()-1); }

Game* Entity::getGame() { return getCell()->getGame(); }

PhysicsRegion* Entity::getRegion() const { return getCell()->getPhysicsRegion(); }

void CSceneData::add2Hash(int x,int y) { getCell(x,y)->SearchedFlag = m_SearchedFlag; }

static ptype_list* search_long_path(losig_list* losig, int ck_include) { loins_list* best_loins=NULL; locon_list* locon; losig_list *best_losig=NULL; loins_list* loins; befig_list* befig; char* signame, *ck=NULL; int reg=0; /*flag for flip-flop*/ chain_list* lofigchain; ptype_list* ptype, *ret; double max_delay=-1, delay; cell_list* cell; biabl_list* biabl; if (!losig) { fprintf(stderr,"search_long_path: NULL pointer\n"); autexit(1); } if (!losig->NAMECHAIN) { fprintf(stderr,"search_long_path: no losig name\n"); autexit(1); } signame=(char*) losig->NAMECHAIN->DATA; /*control combinational loop, not to recurse infinitively*/ if ( searchauthelem( ControlLoop, (char*) losig ) ) { fprintf(stderr,"Warning: combinational loop on signal %s\n", signame ); return ret; } addauthelem( ControlLoop, (char*) losig, 1 ); /*search drivers*/ ptype=getptype(losig->USER,LOFIGCHAIN); if (!ptype || !ptype->DATA) { fprintf(stderr,"search_long_path: no lofigchain found\n"); autexit(1); } for (lofigchain=(chain_list*) ptype->DATA; lofigchain; lofigchain=lofigchain->NEXT) { locon=(locon_list*) lofigchain->DATA; if (locon->DIRECTION==UNKNOWN) { fprintf(stderr,"BEH: 'linkage %s' isn't accepted\n", locon->NAME); autexit(1); } /*only outputs*/ if (isvss(locon->NAME) || isvdd(locon->NAME) || locon->DIRECTION==IN || locon->TYPE==EXTERNAL) continue; loins=locon->ROOT; delay=loins_delay(loins,signame); if (delay>max_delay) { best_loins=loins; max_delay=delay; } } loins=best_loins; ret=addptype(NULL, (long) max_delay>=0?max_delay:getdelay(signame), losig); if (!loins) return ret; /*stop at flip-flop*/ cell=getCell(loins->FIGNAME); if (!cell) { fprintf(stderr,"library error: no cell '%s.vbe' found\n", loins->FIGNAME); autexit(1); } befig=cell->BEFIG; if (befig->BEREG) { for ( biabl = cell->BEFIG->BEREG->BIABL; biabl; biabl = biabl->NEXT ) { ptype=getptype(biabl->USER,ABL_STABLE); if (ptype) { /*do not include clock in path*/ if (!ck_include) return ret; reg=1; ck=ptype->DATA; break; } } } max_delay=-1; /*seek the latest input in cell*/ for (locon=loins->LOCON; locon; locon=locon->NEXT) { if (locon->DIRECTION==UNKNOWN) { fprintf(stderr,"BEH: 'linkage %s' in figure '%s' isn't accepted\n", locon->NAME,loins->FIGNAME); autexit(1); } /*only inputs*/ if (locon->DIRECTION==OUT || locon->DIRECTION==TRISTATE || isvss(locon->NAME) || isvdd(locon->NAME)) continue; /* if flip-flop, accept only clock */ if (reg && ck!=locon->NAME) continue; losig=locon->SIG; if (!losig->NAMECHAIN) { fprintf(stderr,"search_long_path: no name on signal\n"); autexit(1); } signame=(char*) losig->NAMECHAIN->DATA; delay=getdelay(signame); if (delay>max_delay) { best_losig=losig; max_delay=delay; } } losig=best_losig; /*no input found -> constant*/ if (!losig) return ret; ret->NEXT=search_long_path(losig,ck_include); return ret; }

/** * The value of a path is calculated as follows: * For each cell in the path, a NS penalty is applied, * which knocks the points for that cell down by a * percentage. Then, the amount of times the robot * must change directions is summed and subtracted * from the final path value. **/ float Path::getValue() { float value = 0.0; bool used[MAP_WIDTH][MAP_HEIGHT] = { {false, false, false, false, false}, {false, false, false, false, false}, {false, false, false, false, false}, {false, false, false, false, false}, {false, false, false, false, false}, {false, false, false, false, false}, {false, false, false, false, false} }; int opponentX=-1, opponentY=-1; LOG.write(LOG_LOW, "path", "\n\nPATH:\n"); int directionChanges = 0; for (int i = 0; i < length(); i++) { Cell *nextCell = getCell(i); int nextX = nextCell->x; int nextY = nextCell->y; LOG.write(LOG_LOW, "path", "%d, %d", nextX,nextY); if (!used[nextX][nextY]) { int points = nextCell->getPoints(); value += (float)points * (1-NS_PENALTY[nextX][nextY]); used[nextX][nextY] = true; } if (i > 1) { Cell *curCell = getCell(i-1); int curX = curCell->x; int curY = curCell->y; int heading = getHeading(i); switch (heading) { case DIR_NORTH: if (nextY < curY || nextX != curX) { directionChanges++; } break; case DIR_SOUTH: if (nextY > curY || nextX != curX) { directionChanges++; } break; case DIR_EAST: if (nextX > curX || nextY != curY) { directionChanges++; } break; case DIR_WEST: if (nextX < curX || nextY != curY) { directionChanges++; } break; } //apply penalty based on the location of the other robot // to the cell iff they are fairly close /* int diff = abs(curX-)+abs(curY-opponentY); if(diff != 0 && diff <= 3) value -= (1-(1/(2*diff)))*nextCell->getPoints(); */ } } value -= (float)directionChanges; LOG.printfScreen(LOG_LOW, "path", "Path Value = %f\n", value); return value; }

float BuyerParser::getBudget(void) { return std::atof( getCell(Cell('b',4)).c_str()+3 ); }

void Fluid::setupVBOs() { HandleGLError("in setup fluid VBOs"); fluid_particles.clear(); fluid_velocity_vis.clear(); fluid_face_velocity_vis.clear(); fluid_pressure_vis.clear(); fluid_cell_type_vis.clear(); // ===================================================================================== // setup the particles // ===================================================================================== for (int x = 0; x < nx; x++) { for (int y = 0; y < ny; y++) { for (int z = 0; z < nz; z++) { Cell *cell = getCell(x,y,z); std::vector<FluidParticle*> &particles = cell->getParticles(); for (unsigned int iter = 0; iter < particles.size(); iter++) { FluidParticle *p = particles[iter]; Vec3f v = p->getPosition(); fluid_particles.push_back(VBOPos(v)); } } } } // ===================================================================================== // visualize the velocity // ===================================================================================== if (args->dense_velocity == 0) { // one velocity vector per cell, at the centroid for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { for (int k = 0; k < nz; k++) { Vec3f cell_center((i+0.5)*dx,(j+0.5)*dy,(k+0.5)*dz); Vec3f direction(get_u_avg(i,j,k),get_v_avg(i,j,k),get_w_avg(i,j,k)); Vec3f pt2 = cell_center+100*args->timestep*direction; fluid_velocity_vis.push_back(VBOPosColor(cell_center,Vec3f(1,0,0))); fluid_velocity_vis.push_back(VBOPosColor(pt2,Vec3f(1,1,1))); } } } } else if (args->dense_velocity == 1) { double z = nz*dz / 2.0; for (double x = 0; x <= (nx+0.01)*dx; x+=0.25*dx) { for (double y = 0; y <= (ny+0.01)*dy; y+=0.25*dy) { Vec3f vel = getInterpolatedVelocity(Vec3f(x,y,z)); Vec3f pt1(x,y,z); Vec3f pt2 = pt1 + 100*args->timestep*vel; fluid_velocity_vis.push_back(VBOPosColor(pt1,Vec3f(1,0,0))); fluid_velocity_vis.push_back(VBOPosColor(pt2,Vec3f(1,1,1))); } } } else if (args->dense_velocity == 2) { double y = ny*dy / 2.0; for (double x = 0; x <= (nx+0.01)*dx; x+=0.25*dx) { for (double z = 0; z <= (nz+0.01)*dz; z+=0.25*dz) { Vec3f vel = getInterpolatedVelocity(Vec3f(x,y,z)); Vec3f pt1(x,y,z); Vec3f pt2 = pt1 + 100*args->timestep*vel; fluid_velocity_vis.push_back(VBOPosColor(pt1,Vec3f(1,0,0))); fluid_velocity_vis.push_back(VBOPosColor(pt2,Vec3f(1,1,1))); } } } else if (args->dense_velocity == 3) { double x = nx*dx / 2.0; for (double y = 0; y <= (ny+0.01)*dy; y+=0.25*dy) { for (double z = 0; z <= (nz+0.01)*dz; z+=0.25*dz) { Vec3f vel = getInterpolatedVelocity(Vec3f(x,y,z)); Vec3f pt1(x,y,z); Vec3f pt2 = pt1 + 100*args->timestep*vel; fluid_velocity_vis.push_back(VBOPosColor(pt1,Vec3f(1,0,0))); fluid_velocity_vis.push_back(VBOPosColor(pt2,Vec3f(1,1,1))); } } } // ===================================================================================== // visualize the face velocity // render stubby triangles to visualize the u, v, and w velocities between cell faces // ===================================================================================== for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { for (int k = 0; k < nz; k++) { double dt = args->timestep; double u = get_u_plus(i,j,k)*100*dt; double v = get_v_plus(i,j,k)*100*dt; double w = get_w_plus(i,j,k)*100*dt; double x = i*dx; double y = j*dy; double z = k*dz; if (u < -10*dt) { Vec3f pts[5] = { Vec3f(x+dx+u,y+0.5*dy,z+0.5*dz), Vec3f(x+dx,y+0.55*dy,z+0.55*dz), Vec3f(x+dx,y+0.55*dy,z+0.45*dz), Vec3f(x+dx,y+0.45*dy,z+0.45*dz), Vec3f(x+dx,y+0.45*dy,z+0.55*dz) }; setupConeVBO(pts,Vec3f(1,0,0),fluid_face_velocity_vis); } else if (u > 10*dt) { Vec3f pts[5] = { Vec3f(x+dx+u,y+0.5*dy,z+0.5*dz), Vec3f(x+dx,y+0.45*dy,z+0.45*dz), Vec3f(x+dx,y+0.55*dy,z+0.45*dz), Vec3f(x+dx,y+0.55*dy,z+0.55*dz), Vec3f(x+dx,y+0.45*dy,z+0.55*dz) }; setupConeVBO(pts,Vec3f(1,0,0),fluid_face_velocity_vis); } if (v < -10*dt) { Vec3f pts[5] = { Vec3f(x+0.5*dx,y+dy+v,z+0.5*dz), Vec3f(x+0.45*dx,y+dy,z+0.45*dz), Vec3f(x+0.55*dx,y+dy,z+0.45*dz), Vec3f(x+0.55*dx,y+dy,z+0.55*dz), Vec3f(x+0.45*dx,y+dy,z+0.55*dz) }; setupConeVBO(pts,Vec3f(0,1,0),fluid_face_velocity_vis); } else if (v > 10*dt) { Vec3f pts[5] = { Vec3f(x+0.5*dx,y+dy+v,z+0.5*dz), Vec3f(x+0.55*dx,y+dy,z+0.55*dz), Vec3f(x+0.55*dx,y+dy,z+0.45*dz), Vec3f(x+0.45*dx,y+dy,z+0.45*dz), Vec3f(x+0.45*dx,y+dy,z+0.55*dz) }; setupConeVBO(pts,Vec3f(0,1,0),fluid_face_velocity_vis); } if (w < -10*dt) { Vec3f pts[5] = { Vec3f(x+0.5*dx,y+0.5*dy,z+dz+w), Vec3f(x+0.55*dx,y+0.55*dy,z+dz), Vec3f(x+0.55*dx,y+0.45*dy,z+dz), Vec3f(x+0.45*dx,y+0.45*dy,z+dz), Vec3f(x+0.45*dx,y+0.55*dy,z+dz) }; setupConeVBO(pts,Vec3f(0,0,1),fluid_face_velocity_vis); } else if (w > 10*dt) { Vec3f pts[5] = { Vec3f(x+0.5*dx,y+0.5*dy,z+dz+w), Vec3f(x+0.45*dx,y+0.45*dy,z+dz), Vec3f(x+0.55*dx,y+0.45*dy,z+dz), Vec3f(x+0.55*dx,y+0.55*dy,z+dz), Vec3f(x+0.45*dx,y+0.55*dy,z+dz) }; setupConeVBO(pts,Vec3f(0,0,1),fluid_face_velocity_vis); } } } } // ===================================================================================== // visualize the cell pressure // ===================================================================================== for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { for (int k = 0; k < nz; k++) { Vec3f pts[8] = { Vec3f((i+0.1)*dx,(j+0.1)*dy,(k+0.1)*dz), Vec3f((i+0.1)*dx,(j+0.1)*dy,(k+0.9)*dz), Vec3f((i+0.1)*dx,(j+0.9)*dy,(k+0.1)*dz), Vec3f((i+0.1)*dx,(j+0.9)*dy,(k+0.9)*dz), Vec3f((i+0.9)*dx,(j+0.1)*dy,(k+0.1)*dz), Vec3f((i+0.9)*dx,(j+0.1)*dy,(k+0.9)*dz), Vec3f((i+0.9)*dx,(j+0.9)*dy,(k+0.1)*dz), Vec3f((i+0.9)*dx,(j+0.9)*dy,(k+0.9)*dz) }; double p = getCell(i,j,k)->getPressure(); p *= 0.1; if (p > 1) p = 1; if (p < -1) p = -1; assert(p >= -1 && p <= 1); Vec3f color; if (p < 0) { color = Vec3f(1+p,1+p,1); } else { color = Vec3f(1,1-p,1-p); } setupCubeVBO(pts,color,fluid_pressure_vis); } } } // ===================================================================================== // render the MAC cells (FULL, SURFACE, or EMPTY) // ===================================================================================== for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { for (int k = 0; k < nz; k++) { Vec3f pts[8] = { Vec3f((i+0.1)*dx,(j+0.1)*dy,(k+0.1)*dz), Vec3f((i+0.1)*dx,(j+0.1)*dy,(k+0.9)*dz), Vec3f((i+0.1)*dx,(j+0.9)*dy,(k+0.1)*dz), Vec3f((i+0.1)*dx,(j+0.9)*dy,(k+0.9)*dz), Vec3f((i+0.9)*dx,(j+0.1)*dy,(k+0.1)*dz), Vec3f((i+0.9)*dx,(j+0.1)*dy,(k+0.9)*dz), Vec3f((i+0.9)*dx,(j+0.9)*dy,(k+0.1)*dz), Vec3f((i+0.9)*dx,(j+0.9)*dy,(k+0.9)*dz) }; Cell *cell = getCell(i,j,k); Vec3f color; if (cell->getStatus() == CELL_FULL) { color = Vec3f(1,0,0); } else if (cell->getStatus() == CELL_SURFACE) { color=Vec3f(0,0,1); } else { continue; } setupCubeVBO(pts,color,fluid_cell_type_vis); } } } // cleanup old buffer data (if any) cleanupVBOs(); // copy the data to each VBO glBindBuffer(GL_ARRAY_BUFFER,fluid_particles_VBO); glBufferData(GL_ARRAY_BUFFER,sizeof(VBOPos)*fluid_particles.size(),&fluid_particles[0],GL_STATIC_DRAW); if (fluid_velocity_vis.size() > 0) { glBindBuffer(GL_ARRAY_BUFFER,fluid_velocity_vis_VBO); glBufferData(GL_ARRAY_BUFFER,sizeof(VBOPosColor)*fluid_velocity_vis.size(),&fluid_velocity_vis[0],GL_STATIC_DRAW); } if (fluid_face_velocity_vis.size() > 0) { glBindBuffer(GL_ARRAY_BUFFER,fluid_face_velocity_vis_VBO); glBufferData(GL_ARRAY_BUFFER,sizeof(VBOPosNormalColor)*fluid_face_velocity_vis.size(),&fluid_face_velocity_vis[0],GL_STATIC_DRAW); } glBindBuffer(GL_ARRAY_BUFFER,fluid_pressure_vis_VBO); glBufferData(GL_ARRAY_BUFFER,sizeof(VBOPosNormalColor)*fluid_pressure_vis.size(),&fluid_pressure_vis[0],GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER,fluid_cell_type_vis_VBO); glBufferData(GL_ARRAY_BUFFER,sizeof(VBOPosNormalColor)*fluid_cell_type_vis.size(),&fluid_cell_type_vis[0],GL_STATIC_DRAW); HandleGLError("leaving setup fluid"); // ===================================================================================== // setup a marching cubes representation of the surface // ===================================================================================== for (int i = 0; i <= nx; i++) { for (int j = 0; j <= ny; j++) { for (int k = 0; k <= nz; k++) { marchingCubes->set(i,j,k,interpolateIsovalue(Vec3f((i-0.5),(j-0.5),(k-0.5)))); } } } marchingCubes->setupVBOs(); }

void Level::transition(int dir) { if (_transitionTimer > 0.0f) return; _transitionTimer = _transitionTime; _transitionDir = dir; Room &oldRoom = getCurrentRoom(); int oldCellX = _currentCellX; int oldCellY = _currentCellY; switch (_transitionDir) { case 0: _currentCellX++; break; case 1: _currentCellY++; break; case 2: _currentCellX--; break; case 3: _currentCellY--; break; } if (getCell(_currentCellX, _currentCellY)._room == nullptr) { std::cerr << "ERROR: Cannot transition: No room in direction: " << dir << std::endl; _currentCellX = oldCellX; _currentCellY = oldCellY; return; } // Render old room to temporary rt getGame()->_transitionTexture0.clear(); getGame()->_transitionTexture1.clear(); oldRoom.render(getGame()->_transitionTexture0, _backgroundTextures, _doorTextures, _roofTextures); getCurrentRoom().render(getGame()->_transitionTexture1, _backgroundTextures, _doorTextures, _roofTextures); getGame()->_transitionTexture0.display(); getGame()->_transitionTexture1.display(); // Normalize limbo times float maxTime = -99999.0f; for (int i = 0; i < getCell(_currentCellX, _currentCellY)._room->_transitLimbo.size(); i++) maxTime = std::max(maxTime, getCell(_currentCellX, _currentCellY)._room->_transitLimbo[i]->_timeSinceTransit); for (int i = 0; i < getCell(_currentCellX, _currentCellY)._room->_transitLimbo.size(); i++) getCell(_currentCellX, _currentCellY)._room->_transitLimbo[i]->_timeSinceTransit = std::max(-_maxAllowedTransitTime, getCell(_currentCellX, _currentCellY)._room->_transitLimbo[i]->_timeSinceTransit - maxTime); float minTime = 99999.0f; for (int i = 0; i < getCell(_currentCellX, _currentCellY)._room->_transitLimbo.size(); i++) minTime = std::min(minTime, getCell(_currentCellX, _currentCellY)._room->_transitLimbo[i]->_timeSinceTransit); for (int i = 0; i < getCell(_currentCellX, _currentCellY)._room->_transitLimbo.size(); i++) getCell(_currentCellX, _currentCellY)._room->_transitLimbo[i]->_timeSinceTransit = minTime - getCell(_currentCellX, _currentCellY)._room->_transitLimbo[i]->_timeSinceTransit; // If just finished transition, add all units to selection by default getGame()->_selection.clear(); for (int i = 0; i < getCell(_currentCellX, _currentCellY)._room->_transitLimbo.size(); i++) getGame()->_selection.insert(getCell(_currentCellX, _currentCellY)._room->_transitLimbo[i].get()); getCurrentRoom().healEnemies(); }

std::string BuyerParser::getBrandName(size_t b_ind) { const std::string& s = getCell( Cell('c' + b_ind, 1) ); return s.substr(1, s.length()-2); }

cell_t* getCellAndCheckBoundries(int x, int y){ if(x < 0 || x >= worldSideLen || y < 0 || y >= worldSideLen) return NULL; return getCell(x,y); }

void Foam::midPointSet::genSamples() { // Generate midpoints. List<point> midPoints(2*size()); labelList midCells(2*size()); labelList midSegments(2*size()); scalarList midCurveDist(2*size()); label midI = 0; label sampleI = 0; while(true && size()>0) { // calculate midpoint between sampleI and sampleI+1 (if in same segment) while ( (sampleI < size() - 1) && (segments_[sampleI] == segments_[sampleI+1]) ) { midPoints[midI] = 0.5*(operator[](sampleI) + operator[](sampleI+1)); label cell1 = getCell(faces_[sampleI], midPoints[midI]); label cell2 = getCell(faces_[sampleI+1], midPoints[midI]); if (cell1 != cell2) { FatalErrorInFunction << " midI:" << midI << " sampleI:" << sampleI << " pts[sampleI]:" << operator[](sampleI) << " face[sampleI]:" << faces_[sampleI] << " pts[sampleI+1]:" << operator[](sampleI+1) << " face[sampleI+1]:" << faces_[sampleI+1] << " cell1:" << cell1 << " cell2:" << cell2 << abort(FatalError); } midCells[midI] = cell1; midSegments[midI] = segments_[sampleI]; midCurveDist[midI] = mag(midPoints[midI] - start()); midI++; sampleI++; } if (sampleI == size() - 1) { break; } sampleI++; } midPoints.setSize(midI); midCells.setSize(midI); midSegments.setSize(midI); midCurveDist.setSize(midI); setSamples ( midPoints, midCells, labelList(midCells.size(), -1), midSegments, midCurveDist ); }

/** * Seta o valor de uma célula da matriz. Se já existir apenas altera o valor. */ void setCell(SparseMatrix* matrix, long x, long y, long value) { Cell* cell = getCell(matrix, x, y); // Se existir, a célula troca o valor if (cell != NULL) { cell->_value = value; return; } // Verifica os índices máximos da matriz, e os troca se preciso if (x > matrix->_maximumX) { matrix->_maximumX = x; } if (y > matrix->_maximumY) { matrix->_maximumY = y; } // Cria uma nova célula cell = newCell(x, y, value); // Verifica se o índice (linha) atual existe Index* index = matrix->_firstIndex; Index* cellIndex = NULL; while (index != NULL) { // Se a linha for igual, existe if (index->_value == y) { cellIndex = index; break; } index = index->_nextIndex; } // Se o índice não existir, cria um novo if (cellIndex == NULL) { cellIndex = newIndex(y); } // Adiciona o índice a matriz // Se o primeiro for vazio, tá certo if (matrix->_firstIndex == NULL) { matrix->_firstIndex = cellIndex; } // Senão insere o novo índice na ordem else { Index* currentIndex = matrix->_firstIndex; Index* previousIndex = matrix->_firstIndex; while (true) { // Se for maior, vai para frente, senão insere if (currentIndex == NULL || cellIndex->_value < currentIndex->_value) { previousIndex->_nextIndex = cellIndex; cellIndex->_nextIndex = currentIndex; break; } else { previousIndex = currentIndex; currentIndex = currentIndex->_nextIndex; } } } // Insere a célula if (cellIndex->_cell == NULL) { cellIndex->_cell = cell; } else { Cell* currentCell = cellIndex->_cell; Cell* previousCell = currentCell; while (true) { // Se o índice x for maior, vai para frente, senão insere if (currentCell == NULL || cell->_x < currentCell->_x) { previousCell->_nextCell = cell; cell->_nextCell = currentCell; break; } else { previousCell = currentCell; currentCell = currentCell->_nextCell; } } } }

bool CTerrainData::hasGrass(int nCellX, int nCellY)const { const TerrainCell* cell = getCell(nCellX,nCellY); const unsigned char uAttribute = getCellAttribute(nCellX,nCellY); return 0==cell->uTileID[0]&&255==cell->uTileID[1]&&0==(cell->uAttribute&ATTRIBUTE_GRASS); }

Cell *Grid::getCell(const Coord &coord) { return getCell(coord.row, coord.col); }

static int change_instance(loins_list* loins, losig_list* losig, lofig_list* lofig, int optim_level) { losig_list* losig_aux; lofig_list* lofig_aux; double critical, best_critical, delay, best_delay; double RC_max, T_max; locon_list* locon, *locon_aux; int change=0; cell_list* cell, *best; best=getCell(loins->FIGNAME); if (!best || best->NAME!=loins->FIGNAME) { fprintf(stderr,"library error: no cell '%s.vbe' found\n",loins->FIGNAME); autexit(1); } if (!losig->NAMECHAIN) { fprintf(stderr,"change_instance: no name on signal\n"); autexit(1); } best_critical=critical_delay(lofig); best_delay=loins_delay(loins,losig->NAMECHAIN->DATA); /*compare RC and delay of instance*/ RC_max=loins_max_RC(loins,losig->NAMECHAIN->DATA); T_max=loins_max_T(loins); /*check all cell of the same kind*/ for (cell=sameCells(loins->FIGNAME); cell; cell=cell->NEXT) { /*eval critical*/ loins_capacitance(loins,0); /*remove own capacity*/ loins->FIGNAME=cell->NAME; /*change cell*/ loins_capacitance(loins,1); /*add its own capacity (cell has changed)*/ propagate_loins_delay(loins); critical=critical_delay(lofig); delay=loins_delay(loins,losig->NAMECHAIN->DATA); /*take new solution?*/ if ( (critical<best_critical && (cell->AREA<=best->AREA || optim_level>OPTIM_DELAY0)) || (critical==best_critical && delay<best_delay && (cell->AREA<=best->AREA || optim_level>=OPTIM_DELAY4 || (RC_max>T_max && optim_level>=OPTIM_DELAY1))) || (critical==best_critical && delay==best_delay && cell->AREA<best->AREA) ) { best_critical=critical; best=cell; best_delay=delay; change=1; } } /*end of loop on cell*/ loins_capacitance(loins,0); /*substract own capacity*/ loins->FIGNAME=best->NAME; /*capacitance and critical delay*/ loins_capacitance(loins,1); /*add it own capacity (cell has changed)*/ propagate_loins_delay(loins); /*verify change of loins*/ critical=critical_delay(lofig); delay=loins_delay(loins,losig->NAMECHAIN->DATA); if ((int)critical!=(int)best_critical || (int)delay!=(int)best_delay) { fprintf(stderr, "change_instance: compute error %f!=%f ps %f!=%f ps (%sdue to caller)\n", critical,best_critical,delay,best_delay,change?"not ":""); autexit(1); } /*if cell doesn't exist but is composed by several cells*/ /*map port with real order*/ if (best->MODE=='A' || best->MODE=='a') { loins_capacitance(loins,0); /*substract own capacity*/ /*change names*/ loins->FIGNAME=best->BEFIG->NAME; lofig_aux=getlofig(best->NAME,'A'); for (locon=loins->LOCON; locon; locon=locon->NEXT) { /*search locon in model*/ for (locon_aux=lofig_aux->LOCON; locon_aux; locon_aux=locon_aux->NEXT){ if (locon->NAME==locon_aux->NAME) break; } if (!locon_aux) { fprintf(stderr,"change_instance: locon '%s' not found\n", locon->NAME); autexit(1); } losig_aux=locon_aux->SIG; /*search real connection*/ for (locon_aux=lofig_aux->LOINS->LOCON; locon_aux; locon_aux=locon_aux->NEXT){ if (losig_aux==locon_aux->SIG) break; } if (!locon_aux) { fprintf(stderr,"change_instance: locon '%s' not found in cell\n", locon->NAME); autexit(1); } locon->NAME=locon_aux->NAME; } /*capacitance and critical delay*/ loins_capacitance(loins,1); /*add it own capacity (cell has changed)*/ propagate_loins_delay(loins); /*verify change of loins*/ critical=critical_delay(lofig); delay=loins_delay(loins,losig->NAMECHAIN->DATA); if ((int)critical!=(int)best_critical || (int)delay!=(int)best_delay) { fprintf(stderr, "change_instance: flatten error %f!=%f ps %f!=%f ps\n", critical,best_critical,delay,best_delay); autexit(1); } } /*end of change loins*/ return change; }

int FontGrid::getLetter(const QPoint &pos) { return getCell(pos, QSize(15, 15), _letterCountH); }

/* * Have we been here before? returns essentially if the * specified square is now purple */ int Maze::isSearched(point loc){ if(!validRoom(loc)) exitWithPopup("You passed an invalid cell id to is_searched",0); return (getCell(loc.y, loc.x)->getMazeStatus() == SEARCHED); }

Cell* Path::getFirstCell() { return getCell(1); }