void i_charge(pob o) { int i; if (o->blessing > -1) Objects[o->id].known = 1; i = getitem_prompt("A scroll of charging. Charge: ", STICK); if (i != ABORT) { if (o->blessing < 0) { mprint("The stick glows black!"); Player.possessions[i]->charge = 0; } else { mprint("The stick glows blue!"); Player.possessions[i]->charge += (random_range(10)+1)*(o->blessing+1); if (Player.possessions[i]->charge > 99) Player.possessions[i]->charge = 99; } } }
int get_str_basic(unsigned char *out_buffer, unsigned char *in_buffer, int trim_subs, enum ccx_encoding_type in_enc, enum ccx_encoding_type out_enc, int max_len) { int last_non_blank = -1; int first_non_blank = -1; int len = 0; find_limit_characters(in_buffer, &first_non_blank, &last_non_blank, max_len); if (!trim_subs) first_non_blank = 0; if (first_non_blank == -1) { *out_buffer = 0; return 0; } // change encoding only when required switch (in_enc) { case CCX_ENC_UTF_8: len = change_utf8_encoding(out_buffer, in_buffer + first_non_blank, last_non_blank-first_non_blank+1, out_enc); break; case CCX_ENC_LATIN_1: len = change_latin1_encoding(out_buffer, in_buffer + first_non_blank, last_non_blank-first_non_blank+1, out_enc); break; case CCX_ENC_UNICODE: len = change_unicode_encoding(out_buffer, in_buffer + first_non_blank, last_non_blank-first_non_blank+1, out_enc); break; case CCX_ENC_ASCII: len = change_ascii_encoding(out_buffer, in_buffer + first_non_blank, last_non_blank-first_non_blank+1, out_enc); break; } if (len < 0) mprint("WARNING: Could not encode in specified format\n"); else if (len == CCX_ENOSUPP) // we only support ASCII to other encoding std mprint("WARNING: Encoding is not yet supported\n"); else return (unsigned)len; // Return length return 0; // Return length }
void weapon_lightsabre(int dmgmod, Object* o, Monster* m) { if (! o->known) { mprint("Fumbling with the cylinder, you press the wrong stud...."); p_damage(100,UNSTOPPABLE,"fumbling with a lightsabre"); o->known = 1; } else { /* test prevents confusing immunity messages.... */ if (! m_immunityp(m,NORMAL_DAMAGE)) { mprint("Vzzzzmmm!"); m->m_damage(20,NORMAL_DAMAGE); } if ((m->hp>0) && (! m_immunityp(m,FLAME))) { mprint("Zzzzap!"); m->m_damage(20,FLAME); } } }
int write_subtitle_file_footer(struct encoder_ctx *ctx,struct ccx_s_write *out) { int used; int ret = 0; char str[1024]; switch (ctx->write_format) { case CCX_OF_SAMI: sprintf ((char *) str,"</BODY></SAMI>\n"); if (ctx->encoding != CCX_ENC_UNICODE) { dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str); } used = encode_line (ctx, ctx->buffer,(unsigned char *) str); ret = write(out->fh, ctx->buffer, used); if (ret != used) { mprint("WARNING: loss of data\n"); } break; case CCX_OF_SMPTETT: sprintf ((char *) str," </div>\n </body>\n</tt>\n"); if (ctx->encoding != CCX_ENC_UNICODE) { dbg_print(CCX_DMT_DECODER_608, "\r%s\n", str); } used = encode_line (ctx, ctx->buffer,(unsigned char *) str); ret = write (out->fh, ctx->buffer, used); if (ret != used) { mprint("WARNING: loss of data\n"); } break; case CCX_OF_SPUPNG: write_spumux_footer(out); break; default: // Nothing to do, no footer on this format break; } return ret; }
/* perform read command */ static int procread(const char *path, bool mt, int omode, bool wb, bool rnd){ my_my_my_iprintf("<Reading Test>\n seed=%u path=%s mt=%d omode=%d wb=%d rnd=%d\n\n", g_randseed, path, mt, omode, wb, rnd); bool err = false; double stime = tctime(); TCFDB *fdb = tcfdbnew(); if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd); if(mt && !tcfdbsetmutex(fdb)){ eprint(fdb, __LINE__, "tcfdbsetmutex"); err = true; } if(!tcfdbopen(fdb, path, FDBOREADER | omode)){ eprint(fdb, __LINE__, "tcfdbopen"); err = true; } int rnum = tcfdbrnum(fdb); for(int i = 1; i <= rnum; i++){ char kbuf[RECBUFSIZ]; int ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i); int vsiz; if(wb){ char vbuf[RECBUFSIZ]; int vsiz = tcfdbget4(fdb, i, vbuf, RECBUFSIZ); if(vsiz < 0 && !(rnd && tcfdbecode(fdb) == TCENOREC)){ eprint(fdb, __LINE__, "tcfdbget4"); err = true; break; } } else { char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz); if(!vbuf && !(rnd && tcfdbecode(fdb) == TCENOREC)){ eprint(fdb, __LINE__, "tcfdbget"); err = true; break; } tcfree(vbuf); } if(rnum > 250 && i % (rnum / 250) == 0){ iputchar('.'); if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i); } } my_my_my_iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb)); my_my_my_iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb)); mprint(fdb); sysprint(); if(!tcfdbclose(fdb)){ eprint(fdb, __LINE__, "tcfdbclose"); err = true; } tcfdbdel(fdb); my_my_my_iprintf("time: %.3f\n", tctime() - stime); my_my_my_iprintf("%s\n\n", err ? "error" : "ok"); return err ? 1 : 0; }
/* check to see if too much tunneling has been done in this level */ void tunnelcheck() { if ((Level->depth == 0 && Current_Environment != E_DLAIR) || Current_Environment == E_ASTRAL) return; Level->tunnelled++; if ((Level->tunnelled) > LENGTH/4) mprint("Dust and stone fragments fall on you from overhead."); if ((Level->tunnelled) > LENGTH/2) mprint("You hear groaning and creaking noises."); if ((Level->tunnelled) > 3*LENGTH/4) mprint("The floor trembles and you hear a loud grinding screech."); if ((Level->tunnelled) > LENGTH) { mprint("With a scream of tortured stone, the entire dungeon caves in!!!"); gain_experience(5000); if (Player.status[SHADOWFORM]) { change_environment(E_COUNTRYSIDE); switch (Country[Player.x][Player.y].base_terrain_type) { case CASTLE: case STARPEAK: case CAVES: case VOLCANO: Country[Player.x][Player.y].current_terrain_type = MOUNTAINS; break; case DRAGONLAIR: Country[Player.x][Player.y].current_terrain_type = DESERT; break; case MAGIC_ISLE: Country[Player.x][Player.y].current_terrain_type = CHAOS_SEA; break; } Country[Player.x][Player.y].base_terrain_type = Country[Player.x][Player.y].current_terrain_type; c_set(Player.x, Player.y, CHANGED); print1("In your shadowy state, you float back up to the surface."); return; } mprint("You are flattened into an unpleasant jellylike substance."); p_death("dungeon cave-in"); } }
void get_buffer(int n) { while ( n-- ) { *head++ = EMPTY; if ( head == end ) head = buffer; } mprint(BUF_COL, BUF_LIN, BUF_FMT, buffer); }
void i_perm_levitate(pob o) { if (o->known < 1) o->known = 1; Objects[o->id].known = 1; if (o->blessing > -1) { if (o->used) { Player.status[LEVITATING] += 1400; mprint("You start to float a few inches above the floor"); mprint("You find you can easily control your altitude"); } else { Player.status[LEVITATING] -= 1500; if (Player.status[LEVITATING] < 1) { Player.status[LEVITATING] = 0; mprint("You sink to the floor."); } } } else i_perm_burden(o); }
void heal(int amount) { if (amount > -1) { mprint("You feel better."); if (Player.hp < Player.maxhp + amount) { Player.hp += random_range(10*amount)+1; if (Player.hp > Player.maxhp) Player.hp = Player.maxhp + amount; } Player.status[BLINDED] = 0; } else { mprint("You feel unwell."); Player.hp -= random_range(10*abs(amount)+1); if (Player.hp < 0) p_death("magical disruption"); } dataprint(); }
void i_perm_fear_resist(pob o) { if (o->used){ Player.immunity[FEAR]++; if (o->blessing < 0) { Player.status[BERSERK] += 1500; mprint("You feel blood-simple!"); } } else { Player.immunity[FEAR]--; if (o->blessing < 0) { Player.status[BERSERK] -= 1500; if (Player.status[BERSERK] < 1) { mprint("You feel less rabid now."); Player.status[BERSERK] = 0; } } } }
/* select a spell to cast */ int getspell(void) { int spell= ABORT - 1; do { mprint("Cast Spell: [type spell abbrev, ?, or ESCAPE]: "); spell = spellparse(); } while (spell < ABORT); clearmsg(); return(spell); }
void put_buffer(int n) { while ( n-- ) { *tail++ = FULL; if ( tail == end ) tail = buffer; } mprint(BUF_COL, BUF_LIN, BUF_FMT, buffer); }
void m_strike_sonic(pmt m) { if (m->uniqueness == COMMON) { strcpy(Str2,"The "); strcat(Str2,m->monstring); } else strcpy(Str2,m->monstring); strcat(Str2," screams at you!"); mprint(Str2); p_damage(m->dmg,OTHER_MAGIC,"a sonic blast"); }
void Monster::m_strike_sonic() { if (this->uniqueness == COMMON) { strcpy(Str2,"The "); strcat(Str2,this->name); } else strcpy(Str2,this->name); strcat(Str2," screams at you!"); mprint(Str2); p_damage(this->dmg,OTHER_MAGIC,"a sonic blast"); }
/* try to break a weapon (from fumbling) */ void break_weapon(void) { if (Player.possessions[O_WEAPON_HAND] != NULL) { strcpy(Str1,"Your "); strcat(Str1,itemid(Player.possessions[O_WEAPON_HAND])); strcat(Str1," vibrates in your hand...."); mprint(Str1); (void) damage_item(Player.possessions[O_WEAPON_HAND]); morewait(); } }
static void ccx_demuxer_print_cfg(struct ccx_demuxer *ctx) { switch (ctx->auto_stream) { case CCX_SM_ELEMENTARY_OR_NOT_FOUND: mprint ("Elementary"); break; case CCX_SM_TRANSPORT: mprint ("Transport"); break; case CCX_SM_PROGRAM: mprint ("Program"); break; case CCX_SM_ASF: mprint ("DVR-MS"); break; case CCX_SM_WTV: mprint ("Windows Television (WTV)"); break; case CCX_SM_MCPOODLESRAW: mprint ("McPoodle's raw"); break; case CCX_SM_AUTODETECT: mprint ("Autodetect"); break; case CCX_SM_RCWT: mprint ("BIN"); break; case CCX_SM_MP4: mprint ("MP4"); break; #ifdef WTV_DEBUG case CCX_SM_HEX_DUMP: mprint ("Hex"); break; #endif default: fatal(CCX_COMMON_EXIT_BUG_BUG, "BUG: Unknown stream mode.\n"); break; } }
void copy_ccdata_to_buffer (struct avc_ctx *ctx, char *source, int new_cc_count) { ctx->ccblocks_in_avc_total++; if (ctx->cc_buffer_saved == CCX_FALSE) { mprint ("Warning: Probably loss of CC data, unsaved buffer being rewritten, trailing end might get lost\n"); ctx->ccblocks_in_avc_lost++; } memcpy(ctx->cc_data + ctx->cc_count*3, source, new_cc_count*3+1); ctx->cc_count += new_cc_count; ctx->cc_buffer_saved = CCX_FALSE; }
void weapon_defend(int dmgmod, pob o, pmt m) { if ((Player.alignment < 0) && (o->blessing > 0)) { mprint("The Holy Defender screams in your hands...."); mprint("You stagger before the sound of its rage...."); p_damage(50,UNSTOPPABLE,"a pissed-off Holy Defender"); mprint("The weapon finally quiets. It seems less holy now."); o->truename = o->cursestr; Player.status[PROTECTION] -= (o->hit); o->plus = 0-abs(o->plus); o->blessing = -1; } if ((o->blessing > 0) && ((m->specialf == M_SP_DEMON) || (m->meleef == M_MELEE_SPIRIT))) { mprint("Your opponent shies back before your holy weapon!"); m->hit = 0; m->speed *=2; } weapon_normal_hit(dmgmod,o,m); }
void identify(int blessing) { int index; clearmsg(); if (blessing == 0) { index = getitem_prompt("Identify: ", NULL_ITEM); if (index == CASHVALUE) print3("Your money is really money."); else if (index == ABORT) State.setSkipMonsters(); else { if (Player.possessions[index]->objchar == FOOD) Player.possessions[index]->known = 1; else { Player.possessions[index]->known = 2; Objects[Player.possessions[index]->id].known = 1; } print1("Identified: "); mprint(itemid(Player.possessions[index])); } } else if (blessing < 0) { print2("You feel forgetful."); for (index=0; index<MAXITEMS; index++) if (Player.possessions[index] != NULL) { Player.possessions[index]->known = 0; Objects[Player.possessions[index]->id].known = 0; } } else { print2("You feel encyclopaedic."); for (index=0; index<MAXITEMS; index++) if (Player.possessions[index] != NULL) { if (Player.possessions[index]->objchar == FOOD) Player.possessions[index]->known = 1; else { Player.possessions[index]->known = 2; Objects[Player.possessions[index]->id].known = 1; } } for (index=0; index<Player.packptr; index++) if (Player.pack[index] != NULL) { if (Player.pack[index]->objchar == FOOD) Player.pack[index]->known = 1; else { Player.pack[index]->known = 2; Objects[Player.pack[index]->id].known = 1; } } } calc_melee(); }
/* effect of gamma ray radiation... */ void moon_check(void) { /* 24 day lunar cycle */ Phase = (Phase+1)%24; phaseprint(); Lunarity = 0; if (((Player.patron == DRUID) && ((Phase/2 == 3) || (Phase/2 == 9))) || ((Player.alignment > 10) && (Phase/2 == 6)) || ((Player.alignment < -10) && (Phase/2 == 0))) { mprint("As the moon rises you feel unusually vital!"); Lunarity = 1; } else if (((Player.patron == DRUID) && ((Phase/2 == 0) || (Phase/2 == 6))) || ((Player.alignment > 10) && (Phase/2 == 0)) || ((Player.alignment < -10) && (Phase/2 == 6))) { mprint("The rise of the moon tokens a strange enervation!"); Lunarity = -1; } }
/* use a magic key*/ void i_key(pob o) { int dir; int ox,oy; o->used = FALSE; mprint("Unlock door: "); dir = getdir(); if (dir == ABORT) resetgamestatus(SKIP_MONSTERS); else { ox = Player.x + Dirs[0][dir]; oy = Player.y + Dirs[1][dir]; if ((Level->site[ox][oy].locchar != CLOSED_DOOR) || loc_statusp(ox,oy,SECRET)) { mprint("You can't unlock that!"); resetgamestatus(SKIP_MONSTERS); } else if (Level->site[ox][oy].aux == LOCKED) { mprint("The lock clicks open!"); Level->site[ox][oy].aux = UNLOCKED; lset(ox, oy, CHANGED); o->blessing--; if ((o->blessing<0)||(Level->depth == MaxDungeonLevels-1)) { mprint("The key disintegrates!"); conform_lost_objects(1,o); } else mprint("Your key glows faintly."); } else mprint("That door is already unlocked!"); } }
int init_write (struct ccx_s_write *wb,char *filename) { memset(wb, 0, sizeof(struct ccx_s_write)); wb->fh=-1; wb->filename = filename; mprint ("Creating %s\n", filename); wb->fh = open (filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, S_IREAD | S_IWRITE); if (wb->fh == -1) { return CCX_COMMON_EXIT_FILE_CREATION_FAILED; } return EXIT_OK; }
static int write_bom(struct encoder_ctx *ctx, struct ccx_s_write *out) { int ret = 0; if (!ctx->no_bom){ if (ctx->encoding == CCX_ENC_UTF_8){ // Write BOM ret = write(out->fh, UTF8_BOM, sizeof(UTF8_BOM)); if ( ret < sizeof(UTF8_BOM)) { mprint("WARNING: Unable tp write UTF BOM\n"); return -1; } } if (ctx->encoding == CCX_ENC_UNICODE){ // Write BOM ret = write(out->fh, LITTLE_ENDIAN_BOM, sizeof(LITTLE_ENDIAN_BOM)); if ( ret < sizeof(LITTLE_ENDIAN_BOM)) { mprint("WARNING: Unable to write LITTLE_ENDIAN_BOM \n"); return -1; } } } return ret; }
void haste(int blessing) { if (blessing > -1) { if (! Player.status[HASTED]) mprint("The world slows down!"); else mprint("Nothing much happens."); if (Player.status[SLOWED]) Player.status[SLOWED] = 0; /* DAG -- this seems too long */ /* WDT -- I agree. Next version we'll fiddle it a bit. I suspect * that the author of haste/slow didn't really understand the time * system (or perhaps the time system's been changed since). */ Player.status[HASTED] += (blessing*100)+random_range(250); } else { mprint("You feel slower."); if (Player.status[HASTED] > 0) mprint("...but the feeling quickly fades."); /* DAG don't add, so it can't be come permanent. Also, reduce duration. */ else Player.status[SLOWED] = max( random_range(100)+50, Player.status[SLOWED] ); /* was: else Player.status[SLOWED] += random_range(250)+250; */ } }
int TLuaExec::LoadAndExecLua(const char* luafile) { // 加载lua文件 int ret = luaL_loadfile(m_L, luafile); if (ret) { mprint("[ERROR] Load script failed, bad file %s, errno=%d, msg=%s", luafile, ret, lua_tostring(m_L, -1)); return 1; } //函数加载Lua库 luaL_openlibs(m_L); ret = lua_pcall(m_L, 0, -1, 0); if (ret) { mprint("Execute script failed, errno=%d, msg=%s", ret, lua_tostring(m_L, -1)); return 2; } return 0; }
void signalexit(int ignored) { clearmsg(); mprint("Yikes!"); morewait(); mprint("Sorry, caught a core-dump signal."); #if 0 /* DAG used to prompt... space-bar holding through messages could cause * failure to save. Now always just force through with signalsave() */ mprint("Want to try and save the game?"); reply = ynq(); if (reply=='y') save(FALSE, TRUE); /* don't compress, force save */ else if (reply == EOF) signalsave(0); #else signalsave(0); #endif endgraf(); printf("Bye!\n"); exit(0); }
ssize_t readn(int fd, void *vptr, size_t n) { assert(fd > 0); size_t nleft; ssize_t nread; char *ptr; ptr = vptr; nleft = n; while (nleft > 0) { if (NULL == vptr) { char c; nread = recv(fd, &c, 1, 0); } else { nread = recv(fd, (void*)ptr, nleft, 0); } if (nread < 0) { if (errno == EINTR) { nread = 0; } else if (errno == EAGAIN || errno == EWOULDBLOCK) { break; } else { #if _WIN32 wprintf(L"recv() error: %ld\n", WSAGetLastError()); #else mprint("recv() error: %s\n", strerror(errno)); #endif return -1; } } else if (0 == nread) { break; /* EOF */ } nleft -= nread; ptr += nread; } return n - nleft; }
int ffmpeg_getmoredata(struct ccx_demuxer *ctx, struct demuxer_data **ppdata) { struct demuxer_data *data; int ret = 0; if(!*ppdata) { *ppdata = alloc_demuxer_data(); if(!*ppdata) return -1; data = *ppdata; //TODO Set to dummy, find and set actual value data->program_number = 1; data->stream_pid = 1; data->codec = CCX_CODEC_ATSC_CC; data->bufferdatatype = CCX_RAW_TYPE; } else { data = *ppdata; } do { int len = ff_get_ccframe(ctx->ffmpeg_ctx, data->buffer, BUFSIZE); if(len == AVERROR(EAGAIN)) { continue; } else if(len == AVERROR_EOF) { ret = CCX_EOF; break; } else if(len == 0) continue; else if(len < 0 ) { mprint("Error extracting Frame\n"); break; } else { data->len = len; break; } }while(1); return ret; }
tuck void reallocaccounting(Engine *E, Maddr addr, void *oldaddr, char *ID) { int i; if (addr == 0) { mprint(E, NULL, siminfo, "realloc failed for \"%s\"\n", ID); mmblocksdisplay(E); mexit(E, "", -1); } for (i = 0; i < E->nmemblocks; i++) { int nentries = E->memblocks[i].allocs - E->memblocks[i].frees; if (!strncmp(E->memblocks[i].ID, ID, MMALLOC_MAXIDSTRLEN)) { E->memblocks[i].addrs[nentries] = addr; E->memblocks[i].reallocs++; return; } } if (!E->memblocks[i].valid) { mprint(E, NULL, siminfo, "Attempt to realloc an unalloc'd chunk, ID = [%s]\n", ID); mmblocksdisplay(E); mexit(E, "", -1); } return; }
/* do dmg points of damage of type dtype, from source fromstring */ void p_damage(int dmg, int dtype, char *fromstring) { if (State.getFastMove()) { drawvision(Player.x,Player.y); State.setFastMove(false); } if (! p_immune(dtype)) { if (dtype == NORMAL_DAMAGE) Player.hp -= max(1,(dmg-Player.absorption)); else Player.hp -= dmg; if (Player.hp < 1) p_death(fromstring); } else mprint("You resist the effects!"); dataprint(); }