int ObjWat2::GetPassable(u32 index) { #if (__GNUC__ == 4 && __GNUC_MINOR__ == 4) // fixed: array subscript is above array bounds const u8 disabled[] = { 11, 12, 19, 22, 255 }; #else const u8 disabled[] = { 11, 12, 19, 22 }; #endif const u8 restricted[] = { 2, 20 }; if(isShadow(index)) return DIRECTION_ALL; else if(10 == index) return Direction::CENTER | Direction::TOP | Direction::LEFT | Direction::TOP_LEFT; else if(22 == index) return DIRECTION_CENTER_ROW | Direction::BOTTOM | Direction::BOTTOM_LEFT; else if(isAction(index) || ARRAY_COUNT_END(disabled) != std::find(disabled, ARRAY_COUNT_END(disabled), index)) return 0; return ARRAY_COUNT_END(restricted) != std::find(restricted, ARRAY_COUNT_END(restricted), index) ? DIRECTION_CENTER_ROW | DIRECTION_BOTTOM_ROW : DIRECTION_ALL; }
/*! \property bool IrcPrivateMessage::request This property is \c true if the message is a request; otherwise \c false. \par Access function: \li bool <b>isRequest</b>() const */ bool IrcPrivateMessage::isRequest() const { Q_D(const IrcMessage); QString msg = d->param(1); if (flags() & (Identified | Unidentified)) msg.remove(0, 1); return msg.startsWith('\1') && msg.endsWith('\1') && !isAction(); }
/*! \property bool IrcPrivateMessage::request This property is \c true if the message is a request; otherwise \c false. \par Access functions: \li bool <b>isRequest</b>() const */ bool IrcPrivateMessage::isRequest() const { Q_D(const IrcMessage); QByteArray msg = d->parser.params().value(1); if (d->flags & (Identified | Unidentified)) msg.remove(0, 1); return msg.startsWith('\1') && msg.endsWith('\1') && !isAction(); }
/*! This property holds the message content. \par Access function: \li QString <b>content</b>() const */ QString IrcPrivateMessage::content() const { Q_D(const IrcMessage); QString msg = d->param(1); if (flags() & (Identified | Unidentified)) msg.remove(0, 1); const bool act = isAction(); const bool req = isRequest(); if (act) msg.remove(0, 8); if (req) msg.remove(0, 1); if (act || req) msg.chop(1); return msg; }
u16 ObjDirt::GetPassable(const u8 & index) { const u8 disabled[] = { 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 48, 49, 50, 51 }; const u8 restricted[] = { 7, 9, 12, 13, 15, 16, 17, 18 ,19, 20, 21, 22, 40, 41, 42, 43, 44, 45, 53, 54, 55, 56, 57, 58, 60, 61, 63, 64, 66, 67, 69, 71, 73, 74, 76, 77, 79, 80, 82, 83, 85, 86, 88, 89, 90, 92, 93, 98, 99, 101, 102, 104, 105, 118, 123, 127, 130, 133, 134, 137, 139, 152, 189 }; if(isShadow(index)) return DIRECTION_ALL; else if(isAction(index) || ARRAY_COUNT_END(disabled) != std::find(disabled, ARRAY_COUNT_END(disabled), index)) return 0; return ARRAY_COUNT_END(restricted) != std::find(restricted, ARRAY_COUNT_END(restricted), index) ? DIRECTION_CENTER_ROW | DIRECTION_BOTTOM_ROW : DIRECTION_ALL; }
int ObjWatr::GetPassable(u32 index) { #if (__GNUC__ == 4 && __GNUC_MINOR__ == 4) // fixed: array subscript is above array bounds const u8 disabled[] = { 11, 12, 19, 22, 255 }; #else const u8 disabled[] = { 11, 12, 19, 22 }; #endif const u8 restricted[] = { 69, 182, 183, 185, 186, 187, 248 }; if(isShadow(index)) return DIRECTION_ALL; else if(isAction(index) || ARRAY_COUNT_END(disabled) != std::find(disabled, ARRAY_COUNT_END(disabled), index)) return 0; return ARRAY_COUNT_END(restricted) != std::find(restricted, ARRAY_COUNT_END(restricted), index) ? DIRECTION_CENTER_ROW | DIRECTION_BOTTOM_ROW : DIRECTION_ALL; }
//@inputs: array of sensor readings, current average //@outputs: new average //Is used to have a moving average, based on the current data input and previous average int* recognize(int *array, int* avg) { int j,k,l; for (k=0;k<11;k++) { avg[k] = (5*avg[k] + array[k])/6; //Puts more weighting on the previous average } for(k=0;k<11;k++) { //If the difference is more than 3, break out of the method and take another input if(abs(avg[k]-array[k])>8) { digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,LOW); holding=0; return avg; } } int i; isAction(peter,array); return avg; }
void MADSAction::checkAction() { if (isAction(VERB_LOOK) || isAction(VERB_THROW)) _vm->_game->_player._needToWalk = false; }
/* * Main */ int main (int argc, char** argv) { int k[10]; int i, j; struct gameState state; int hasEstate; int turnCount = 0; // Open the log file, gameResults.out gameResults = fopen("gameResults.out", "w"); if(gameResults == NULL) { fprintf(stderr, "Error: could not open gameResults.out for writing.\n"); exit(1); } signal(SIGSEGV, seg_handler); signal(SIGBUS, bus_handler); signal(SIGFPE, float_handler); // Initialize the seed if(argc == 2) { srand(atoi(argv[1])); } else { struct timeval tv; gettimeofday(&tv,NULL); srand((tv.tv_sec * 1000) + (tv.tv_usec / 1000)); } // Get 10 random kingdom cards i = 0; while(i < 10) { // Choose a card k[i] = rand() % (treasure_map - adventurer + 1) + adventurer; // Make sure the card wasn't chosen already int duplicate = FALSE; for(j = 0; j < i; j++) { if(k[j] == k[i]) { duplicate = TRUE; break; } } // Card is not a duplicate; we can continue to the next spot if(!duplicate) { i++; } } initializeGame(rand() % 3 + 2, k, rand(), &state); for(i = 0; i < 10; i++) { fprintf(gameResults, "Kingdom card %d: %s\n", i + 1, getName(k[i])); } // Main game loop while(!isGameOver(&state)) { fprintf(gameResults, "Player %d turn start. Hand contains: ", whoseTurn(&state) + 1); for(i = 0; i < numHandCards(&state); i++) { fprintf(gameResults, "%s", getName(handCard(i, &state))); if(i != numHandCards(&state) - 1) { fprintf(gameResults, ", "); } } fprintf(gameResults, "\n"); // Step 1: Play as many action cards as possible, starting from the left // and going right i = 0; while(i < numHandCards(&state) && state.numActions > 0) { if(isAction(handCard(i, &state))) { // Check if we need choices for this card switch(handCard(i, &state)) { // These cards don't need any choices, so just play it case adventurer: case council_room: case smithy: case village: case great_hall: case tribute: case cutpurse: case outpost: case sea_hag: case treasure_map: fprintf(gameResults, "Player %d plays %s\n", whoseTurn(&state) + 1, getName(handCard(i, &state))); playCard(i, 0, 0, 0, &state); break; // These things need choices case feast: playCard(i, getMostExpensiveCard(&state, 5), 0, 0, &state); break; case mine: // Choose the first copper/silver for(j = 0; j < numHandCards(&state); j++) { if(handCard(j, &state) == copper) { playCard(i, copper, silver, 0, &state); break; } else if(handCard(j, &state) == silver) { playCard(i, copper, silver, 0, &state); break; } } break; case remodel: // Remodel the first thing valid thing in hand if(i == 0 && numHandCards(&state) > 1) { playCard(i, 1, getMostExpensiveCard(&state, getCost(handCard(1, &state))) + 2, 0, &state); } else if(i != 0) { playCard(i, 0, getMostExpensiveCard(&state, getCost(handCard(0, &state))) + 2, 0, &state); } break; case baron: // play with an estate if we have one hasEstate = FALSE; for(j = 0; j < numHandCards(&state); j++) { if(handCard(j, &state) == estate) { hasEstate = TRUE; break; } } playCard(i, hasEstate, 0, 0, &state); break; case minion: if(rand() % 2 == 0) { playCard(i, 1, 0, 0, &state); } else { playCard(i, 0, 1, 0, &state); } break; case steward: playCard(i, rand() % 3 + 1, 0, 0, &state); break; case ambassador: // Reveal the first non-ambassador card if(i == 0 && numHandCards(&state) > 1) { playCard(i, 1, rand() % 3, 0, &state); } else if(i != 0) { playCard(i, 0, rand() % 3, 0, &state); } break; case embargo: playCard(i, rand() % (treasure_map - adventurer) + 1, 0, 0, &state); break; case salvager: // Reveal the first non-ambassador card if(i == 0 && numHandCards(&state) > 1) { playCard(i, 1, 0, 0, &state); } else if(i != 0) { playCard(i, 0, 0, 0, &state); } break; default: fprintf(gameResults, "%s WAS NOT AN ACTION!\n", getName(handCard(i, &state))); break; }; } i++; } // Step 2: Buy the most expensive things we can int done = FALSE; while(!done && state.numBuys > 0) { int mostExpensiveCard = getMostExpensiveCard(&state, state.coins); if(mostExpensiveCard != copper && mostExpensiveCard != curse) { if(buyCard(mostExpensiveCard, &state) != -1) { fprintf(gameResults, "Player %d buys %s\n", whoseTurn(&state) + 1, getName(mostExpensiveCard)); } else { fprintf(gameResults, "I thought I could afford that %s...\n", getName(mostExpensiveCard)); } } else { done = TRUE; } } endTurn(&state); turnCount++; if(turnCount == TURN_LIMIT) { fprintf(gameResults, "Terminating game after %d turns.", TURN_LIMIT); fclose(gameResults); exit(0); } } fprintf(gameResults, "Game over. Final scores:\n"); for(i = 0; i < state.numPlayers; i++) { fprintf(gameResults, "Player %d: %d\n", i + 1, scoreFor(i, &state)); } int winners[MAX_PLAYERS]; getWinners(winners, &state); fprintf(gameResults, "The winners are:\n"); for(i = 0; i < MAX_PLAYERS; i++) { if(winners[i] == 1) { fprintf(gameResults, "Player %d!\n", i + 1); } } fclose(gameResults); return 0; }
void MadsAction::checkAction() { if (isAction(kVerbLookAt) || isAction(kVerbThrow)) _startWalkFlag = 0; }
bool CompOption::set (CompOption::Value &val) { if (isAction () && priv->type != CompOption::TypeAction) val.action ().copyState (priv->value.action ()); if (priv->type != val.type () && (!isAction () || !checkIsAction (val.type ()))) { compLogMessage ("core", CompLogLevelWarn, "Can't set Value with type %d to " "option \"%s\" with type %d", val.type (), priv->name.c_str (), priv->type); return false; } if (priv->value == val) return false; if (isAction () && priv->value.action ().state () & CompAction::StateAutoGrab && screen) { if (!screen->addAction (&val.action ())) return false; else screen->removeAction (&priv->value.action ()); } switch (priv->type) { case CompOption::TypeInt: if (!priv->rest.inRange (val.i ())) return false; break; case CompOption::TypeFloat: { float v, p; int sign = (val.f () < 0 ? -1 : 1); if (!priv->rest.inRange (val.f ())) return false; p = 1.0f / priv->rest.fPrecision (); v = ((int) (val.f () * p + sign * 0.5f)) / p; priv->value.set (v); return true; } case CompOption::TypeAction: return false; case CompOption::TypeKey: if (val.action ().type () == value().action ().type () && !(val.action ().type () & CompAction::BindingTypeKey)) return false; break; case CompOption::TypeButton: if (val.action ().type () == value().action ().type () && !(val.action ().type () & (CompAction::BindingTypeButton | CompAction::BindingTypeEdgeButton))) return false; break; default: break; } priv->value = val; return true; }
void nearCallback (void *data, dGeomID o1, dGeomID o2) { int i,n; dBodyID b1,b2; // only collide things with the ground int g1 = (o1 == ground ); int g2 = (o2 == ground ); if (!(g1 ^ g2)) { //printf ("Ground colliding..\n"); //return; } b1 = dGeomGetBody(o1); b2 = dGeomGetBody(o2); if (b1 && b2 && dAreConnected (b1,b2)) return; if (b1 && isAction(b1) && b2 && (isType(b2,WALRUS) || (isType(b2,MANTA))) && isMineFire(gVehicle(b2),(Gunshot*)gVehicle(b1)) ) return; if (b2 && isAction(b2) && b1 && (isType(b1,WALRUS) || (isType(b1,MANTA))) && isMineFire(gVehicle(b1),(Gunshot*)gVehicle(b2)) ) return; int val[]={CARRIER,WALRUS,MANTA}; if (o1 && isRay(o1) && b2 && isType(b2,val,3) && rayHit(gVehicle(b2),(LaserRay*)gVehicle(o1))) {return;} if (o2 && isRay(o2) && b1 && isType(b1,val,3) && rayHit(gVehicle(b1),(LaserRay*)gVehicle(o2))) {return;} const int N = 10; dContact contact[N]; n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact)); if (n > 0) { for (i=0; i<n; i++) { Vehicle *v1=NULL,*v2=NULL; Structure *s1=NULL, *s2=NULL; gVehicle(v1,v2,dGeomGetBody(contact[i].geom.g1), dGeomGetBody(contact[i].geom.g2),s1,s2,contact[i].geom.g1,contact[i].geom.g2); // Bullets if ((isAction(v1) && isWalrus(v2) && isMineFire(v2,(Gunshot*)v1)) || (isAction(v2) && isWalrus(v1) && isMineFire(v1,(Gunshot*)v2))) { // Water buyoncy reaction contact[i].surface.mode = dContactSlip1 | dContactSlip2 | dContactSoftERP | dContactSoftCFM | dContactApprox1; contact[i].surface.mu = 0.0f; contact[i].surface.slip1 = 1.0f; contact[i].surface.slip2 = 1.0f; contact[i].surface.soft_erp = 1.0f; // 0 in both will force the surface to be tight. contact[i].surface.soft_cfm = 1.0f; } else if ( isAction(v1) || isAction(v2)) { contact[i].surface.mode = dContactSlip1 | dContactSlip2 | dContactSoftERP | dContactSoftCFM | dContactApprox1; contact[i].surface.mu = 0; contact[i].surface.slip1 = 0.1f; contact[i].surface.slip2 = 0.1f; if (isAction(v1) && isCarrier(v2) && hit(v2,(Gunshot*)v1)) {} if (isAction(v2) && isCarrier(v1) && hit(v1,(Gunshot*)v2)) {} if (isAction(v1) && isManta(v2) && hit(v2,(Gunshot*)v1)) {} if (isAction(v2) && isManta(v1) && hit(v1,(Gunshot*)v2)) {} if (isAction(v1) && isWalrus(v2) && hit(v2,(Gunshot*)v1)) {} if (isAction(v2) && isWalrus(v1) && hit(v1,(Gunshot*)v2)) {} if (isAction(v1) && s2 && hit(s2)) {} if (isAction(v2) && s1 && hit(s1)) {} } else if ( ( isManta(v1) && isCarrier(v2) && releasecontrol(v1) ) || ( isManta(v2) && isCarrier(v1) && releasecontrol(v2) ) ) { // Manta landing on Carrier contact[i].surface.mode = dContactBounce | dContactApprox1; contact[i].surface.mu = dInfinity; contact[i].surface.slip1 = 0.0f; contact[i].surface.slip2 = 0.0f; contact[i].surface.bounce = 0.2f; } else if (isRunway(s1) || isRunway(s2)) { // Manta landing on Runways. contact[i].surface.mode = dContactBounce | dContactApprox1; contact[i].surface.mu = 0.99f; contact[i].surface.slip1 = 0.9f; contact[i].surface.slip2 = 0.9f; contact[i].surface.bounce = 0.2f; if ( isRunway(s1) && isManta(v2) && landed(v2, s1->island)) {} if ( isRunway(s2) && isManta(v1) && landed(v1, s2->island)) {} } else if (isIsland(contact[i].geom.g1) || isIsland(contact[i].geom.g2)) { // Island reaction contact[i].surface.mode = dContactBounce | dContactApprox1; contact[i].surface.mu = 0; contact[i].surface.bounce = 0.2f; contact[i].surface.slip1 = 0.1f; contact[i].surface.slip2 = 0.1f; contact[i].surface.soft_erp = 0; // 0 in both will force the surface to be tight. contact[i].surface.soft_cfm = 0; // Carrier stranded and Walrus arrived on island. if (isIsland(contact[i].geom.g1) && isCarrier(v2) && stranded(v2,getIsland(contact[i].geom.g1))) {} if (isIsland(contact[i].geom.g2) && isCarrier(v1) && stranded(v1,getIsland(contact[i].geom.g2))) {} if (isIsland(contact[i].geom.g1) && isWalrus(v2) && arrived(v2,getIsland(contact[i].geom.g1))) {} if (isIsland(contact[i].geom.g2) && isWalrus(v1) && arrived(v1,getIsland(contact[i].geom.g2))) {} } else if (ground == contact[i].geom.g1 || ground == contact[i].geom.g2 ) { // Water buyoncy reaction contact[i].surface.mode = dContactSlip1 | dContactSlip2 | dContactSoftERP | dContactSoftCFM | dContactApprox1; contact[i].surface.mu = 0.0f; contact[i].surface.slip1 = 0.1f; contact[i].surface.slip2 = 0.1f; contact[i].surface.soft_erp = .5f; // 0 in both will force the surface to be tight. contact[i].surface.soft_cfm = .3f; // Walrus reaching shore. if (ground == contact[i].geom.g1 && isWalrus(v2) && departed(v2)) {} if (ground == contact[i].geom.g2 && isWalrus(v1) && departed(v1)) {} if (ground == contact[i].geom.g1 && v2 && isManta(v2) && groundcollisions(v2)) {} if (ground == contact[i].geom.g2 && v1 && isManta(v1) && groundcollisions(v1)) {} } else { /** // Water buyoncy reaction contact[i].surface.mode = dContactSlip1 | dContactSlip2 | dContactSoftERP | dContactSoftCFM | dContactApprox1; contact[i].surface.mu = 0.0f; contact[i].surface.slip1 = 0.1f; contact[i].surface.slip2 = 0.1f; contact[i].surface.soft_erp = .5f; // 0 in both will force the surface to be tight. contact[i].surface.soft_cfm = .3f; **/ if (v1 && isManta(v1) && groundcollisions(v1)) {} if (v2 && isManta(v2) && groundcollisions(v2)) {} } dJointID c = dJointCreateContact (world,contactgroup,&contact[i]); dJointAttach (c, dGeomGetBody(contact[i].geom.g1), dGeomGetBody(contact[i].geom.g2)); } } }
int optionCompatible(char *liste_options, char* pile_options) { int nb_traitees = 0; char* chaine = malloc(sizeof (char)); bool repetition_v = false; bool repetition_z = false; bool repetition_f = false; int taille = strlen(liste_options); // la taille de la chaine de caractères indique le nombre d'options à vérifier if (strcmp(liste_options, "v") == 0) { printf("Le mode verbose n'est pas accepté seul !\n"); nb_traitees = -1; } else if (strcmp(liste_options, "vf") == 0 || strcmp(liste_options, "fv") == 0) { printf("Il doit y avoir au moins une action pour utiliser le mode verbose et préciser le nom de l'archive !!\n"); nb_traitees = -1; } else if (isExclusif(liste_options[0])) // on teste si la première option est exclusive ou pas { sprintf(chaine, "%c", liste_options[0]); // on empile cet option strcat(pile_options, chaine); nb_traitees = 1; } else if (isAction(liste_options[0])) // on teste si la première option est une action ou pas { if (taille > 1) { sprintf(chaine, "%c", liste_options[0]); strcat(pile_options, chaine); int i; for (i = 1; i < taille - 1; i++) // on parcourt le reste des options à tester { if (isAction(liste_options[i]) || isExclusif(liste_options[i])) // si on se retrouve avec plusieurs actions ou options exclusives { printf("Deux options exclusives ou actions ne peuvent pas être utilisées en même temps\n%c est fautif !\n", liste_options[i]); nb_traitees = -1; // on indique une erreur et on sort de la boucle ! break; } else { sprintf(chaine, "%c", liste_options[i]); if (strcmp(chaine, "f") == 0) { if(repetition_f){ printf("L'option f ne peut pas être présente plusieurs fois ! Veuillez vérifier vos options\n"); nb_traitees = -1; break; } repetition_f = true; } else if (strcmp(chaine, "v") == 0) { if (repetition_v) { printf("Le mode verbose ne peut pas être changé plusieurs fois ! Veuillez vérifier vos options\n"); nb_traitees = -1; break; } repetition_v = true; } else if (strcmp(chaine, "z") == 0) { if (repetition_z) { printf("On ne peut pas compresser plusieurs fois ! Veuillez vérifier vos options\n"); nb_traitees = -1; break; } repetition_z = true; } strcat(pile_options, chaine); nb_traitees++; } } if (nb_traitees > 0) { sprintf(chaine, "%c", liste_options[taille - 1]); strcat(pile_options, chaine); } } else { printf("Avec une action, vous devez au moins indiquer le nom de l'archive et décider si le mode verbose doit être activé\n"); nb_traitees = -1; } } else { printf("Le premier caractère doit être une action ou une option exclusive !\n"); nb_traitees = -1; } free(chaine); return nb_traitees; }