NEVER_INLINE StringData* StringData::MakeProxySlowPath(const APCString* apcstr) { #ifdef NO_M_DATA always_assert(false); not_reached(); #else auto const sd = static_cast<StringData*>( MM().mallocSmallSize(sizeof(StringData) + sizeof(Proxy)) ); auto const data = apcstr->getStringData(); sd->m_data = const_cast<char*>(data->m_data); sd->m_hdr.init(data->m_hdr, 1); sd->m_lenAndHash = data->m_lenAndHash; sd->proxy()->apcstr = apcstr; sd->enlist(); apcstr->reference(); assert(sd->m_len == data->size()); assert(sd->m_hdr.aux == data->m_hdr.aux); assert(sd->m_hdr.kind == HeaderKind::String); assert(sd->hasExactlyOneRef()); assert(sd->m_hash == data->m_hash); assert(sd->isProxy()); assert(sd->checkSane()); return sd; #endif }
NEVER_INLINE StringData* StringData::MakeSVSlowPath(APCString* shared, uint32_t len) { auto const data = shared->getStringData(); auto const hash = data->m_hash & STRHASH_MASK; auto const capAndHash = static_cast<uint64_t>(hash) << 32; auto const sd = static_cast<StringData*>( MM().smartMallocSize(sizeof(StringData) + sizeof(SharedPayload)) ); sd->m_data = const_cast<char*>(data->m_data); sd->m_lenAndCount = len; sd->m_capAndHash = capAndHash; sd->sharedPayload()->shared = shared; sd->enlist(); shared->getHandle()->reference(); assert(sd->m_len == len); assert(sd->m_count == 0); assert(sd->m_cap == 0); // cap == 0 means shared assert(sd->m_hash == hash); assert(sd->checkSane()); return sd; }
int main() { long number; number = NUMBER; long num, maxPrime; maxPrime = 0; num = 1; linkedList *primeList; primeList = createLinkedList(); enlist(primeList, 2); while (num <= number) { if (checkPrime(primeList, num) && num > maxPrime) { maxPrime = num; printf("%ld\n", maxPrime); if (number%maxPrime == 0) { number /= maxPrime; } } num += 2; } printf("The largest prime factor is: %ld\n", maxPrime); printf("destroying linked list...\n"); destroyLinkedList(primeList); return 0; }
MemBlock BigHeap::allocBig(size_t bytes, HeaderKind kind) { #ifdef USE_JEMALLOC auto n = static_cast<BigNode*>(mallocx(bytes + sizeof(BigNode), 0)); auto cap = sallocx(n, 0); #else auto cap = bytes + sizeof(BigNode); auto n = static_cast<BigNode*>(safe_malloc(cap)); #endif enlist(n, kind, cap); return {n + 1, cap - sizeof(BigNode)}; }
void TimerQueue::event::attach(TimerQueue *tq) { if(tq == list()) return; detach(); if(!tq) return; tq->modify(); enlist(tq); Timer::update(); tq->update(); }
stack::call::call() : LinkedList(), segments() { arm(stack::resetTimeout()); count = 0; forwarding = diverting = NULL; answering = 16; // should set from cfna timer... invited = ringing = ringbusy = unreachable = 0; phone = false; expires = 0l; target = source = NULL; state = INITIAL; enlist(&stack::sip); starting = ending = 0l; reason = joined = NULL; map = NULL; timer = Timer::inf; }
//TODO: for derived verbs like +/ you can add the sub-pieces in parallel Z K overDyad(K a, V *p, K b) { V *o=p-1; K(*f)(K,K); K k=0; if(VA(*o) && (f=DT[(L)*o].alt_funcs.verb_over))k=f(a,b); //k==0 just means not handled. Errors are not set to come from alt_funcs P(k,k) K u=0,v=0; K y=a?v=join(u=enlist(a),b):b; //oom u (TODO: need to unroll to 'x f/y' and 'f/y' to optimize?) K z=0,g=0; if(yt > 0){z=ci(y); GC;} if(yn == 0){if(VA(*o))z=LE; GC; } //Some verbs will handle this in alt_funcs K c=first(y),d;//mm/o //TODO: this reuse of g should be implemented in other adverbs if(0 >yt) DO(yn-1, d=c; if(!g)g=newK(ABS(yt),1); memcpy(g->k,((V)y->k)+(i+1)*bp(yt),bp(yt)); c=dv_ex(d,p-1,g); if(2==g->c){cd(g);g=0;} cd(d); if(!c) GC;) //TODO: oom err/mmo unwind above - oom-g if(0==yt) DO(yn-1, d=c; c=dv_ex(d,p-1,kK(y)[i+1]); cd(d); if(!c) GC;) //TODO: err/mmo unwind above
NEVER_INLINE StringData* StringData::MakeAPCSlowPath(const APCString* shared) { auto const sd = static_cast<StringData*>( MM().mallocSmallSize(sizeof(StringData) + sizeof(SharedPayload)) ); auto const data = shared->getStringData(); sd->m_data = const_cast<char*>(data->m_data); sd->m_hdr.init(data->m_hdr, 1); sd->m_lenAndHash = data->m_lenAndHash; sd->sharedPayload()->shared = shared; sd->enlist(); shared->getHandle()->reference(); assert(sd->m_len == data->size()); assert(sd->m_hdr.aux == data->m_hdr.aux); assert(sd->m_hdr.kind == HeaderKind::String); assert(sd->hasExactlyOneRef()); assert(sd->m_hash == data->m_hash); assert(sd->isShared()); assert(sd->checkSane()); return sd; }
HOT_FUNC StringData::StringData(SharedVariant* shared) : m_count(0) { assert(shared && size_t(shared->stringLength()) <= size_t(MaxSize)); m_hash = 0; auto len = shared->stringLength(); auto data = shared->stringData(); if (len <= MaxSmallSize) { memcpy(m_small, data, len + 1); // include \0 m_len = len; m_data = m_small; setSmall(); assert(m_small[len] == 0); } else { shared->incRef(); m_len = len; m_cdata = data; m_big.shared = shared; setModeAndCap(Mode::Shared, len + 1); enlist(); } }
NEVER_INLINE StringData* StringData::MakeAPCSlowPath(const APCString* shared) { auto const sd = static_cast<StringData*>( MM().smartMallocSize(sizeof(StringData) + sizeof(SharedPayload)) ); auto const data = shared->getStringData(); sd->m_data = const_cast<char*>(data->m_data); sd->m_capAndCount = data->m_capCode; // count=0, kind=data->kind sd->m_lenAndHash = data->m_lenAndHash; sd->sharedPayload()->shared = shared; sd->enlist(); shared->getHandle()->reference(); assert(sd->m_len == data->size()); assert(sd->m_count == 0); assert(sd->m_capCode == data->m_capCode); assert(sd->m_hash == data->m_hash); assert(sd->m_kind == HeaderKind::String); assert(sd->isShared()); assert(sd->checkSane()); return sd; }
int checkPrime(linkedList *LinkedList, long number) { int flag; flag = 1; linkedListNode *conductor; conductor = LinkedList->head; while (conductor && conductor->prime <= ((long)sqrt(number)) ) { if ((number)%(conductor->prime) == 0) { flag = 0; return flag; } conductor = conductor->next; } if (flag && number > 1) { enlist(LinkedList, number); } else { return (flag = 0); } return flag; }
MemBlock BigHeap::callocBig(size_t nbytes) { auto cap = nbytes + sizeof(BigNode); auto const n = static_cast<BigNode*>(safe_calloc(cap, 1)); enlist(n, HeaderKind::BigMalloc, cap); return {n + 1, nbytes}; }
/* * Produce for a specific nation */ void produce_sect(int natnum, int etu, struct bp *bp, int p_sect[][2]) { struct sctstr *sp; struct natstr *np; short buf[I_MAX + 1]; short *vec; int work, cost, ecost, pcost, sctwork; int n, desig, neweff, amount; for (n = 0; NULL != (sp = getsectid(n)); n++) { if (sp->sct_type == SCT_WATER) continue; if (sp->sct_own != natnum) continue; if (sp->sct_updated != 0) continue; np = getnatp(natnum); if (player->simulation) { /* work on a copy, which will be discarded */ memcpy(buf, sp->sct_item, sizeof(buf)); vec = buf; } else vec = sp->sct_item; /* If everybody is dead, the sector reverts to unowned. * This is also checked at the end of the production in * they all starved or were plagued off. */ if (vec[I_CIVIL] == 0 && vec[I_MILIT] == 0 && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, NULL)) { if (!player->simulation) { makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); sp->sct_own = 0; sp->sct_oldown = 0; } continue; } sp->sct_updated = 1; work = 0; sctwork = do_feed(sp, np, vec, &work, etu); bp_put_items(bp, sp, vec); if (sp->sct_off || np->nat_money < 0) continue; neweff = sp->sct_effic; amount = 0; pcost = cost = ecost = 0; desig = sp->sct_type; if (dchr[desig].d_maint) { cost = etu * dchr[desig].d_maint; p_sect[SCT_MAINT][0]++; p_sect[SCT_MAINT][1] += cost; if (!player->simulation) np->nat_money -= cost; } if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) && np->nat_money >= 0) { neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork, &cost); bp_put_items(bp, sp, vec); p_sect[SCT_EFFIC][0]++; p_sect[SCT_EFFIC][1] += cost; if (!player->simulation) { np->nat_money -= cost; sp->sct_type = desig; sp->sct_effic = neweff; } } if (desig == SCT_ENLIST && neweff >= 60 && sp->sct_own == sp->sct_oldown) { p_sect[desig][0] += enlist(vec, etu, &ecost); p_sect[desig][1] += ecost; if (!player->simulation) np->nat_money -= ecost; bp_put_items(bp, sp, vec); } /* * now do the production (if sector effic >= 60%) */ if (neweff >= 60) { if (np->nat_money >= 0 && dchr[desig].d_prd >= 0) work -= produce(np, sp, vec, work, desig, neweff, &pcost, &amount); bp_put_items(bp, sp, vec); } bp_put_avail(bp, sp, work); p_sect[desig][0] += amount; p_sect[desig][1] += pcost; if (!player->simulation) { sp->sct_avail = work; np->nat_money -= pcost; } } }
/*! \brief Double click \author Ripper, rewrite by Endymion \param ps client of player dbclick \note Completely redone by Morrolan 20-07-99 \warning I use a define CASE for make more readable the code, if you change name of P_ITEM pi chage also the macro \todo los */ void doubleclick(NXWCLIENT ps) { if(ps==NULL) return; P_CHAR pc = ps->currChar(); VALIDATEPC( pc ); NXWSOCKET s = ps->toInt(); // the 0x80 bit in the first byte is used later for "keyboard" and should be ignored SERIAL serial = LongFromCharPtr(buffer[s] +1) & 0x7FFFFFFF; if (isCharSerial(serial)) { P_CHAR pd=pointers::findCharBySerial(serial); if(ISVALIDPC(pd)) dbl_click_character(ps, pd); return; } P_ITEM pi = pointers::findItemBySerial(serial); VALIDATEPI(pi); if (pi->amxevents[EVENT_IONDBLCLICK]!=NULL) { g_bByPass = false; pi->amxevents[EVENT_IONDBLCLICK]->Call( pi->getSerial32(), pc->getSerial32() ); if (g_bByPass==true) return; } /* g_bByPass = false; pi->runAmxEvent( EVENT_IONDBLCLICK, pi->getSerial32(), s ); if (g_bByPass==true) return; */ if (!checkItemUsability(pc , pi, ITEM_USE_DBLCLICK)) return; Location charpos= pc->getPosition(); if (pc->IsHiddenBySpell()) return; //Luxor: cannot use items if under invisible spell if ( !pc->IsGM() && pc->objectdelay >= uiCurrentTime ) { pc->sysmsg(TRANSLATE("You must wait to perform another action.")); return; } else pc->objectdelay = SrvParms->objectdelay * MY_CLOCKS_PER_SEC + uiCurrentTime; ///MODIFY, CANT CLICK ITEM AT DISTANCE >2////////////// if ( (pc->distFrom(pi)>2) && !pc->IsGM() && !(pc->nxwflags[0] & cChar::flagSpellTelekinesys) ) //Luxor: let's check also for the telekinesys spell { pc->sysmsg( TRANSLATE("Must be closer to use this!")); pc->objectdelay=0; return; } //<Anthalir> VARIAIBLI tile_st item; P_ITEM pack= pc->getBackpack(); VALIDATEPI( pack ); data::seekTile( pi->getId(), item ); //////FINEVARIABILI if ( ServerScp::g_nEquipOnDclick ) { // equip the item only if it is in the backpack of the player if ((pi->getContSerial() == pack->getSerial32()) && (item.quality != 0) && (item.quality != LAYER_BACKPACK) && (item.quality != LAYER_MOUNT)) { int drop[2]= {-1, -1}; // list of items to drop, there no reason for it to be larger int curindex= 0; NxwItemWrapper wea; wea.fillItemWeared( pc, true, true, true ); for( wea.rewind(); !wea.isEmpty(); wea++ ) { P_ITEM pj=wea.getItem(); if(!ISVALIDPI(pj)) continue; if ((item.quality == LAYER_1HANDWEAPON) || (item.quality == LAYER_2HANDWEAPON))// weapons { if (pi->itmhand == 2) // two handed weapons or shield { if (pj->itmhand == 2) drop[curindex++]= DEREF_P_ITEM(pj); if ( (pj->itmhand == 1) || (pj->itmhand == 3) ) drop[curindex++]= DEREF_P_ITEM(pj); } if (pi->itmhand == 3) { if ((pj->itmhand == 2) || pj->itmhand == 3) drop[curindex++]= DEREF_P_ITEM(pj); } if ((pi->itmhand == 1) && ((pj->itmhand == 2) || (pj->itmhand == 1))) drop[curindex++]= DEREF_P_ITEM(pj); } else // not a weapon { if (pj->layer == item.quality) drop[curindex++]= DEREF_P_ITEM(pj); } } if (ServerScp::g_nUnequipOnReequip) { if (drop[0] > -1) // there is at least one item to drop { for (int i= 0; i< 2; i++) { if (drop[i] > -1) { P_ITEM p_drop=MAKE_ITEM_REF(drop[i]); if(ISVALIDPI(p_drop)) pc->UnEquip( p_drop ); } } } pc->playSFX( itemsfx(pi->getId()) ); pc->Equip( pi ); } else { if (drop[0] == -1) { pc->playSFX( itemsfx(pi->getId()) ); pc->Equip( pi ); } } return; } } // </Anthalir> //<Luxor>: Circle of transparency bug fix P_ITEM pCont; Location dst; pCont = pi->getOutMostCont(); if(pCont->isInWorld()) { dst = pCont->getPosition(); } else { P_CHAR pg_dst = pointers::findCharBySerial( pCont->getContSerial() ); VALIDATEPC(pg_dst); dst = pg_dst->getPosition(); } Location charPos = pc->getPosition(); charPos.z = dst.z; charPos.dispz = dst.dispz; if ( !pc->IsGM() && !lineOfSight( charPos, dst ) && !(pc->nxwflags[0] & cChar::flagSpellTelekinesys) ) { pc->sysmsg( TRANSLATE( "You cannot reach the item" ) ); return; } //</Luxor> P_CHAR itmowner = pi->getPackOwner(); if(!pi->isInWorld()) { if (isItemSerial(pi->getContSerial()) && pi->type != ITYPE_CONTAINER) {// Cant use stuff that isn't in your pack. if ( ISVALIDPC(itmowner) && (itmowner->getSerial32()!=pc->getSerial32()) ) return; } else if (isCharSerial(pi->getContSerial()) && pi->type!=(UI32)INVALID) {// in a character. P_CHAR wearedby = pointers::findCharBySerial(pi->getContSerial()); if (ISVALIDPC(wearedby)) if (wearedby->getSerial32()!=pc->getSerial32() && pi->layer!=LAYER_UNUSED_BP && pi->type!=ITYPE_CONTAINER) return; } } if ((pi->magic==4) && (pi->secureIt==1)) { if (!pc->isOwnerOf(pi) || !pc->IsGMorCounselor()) { pc->sysmsg( TRANSLATE("That is a secured chest!")); return; } } if (pi->magic == 4) { pc->sysmsg( TRANSLATE("That item is locked down.")); return; } if (pc->dead && pi->type!=ITYPE_RESURRECT) // if you are dead and it's not an ankh, FORGET IT! { pc->sysmsg(TRANSLATE("You may not do that as a ghost.")); return; } else if (!pc->IsGMorCounselor() && pi->layer!=0 && !pc->IsWearing(pi)) {// can't use other people's things! if (!(pi->layer==LAYER_BACKPACK && SrvParms->rogue==1)) // bugfix for snooping not working, LB { pc->sysmsg(TRANSLATE("You cannot use items equipped by other players.")); return; } } // Begin checking objects that we force an object delay for (std objects) // start trigger stuff if (pi->trigger > 0) { if (pi->trigtype == 0) { if ( TIMEOUT( pi->disabled ) ) // changed by Magius(CHE) § { triggerItem(s, pi, TRIGTYPE_DBLCLICK); // if players uses trigger return; } else { if ( pi->disabledmsg!=NULL ) pc->sysmsg("%s", pi->disabledmsg->c_str()); else pc->sysmsg(TRANSLATE("That doesnt seem to work right now.")); return; } } else { pc->sysmsg( TRANSLATE("You are not close enough to use that.")); return; } } // check this on trigger in the event that the .trigger property is not set on the item // trigger code. Check to see if item is envokable by id else if (checkenvoke( pi->getId() )) { pc->envokeitem = pi->getSerial32(); pc->envokeid = pi->getId(); P_TARGET targ = clientInfo[s]->newTarget( new cObjectTarget() ); targ->code_callback=target_envoke; targ->send( ps ); ps->sysmsg( TRANSLATE("What will you use this on?")); return; } // end trigger stuff // BEGIN Check items by type int los = 0; BYTE map1[20] = "\x90\x40\x01\x02\x03\x13\x9D\x00\x00\x00\x00\x13\xFF\x0F\xFF\x01\x90\x01\x90"; BYTE map2[12] = "\x56\x40\x01\x02\x03\x05\x00\x00\x00\x00\x00"; // By Polygon: This one is needed to show the location on treasure maps BYTE map3[12] = "\x56\x40\x01\x02\x03\x01\x00\x00\x00\x00\x00"; P_TARGET targ = NULL; switch (pi->type) { case ITYPE_RESURRECT: // Check for 'resurrect item type' this is the ONLY type one can use if dead. if (pc->dead) { pc->resurrect(); pc->sysmsg(TRANSLATE("You have been resurrected.")); return; } else { pc->sysmsg(TRANSLATE("You are already living!")); return; } case ITYPE_BOATS:// backpacks - snooping a la Zippy - add check for SrvParms->rogue later- Morrolan if (pi->type2 == 3) { switch( pi->getId() & 0xFF ) { case 0x84: case 0xD5: case 0xD4: case 0x89: Boats->PlankStuff(pc, pi); break; default: pc->sysmsg( TRANSLATE("That is locked.")); break; } return; } case ITYPE_CONTAINER: // bugfix for snooping not working, lb case ITYPE_UNLOCKED_CONTAINER: // Wintermute: GMs or Counselors should be able to open trapped containers always if (pi->moreb1 > 0 && !pc->IsGMorCounselor()) { magic::castAreaAttackSpell(pi->getPosition("x"), pi->getPosition("y"), magic::SPELL_EXPLOSION); pi->moreb1--; } //Magic->MagicTrap(currchar[s], pi); // added by AntiChrist // only 1 and 63 can be trapped, so pleaz leave it here :) - Anti case ITYPE_NODECAY_ITEM_SPAWNER: // nodecay item spawner..Ripper case ITYPE_DECAYING_ITEM_SPAWNER: // decaying item spawner..Ripper if (pi->isInWorld() || (pc->IsGMorCounselor()) || // Backpack in world - free access to everyone ( isCharSerial(pi->getContSerial()) && pi->getContSerial()==pc->getSerial32())) // primary pack { pc->showContainer(pi); pc->objectdelay=0; return; } else if( isItemSerial(pi->getContSerial()) ) { P_ITEM pio = pi->getOutMostCont(); if (pio->getContSerial()==pc->getSerial32() || pio->isInWorld() ) { pc->showContainer(pi); pc->objectdelay=0; return; } } if(ISVALIDPC(itmowner)) snooping(pc, pi ); return; case ITYPE_TELEPORTRUNE: targ = clientInfo[s]->newTarget( new cLocationTarget() ); targ->code_callback = target_tele; targ->send( ps ); ps->sysmsg( TRANSLATE("Select teleport target.")); return; case ITYPE_KEY: targ = clientInfo[s]->newTarget( new cItemTarget() ); targ->code_callback = target_key; targ->buffer[0]= pi->more1; targ->buffer[1]= pi->more2; targ->buffer[2]= pi->more3; targ->buffer[3]= pi->more4; targ->send( ps ); ps->sysmsg( TRANSLATE("Select item to use the key on.")); return; case ITYPE_LOCKED_ITEM_SPAWNER: case ITYPE_LOCKED_CONTAINER: // Added traps effects by AntiChrist // Wintermute: GMs or Counselors should be able to open locked containers always if ( !pc->IsGMorCounselor() ) { if (pi->moreb1 > 0 ) { magic::castAreaAttackSpell(pi->getPosition().x, pi->getPosition().y, magic::SPELL_EXPLOSION); pi->moreb1--; } pc->sysmsg(TRANSLATE("This item is locked.")); return; } else { pc->showContainer(pi); return; } case ITYPE_SPELLBOOK: if (ISVALIDPI(pack)) // morrolan if(pi->getContSerial()==pack->getSerial32() || pc->IsWearing(pi)) ps->sendSpellBook(pi); else pc->sysmsg(TRANSLATE("If you wish to open a spellbook, it must be equipped or in your main backpack.")); return; case ITYPE_MAP: LongToCharPtr(pi->getSerial32(), map1 +1); map2[1] = map1[1]; map2[2] = map1[2]; map2[3] = map1[3]; map2[4] = map1[4]; /* By Polygon: Assign areas and map size before sending */ map1[7] = pi->more1; // Assign topleft x map1[8] = pi->more2; map1[9] = pi->more3; // Assign topleft y map1[10] = pi->more4; map1[11] = pi->moreb1; // Assign lowright x map1[12] = pi->moreb2; map1[13] = pi->moreb3; // Assign lowright y map1[14] = pi->moreb4; int width, height; // Tempoary storage for w and h; width = 134 + (134 * pi->morez); // Calculate new w and h height = 134 + (134 * pi->morez); ShortToCharPtr(width, map1 +15); ShortToCharPtr(height, map1 +17); // END OF: By Polygon Xsend(s, map1, 19); //AoS/ Network->FlushBuffer(s); Xsend(s, map2, 11); //AoS/ Network->FlushBuffer(s); return; case ITYPE_BOOK: Books::DoubleClickBook(s, pi); return; case ITYPE_DOOR: dooruse(s, pi); return; case ITYPE_LOCKED_DOOR: // Wintermute: GMs or Counselors should be able to open locked doors always if ( pc->IsGMorCounselor()) { dooruse(s, pi); return; } if (ISVALIDPI(pack)) { NxwItemWrapper si; si.fillItemsInContainer( pack ); for( si.rewind(); !si.isEmpty(); si++ ) { P_ITEM pj = si.getItem(); if (ISVALIDPI(pj) && pj->type==ITYPE_KEY) if (((pj->more1 == pi->more1) && (pj->more2 == pi->more2) && (pj->more3 == pi->more3) && (pj->more4 == pi->more4)) ) { pc->sysmsg(TRANSLATE("You quickly unlock, use, and then relock the door.")); dooruse(s, pi); return; } } } pc->sysmsg(TRANSLATE("This door is locked.")); return; case ITYPE_FOOD: if (pc->hunger >= 6) { pc->sysmsg( TRANSLATE("You are simply too full to eat any more!")); return; } else { switch (RandomNum(0, 2)) { case 0: pc->playSFX(0x3A); break; case 1: pc->playSFX(0x3B); break; case 2: pc->playSFX(0x3C); break; } switch (pc->hunger) { case 0: pc->sysmsg( TRANSLATE("You eat the food, but are still extremely hungry.")); break; case 1: pc->sysmsg( TRANSLATE("You eat the food, but are still extremely hungry.")); break; case 2: pc->sysmsg( TRANSLATE("After eating the food, you feel much less hungry.")); break; case 3: pc->sysmsg( TRANSLATE("You eat the food, and begin to feel more satiated.")); break; case 4: pc->sysmsg( TRANSLATE("You feel quite full after consuming the food.")); break; case 5: pc->sysmsg( TRANSLATE("You are nearly stuffed, but manage to eat the food.")); break; default: pc->sysmsg( TRANSLATE("You are simply too full to eat any more!")); break; } if (pi->poisoned) { pc->sysmsg(TRANSLATE("The food was poisoned!")); pc->applyPoison(PoisonType(pi->poisoned)); } pi->ReduceAmount(1); pc->hunger++; } return; case ITYPE_WAND: // -Fraz- Modified and tuned up, Wands must now be equipped or in pack case ITYPE_MANAREQ_WAND: // magic items requiring mana (xan) if (ISVALIDPI(pack)) { if (pi->getContSerial() == pack->getSerial32() || pc->IsWearing(pi)) { if (pi->morez != 0) { pi->morez--; if (magic::beginCasting( static_cast<magic::SpellId>((8*(pi->morex - 1)) + pi->morey - 1), ps, (pi->type==ITYPE_WAND) ? magic::CASTINGTYPE_ITEM : magic::CASTINGTYPE_NOMANAITEM)) { if (pi->morez == 0) { pi->type = pi->type2; pi->morex = 0; pi->morey = 0; pi->offspell = 0; } } } } else { pc->sysmsg(TRANSLATE("If you wish to use this, it must be equipped or in your backpack.")); } } return; // case 15 (magic items) /*////////////////////REMOVE///////////////////////////////////// case 18: // crystal ball? switch (RandomNum(0, 9)) { case 0: itemmessage(s, TRANSLATE("Seek out the mystic llama herder."), pi->getSerial32()); break; case 1: itemmessage(s, TRANSLATE("Wherever you go, there you are."), pi->getSerial32()); break; case 4: itemmessage(s, TRANSLATE("The message appears to be too cloudy to make anything out of it."), pi->getSerial32()); break; case 5: itemmessage(s, TRANSLATE("You have just lost five strength.. not!"), pi->getSerial32()); break; case 6: itemmessage(s, TRANSLATE("You're really playing a game you know"), pi->getSerial32()); break; case 7: itemmessage(s, TRANSLATE("You will be successful in all you do."), pi->getSerial32()); break; case 8: itemmessage(s, TRANSLATE("You are a person of culture."), pi->getSerial32()); break; default: itemmessage(s, TRANSLATE("Give me a break! How much good fortune do you expect!"), pi->getSerial32()); break; }// switch soundeffect2(pc_currchar, 0x01EC); return;// case 18 (crystal ball?) */////////////////////ENDREMOVE///////////////////////////////////// case ITYPE_POTION: // potions if (pi->morey != 3) pc->drink(pi); //Luxor: delayed potions drinking else //explosion potion usepotion(pc, pi); return; case ITYPE_RUNE: if (pi->morex==0 && pi->morey==0 && pi->morez==0) { pc->sysmsg( TRANSLATE("That rune is not yet marked!")); } else { pc->runeserial = pi->getSerial32(); pc->sysmsg( TRANSLATE("Enter new rune name.")); } return; case ITYPE_SMOKE: pc->smoketimer = pi->morex*MY_CLOCKS_PER_SEC + getclock(); pi->ReduceAmount(1); return; case ITYPE_RENAME_DEED: pc->namedeedserial = pi->getSerial32(); pc->sysmsg( TRANSLATE("Enter your new name.")); pi->ReduceAmount(1); return; case ITYPE_POLYMORPH: pc->setId( pi->morex ); pc->teleport(); pi->type = ITYPE_POLYMORPH_BACK; return; case ITYPE_POLYMORPH_BACK: pc->setId( pc->getOldId() ); pc->teleport(); pi->type = ITYPE_POLYMORPH; return; case ITYPE_ARMY_ENLIST: enlist(s, pi->morex); pi->Delete(); return; case ITYPE_TELEPORT: pc->MoveTo( pi->morex,pi->morey,pi->morez ); pc->teleport(); return; case ITYPE_DRINK: switch (rand()%2) { case 0: pc->playSFX(0x0031); break; case 1: pc->playSFX(0x0030); break; } pi->ReduceAmount(1); pc->sysmsg( TRANSLATE("Gulp !")); return; case ITYPE_GUILDSTONE: if ( pi->getId() == 0x14F0 || pi->getId() == 0x1869 ) // Check for Deed/Teleporter + Guild Type { pc->fx1 = DEREF_P_ITEM(pi); Guilds->StonePlacement(s); return; } else if (pi->getId() == 0x0ED5) // Check for Guildstone + Guild Type { pc->fx1 = DEREF_P_ITEM(pi); Guilds->Menu(s, 1); return; } else WarnOut("Unhandled guild item type named: %s with ID of: %X\n", pi->getCurrentNameC(), pi->getId()); return; case ITYPE_PLAYER_VENDOR_DEED: // PlayerVendors deed { P_CHAR vendor = npcs::AddNPCxyz(-1, 2117, charpos.x, charpos.y, charpos.z); if ( !ISVALIDPC(vendor) ) { WarnOut("npc-script couldnt find vendor !\n"); return; } los = 0; vendor->npcaitype = NPCAI_PLAYERVENDOR; vendor->MakeInvulnerable(); vendor->unHide(); vendor->stealth=INVALID; vendor->dir = pc->dir; vendor->npcWander = WANDER_NOMOVE; vendor->SetInnocent(); vendor->setOwnerSerial32( pc->getSerial32() ); vendor->tamed = false; pi->Delete(); vendor->teleport(); char temp[TEMP_STR_SIZE]; //xan -> this overrides the global temp var sprintf( temp, TRANSLATE("Hello sir! My name is %s and i will be working for you."), vendor->getCurrentNameC()); vendor->talk(s, temp, 0); return; } case ITYPE_TREASURE_MAP: Skills::Decipher(pi, s); return; case ITYPE_DECIPHERED_MAP: map1[ 1] = map2[1] = map3[1] = pi->getSerial().ser1; map1[ 2] = map2[2] = map3[2] = pi->getSerial().ser2; map1[ 3] = map2[3] = map3[3] = pi->getSerial().ser3; map1[ 4] = map2[4] = map3[4] = pi->getSerial().ser4; map1[ 7] = pi->more1; // Assign topleft x map1[ 8] = pi->more2; map1[ 9] = pi->more3; // Assign topleft y map1[10] = pi->more4; map1[11] = pi->moreb1; // Assign lowright x map1[12] = pi->moreb2; map1[13] = pi->moreb3; // Assign lowright y map1[14] = pi->moreb4; ShortToCharPtr(0x0100, map1 +15); // Let width and height be 256 ShortToCharPtr(0x0100, map1 +17); Xsend(s, map1, 19); //AoS/ Network->FlushBuffer(s); Xsend(s, map2, 11); //AoS/ Network->FlushBuffer(s); // Generate message to add a map point SI16 posx, posy; // tempoary storage for map point SI16 tlx, tly, lrx, lry; // tempoary storage for map extends tlx = (pi->more1 << 8) | pi->more2; tly = (pi->more3 << 8) | pi->more4; lrx = (pi->moreb1 << 8) | pi->moreb2; lry = (pi->moreb3 << 8) | pi->moreb4; posx = (256 * (pi->morex - tlx)) / (lrx - tlx); // Generate location for point posy = (256 * (pi->morey - tly)) / (lry - tly); ShortToCharPtr(posx, map3 +7); // Store the point position ShortToCharPtr(posy, map3 +9); Xsend(s, map3, 11); // Fire data to client :D //AoS/ Network->FlushBuffer(s); return; default: break; } ///END IDENTIFICATION BY TYPE /////////////////READ UP :D//////////////////////////////// ///BEGIN IDENTIFICATION BY ID if (pi->IsSpellScroll()) { if (ISVALIDPI(pack)) if( pi->getContSerial()==pack->getSerial32()) { magic::SpellId spn = magic::spellNumberFromScrollId(pi->getId()); // avoid reactive armor glitch if ((spn>=0)&&(magic::beginCasting(spn, ps, magic::CASTINGTYPE_SCROLL))) pi->ReduceAmount(1); // remove scroll if successful } else pc->sysmsg(TRANSLATE("The scroll must be in your backpack to envoke its magic.")); } CASE(IsAnvil) { targ = clientInfo[s]->newTarget( new cItemTarget() ); targ->code_callback=Skills::target_repair; targ->send( ps ); ps->sysmsg( TRANSLATE("Select item to be repaired.")); } CASE(IsAxe) { targ = clientInfo[s]->newTarget( new cTarget() ); targ->code_callback=target_axe; targ->buffer[0]=pi->getSerial32(); targ->send( ps ); ps->sysmsg( TRANSLATE("What would you like to use that on ?")); } CASEOR(IsFeather, IsShaft) { targ = clientInfo[s]->newTarget( new cItemTarget() ); targ->buffer[0]= pi->getSerial32(); targ->code_callback=Skills::target_fletching; targ->send( ps ); ps->sysmsg( TRANSLATE("What would you like to use this with?")); }
/********************************************************************* * * Function : load_one_re_filterfile * * Description : Load a re_filterfile. * Generate a chained list of re_filterfile_spec's from * the "FILTER: " blocks, compiling all their substitutions * into chained lists of pcrs_job structs. * * Parameters : * 1 : csp = Current client state (buffers, headers, etc...) * * Returns : 0 => Ok, everything else is an error. * *********************************************************************/ int load_one_re_filterfile(struct client_state *csp, int fileid) { FILE *fp; struct re_filterfile_spec *new_bl, *bl = NULL; struct file_list *fs; char buf[BUFFER_SIZE]; int error; unsigned long linenum = 0; pcrs_job *dummy, *lastjob = NULL; /* * No need to reload if unchanged */ if (!check_file_changed(current_re_filterfile[fileid], csp->config->re_filterfile[fileid], &fs)) { if (csp) { csp->rlist[fileid] = current_re_filterfile[fileid]; } return(0); } if (!fs) { goto load_re_filterfile_error; } /* * Open the file or fail */ if ((fp = fopen(csp->config->re_filterfile[fileid], "r")) == NULL) { goto load_re_filterfile_error; } /* * Read line by line */ while (read_config_line(buf, sizeof(buf), fp, &linenum) != NULL) { int new_filter = NO_NEW_FILTER; if (strncmp(buf, "FILTER:", 7) == 0) { new_filter = FT_CONTENT_FILTER; } else if (strncmp(buf, "SERVER-HEADER-FILTER:", 21) == 0) { new_filter = FT_SERVER_HEADER_FILTER; } else if (strncmp(buf, "CLIENT-HEADER-FILTER:", 21) == 0) { new_filter = FT_CLIENT_HEADER_FILTER; } else if (strncmp(buf, "CLIENT-HEADER-TAGGER:", 21) == 0) { new_filter = FT_CLIENT_HEADER_TAGGER; } else if (strncmp(buf, "SERVER-HEADER-TAGGER:", 21) == 0) { new_filter = FT_SERVER_HEADER_TAGGER; } /* * If this is the head of a new filter block, make it a * re_filterfile spec of its own and chain it to the list: */ if (new_filter != NO_NEW_FILTER) { new_bl = (struct re_filterfile_spec *)zalloc(sizeof(*bl)); if (new_bl == NULL) { goto load_re_filterfile_error; } if (new_filter == FT_CONTENT_FILTER) { new_bl->name = chomp(buf + 7); } else { new_bl->name = chomp(buf + 21); } new_bl->type = new_filter; /* * If a filter description is available, * encode it to HTML and save it. */ if (NULL != (new_bl->description = strpbrk(new_bl->name, " \t"))) { *new_bl->description++ = '\0'; new_bl->description = html_encode(chomp(new_bl->description)); if (NULL == new_bl->description) { new_bl->description = strdup("Out of memory while encoding this filter's description to HTML"); } } else { new_bl->description = strdup("No description available for this filter"); } new_bl->name = strdup(chomp(new_bl->name)); /* * If this is the first filter block, chain it * to the file_list rather than its (nonexistant) * predecessor */ if (fs->f == NULL) { fs->f = new_bl; } else { assert(NULL != bl); bl->next = new_bl; } bl = new_bl; log_error(LOG_LEVEL_RE_FILTER, "Reading in filter \"%s\" (\"%s\")", bl->name, bl->description); continue; } /* * Else, save the expression, make it a pcrs_job * and chain it into the current filter's joblist */ if (bl != NULL) { error = enlist(bl->patterns, buf); if (JB_ERR_MEMORY == error) { log_error(LOG_LEVEL_FATAL, "Out of memory while enlisting re_filter job \'%s\' for filter %s.", buf, bl->name); } assert(JB_ERR_OK == error); if (pcrs_job_is_dynamic(buf)) { /* * Dynamic pattern that might contain variables * and has to be recompiled for every request */ if (bl->joblist != NULL) { pcrs_free_joblist(bl->joblist); bl->joblist = NULL; } bl->dynamic = 1; log_error(LOG_LEVEL_RE_FILTER, "Adding dynamic re_filter job \'%s\' to filter %s succeeded.", buf, bl->name); continue; } else if (bl->dynamic) { /* * A previous job was dynamic and as we * recompile the whole filter anyway, it * makes no sense to compile this job now. */ log_error(LOG_LEVEL_RE_FILTER, "Adding static re_filter job \'%s\' to dynamic filter %s succeeded.", buf, bl->name); continue; } if ((dummy = pcrs_compile_command(buf, &error)) == NULL) { log_error(LOG_LEVEL_ERROR, "Adding re_filter job \'%s\' to filter %s failed with error %d.", buf, bl->name, error); continue; } else { if (bl->joblist == NULL) { bl->joblist = dummy; } else if (NULL != lastjob) { lastjob->next = dummy; } lastjob = dummy; log_error(LOG_LEVEL_RE_FILTER, "Adding re_filter job \'%s\' to filter %s succeeded.", buf, bl->name); } } else { log_error(LOG_LEVEL_ERROR, "Ignoring job %s outside filter block in %s, line %d", buf, csp->config->re_filterfile[fileid], linenum); } } fclose(fp); /* * Schedule the now-obsolete old data for unloading */ if ( NULL != current_re_filterfile[fileid] ) { current_re_filterfile[fileid]->unloader = unload_re_filterfile; } /* * Chain this file into the global list of loaded files */ fs->next = files->next; files->next = fs; current_re_filterfile[fileid] = fs; if (csp) { csp->rlist[fileid] = fs; } return( 0 ); load_re_filterfile_error: log_error(LOG_LEVEL_FATAL, "can't load re_filterfile '%s': %E", csp->config->re_filterfile[fileid]); return(-1); }