/** * \brief Activation by all players. * \param p1 The first player. * \param p2 The second player. NULL in a single player game. */ void ptb::hideout_bonus_item::on_all_players ( const player_proxy& p1, const player_proxy& p2 ) { if (p2 == NULL) discover(p1.get_index()); else discover(0); } // hideout_bonus_item::on_all_players()
bool discover( int y, int x, bool explore_neighbors ) { /* Selected tile. */ if( x < 0 || y < 0 || x > width - 1 || y > height - 1) return false; if( minefield[y][x].known || minefield[y][x].mine || minefield[y][x].flag ) { if( !minefield[y][x].flag && minefield[y][x].mine ) return true; if( explore_neighbors && minefield[y][x].known && minefield[y][x].neighbors == neighbors_flagged( y, x ) ) { return discover( y-1, x-1, false ) || discover( y-1, x, false ) || discover( y-1, x+1, false ) || discover( y, x-1, false ) || discover( y, x, false ) || discover( y, x+1, false ) || discover( y+1, x-1, false ) || discover( y+1, x, false ) || discover( y+1, x+1, false ); } return false; } minefield[y][x].known = 1; /* Exit if the tile is not empty. (no mines nearby) */ if( minefield[y][x].neighbors ) return false; int stack[height*width]; push( stack, y, x ); /* Scan all nearby tiles. If we meet a tile with a number we just unveil * it. If we meet an empty tile, we push the location in stack. For each * location in stack we do the same thing. (scan again all nearby tiles) */ while( stack_pos ) { /* Pop x, y from stack. */ x = stack[stack_pos--]; y = stack[stack_pos--]; unveil( stack, y-1, x-1 ); unveil( stack, y-1, x ); unveil( stack, y-1, x+1 ); unveil( stack, y, x+1 ); unveil( stack, y+1, x+1 ); unveil( stack, y+1, x ); unveil( stack, y+1, x-1 ); unveil( stack, y, x-1 ); } return false; }
void main() { unsigned addr; // Initialize hardware discover(); // Initialize screen d_screen = getdevice(screenId); addr = d_screen->address; asm("SET B, [%vram]"); interrupt(addr); // Initialize keyboard d_keyboard = getdevice(keyboardId); // Initialize clock d_clock = getdevice(clockId); updateclockfreq(); print("Booted!\n"); kernel(); }
void Consumer::run(const Name& prefix, const size_t pipelineSize, const bool mustBeFresh, const time::milliseconds& lifetime, const bool isVerbose) { m_nextToPrint = 0; Face face; engine::PipelineInterests pipeline(face, pipelineSize, bind(&Consumer::onData, this, _1, _2), bind(&Consumer::onFailure, this, _1), mustBeFresh, lifetime, 3, isVerbose); engine::DiscoverVersion discover(face, prefix, bind(&engine::PipelineInterests::runWithData, &pipeline, _2), bind(&Consumer::onFailure, this, _1), mustBeFresh, lifetime, isVerbose); discover.run(); try { face.processEvents(); } catch (std::exception& e) { std::cerr << "ERROR: " << e.what() << std::endl; } }
inline ndt::type discover(const std::string &str) { ndt::type res; discover(res, str); return res; }
static void incoming(Conn *cp, If *ifc, Pkt *p) { int i; Block *bp; Pkt *np; /* ack it no matter what its sequence number */ bp = sethdr(ifc, p->src, &np, 0); np->type = Tack; np->seq = p->seq; np->conn = cp->cno; np->len = 0; trace(bp); ifc->d->bwrite(ifc->dc, bp, 0); if(cp->state == Cunused){ /* connection */ discover(ifc, p); return; } if(p->seq == cp->rcvseq) return; cp->rcvseq = p->seq; if(cp->state == Copen){ for (i = 0; i < p->len; i++) kbdcr2nl(nil, (char)p->data[i]); }else if(cp->state == Clogin) checkpw(cp, (char *)p->data, p->len); }
void refresh_anchors(void) { init_anchors(); // Discover anchors uint32_t anchor_refresh_ts = 0; while (anchors_status) { printf("Discovering anchors .. anchors_status:%02X\r\n", anchors_status); // Check for refresh of anchors uint32_t elapsed = cph_get_millis() - anchor_refresh_ts; if (elapsed > ANCHORS_REFRESH_INTERVAL) { printf("Anchors discovery timeout. anchors_status:%02X\r\n", anchors_status); init_anchors(); anchor_refresh_ts = cph_get_millis(); } for (int i=0;i<ANCHORS_MIN;i++) { if (anchors_status & (1 << i)) { int result = discover(i); if (result == CPH_OK) { anchors_status &= (~(1 << i)); printf("anchor[%d] %04X\r\n", i, anchors[i].shortid); } deca_sleep(RNG_DELAY_MS); } } deca_sleep(POLL_DELAY_MS); } printf("Anchors discovered. Moving to poll. anchors_status:%02X\r\n", anchors_status); }
/** * Discover available (pre-allocated) nodes and report * them back to the caller. * */ static int allocate(opal_list_t *nodes) { int ret; char *pbs_jobid; /* get our PBS jobid from the environment */ if (NULL == (pbs_jobid = getenv("PBS_JOBID"))) { ORTE_ERROR_LOG(ORTE_ERR_NOT_FOUND); return ORTE_ERR_NOT_FOUND; } /* save that value in the global job ident string for * later use in any error reporting */ orte_job_ident = strdup(pbs_jobid); if (ORTE_SUCCESS != (ret = discover(nodes, pbs_jobid))) { ORTE_ERROR_LOG(ret); return ret; } /* in the TM world, if we didn't find anything, then this * is an unrecoverable error - report it */ if (opal_list_is_empty(nodes)) { orte_show_help("help-ras-tm.txt", "no-nodes-found", true, filename); return ORTE_ERR_NOT_FOUND; } /* All done */ return ORTE_SUCCESS; }
bool Polymorph::Zap(Coord dir) { Monster* monster = get_monster_in_direction(dir, true); if (!monster) return true; //cancel the holding effect as the monster is changing if (game->hero().is_held_by(monster)) { game->hero().clear_hold(); } //restore the level tile, as the new monster may be invisible Coord p = monster->position(); if (game->hero().can_see_monster(monster)) game->screen().add_tile(p, game->level().get_tile(p)); //create a random monster Monster* new_monster = Monster::CreateMonster(rnd(26) + 'A', &p, game->get_level()); new_monster->set_tile_beneath(monster->tile_beneath()); new_monster->m_pack = monster->m_pack; if (new_monster->m_type != monster->m_type) discover(false); if (game->hero().can_see_monster(new_monster)) game->screen().add_tile(p, new_monster->m_type); //the monster chases the player new_monster->start_run(&game->hero()); //destroy the original game->level().monsters.remove(monster); delete monster; return true; }
/** * Discover available (pre-allocated) nodes. Allocate the * requested number of nodes/process slots to the job. * */ static int allocate(orte_jobid_t jobid, opal_list_t *attributes) { int ret; opal_list_t nodes; opal_list_item_t* item; OBJ_CONSTRUCT(&nodes, opal_list_t); if (ORTE_SUCCESS != (ret = discover(jobid, &nodes))) { opal_output(orte_ras_base.ras_output, "ras:xgrid:allocate: discover failed!"); return ret; } ret = orte_ras_base_allocate_nodes(jobid, &nodes); while (NULL != (item = opal_list_remove_first(&nodes))) { OBJ_RELEASE(item); } OBJ_DESTRUCT(&nodes); /* All done */ if (ORTE_SUCCESS == ret) { opal_output(orte_ras_base.ras_output, "ras:xgrid:allocate: success"); } else { opal_output(orte_ras_base.ras_output, "ras:xgrid:allocate: failure (base_allocate_nodes=%d)", ret); } return ret; }
int main (void) { /* graceful exit */ atexit(cleanup); init(); discover(); events_loop(); return 0; }
int main() { int fd; if(( fd = open(FILE_NAME, O_WRONLY | O_CREAT | O_TRUNC)) == -1 ) { perror("Failed to open input file"); return 1; } close(fd); int i=1; int childpid; printf("%s\n", "enes" ); for(i=1; i < 259; i++) { if ((childpid = fork()) == 0 && (i < 255) ) { char des[LAN_IP_SIZE]; snprintf(des, LAN_IP_SIZE, "%s%d",LAN_IP,i); const char *destination = des; discover(destination, PORT0); break; } else if(childpid == -1) { perror("FORK NOT OPERATED"); exit(1); } if((childpid == 0) && (i == 255) ) listenRequest(); else if((childpid == 0) && (i == 256)) listenResponce(); else if((childpid == 0) && (i == 257)) listenMessage(); else if((childpid == 0) && (i == 258)) responceMessage(); } while(childpid = wait(NULL) ) if ((childpid == -1) && (errno != EINTR)) break; return 0; }
bool MagicMissileStick::Zap(Coord dir) { discover(false); Item* missile = new MagicMissile; do_motion(missile, dir); Agent* monster; if ((monster = game->level().monster_at(missile->position())) != NULL && !save_throw(VS_MAGIC, monster)) projectile_hit(missile->position(), missile); else msg("the missile vanishes with a puff of smoke"); return true; }
void ServiceDiscoveryWidget::SetAccount (QObject *obj) { const int pos = AccountBox_->findData (QVariant::fromValue<QObject*> (obj)); if (pos == -1) return; AccountBox_->setCurrentIndex (pos); auto ihsd = qobject_cast<IHaveServiceDiscovery*> (obj); const auto& query = ihsd->GetDefaultQuery (); if (query.isEmpty ()) return; AddressLine_->setText (query); discover (); }
static void aoeclose(Chan *c) { Aoedev *d; if(TYPE(c->qid) != Qdata || (c->flag&COPEN) == 0) return; d = unit2dev(UNIT(c->qid)); qlock(d); if(--d->nopen == 0 && !waserror()){ discover(d->major, d->minor); poperror(); } qunlock(d); }
CoreServer::Result CoreServer::initialize() { Result r; // Only core0 needs to start other coreservers if (m_info.coreId != 0) return setupChannels(); if ((r = loadKernel()) != Success) return r; if ((r = discover()) != Success) return r; if ((r = setupChannels()) != Success) return r; return bootAll(); }
void discover(int x, int y){ if(x<0) return; if(y<0) return; if(x>width-1) return; if(y>height-1) return; if(minefield[y][x].known) return; minefield[y][x].known = 1; if(minefield[y][x].neighbors == 0){ discover(x-1,y-1); discover(x,y-1); discover(x+1,y-1); discover(x+1,y); discover(x+1,y+1); discover(x,y+1); discover(x-1,y+1); discover(x-1,y); } return; }
void setupold() { //mySerial.begin(4800); //mySerial.println("Hello world"); for (int i= 0; i<CHANNELS; i++) { pinMode(channels[i].button_pin,INPUT); digitalWrite(channels[i].button_pin,HIGH); //enable internal 20K pullup pinMode(channels[i].led_pin,OUTPUT); //blink leds a bit digitalWrite(channels[i].led_pin,HIGH); delay(200); digitalWrite(channels[i].led_pin,LOW); } //debug led //pinMode(13,OUTPUT); //digitalWrite(13,HIGH); //delay(500); //digitalWrite(13,LOW); xbee.begin(XBEE_BAUD); //discover the other XBEE's address discover(); zbTx = ZBTxRequest(addr64, payload, sizeof(payload)); //send a no-op packet so that the xbees can do their magic and find each other payload[0] = 254; xbee.send(zbTx); //Flash all leds once so the user knows flashAll(500); //mySerial.println("Discovered address"); //mySerial.print("MSB: "); //mySerial.println(addr64.getMsb()); //mySerial.println(addr64.getMsb()==0x0013a200?"Yes!":"NO"); //mySerial.print("LSB: "); //mySerial.println(addr64.getLsb()); //mySerial.println(addr64.getLsb()==0x403141DA?"Yes!":"NO"); }
int scan(int* ips_tosave, struct in_addr** ips_array_tosave) { int ips = 0, i = 0; struct in_addr* ips_array = NULL; int cond = 0; cond = discover(&ips_array, &ips); if (cond == -1) return -1; //============================================================================== printf( "Got %d responds\n" "Discover returned %d\n" "Printing connected IPs...\n\n", ips, cond); for (i = 0; i < ips; ++i) fprintf(stderr, "%s\n", inet_ntoa(ips_array[i])); //============================================================================== *ips_tosave = ips; *ips_array_tosave = ips_array; return 0; }
bool Light::Zap(Coord dir) { //Ready Kilowatt wand. Light up the room if (game->hero().is_blind()) msg("you feel a warm glow around you"); else { discover(false); if (game->hero().room()->is_gone()) msg("the corridor glows and then fades"); else msg("the room is lit by a shimmering blue light"); } if (!game->hero().room()->is_gone()) { game->hero().room()->set_dark(false); //Light the room and put the player back up enter_room(game->hero().position()); } return true; }
void discovery() { devices=0; selected_device=0; struct ifaddrs *addrs,*ifa; getifaddrs(&addrs); ifa = addrs; while (ifa) { if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) { if((ifa->ifa_flags&IFF_UP)==IFF_UP && (ifa->ifa_flags&IFF_RUNNING)==IFF_RUNNING && (ifa->ifa_flags&IFF_LOOPBACK)!=IFF_LOOPBACK) { discover(ifa); } } ifa = ifa->ifa_next; } freeifaddrs(addrs); fprintf(stderr, "discovery found %d devices\n",devices); int i; for(i=0;i<devices;i++) { fprintf(stderr,"discovery: found device=%d software_version=%d status=%d address=%s (%02X:%02X:%02X:%02X:%02X:%02X) on %s\n", discovered[i].device, discovered[i].software_version, discovered[i].status, inet_ntoa(discovered[i].address.sin_addr), discovered[i].mac_address[0], discovered[i].mac_address[1], discovered[i].mac_address[2], discovered[i].mac_address[3], discovered[i].mac_address[4], discovered[i].mac_address[5], discovered[i].interface_name); } }
ENTRYPOINT void init_flow (ModeInfo * mi) { flowstruct *sp; char *name; if (flows == NULL) { if ((flows = (flowstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (flowstruct))) == NULL) return; } sp = &flows[MI_SCREEN(mi)]; sp->count2 = 0; sp->taillen = MI_SIZE(mi); if (sp->taillen < -MINTRAIL) { /* Change by sqrt so it seems more variable */ sp->taillen = NRAND((int)sqrt((double) (-sp->taillen - MINTRAIL + 1))); sp->taillen = sp->taillen * sp->taillen + MINTRAIL; } else if (sp->taillen < MINTRAIL) { sp->taillen = MINTRAIL; } if(!rotatep && !ridep) rotatep = True; /* We need at least one viewpoint */ /* Start camera at Orbit or Bee */ if(rotatep) { sp->chaseto = ORBIT; } else { sp->chaseto = BEE; } sp->chasetime = 1; /* Go directly to target */ sp->lyap = 0; sp->yperiod = 0; sp->step2 = INITIALSTEP; /* Zero parameter set */ memset(sp->par2, 0, N_PARS * sizeof(dvector)); /* Set up standard examples */ switch (NRAND((periodicp) ? 5 : 3)) { case 0: /* x' = a(y - x) y' = x(b - z) - y z' = xy - cz */ name = "Lorentz"; sp->par2[Y].x = 10 + balance_rand(5*0); /* a */ sp->par2[X].x = - sp->par2[Y].x; /* -a */ sp->par2[X].y = 28 + balance_rand(5*0); /* b */ sp->par2[XZ].y = -1; sp->par2[Y].y = -1; sp->par2[XY].z = 1; sp->par2[Z].z = - 2 + balance_rand(1*0); /* -c */ break; case 1: /* x' = -(y + az) y' = x + by z' = c + z(x - 5.7) */ name = "Rossler"; sp->par2[Y].x = -1; sp->par2[Z].x = -2 + balance_rand(1); /* a */ sp->par2[X].y = 1; sp->par2[Y].y = 0.2 + balance_rand(0.1); /* b */ sp->par2[C].z = 0.2 + balance_rand(0.1); /* c */ sp->par2[XZ].z = 1; sp->par2[Z].z = -5.7; break; case 2: /* x' = -(y + az) y' = x + by - cz^2 z' = 0.2 + z(x - 5.7) */ name = "RosslerCone"; sp->par2[Y].x = -1; sp->par2[Z].x = -2; /* a */ sp->par2[X].y = 1; sp->par2[Y].y = 0.2; /* b */ sp->par2[ZZ].y = -0.331 + balance_rand(0.01); /* c */ sp->par2[C].z = 0.2; sp->par2[XZ].z = 1; sp->par2[Z].z = -5.7; break; case 3: /* x' = -z + b sin(y) y' = c z' = 0.7x + az(0.1 - x^2) */ name = "Birkhoff"; sp->par2[Z].x = -1; sp->par2[SINY].x = 0.35 + balance_rand(0.25); /* b */ sp->par2[C].y = 1.57; /* c */ sp->par2[X].z = 0.7; sp->par2[Z].z = 1 + balance_rand(0.5); /* a/10 */ sp->par2[XXZ].z = -10 * sp->par2[Z].z; /* -a */ sp->yperiod = 2 * M_PI; break; default: /* x' = -ax - z/2 - z^3/8 + b sin(y) y' = c z' = 2x */ name = "Duffing"; sp->par2[X].x = -0.2 + balance_rand(0.1); /* a */ sp->par2[Z].x = -0.5; sp->par2[ZZZ].x = -0.125; sp->par2[SINY].x = 27.0 + balance_rand(3.0); /* b */ sp->par2[C].y = 1.33; /* c */ sp->par2[X].z = 2; sp->yperiod = 2 * M_PI; break; } sp->range.x = 5; sp->range.z = 5; if(sp->yperiod > 0) { sp->ODE = Periodic; /* periodic flows show either uniform distribution or a snapshot on the 'time' axis */ sp->range.y = NRAND(2)? sp->yperiod : 0; } else { sp->range.y = 5; sp->ODE = Cubic; } /* Run discoverer to set up bounding box, etc. Lyapunov will probably be innaccurate, since we're only running it once, but we're using known strange attractors so it should be ok. */ discover(mi); if(MI_IS_VERBOSE(mi)) fprintf(stdout, "flow: Lyapunov exponent: %g, step: %g, size: %g (%s)\n", sp->lyap2, sp->step2, sp->size2, name); /* Install new params */ sp->lyap = sp->lyap2; sp->size = sp->size2; sp->mid = sp->mid2; sp->step = sp->step2; memcpy(sp->par, sp->par2, sizeof(sp->par2)); sp->count2 = 0; /* Reset search */ free_flow(sp); sp->beecount = MI_COUNT(mi); if (sp->beecount < 0) { /* random variations */ sp->beecount = NRAND(-sp->beecount) + 1; /* Minimum 1 */ } # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ dbufp = False; # endif if(dbufp) { /* Set up double buffer */ if (sp->buffer != None) XFreePixmap(MI_DISPLAY(mi), sp->buffer); sp->buffer = XCreatePixmap(MI_DISPLAY(mi), MI_WINDOW(mi), MI_WIDTH(mi), MI_HEIGHT(mi), MI_DEPTH(mi)); } else { sp->buffer = MI_WINDOW(mi); } /* no "NoExpose" events from XCopyArea wanted */ XSetGraphicsExposures(MI_DISPLAY(mi), MI_GC(mi), False); /* Make sure we're using 'thin' lines */ XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), 0, LineSolid, CapNotLast, JoinMiter); /* Clear the background (may be slow depending on user prefs). */ MI_CLEARWINDOW(mi); /* Allocate memory. */ if (sp->csegs == NULL) { allocate(sp->csegs, XSegment, (sp->beecount + BOX_L) * MI_NPIXELS(mi) * sp->taillen); allocate(sp->cnsegs, int, MI_NPIXELS(mi)); allocate(sp->old_segs, XSegment, sp->beecount * sp->taillen); allocate(sp->p, dvector, sp->beecount * sp->taillen); }
int main(int argc, char *argv[]) { peerinit(NULL); discover(NULL); return 0; };
bool Lightning::Zap(Coord dir) { fire_bolt(game->hero().position(), &dir, "bolt"); discover(false); return true; }
/** * Discover available (pre-allocated) nodes. Allocate the * requested number of nodes/process slots to the job. */ static int orte_ras_ccp_allocate(opal_list_t *nodes) { int ret, i; size_t len; char *cluster_head = NULL; HRESULT hr = S_OK; ICluster* pCluster = NULL; /* CCP is not thread safe. Use the apartment model. */ CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); /* Create the Cluster object. */ hr = CoCreateInstance( __uuidof(Cluster), NULL, CLSCTX_INPROC_SERVER, __uuidof(ICluster), reinterpret_cast<void **> (&pCluster) ); if (FAILED(hr)) { OPAL_OUTPUT_VERBOSE((1, orte_ras_base.ras_output, "ras:ccp:allocate: failed to create cluster object!")); return ORTE_ERROR; } if(NULL == orte_ccp_headnode) { /* Get the cluster head nodes name */ _dupenv_s(&cluster_head, &len, "LOGONSERVER"); if(cluster_head == NULL) { OPAL_OUTPUT_VERBOSE((1, orte_ras_base.ras_output, "ras:ccp:allocate: connot find cluster head node!")); return ORTE_ERROR; } /* Get rid of the beginning '//'. */ for( i = 0; i < len - 2; i++){ cluster_head[i] = cluster_head[i+2]; cluster_head[i+2] = '\0'; } } else { cluster_head = orte_ccp_headnode; } /* Connect to the cluster's head node */ hr = pCluster->Connect(_bstr_t(cluster_head)); if (FAILED(hr)) { ras_get_cluster_message(pCluster); OPAL_OUTPUT_VERBOSE((1, orte_ras_base.ras_output, "ras:ccp:allocate: connection failed!")); return ORTE_ERROR; } if (ORTE_SUCCESS != (ret = discover(nodes, pCluster))) { OPAL_OUTPUT_VERBOSE((1, orte_ras_base.ras_output, "ras:ccp:allocate: discover failed!")); return ret; } /* in the CCP world, if we didn't find anything, then this * is an unrecoverable error - report it */ if (opal_list_is_empty(nodes)) { orte_show_help("help-ras-ccp.txt", "no-nodes-found", true); return ORTE_ERR_NOT_FOUND; } /* All finished, release cluster object*/ pCluster->Release(); CoUninitialize(); return ret; }
bool Cold::Zap(Coord dir) { fire_bolt(game->hero().position(), &dir, "ice"); discover(false); return true; }
inline void discover(ndt::type &res, const std::string &str) { discover(res, str.data(), str.data() + str.size()); }
/* * Check all frames on device and resend any frames that have been * outstanding for 200% of the device round trip time average. */ static void aoesweepproc(void*) { ulong i, tx, timeout, nbc; vlong starttick; enum { Nms = 100, Nbcms = 30*1000, }; /* magic */ uchar *ea; Aoeata *a; Aoedev *d; Devlink *l; Frame *f, *e; nbc = Nbcms/Nms; loop: if(nbc-- == 0){ if(rediscover && !waserror()){ discover(0xffff, 0xff); poperror(); } nbc = Nbcms/Nms; } starttick = MACHP(0)->ticks; rlock(&devs); for(d = devs.d; d; d = d->next){ if(!canqlock(d)) continue; if(!UP(d)){ qunlock(d); continue; } tx = 0; f = d->frames; e = f + d->nframes; for (; f < e; f++){ if(f->tag == Tfree) continue; l = f->dl; timeout = l->rttavg << 1; i = tsince(f->tag); if(i < timeout) continue; if(d->nout == d->maxout){ if(d->maxout > 1) d->maxout--; d->lastwadj = MACHP(0)->ticks; } a = (Aoeata*)f->hdr; if(a->scnt > Dbcnt / Aoesectsz && ++f->nl->lostjumbo > (d->nframes << 1)){ ea = f->dl->eatab[f->eaidx]; eventlog("%æ: jumbo failure on %s:%E; lba%lld\n", d, f->nl->path, ea, f->lba); d->maxbcnt = Dbcnt; d->flag &= ~Djumbo; } resend(d, f); if(tx++ == 0){ if((l->rttavg <<= 1) > Rtmax) l->rttavg = Rtmax; eventlog("%æ: rtt %ldms\n", d, TK2MS(l->rttavg)); } } if(d->nout == d->maxout && d->maxout < d->nframes && TK2MS(MACHP(0)->ticks - d->lastwadj) > 10*1000){ /* more magic */ d->maxout++; d->lastwadj = MACHP(0)->ticks; } qunlock(d); } runlock(&devs); i = Nms - TK2MS(MACHP(0)->ticks - starttick); if(i > 0) tsleep(&up->sleep, return0, 0, i); goto loop; }
/* the big and ugly game function */ enum minesweeper_status minesweeper( void ) { int i, j; int button; #if defined(HAVE_TOUCHSCREEN) || defined(MINESWP_TOGGLE_PRE) int lastbutton = BUTTON_NONE; #endif /* the cursor coordinates */ int x=0, y=0; /** * Show the menu */ if( ( i = menu() ) != MINESWEEPER_WIN ) return i; /** * Init game */ top = (LCD_HEIGHT-height*TileSize)/2; left = (LCD_WIDTH-width*TileSize)/2; #ifdef HAVE_TOUCHSCREEN mine_raster.tl_x = left; mine_raster.tl_y = top; mine_raster.width = width*TileSize; mine_raster.height = height*TileSize; #endif rb->srand( *rb->current_tick ); minesweeper_init(); x = 0; y = 0; /** * Play */ while( true ) { /* clear the screen buffer */ #ifdef HAVE_LCD_COLOR rb->lcd_set_background( BackgroundColor ); #endif rb->lcd_clear_display(); /* display the mine field */ for( i = 0; i < height; i++ ) { for( j = 0; j < width; j++ ) { if( minefield[i][j].known ) { draw_tile( minefield[i][j].neighbors, j, i ); } else if(minefield[i][j].flag) { draw_tile( Flag, j, i ); } else { draw_tile( Unknown, j, i ); } } } /* display the cursor */ invert_tile( x, y ); /* update the screen */ rb->lcd_update(); button = rb->button_get(true); #ifdef HAVE_TOUCHSCREEN if(button & BUTTON_TOUCHSCREEN) { struct ts_raster_result res; if(touchscreen_map_raster(&mine_raster, rb->button_get_data() >> 16, rb->button_get_data() & 0xffff, &res) == 1) { button &= ~BUTTON_TOUCHSCREEN; lastbutton &= ~BUTTON_TOUCHSCREEN; if(button & BUTTON_REPEAT && lastbutton != MINESWP_TOGGLE && lastbutton ^ BUTTON_REPEAT) button = MINESWP_TOGGLE; else if(button == BUTTON_REL && lastbutton ^ BUTTON_REPEAT) button = MINESWP_DISCOVER; else button |= BUTTON_TOUCHSCREEN; x = res.x; y = res.y; } } #endif switch(button) { /* quit minesweeper (you really shouldn't use this button ...) */ #ifdef MINESWP_RC_QUIT case MINESWP_RC_QUIT: #endif case MINESWP_QUIT: return MINESWEEPER_QUIT; /* move cursor left */ case MINESWP_LEFT: case MINESWP_LEFT|BUTTON_REPEAT: if( --x < 0) x += width; break; /* move cursor right */ case MINESWP_RIGHT: case MINESWP_RIGHT|BUTTON_REPEAT: if( ++x >= width ) x -= width; break; /* move cursor down */ case MINESWP_DOWN: case MINESWP_DOWN|BUTTON_REPEAT: if( ++y >= height ) y -= height; break; /* move cursor up */ case MINESWP_UP: case MINESWP_UP|BUTTON_REPEAT: if( --y < 0 ) y += height; break; /*move cursor though the entire field*/ #ifdef MINESWP_SCROLLWHEEL case MINESWP_NEXT: case MINESWP_NEXT|BUTTON_REPEAT: if (x == width -1 ) { if( ++y >= height ) y -= height; } if( ++x >= width ) x -= width; break; case MINESWP_PREV: case MINESWP_PREV|BUTTON_REPEAT: if (x == 0) { if( --y < 0 ) y += height; } if( --x < 0 ) x += width; break; #endif /* discover a tile (and it's neighbors if .neighbors == 0) */ case MINESWP_DISCOVER: #ifdef MINESWP_DISCOVER2 case MINESWP_DISCOVER2: #endif if( minefield[y][x].flag ) break; /* we put the mines on the first "click" so that you don't * lose on the first "click" */ if( tiles_left == width*height && no_mines ) minesweeper_putmines(percent,x,y); if( discover( y, x, true ) ) { minefield[y][x].known = 1; return MINESWEEPER_LOSE; } tiles_left = count_tiles_left(); if( tiles_left == mine_num ) { return MINESWEEPER_WIN; } break; /* toggle flag under cursor */ case MINESWP_TOGGLE: #ifdef MINESWP_TOGGLE_PRE if( lastbutton != MINESWP_TOGGLE_PRE ) break; #endif #ifdef MINESWP_TOGGLE2 case MINESWP_TOGGLE2: #endif if( !minefield[y][x].known ) minefield[y][x].flag = !minefield[y][x].flag; break; /* show how many mines you think you have found and how many * there really are on the game */ case MINESWP_INFO: if( no_mines ) break; int flags_used = count_flags(); if (flags_used == 1) { rb->splashf( HZ*2, "You marked 1 field. There are %d mines.", mine_num ); } else { rb->splashf( HZ*2, "You marked %d fields. There are %d mines.", flags_used, mine_num ); } break; default: if( rb->default_event_handler( button ) == SYS_USB_CONNECTED ) return MINESWEEPER_USB; break; } #if defined(HAVE_TOUCHSCREEN) || defined(MINESWP_TOGGLE_PRE) if( button != BUTTON_NONE ) lastbutton = button; #endif } }
/** * \brief Activation by one player among the two players. * \param p The player. */ void ptb::hideout_bonus_item::on_one_player( const player_proxy& p ) { discover(p.get_index()); } // hideout_bonus_item::on_one_player()