void RotateLeft( pNode * pLev0 ) { #define Lev0 (*pLev0) pNode Lev1 = Lev0->Right; Lev0->Right = Lev1->Left; Lev1->Left = Lev0;Lev0 = Lev1; fix_size( Lev0->Left ); fix_size( Lev0 ); #undef Lev0 }
void InsertRand( pNode * proot, Item D ) { #define root (*proot) if( root == NULL ) { root = NewNode( D ); } else if ( D == root->Data ) { return; } else if( rand() < RAND_MAX / root->Size ) { InsertRoot( proot, D ); } else if( D < root->Data ) { InsertRand( &(root->Left), D ); fix_size( root ); } else { InsertRand( &(root->Right), D ); fix_size( root ); } #undef root }
/***************************************************************************** Perform rtkgps status command. *****************************************************************************/ void cmd_status(cmdlnopts_t *cmdopt) { int fd; unsigned int mu = 0; status_t status; logfile_t lgfl; log_bndry_t lgbd; memory_t mem; firmware_t frm; fd = coms_open(cmdopt); if (cmdopt->vflg) printf("Requesting logger status information\n"); status_read(fd, &status, cmdopt); if (cmdopt->eflg) { if (cmdopt->vflg) printf("Requesting extended logger information\n"); gpsmouse_disable(fd, status.gpsms, cmdopt); if (get_log_bndry(fd, &lgbd) < 0) { fprintf(stderr,"rtkgps: Failed to read log start/end details [%s]\n", gcstrerror(rcerrno)); gpsmouse_enable(fd, status.gpsms, cmdopt); coms_close(fd, cmdopt); exit(5); } if (get_memory_info(fd, &mem) < 0) { fprintf(stderr,"rtkgps: Failed to read logger memory details [%s]\n", gcstrerror(rcerrno)); gpsmouse_enable(fd, status.gpsms, cmdopt); coms_close(fd, cmdopt); exit(5); } if (get_firmware_info(fd, &frm) < 0) { fprintf(stderr,"rtkgps: Failed to read logger firmware details [%s]\n", gcstrerror(rcerrno)); gpsmouse_enable(fd, status.gpsms, cmdopt); coms_close(fd, cmdopt); exit(5); } /* Get info for first logfile */ if (get_file_info(fd, 0, &lgfl) < 0) { fprintf(stderr,"rtkgps: Error reading information for file %d [%s]\n", 0, gcstrerror(rcerrno)); gpsmouse_enable(fd, status.gpsms, cmdopt); coms_close(fd, cmdopt); exit(5); } if (lgfl.memp == 0) { /* Memory has not wrapped around in overwrite mode */ /* Get info for last logfile */ if (get_file_info(fd, status.nfile-1, &lgfl) < 0) { fprintf(stderr,"rtkgps: Error reading information for file %d [%s]\n", status.nfile-1, gcstrerror(rcerrno)); gpsmouse_enable(fd, status.gpsms, cmdopt); coms_close(fd, cmdopt); exit(5); } /* Memory used computed from last logfile pointer plus number of fixes in active logfile */ mu = lgfl.memp + status.nfix*fix_size(status.fxtyp); } else { /* Memory has wrapped around in overwrite mode */ int n; /* Need to compute memory used by adding up number of fixes in each log file */ mu = lgfl.nfix*fix_size(lgfl.fxtyp); for (n = 1; n < status.nfile; n++) { if (get_file_info(fd, n, &lgfl) < 0) { fprintf(stderr,"rtkgps: Error reading information for file " "%d [%s]\n", n, gcstrerror(rcerrno)); gpsmouse_enable(fd, status.gpsms, cmdopt); coms_close(fd, cmdopt); exit(5); } mu += lgfl.nfix*fix_size(lgfl.fxtyp); } } gpsmouse_enable(fd, status.gpsms, cmdopt); } printf("GPS Fix: %s\nGPS mouse mode: %s\n" "Record type: %s\nMemory full: %s\n" "Sampling interval: %hds\nNumber of files: %hd\n" "Fixes in last file: %d\n", gpsrx_string(status.gpsrx), gpsms_string(status.gpsms), fxtyp_string(status.fxtyp), mfowm_string(status.mfowm), status.sntvl, status.nfile, status.nfix ); if (cmdopt->eflg) { printf("First log fix: %.4s-%.2s-%.2s %.2s:%.2s:%.2s\n" "Last log fix: %.4s-%.2s-%.2s %.2s:%.2s:%.2s\n", lgbd.first.date,lgbd.first.date+4,lgbd.first.date+6, lgbd.first.time, lgbd.first.time+2, lgbd.first.time+4, lgbd.last.date,lgbd.last.date+4,lgbd.last.date+6, lgbd.last.time, lgbd.last.time+2, lgbd.last.time+4); printf("Device memory: %7.2fkb\n" "Memory used: %7.2fkb (%.2f%%)\n", mem.nbytes / 1024.0, mu / 1024.4, ((float)mu / mem.nbytes)*100.0); printf("Version: %s\n" "Firmware: %s\n", frm.vrsnr, frm.frmwr); } coms_close(fd, cmdopt); }
/* do_simple_move assumes * 1. That there is no master and no followers. * 2. That the direction exists. * * Returns : * 1 : If succes. * 0 : If fail */ int do_simple_move(struct char_data *ch, int dir, int need_specials_check) { char throwaway[MAX_INPUT_LENGTH] = ""; /* Functions assume writable. */ room_rnum was_in; int need_movement, moveadd = 0; struct obj_data *k; /* * Check for special routines (North is 1 in command list, but 0 here) Note * -- only check if following; this avoids 'double spec-proc' bug */ if (need_specials_check && special(ch, dir + 1, throwaway)) return (0); /* blocked by a leave trigger ? */ if (!leave_mtrigger(ch, dir)) return 0; if (!leave_wtrigger(&world[IN_ROOM(ch)], ch, dir)) return 0; /* charmed? */ if (AFF_FLAGGED(ch, AFF_CHARM) && ch->master && IN_ROOM(ch) == IN_ROOM(ch->master)) { send_to_char(ch, "The thought of leaving your master makes you weep.\r\n"); act("$n bursts into tears.", FALSE, ch, 0, 0, TO_ROOM); return (0); } /* if this room or the one we're going to needs a boat, check for one */ if ((SECT(IN_ROOM(ch)) == SECT_WATER_NOSWIM) || (SECT(EXIT(ch, dir)->to_room) == SECT_WATER_NOSWIM)) { if (!has_boat(ch)) { send_to_char(ch, "You need a boat to go there.\r\n"); return (0); } } /* move points needed is avg. move loss for src and destination sect type * You know .. I don't like this system, let's base this not ONLY on terrain type * but also on dex of char. * Needs to adjust on max abils * Original: * need_movement = (movement_loss[SECT(IN_ROOM(ch))] + movement_loss[SECT(EXIT(ch, dir)->to_room)]) / 2; */ if (GET_DEX(ch) <= 5) /* 0(1?)-5 Dex */ moveadd = 8; if ((GET_DEX(ch) >= 6) && (GET_DEX(ch) <= 10)) /* 6-10 Dex */ moveadd = 6; if ((GET_DEX(ch) >= 11) && (GET_DEX(ch) <= 15)) /* 11-15 Dex */ moveadd = 4; if (GET_DEX(ch) >= 16) /* 16+ Up to ..? Dex */ moveadd = 2; need_movement = (movement_loss[SECT(IN_ROOM(ch))] + movement_loss[SECT(EXIT(ch, dir)->to_room)] + moveadd) / 2; if (GET_MOVE(ch) < need_movement && !IS_NPC(ch)) { if (need_specials_check && ch->master) send_to_char(ch, "You are too exhausted to follow.\r\n"); else send_to_char(ch, "You are too exhausted.\r\n"); return (0); } if (ROOM_FLAGGED(IN_ROOM(ch), ROOM_ATRIUM)) { if (!House_can_enter(ch, GET_ROOM_VNUM(EXIT(ch, dir)->to_room))) { send_to_char(ch, "That's private property -- no trespassing!\r\n"); return (0); } } if (ROOM_FLAGGED(EXIT(ch, dir)->to_room, ROOM_TUNNEL) && num_pc_in_room(&(world[EXIT(ch, dir)->to_room])) >= tunnel_size) { if (tunnel_size > 1) send_to_char(ch, "There isn't enough room for you to go there!\r\n"); else send_to_char(ch, "There isn't enough room there for more than one person!\r\n"); return (0); } /* Room big enough for you? */ if ((SIZE(EXIT(ch, dir)->to_room) < GET_SIZE(ch)) && (SIZE(EXIT(ch, dir)->to_room) != SIZE_SPECIAL) && (GET_LEVEL(ch) < LVL_GOD)) { //GOD+ can enter any room send_to_char(ch, "You are too big to fit in there!\r\n"); return (0); } /* Mortals and low level gods cannot enter greater god rooms. */ /* irrelevant because of min/max level -mak 8.21.05 -reinstated 2.9.06 if (ROOM_FLAGGED(EXIT(ch, dir)->to_room, ROOM_GODROOM) && GET_LEVEL(ch) < LVL_GOD) { send_to_char(ch, "You aren't godly enough to use that room!\r\n"); return (0); } uncomment to fix GODROOM */ /* No access for non-IMPs */ if (ROOM_FLAGGED(EXIT(ch, dir)->to_room, ROOM_IMPROOM) && GET_LEVEL(ch) < LVL_IMPL) { send_to_char(ch, "You dare not disturb the Implementors!\r\n"); return (0); } if (GET_LEVEL(ch) < ROOM_MIN_LEVEL(EXIT(ch, dir)->to_room)) { if (world[EXIT(ch, dir)->to_room].max_level_message ) { send_to_char(ch, world[EXIT(ch, dir)->to_room].min_level_message); send_to_char(ch, "\r\n"); } else send_to_char(ch, "You are not experienced enough to enter that room.\r\n"); return 0; } if (ROOM_MAX_LEVEL(EXIT(ch, dir)->to_room) > 0) { if (GET_LEVEL(ch) > ROOM_MAX_LEVEL(EXIT(ch, dir)->to_room) && GET_LEVEL(ch) < LVL_SAINT ) { if (world[EXIT(ch, dir)->to_room].max_level_message ){ send_to_char(ch, world[EXIT(ch, dir)->to_room].max_level_message); send_to_char(ch, "\r\n"); } else send_to_char(ch, "You are too experienced to enter that room.\r\n"); return 0; } } if (AFF_FLAGGED(ch, AFF_FLEET_FEET)) { need_movement = need_movement / 2; if (need_movement < 2) need_movement = 1;} if (AFF_FLAGGED(ch, AFF_AIRWALK)) need_movement = 1; /* Now we know we're allowed to go into the room. */ if (GET_LEVEL(ch) < LVL_SAINT && !IS_NPC(ch)) GET_MOVE(ch) -= need_movement; if (!AFF_FLAGGED(ch, AFF_SNEAK)) { char buf2[MAX_STRING_LENGTH]; snprintf(buf2, sizeof(buf2), "$n leaves %s.", dirs[dir]); act(buf2, TRUE, ch, 0, 0, TO_ROOM); } was_in = IN_ROOM(ch); char_from_room(ch); char_to_room(ch, world[was_in].dir_option[dir]->to_room); /* move them first, then move them back if they aren't allowed to go. */ /* see if an entry trigger disallows the move */ if (!entry_mtrigger(ch) || !enter_wtrigger(&world[IN_ROOM(ch)], ch, dir)) { char_from_room(ch); char_to_room(ch, was_in); return 0; } if (!AFF_FLAGGED(ch, AFF_SNEAK)) act("$n has arrived.", TRUE, ch, 0, 0, TO_ROOM); if (ch->desc != NULL) look_at_room(IN_ROOM(ch), ch, 0); if (ROOM_FLAGGED(IN_ROOM(ch), ROOM_DEATH) && GET_LEVEL(ch) < LVL_SAINT) { clanlog(ch, "%s entered a Death Room", GET_NAME(ch)); was_in = IN_ROOM(ch); log_death_trap(ch); death_cry(ch); /* Fix the PCs size first if it needs fixing */ fix_size(ch); extract_char(ch); for (k = world[was_in].contents; k; k = world[was_in].contents) extract_obj(k); return (0); } entry_memory_mtrigger(ch); if (!greet_mtrigger(ch, dir)) { char_from_room(ch); char_to_room(ch, was_in); look_at_room(IN_ROOM(ch), ch, 0); } else greet_memory_mtrigger(ch); /* send warning message if moves are getting low */ if ( GET_MOVE(ch) < (GET_MAX_MOVE(ch) / 10) ) { send_to_char(ch, "You cannot go much further.\r\n"); } return (1); }