//************************************************************************************* //************************************************************************************* void ARX_FOGS_Render(long init) { if (ARXPausedTimer) return; int iDiv = 2; if (pMenuConfig) { iDiv += 2 - pMenuConfig->iLevelOfDetails; } float flDiv = ARX_CLEAN_WARN_CAST_FLOAT(1 << iDiv); for (long i = 0; i < MAX_FOG; i++) { if (fogs[i].exist) { unsigned long offs; float fval; offs = 0; ARX_CHECK_LONG(FrameDiff / flDiv); long count = ARX_CLEAN_WARN_CAST_LONG(FrameDiff / flDiv); if (count < 1) count = 1; while (count) { count--; long j = ARX_PARTICLES_GetFree(); if ((j != -1) && (rnd() * 2000.f < (float)fogs[i].frequency)) { ParticleCount++; particle[j].special = FADE_IN_AND_OUT | ROTATING | MODULATE_ROTATION | DISSIPATING; particle[j].exist = true; particle[j].zdec = 0; if (fogs[i].special & FOG_DIRECTIONAL) { particle[j].ov.x = fogs[i].pos.x; particle[j].ov.y = fogs[i].pos.y; particle[j].ov.z = fogs[i].pos.z; fval = fogs[i].speed * DIV10; particle[j].move.x = (fogs[i].move.x * fval); particle[j].move.y = (fogs[i].move.y * fval); particle[j].move.z = (fogs[i].move.z * fval); } else { particle[j].ov.x = fogs[i].pos.x + 100.f - 200.f * rnd(); particle[j].ov.y = fogs[i].pos.y + 100.f - 200.f * rnd(); particle[j].ov.z = fogs[i].pos.z + 100.f - 200.f * rnd(); fval = fogs[i].speed * DIV5; particle[j].move.x = (fogs[i].speed - rnd() * 2.f) * fval; particle[j].move.y = (fogs[i].speed - rnd() * 2.f) * DIV15; particle[j].move.z = (fogs[i].speed - rnd() * 2.f) * fval; } particle[j].scale.x = particle[j].scale.y = particle[j].scale.z = fogs[i].scale; particle[j].timcreation = lARXTime; particle[j].tolive = fogs[i].tolive + (unsigned long)(rnd() * fogs[i].tolive); particle[j].tc = TC_smoke; particle[j].siz = (fogs[i].size + rnd() * fogs[i].size * 2.f) * DIV3; particle[j].r = fogs[i].rgb.r; particle[j].g = fogs[i].rgb.g; particle[j].b = fogs[i].rgb.b; particle[j].fparam = fogs[i].rotatespeed; } fogs[i].lastupdate = ARXTimeUL(); } } } }
int chooseslot() const { return numslots > 1 ? slots + rnd(numslots) : slots; }
void localservertoclient(uchar *buf, int len) // processes any updates from the server { if (ENET_NET_TO_HOST_16(*(ushort *)buf) != len) neterr("packet length"); incomingdemodata(buf, len); uchar *end = buf + len; uchar *p = buf + 2; char text[MAXTRANS]; int cn = -1, type; Sprite *spr = NULL; bool mapchanged = false; while (p < end) switch (type = getint(p)) { case SV_INITS2C: // welcome messsage from the server { cn = getint(p); int prot = getint(p); if (prot != PROTOCOL_VERSION) { conoutf( "you are using a different game protocol (you: %d, server: %d)", PROTOCOL_VERSION, prot); disconnect(); return; }; toservermap = ""; clientnum = cn; // we are now fully connected if (!getint(p)) { toservermap = getclientmap(); // we are the first client on this server, set map } sgetstr(); if (text[0] && strcmp(text, clientpassword)) { conoutf( "you need to set the correct password to join this server!"); disconnect(); return; }; if (getint(p) == 1) { conoutf("server is FULL, disconnecting.."); }; break; } case SV_POS: // position of another client { cn = getint(p); spr = getclient(cn); if (!spr) return; spr->o.x = getint(p) / DMF; spr->o.y = getint(p) / DMF; spr->o.z = getint(p) / DMF; spr->yaw = getint(p) / DAF; spr->pitch = getint(p) / DAF; spr->roll = getint(p) / DAF; spr->vel.x = getint(p) / DVF; spr->vel.y = getint(p) / DVF; spr->vel.z = getint(p) / DVF; int f = getint(p); spr->strafe = (f & 3) == 3 ? -1 : f & 3; f >>= 2; spr->move = (f & 3) == 3 ? -1 : f & 3; spr->onfloor = (f >> 2) & 1; int state = f >> 3; if (state == CS_DEAD && spr->state != CS_DEAD) spr->lastaction = lastmillis; spr->state = state; if (!demoplayback) updatepos(spr); break; } case SV_SOUND: playsound(getint(p), &spr->o); break; case SV_TEXT: sgetstr(); conoutf("%s:\f %s", spr->name, text); break; case SV_MAPCHANGE: sgetstr(); changemapserv(text, getint(p)); mapchanged = true; break; case SV_ITEMLIST: { int n; if (mapchanged) { senditemstoserver = false; resetspawns(); }; while ((n = getint(p)) != -1) { if (mapchanged) setspawn(n, true); } break; } case SV_MAPRELOAD: // server requests next map { getint(p); std::string nextmapalias = std::string("nextmap_") + getclientmap(); std::string map = getalias(nextmapalias); // look up map in the cycle changemap(map.empty() ? getclientmap() : map); break; } case SV_INITC2S: // another client either connected or changed name/team { sgetstr(); if (spr->name[0]) { // already connected if (strcmp(spr->name, text)) conoutf("%s is now known as %s", spr->name, text); } else { // new client c2sinit = false; // send new players my info again conoutf("connected: %s", text); }; strcpy_s(spr->name, text); sgetstr(); strcpy_s(spr->team, text); spr->lifesequence = getint(p); break; } case SV_CDIS: cn = getint(p); if (!(spr = getclient(cn))) break; conoutf("player %s disconnected", spr->name[0] ? spr->name : "[incompatible client]"); zapSprite(players[cn]); break; case SV_SHOT: { int gun = getint(p); Vec3 s, e; s.x = getint(p) / DMF; s.y = getint(p) / DMF; s.z = getint(p) / DMF; e.x = getint(p) / DMF; e.y = getint(p) / DMF; e.z = getint(p) / DMF; if (gun == GUN_SG) createrays(s, e); shootv(gun, s, e, spr); break; } case SV_DAMAGE: { int target = getint(p); int damage = getint(p); int ls = getint(p); if (target == clientnum) { if (ls == player1->lifesequence) selfdamage(damage, cn, spr); } else playsound(S_PAIN1 + rnd(5), &getclient(target)->o); break; } case SV_DIED: { int actor = getint(p); if (actor == cn) { conoutf("%s suicided", spr->name); } else if (actor == clientnum) { int frags; if (isteam(player1->team, spr->team)) { frags = -1; conoutf("you fragged a teammate (%s)", spr->name); } else { frags = 1; conoutf("you fragged %s", spr->name); }; addmsg(1, 2, SV_FRAGS, player1->frags += frags); } else { Sprite *a = getclient(actor); if (a) { if (isteam(a->team, spr->name)) { conoutf("%s fragged his teammate (%s)", a->name, spr->name); } else { conoutf("%s fragged %s", a->name, spr->name); }; }; }; playsound(S_DIE1 + rnd(2), &spr->o); spr->lifesequence++; break; } case SV_FRAGS: players[cn]->frags = getint(p); break; case SV_ITEMPICKUP: setspawn(getint(p), false); getint(p); break; case SV_ITEMSPAWN: { int i = getint(p); setspawn(i, true); if (i >= entityList.size()) break; Vec3 v = { entityList[i].x, entityList[i].y, entityList[i].z }; playsound(S_ITEMSPAWN, &v); break; } case SV_ITEMACC: // server acknowledges that I picked up this item realpickup(getint(p), player1); break; case SV_EDITH: // coop editing messages, should be extended to include all possible editing ops case SV_EDITT: case SV_EDITS: case SV_EDITD: case SV_EDITE: { int x = getint(p); int y = getint(p); int xs = getint(p); int ys = getint(p); int v = getint(p); Rect b = { x, y, xs, ys }; switch (type) { case SV_EDITH: editheightxy(v != 0, getint(p), b); break; case SV_EDITT: edittexxy(v, getint(p), b); break; case SV_EDITS: edittypexy(v, b); break; case SV_EDITD: setvdeltaxy(v, b); break; case SV_EDITE: editequalisexy(v != 0, b); break; }; break; } case SV_EDITENT: // coop edit of ent { int i = getint(p); while (entityList.size() <= i) { entityList.emplace_back(Entity()); entityList.back().type = NOTUSED; } int to = entityList[i].type; entityList[i].type = getint(p); entityList[i].x = getint(p); entityList[i].y = getint(p); entityList[i].z = getint(p); entityList[i].attr1 = getint(p); entityList[i].attr2 = getint(p); entityList[i].attr3 = getint(p); entityList[i].attr4 = getint(p); entityList[i].spawned = false; if (entityList[i].type == LIGHT || to == LIGHT) calclight(); break; } case SV_PING: getint(p); break; case SV_PONG: addmsg(0, 2, SV_CLIENTPING, player1->ping = (player1->ping * 5 + lastmillis - getint(p)) / 6); break; case SV_CLIENTPING: players[cn]->ping = getint(p); break; case SV_GAMEMODE: nextmode = getint(p); break; case SV_TIMEUP: timeupdate(getint(p)); break; case SV_RECVMAP: { sgetstr(); conoutf("received map \"%s\" from server, reloading..", text); int mapsize = getint(p); writemap(text, mapsize, p); p += mapsize; changemapserv(text, gamemode); break; } case SV_SERVMSG: sgetstr(); conoutf("%s", text); break; case SV_EXT: // so we can messages without breaking previous clients/servers, if necessary { for (int n = getint(p); n; n--) getint(p); break; } default: neterr("type"); return; } }
int GeneDouble :: mutate(const double& lo, const double& hi) { geneVal = lo + rnd(hi - lo); return 0; }
void main(int argc, char *argv[]) { int i, c; char *a; char name[LIBNAMELEN]; Binit(&bso, 1, OWRITE); cout = -1; listinit(); memset(debug, 0, sizeof(debug)); nerrors = 0; outfile = "6.out"; HEADTYPE = -1; INITTEXT = -1; INITTEXTP = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; ARGBEGIN { default: c = ARGC(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': /* output to (next arg) */ outfile = ARGF(); break; case 'E': a = ARGF(); if(a) INITENTRY = a; break; case 'H': a = ARGF(); if(a) HEADTYPE = atolwhex(a); break; case 'L': addlibpath(EARGF(usage())); break; case 'T': a = ARGF(); if(a) INITTEXT = atolwhex(a); break; case 'P': a = ARGF(); if(a) INITTEXTP = atolwhex(a); break; case 'D': a = ARGF(); if(a) INITDAT = atolwhex(a); break; case 'R': a = ARGF(); if(a) INITRND = atolwhex(a); break; case 'x': /* produce export table */ doexp = 1; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SEXPORT); break; case 'u': /* produce dynamically loadable module */ dlm = 1; debug['l']++; if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1])) readundefs(ARGF(), SIMPORT); break; } ARGEND USED(argc); if(*argv == 0) usage(); if(!debug['9'] && !debug['U'] && !debug['B']) debug[DEFAULT] = 1; a = getenv("ccroot"); if(a != nil && *a != '\0') { if(!fileexists(a)) { diag("nonexistent $ccroot: %s", a); errorexit(); } }else a = ""; snprint(name, sizeof(name), "%s/%s/lib", a, thestring); addlibpath(name); if(HEADTYPE == -1) { if(debug['B']) HEADTYPE = 2; if(debug['9']) HEADTYPE = 2; } switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case 2: /* plan 9 */ HEADR = 32L+8L; if(INITTEXT == -1) INITTEXT = 0x200000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 0x200000; break; case 5: /* elf32 executable */ HEADR = rnd(Ehdr32sz+3*Phdr32sz, 16); if(INITTEXT == -1) INITTEXT = 0xf0110000L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case 6: /* ELF64 executable */ HEADR = rnd(Ehdr64sz+3*Phdr64sz, 16); if(INITTEXT == -1) INITTEXT = 0x200000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 0x200000; break; } if (INITTEXTP == -1) INITTEXTP = INITTEXT; if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%llux is ignored because of -R0x%lux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H%ld -T0x%llux -D0x%llux -R0x%lux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); for(i=1; optab[i].as; i++) { c = optab[i].as; if(opindex[c] != nil) { diag("phase error in optab: %d (%A)", i, c); errorexit(); } opindex[c] = &optab[i]; } for(i=0; i<Ymax; i++) ycover[i*Ymax + i] = 1; ycover[Yi0*Ymax + Yi8] = 1; ycover[Yi1*Ymax + Yi8] = 1; ycover[Yi0*Ymax + Ys32] = 1; ycover[Yi1*Ymax + Ys32] = 1; ycover[Yi8*Ymax + Ys32] = 1; ycover[Yi0*Ymax + Yi32] = 1; ycover[Yi1*Ymax + Yi32] = 1; ycover[Yi8*Ymax + Yi32] = 1; ycover[Ys32*Ymax + Yi32] = 1; ycover[Yi0*Ymax + Yi64] = 1; ycover[Yi1*Ymax + Yi64] = 1; ycover[Yi8*Ymax + Yi64] = 1; ycover[Ys32*Ymax + Yi64] = 1; ycover[Yi32*Ymax + Yi64] = 1; ycover[Yal*Ymax + Yrb] = 1; ycover[Ycl*Ymax + Yrb] = 1; ycover[Yax*Ymax + Yrb] = 1; ycover[Ycx*Ymax + Yrb] = 1; ycover[Yrx*Ymax + Yrb] = 1; ycover[Yrl*Ymax + Yrb] = 1; ycover[Ycl*Ymax + Ycx] = 1; ycover[Yax*Ymax + Yrx] = 1; ycover[Ycx*Ymax + Yrx] = 1; ycover[Yax*Ymax + Yrl] = 1; ycover[Ycx*Ymax + Yrl] = 1; ycover[Yrx*Ymax + Yrl] = 1; ycover[Yf0*Ymax + Yrf] = 1; ycover[Yal*Ymax + Ymb] = 1; ycover[Ycl*Ymax + Ymb] = 1; ycover[Yax*Ymax + Ymb] = 1; ycover[Ycx*Ymax + Ymb] = 1; ycover[Yrx*Ymax + Ymb] = 1; ycover[Yrb*Ymax + Ymb] = 1; ycover[Yrl*Ymax + Ymb] = 1; ycover[Ym*Ymax + Ymb] = 1; ycover[Yax*Ymax + Yml] = 1; ycover[Ycx*Ymax + Yml] = 1; ycover[Yrx*Ymax + Yml] = 1; ycover[Yrl*Ymax + Yml] = 1; ycover[Ym*Ymax + Yml] = 1; ycover[Yax*Ymax + Ymm] = 1; ycover[Ycx*Ymax + Ymm] = 1; ycover[Yrx*Ymax + Ymm] = 1; ycover[Yrl*Ymax + Ymm] = 1; ycover[Ym*Ymax + Ymm] = 1; ycover[Ymr*Ymax + Ymm] = 1; ycover[Yax*Ymax + Yxm] = 1; ycover[Ycx*Ymax + Yxm] = 1; ycover[Yrx*Ymax + Yxm] = 1; ycover[Yrl*Ymax + Yxm] = 1; ycover[Ym*Ymax + Yxm] = 1; ycover[Yxr*Ymax + Yxm] = 1; for(i=0; i<D_NONE; i++) { reg[i] = -1; if(i >= D_AL && i <= D_R15B) { reg[i] = (i-D_AL) & 7; if(i >= D_SPB && i <= D_DIB) regrex[i] = 0x40; if(i >= D_R8B && i <= D_R15B) regrex[i] = Rxr | Rxx | Rxb; } if(i >= D_AH && i<= D_BH) reg[i] = 4 + ((i-D_AH) & 7); if(i >= D_AX && i <= D_R15) { reg[i] = (i-D_AX) & 7; if(i >= D_R8) regrex[i] = Rxr | Rxx | Rxb; } if(i >= D_F0 && i <= D_F0+7) reg[i] = (i-D_F0) & 7; if(i >= D_M0 && i <= D_M0+7) reg[i] = (i-D_M0) & 7; if(i >= D_X0 && i <= D_X0+15) { reg[i] = (i-D_X0) & 7; if(i >= D_X0+8) regrex[i] = Rxr | Rxx | Rxb; } if(i >= D_CR+8 && i <= D_CR+15) regrex[i] = Rxr; } zprg.link = P; zprg.pcond = P; zprg.back = 2; zprg.as = AGOK; zprg.from.type = D_NONE; zprg.from.index = D_NONE; zprg.from.scale = 1; zprg.to = zprg.from; zprg.mode = 64; pcstr = "%.6llux "; nuxiinit(); histgen = 0; textp = P; datap = P; edatap = P; pc = 0; dtype = 4; cout = create(outfile, 1, 0775); if(cout < 0) { diag("cannot create %s: %r", outfile); errorexit(); } version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); firstp = prg(); lastp = firstp; if(INITENTRY == 0) { INITENTRY = "_main"; if(debug['p']) INITENTRY = "_mainp"; if(!debug['l']) lookup(INITENTRY, 0)->type = SXREF; } else if(!(*INITENTRY >= '0' && *INITENTRY <= '9')) lookup(INITENTRY, 0)->type = SXREF; while(*argv) objfile(*argv++); if(!debug['l']) loadlib(); firstp = firstp->link; if(firstp == P) errorexit(); if(doexp || dlm){ EXPTAB = "_exporttab"; zerosig(EXPTAB); zerosig("etext"); zerosig("edata"); zerosig("end"); if(dlm){ import(); HEADTYPE = 2; INITTEXT = 0; INITDAT = 0; INITRND = 8; INITENTRY = EXPTAB; } export();
void W(point & r1, point_ & r1_, point & r2, point_ & r2_, n_type &u, n_type & a1, n_type &a2) //"perturbation generator" //generates time points and zone numbers, so that U=\bar{u} { double tau=beta*rnd(); r1.t=tau; r1_.t=tau; r2.t=tau; r2_.t=tau; r1.i=0; r1_.i=0; r2.i=0; r2_.i=0; int i=rnd(n_zone/2); int j=rnd(n_zone/2); while (j==i) j=rnd(n_zone/2); int n_terms=4; int term=rnd(n_terms); n_type C=n_zone/2; switch (term) { case 0 : // nn { // r1.i=i; r1_.i=i; r2.i=i; r2_.i=i; int z=rnd(2); r1.z=2*i+z; r1_.z=2*i+z; r2.z=2*i+1-z; r2_.z=2*i+1-z; u=n_terms*beta*U*C; break; ;} case 1 : // ss { // r1.i=i; r1_.i=i; r2.i=j; r2_.i=j; int z=rnd(2); r1.z=2*i+z; r1_.z=2*i+z; r2.z=2*j+1-z; r2_.z=2*j+1-z; u=n_terms*beta*(U-2*J)*C*(C-1); break; ;} case 2 : //s { // r1.i=i; r1_.i=i; r2.i=j; r2_.i=j; int z=rnd(2); r1.z=2*i+z; r1_.z=2*i+z; r2.z=2*j+z; r2_.z=2*j+z; u=n_terms*beta*(U-3*J)*C*(C-1); break; ;} case 3 : //ss { // r1.i=i; r1_.i=j; r2.i=j; r2_.i=i; int z=rnd(2); r1.z=2*i+z; r1_.z=2*j+z; r2.z=2*j+1-z; r2_.z=2*i+1-z; u=-n_terms*beta*J*C*(C-1); break; ;} /* case 4 : //pair hopping 2 { // r1.i=j; r1_.i=i; r2.i=j; r2_.i=i; int z=rnd(2); r1.z=2*j+z; r1_.z=2*i+z; r2.z=2*j+1-z; r2_.z=2*i+1-z; u=-n_terms*beta*J*C*(C-1); break; ;}*/ } define_alpha(r1,r1_,r2,r2_,u,a1,a2);//alpha's are defined by a standard recipe ;}
void objectai(int objectnum) { float vec[3]; float intersectpoint[3]; float normal[3]; float scale; object[objectnum].axis[0]=0.0f; object[objectnum].axis[1]=0.0f; object[objectnum].button=0; if (object[objectnum].type==1) if (game.levelnum==34) { /* object[objectnum].axis[0]=-object[0].axis[0]; object[objectnum].axis[1]=object[0].axis[0]; object[objectnum].button=object[0].button; */ subtractvectors(vec,object[0].position,object[objectnum].position); if (vec[0]<-0.5f) object[objectnum].axis[0]=-1.0f; if (vec[0]>0.5f) object[objectnum].axis[0]=1.0f; if (vectorlength(vec)<2.0f) object[objectnum].button|=8; /* subtractvectors(vec,object[2].position,object[objectnum].position); if (vectorlength(vec)>3.0f) object[objectnum].button=1; */ } if (object[objectnum].type==4) { if (object[0].idata[0]==0) if (fabs(object[0].position[0]-object[objectnum].position[0])<12.0f) if (fabs(object[0].position[1]-object[objectnum].position[1])<8.0f) { if (object[objectnum].beasttype!=7 && object[objectnum].beasttype!=13) { subtractvectors(vec,object[0].position,object[objectnum].position); if ((vec[0]>-2.5f && vec[0]<0.0f && object[objectnum].direction==0) || (vec[0]<2.5f && vec[0]>0.0f && object[objectnum].direction==1)) if (fabs(vec[1])<1.0f) object[objectnum].button|=1; //if (object[objectnum].beasttype==12) //if ((game.framenum&511)==0) // object[objectnum].button|=2; if ((rnd()&7)!=7) { if (object[0].position[0]<object[objectnum].position[0]) object[objectnum].axis[0]-=1.0f; else object[objectnum].axis[0]+=1.0f; if (object[objectnum].beasttype!=12) if ((rnd()&255)==0) object[objectnum].button|=2; if (object[objectnum].beasttype==12) if ((rnd()&255)==0 && (rnd()&1)==0) object[objectnum].button|=2; } } else { subtractvectors(vec,object[0].position,object[objectnum].position); if (vec[0]>-8.0f && vec[0]<8.0f) if (fabs(vec[1])<6.0f) if ((game.framenum&127)==0) object[objectnum].button|=1; /* if (object[0].position[0]<object[objectnum].position[0]-5.0f) object[objectnum].axis[0]-=1.0f; if (object[0].position[0]>object[objectnum].position[0]+5.0f) object[objectnum].axis[0]+=1.0f; */ //if (object[0].position[0]<object[objectnum].position[0]) if (object[0].position[0]<object[objectnum].position[0]-5.0f) { scaleaddvectors(vec,object[objectnum].position,object[objectnum].orientation[0],-3.0f); scaleaddvectors(vec,vec,object[objectnum].orientation[1],-2.0); if (lineintersectlevel(intersectpoint,normal,&scale,object[objectnum].position,vec)) object[objectnum].axis[0]-=1.0f; else { if (object[objectnum].velocity[0]<-0.01f) object[objectnum].axis[0]+=1.0f; } } if (object[0].position[0]>object[objectnum].position[0]+5.0f) { scaleaddvectors(vec,object[objectnum].position,object[objectnum].orientation[0],3.0f); scaleaddvectors(vec,vec,object[objectnum].orientation[1],-2.0f); if (lineintersectlevel(intersectpoint,normal,&scale,object[objectnum].position,vec)) object[objectnum].axis[0]+=1.0f; else { if (object[objectnum].velocity[0]>0.01f) object[objectnum].axis[0]-=1.0f; } } } } } if (object[objectnum].axis[0]<-1.0f) object[objectnum].axis[0]=-1.0f; if (object[objectnum].axis[0]>1.0f) object[objectnum].axis[0]=1.0f; if (object[objectnum].axis[1]<-1.0f) object[objectnum].axis[1]=-1.0f; if (object[objectnum].axis[1]>1.0f) object[objectnum].axis[1]=1.0f; }
bool CACBot::ChoosePreferredWeapon() { if(lastmillis < m_iChangeWeaponDelay) return false; short bestWeapon = m_pMyEnt->gunselect; short bestWeaponScore = SHRT_MIN; short sWeaponScore; float flDist = GetDistance(m_pMyEnt->enemy->o); char bestWeap[NUMGUNS]; loopi(NUMGUNS) bestWeap[i] = 0; // Choose a weapon for(int i=0; i<NUMGUNS; i++) { sWeaponScore = primary_weap(i) ? 5 : 0; // Primary are usually better if (!m_pMyEnt->mag[i] && WeaponInfoTable[i].eWeaponType != TYPE_MELEE) continue; sWeaponScore += 3*m_pMyEnt->weapstats[i].kills/(m_pMyEnt->weapstats[i].deaths ? m_pMyEnt->weapstats[i].deaths : 0.5f); sWeaponScore -= 2*m_pMyEnt->weapstats[i].deaths/(m_pMyEnt->weapstats[i].kills ? m_pMyEnt->weapstats[i].kills : 0.5f); if((flDist >= WeaponInfoTable[i].flMinDesiredDistance) && (flDist <= WeaponInfoTable[i].flMaxDesiredDistance)) { // In desired range for this weapon sWeaponScore += 5; // Increase score much if(i == GUN_PISTOL || WeaponInfoTable[i].eWeaponType == TYPE_MELEE) { if(WeaponInfoTable[m_pMyEnt->primary].eWeaponType == TYPE_SNIPER) sWeaponScore += 10; // At a close range, knife & pistol are strong with a sniper like primary weapon if(WeaponInfoTable[m_pMyEnt->primary].eWeaponType == TYPE_SHOTGUN) sWeaponScore -= 2; // Penalize a bit knife and pistol on close range with shotgun } } else if (((flDist < WeaponInfoTable[i].flMinFireDistance) || (flDist > WeaponInfoTable[i].flMaxFireDistance)) && i != GUN_GRENADE && i != GUN_RPG) continue; // Wrong distance for this weapon if(i == GUN_GRENADE) sWeaponScore += 30; // Nades have high priority // Score on the distance to the ideal distance float flIdealDiff = fabs(flDist - WeaponInfoTable[i].flIdealDistance); if(flIdealDiff < 1.0f) sWeaponScore += 10; else if(flIdealDiff <= 5.0f) sWeaponScore += 4; else if(flIdealDiff <= 7.5f) sWeaponScore += 2; else if(flIdealDiff <= 10.0f) ++sWeaponScore; // Now rate the weapon on available ammo in magazine... if (WeaponInfoTable[i].sMinDesiredAmmo > 0) { // Calculate how much percent of the min desired ammo in mag the bot has float flDesiredPercent = (float(m_pMyEnt->mag[i])/float(WeaponInfoTable[i].sMinDesiredAmmo))*100.0f; if (flDesiredPercent >= 400.0f) sWeaponScore += 10; else if (flDesiredPercent >= 200.0f) sWeaponScore += 8; else if (flDesiredPercent >= 100.0f) sWeaponScore += 3; else if (flDesiredPercent >= 50.0f) sWeaponScore -= 2; else sWeaponScore -= 5; } else sWeaponScore += 15; // Not needing ammo is an advantage... if(sWeaponScore > bestWeaponScore) { bestWeaponScore = sWeaponScore; bestWeapon = i; loopi(bestWeapon) bestWeap[i] = 0; bestWeap[bestWeapon] = 1; } else if(sWeaponScore == bestWeaponScore) bestWeap[i] = 1; } int tie = 0; loopi(NUMGUNS) tie += bestWeap[i]; if (tie) { if (tie > 1) { int select = rnd(tie), i = 0; while (select >= 0) { bestWeapon = i; select -= bestWeap[i++]; } } } else bestWeapon = GUN_KNIFE; return SelectGun(bestWeapon); };
static Word cbsRnd(Word limit) { /* Not very uniform, but never mind. */ return (Word)rnd() % limit; }
void span(void) { Prog *p, *q; long v, c, idat; int m, n, again; xdefine("etext", STEXT, 0L); idat = INITDAT; for(p = firstp; p != P; p = p->link) { if(p->as == ATEXT) curtext = p; n = 0; if(p->to.type == D_BRANCH) if(p->pcond == P) p->pcond = p; if((q = p->pcond) != P) if(q->back != 2) n = 1; p->back = n; if(p->as == AADJSP) { p->to.type = D_SP; v = -p->from.offset; p->from.offset = v; p->as = AADDL; if(v < 0) { p->as = ASUBL; v = -v; p->from.offset = v; } if(v == 0) p->as = ANOP; } } n = 0; start: if(debug['v']) Bprint(&bso, "%5.2f span\n", cputime()); Bflush(&bso); c = INITTEXT; for(p = firstp; p != P; p = p->link) { if(p->as == ATEXT) curtext = p; if(p->to.type == D_BRANCH) if(p->back) p->pc = c; asmins(p); p->pc = c; m = andptr-and; p->mark = m; c += m; } loop: n++; if(debug['v']) Bprint(&bso, "%5.2f span %d\n", cputime(), n); Bflush(&bso); if(n > 50) { print("span must be looping\n"); errorexit(); } again = 0; c = INITTEXT; for(p = firstp; p != P; p = p->link) { if(p->as == ATEXT) curtext = p; if(p->to.type == D_BRANCH) { if(p->back) p->pc = c; asmins(p); m = andptr-and; if(m != p->mark) { p->mark = m; again++; } } p->pc = c; c += p->mark; } if(again) { textsize = c; goto loop; } if(INITRND) { INITDAT = rnd(c, INITRND); if(INITDAT != idat) { idat = INITDAT; goto start; } } xdefine("etext", STEXT, c); if(debug['v']) Bprint(&bso, "etext = %lux\n", c); Bflush(&bso); for(p = textp; p != P; p = p->pcond) p->from.sym->value = p->pc; textsize = c - INITTEXT; }
void main(){ //init pattern { asm("lda #$00"); //*(char*)(0x2006)=0; asm("sta $2006"); //*(char*)(0x2006)=0; asm("sta $2006"); //for(i=0;i<255;i++) asm("ldx #$00"); for1: //*(char*)(0x2007)=img1[i]; asm("lda %v,X",img1); asm("sta $2007"); asm("inx"); asm("cpx #$FF"); asm("bne %g",for1); //*(char*)(0x2007)=img1[255]; asm("lda %v,X",img1); asm("sta $2007"); //for(i=0;i<255;i++) asm("ldx #$00"); for2: //*(char*)(0x2007)=img2[i]; asm("lda %v,X",img2); asm("sta $2007"); asm("inx"); asm("cpx #$FF"); asm("bne %g",for2); //*(char*)(0x2007)=img1[255]; asm("lda %v,X",img2); asm("sta $2007"); } //clear SP { //*(char*)(0x2003)=0; //i<<2 asm("lda #$00"); asm("sta $2003"); //for(i=255;i>0;i--) asm("ldx #$FF"); for3: //*(char*)(0x2004)=0; asm("sta $2004"); asm("dex"); asm("bne %g",for3); //*(char*)(0x2004)=0; asm("sta $2004"); } //set background black { //*(char*)(0x2006)=0x20; asm("lda #$20");asm("sta $2006"); //*(char*)(0x2006)=0x20; asm("sta $2006"); //for(i=0;i<255;i++) asm("lda #$10"); asm("ldx #$FF"); for4: //*(char*)(0x2007)=0x10; asm("sta $2007"); asm("dex"); asm("bne %g",for4); //*(char*)(0x2007)=0x10; asm("sta $2007"); //for(i=0;i<255;i++) asm("ldx #$FF"); for5: //*(char*)(0x2007)=0x10; asm("sta $2007"); asm("dex"); asm("bne %g",for5); //*(char*)(0x2007)=0x10; asm("sta $2007"); //for(i=0;i<255;i++) asm("ldx #$FF"); for6: //*(char*)(0x2007)=0x10; asm("sta $2007"); asm("dex"); asm("bne %g",for6); //*(char*)(0x2007)=0x10; asm("sta $2007"); //for(i=0;i<128;i++) asm("ldx #$80"); for7: //*(char*)(0x2007)=0x10; asm("sta $2007"); asm("dex"); asm("bne %g",for7); } //set color { //*(char*)(0x2006)=0x3F; asm("lda #$3F");asm("sta $2006"); //*(char*)(0x2006)=0x00; asm("ldx #$00");asm("stx $2006"); //*(char*)(0x2007)=0x2C; asm("ldx #$2C");asm("stx $2007"); //*(char*)(0x2007)=0x30; asm("ldx #$30");asm("stx $2007"); //*(char*)(0x2007)=0x00; asm("ldx #$00");asm("stx $2007"); //*(char*)(0x2007)=0x3F; asm("sta $2007"); //*(char*)(0x2006)=0x3F; asm("sta $2006"); //*(char*)(0x2006)=0x11; asm("ldx #$11");asm("stx $2006"); //*(char*)(0x2007)=0x30; asm("ldx #$30");asm("stx $2007"); //*(char*)(0x2007)=0x22; asm("ldx #$22");asm("stx $2007"); //*(char*)(0x2007)=0x3F; asm("sta $2007"); } //show init title { //*(char*)(0x2006)=0x20; asm("lda #$20");asm("sta $2006"); //*(char*)(0x2006)=0xC5; asm("lda #$C5");asm("sta $2006"); //*(char*)(0x2007)=0x11; asm("ldx #$11");asm("stx $2007"); //*(char*)(0x2007)=0x12; asm("inx");asm("stx $2007"); //*(char*)(0x2007)=0x13; asm("inx");asm("stx $2007"); //*(char*)(0x2007)=0x14; asm("inx");asm("stx $2007"); //*(char*)(0x2007)=0x10; asm("lda #$10");asm("sta $2007"); //*(char*)(0x2007)=0x15; asm("inx");asm("stx $2007"); //*(char*)(0x2007)=0x10; asm("sta $2007"); //*(char*)(0x2007)=0x16; asm("inx");asm("stx $2007"); //*(char*)(0x2007)=0x17; asm("inx");asm("stx $2007"); //*(char*)(0x2007)=0x18; asm("inx");asm("stx $2007"); //*(char*)(0x2005) = 0; asm("stx $2005"); //*(char*)(0x2005) = 0; asm("stx $2005"); } //init ppu { //*(char*)(0x2000) = 0x80; //10 00 00 00 asm("lda #$80");asm("sta $2000"); //*(char*)(0x2001) = 0x18; //00 01 10 00 asm("lda #$18");asm("sta $2001"); //*(char*)(0x2005) = 0; asm("lda #$00");asm("sta $2005"); //*(char*)(0x2005) = 0; asm("sta $2005"); } //wait for key pressed (randomize) while1: rnd(); readJoystick(); asm("lda %b",key1); //if(key1)break; asm("bne %g",endwhile1); asm("jmp %g",while1); endwhile1: Clear(); //clear 4*4 nextShape { waitvblank(); asm("ldx #$00"); //*(char*)(0x2006)=0x20; asm("lda #$20");asm("sta $2006"); //*(char*)(0x2006)=0xAE; asm("lda #$AE");asm("sta $2006"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2006)=0x20; asm("lda #$20");asm("sta $2006"); //*(char*)(0x2006)=0xCE; asm("lda #$CE");asm("sta $2006"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2006)=0x20; asm("lda #$20");asm("sta $2006"); //*(char*)(0x2006)=0xEE; asm("lda #$EE");asm("sta $2006"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2006)=0x21; asm("lda #$21");asm("sta $2006"); //*(char*)(0x2006)=0x0E; asm("lda #$0E");asm("sta $2006"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2007)=0; asm("stx $2007"); //*(char*)(0x2005) = 0; asm("stx $2005"); //*(char*)(0x2005) = 0; asm("stx $2005"); } NextShape(); NextShape(); //main cycle { //main_cnt = 50; asm("lda #$32"); asm("sta %b",main_cnt); while2: rnd(); waitvblank(); //one second count //if(main_cnt--==0) asm("dec %b",main_cnt); asm("bne %g",else1); //main_cnt=50; asm("lda #$32"); asm("sta %b",main_cnt); slowdown(); else1: readJoystick(); //key2 = key1 ^ lastkey; asm("lda %b",key1); asm("eor %b",lastkey); //key2 = key2 & key1; asm("and %b",key1); //if(key2!=0) asm("beq %g",else2); asm("sta %b",key2); //if(key2&0x01){movelr_n=1;movelr();}//button_RIGHT asm("and #$01"); asm("beq %g",elseKey1); asm("lda #$01"); asm("sta %b",movelr_n); movelr(); elseKey1: //if(key2&0x02){movelr_n=-1;movelr();}//button_LEFT asm("lda %b",key2); asm("and #$02"); asm("beq %g",elseKey2); asm("lda #$FF"); asm("sta %b",movelr_n); movelr(); elseKey2: //if(key2&0x04)down();//button_DOWN asm("lda %b",key2); asm("and #$04"); asm("beq %g",elseKey3); down(); elseKey3: //if(key2&0x08)slowdown();//button_UP asm("lda %b",key2); asm("and #$08"); asm("beq %g",elseKey4); slowdown(); elseKey4: //if(key2&0x10);//button_START //if(key2&0x20);//button_SELECT //if(key2&0x40){rotate_n=-1;rotate();}//button_B asm("lda %b",key2); asm("and #$40"); asm("beq %g",elseKey5); asm("lda #$FF"); asm("sta %b",rotate_n); rotate(); elseKey5: //if(key2&0x80){rotate_n=1;rotate();}//button_A asm("lda %b",key2); asm("and #$80"); asm("beq %g",elseKey6); asm("lda #$01"); asm("sta %b",rotate_n); rotate(); elseKey6: else2: //lastkey = key1; asm("lda %b",key1); asm("sta %b",lastkey); asm("jmp %g",while2); } }
/* a subroutine to raise or lower character levels if x > 0 they are raised if x < 0 they are lowered */ void fntchange(int how) { long j; lprc('\n'); switch (rnd(9)) { case 1: lprcat("Your strength"); fch(how, &c[0]); break; case 2: lprcat("Your intelligence"); fch(how, &c[1]); break; case 3: lprcat("Your wisdom"); fch(how, &c[2]); break; case 4: lprcat("Your constitution"); fch(how, &c[3]); break; case 5: lprcat("Your dexterity"); fch(how, &c[4]); break; case 6: lprcat("Your charm"); fch(how, &c[5]); break; case 7: j = rnd(level + 1); if (how < 0) { lprintf("You lose %ld hit point", (long) j); if (j > 1) lprcat("s!"); else lprc('!'); losemhp((int) j); } else { lprintf("You gain %ld hit point", (long) j); if (j > 1) lprcat("s!"); else lprc('!'); raisemhp((int) j); } bottomline(); break; case 8: j = rnd(level + 1); if (how > 0) { lprintf("You just gained %ld spell", (long) j); raisemspells((int) j); if (j > 1) lprcat("s!"); else lprc('!'); } else { lprintf("You just lost %ld spell", (long) j); losemspells((int) j); if (j > 1) lprcat("s!"); else lprc('!'); } bottomline(); break; case 9: j = 5 * rnd((level + 1) * (level + 1)); if (how < 0) { lprintf("You just lost %ld experience point", (long) j); if (j > 1) lprcat("s!"); else lprc('!'); loseexperience((long) j); } else { lprintf("You just gained %ld experience point", (long) j); if (j > 1) lprcat("s!"); else lprc('!'); raiseexperience((long) j); } break; } cursors(); }
miTag createNativeParticles(miState *state, mrParticleGeoShader_paras *paras, PartioContainer& pc) { miBoolean useAllAttributes = *mi_eval_boolean(¶s->useAllAttributes); int i_a = *mi_eval_integer(¶s->i_attributeNames); int n_a = *mi_eval_integer(¶s->n_attributeNames); miTag *attributeNames = mi_eval_tag(paras->attributeNames) + i_a; if( !pc.good()) { mi_info("createNativeParticles: Invalid patioContainer"); return miNULLTAG; } Partio::ParticleAttribute posAttr; if(!pc.assertAttribute("position", posAttr)) { mi_info("createNativeParticles: partioContainer: no position."); return miNULLTAG; } Partio::ParticleAttribute idAttr; bool hasId = true; if(!pc.assertAttribute("id", idAttr)) hasId = false; Partio::ParticleAttribute radiusPPAttr; bool hasRadiusPP = true; if(!pc.assertAttribute("radiusPP", radiusPPAttr)) hasRadiusPP = false; Partio::ParticleAttribute radiusRGBPPAttr; bool hasRgbPP = true; if(!pc.assertAttribute("rgbPP", radiusRGBPPAttr)) hasRgbPP = false; mi_info("Creating native particles for cache file: %s", pc.cacheFileName.c_str()); // declare the map as a 3-dimensional map mi_api_map_decl_dim ( 3 ); // the 'mi_api_map_field_decl' function takes four arguments: // // miParam_type type: basic type of the field (miTYPE_SCALAR or miTYPE_INTEGER) // char *name : field name // int dimension : dimension of the field, 0 for single values, > 0 for arrays // miBoolean global : miTRUE if it's a global field, miFALSE otherwise // add the "extension" field as a single float miParameter *extension_field = mi_api_map_field_decl ( miTYPE_SCALAR , mi_mem_strdup("extension") , 0 , miFALSE ); // add the "color" field as an array of 1 color miParameter *color_field = mi_api_map_field_decl ( miTYPE_SCALAR , mi_mem_strdup("color") , 3 , miFALSE ); // append the color to the extension for the declaration // (this also frees the 'color_field' miParameter) miParameter *fields_list = mi_api_map_field_append ( extension_field , color_field ); // create a declaration called "particles" with the given fields list // (this also frees the 'fields_list' miParameter) miMap_decl *decl = mi_api_map_decl_begin ( mi_mem_strdup("particles") , fields_list ); // ends the declaration mi_api_map_decl_end (); // Then you begin the object definition, by calling 'mi_api_object_begin' and possibly setting the object flags as needed, then you begin the definition of the particle object as a set of spheres: miObject *obj = mi_api_object_begin(mi_mem_strdup("TestParticleObject")); obj->visible = miTRUE; // begin the definition of the particle object as spheres mi_api_map_obj_type ( mi_mem_strdup("spheres") ); // the 'mi_api_map_obj_field' function takes 2 arguments: // // char *field_name : name of the field to map ("radius" in this case) // char *mapped_name : name of the mapped field ("extension" in this case) // maps the "radius" field to the "extension" field of this map mi_api_map_obj_field( mi_mem_strdup("radius") , mi_mem_strdup("extension") ); // begins the definition of the map, taking "particles" as the declaration name mi_api_map_begin ( mi_mem_strdup("particles") ); int num_elements = pc.data->numParticles(); for ( int i = 0 ; i < num_elements ; ++i ) { float pos[3]; pc.getPosition(i, pos); // define the position of this element mi_api_map_value ( miTYPE_SCALAR , &pos[0] ); mi_api_map_value ( miTYPE_SCALAR , &pos[1] ); mi_api_map_value ( miTYPE_SCALAR , &pos[2] ); mi_api_map_field_end (); float radiusPP = 1.0f; if( hasRadiusPP ) radiusPP = *pc.data->data<float>(radiusPPAttr, i); radiusPP = rnd() * 0.3; // define the radius of this element mi_api_map_value ( miTYPE_SCALAR , &radiusPP ); mi_api_map_field_end (); // // compute the color in r, g and b // miScalar r = rnd(); miScalar g = rnd(); miScalar b = rnd(); miColor col; col.r = r; col.g = g; col.b = b; // define the color of this element //mi_api_map_value ( miTYPE_COLOR , &col ); mi_api_map_value ( miTYPE_SCALAR , &r ); mi_api_map_value ( miTYPE_SCALAR , &g ); mi_api_map_value ( miTYPE_SCALAR , &b ); mi_api_map_field_end(); // end the definition of this element mi_api_map_element_end (); } // terminates the map definition and stores it in the DB miTag map_tag = mi_api_map_end ( 0 ); miTag particleObjTag = mi_api_object_end(); miEchoOptions options; memset(&options, 0, sizeof(options)); options.ascii_output = true; options.compressed_output = false; options.dont_echo = false; mi_info("Writing to geodump.mi file."); const char *mode = "w"; FILE *fh = fopen("C:/daten/3dprojects/Maya2013/scenes/geodump.mi", mode); //mi_geoshader_echo_tag(fh, particleObjTag, &options); fclose(fh); mi::shader::Access_map map(map_tag); mi::shader::Map_status status; mi::shader::Map_declaration map_declaration(map, &status); mi::shader::Map_field_id field_id = map_declaration->get_field_id(mi_mem_strdup("color"), &status); if (!status.is_ok()) { mi_error("problems getting field_id for color"); return particleObjTag; } mi_info("Field id %d", field_id); mi::shader::Map_field_type f_type; miUint f_dimension; bool f_is_global; status = map_declaration->get_field_info(field_id, f_type, f_dimension, f_is_global); if (!status.is_ok()) { mi_error("problems get_field_info"); return particleObjTag; } mi_info("Field type %d is global %d", f_type.type(), f_is_global); return particleObjTag; }
miTag createMeshParticles(miState *state, mrParticleGeoShader_paras *paras, PartioContainer& pc) { mi_info("Creating mesh particles for cache file: %s", pc.cacheFileName.c_str()); if( ! pc.good()) { mi_error("Invalid PartioContainer."); return miNULLTAG; } Partio::ParticleAttribute posAttr; if(!pc.assertAttribute("position", posAttr)) return miNULLTAG; Partio::ParticleAttribute idAttr; bool hasId = true; if(!pc.assertAttribute("id", idAttr)) hasId = false; Partio::ParticleAttribute radiusPPAttr; bool hasRadiusPP = true; if(!pc.assertAttribute("radiusPP", radiusPPAttr)) hasRadiusPP = false; Partio::ParticleAttribute velocityAttr; bool hasVelocity = true; if(!pc.assertAttribute("velocity", velocityAttr)) hasVelocity = false; miObject *obj = beginObject(); float *fpos; srand(123345); int numParticles = pc.data->numParticles(); float sizeMultiplier = *mi_eval_scalar(¶s->sizeMultiplier); float density = *mi_eval_scalar(¶s->density); float size = *mi_eval_scalar(¶s->size); float sizeVariation = *mi_eval_scalar(¶s->sizeVariation); // particle number can vary because of density value int numWrittenParticles = 0; // define vectors for(int vtxId = 0; vtxId < numParticles; vtxId++) { miVector pos; fpos = (float *)pc.data->data<float>(posAttr, vtxId); int id = vtxId; if( hasId) id = *pc.data->data<int>(idAttr, vtxId); float radiusPP = 1.0f; if( hasRadiusPP ) radiusPP = *pc.data->data<float>(radiusPPAttr, vtxId); miVector vel = {0.0, 0.0, 0.0}; if(hasVelocity) { float *v; v = (float *)pc.data->data<float>(velocityAttr, vtxId); vel.x = v[0]; vel.y = v[1]; vel.z = v[2]; // velocity ist distance/sekunde, eine velocity von 24 legt also eine Distanz von 1 Einheit pro frame bei 24fps zurück // zusätzlich muss man noch den shutter angle beachten, bei 140° sind das -.2 -> 0.2 also 0.4 * 1 und damit grob .4 Einheiten float factor = 1.0f/24.0f * 0.4f; mi_vector_mul(&vel, factor); } pos.x = fpos[0]; pos.y = fpos[1]; pos.z = fpos[2]; miVector camPos = pos; // ich transformiere das particle in camera space und gehe dann einfach size/2 nach rechts und oben miMatrix matrix; mi_matrix_ident(matrix); miInstance *inst = (miInstance *)mi_db_access(state->instance); mi_matrix_copy(matrix, inst->tf.global_to_local); mi_db_unpin(state->instance); mi_point_from_world(state, &camPos, &pos); mi_point_from_world(state, &camPos, &camPos); mi_point_to_camera(state, &camPos, &camPos); float psize = radiusPP * sizeMultiplier; int pId = vtxId; double rndVal = rnd(id * state->camera->frame + 5); if( rndVal > density) continue; float srndVal = (rndVal - 0.5f) * 2.0f; psize *= size + (size * srndVal * sizeVariation * 0.5f); psize = fabs(psize); if(psize == 0.0f) continue; miVector upRight, bottomLeft; upRight = camPos; upRight.x += psize/2.0f; upRight.y += psize/2.0f; bottomLeft = camPos; bottomLeft.x -= psize/2.0f; bottomLeft.y -= psize/2.0f; // checkScreenSpace in Screenspace und testet auf minPixelSize. if(!checkScreenSpace(state, paras, camPos, bottomLeft, upRight) ) continue; numWrittenParticles++; miVector v0, v1, v2, v3; v0 = bottomLeft; v2 = upRight; v1 = bottomLeft; v1.y = upRight.y; v3 = upRight; v3.y = bottomLeft.y; mi_point_from_camera(state, &v0, &v0); mi_point_from_camera(state, &v1, &v1); mi_point_from_camera(state, &v2, &v2); mi_point_from_camera(state, &v3, &v3); mi_point_to_world(state, &v0, &v0); mi_point_to_world(state, &v1, &v1); mi_point_to_world(state, &v2, &v2); mi_point_to_world(state, &v3, &v3); miVector v01, v02, v03; mi_vector_sub(&v01, &v0, &v1); mi_vector_sub(&v02, &v0, &v2); mi_vector_sub(&v03, &v0, &v3); mi_vector_transform(&v01, &v01, matrix); mi_vector_transform(&v02, &v02, matrix); mi_vector_transform(&v03, &v03, matrix); mi_vector_add(&v1, &v0, &v01); mi_vector_add(&v2, &v0, &v02); mi_vector_add(&v3, &v0, &v03); // add geometry vectors // e.g. -0.5 -0.5 0.5 add_vector(v0.x, v0.y, v0.z); add_vector(v1.x, v1.y, v1.z); add_vector(v2.x, v2.y, v2.z); add_vector(v3.x, v3.y, v3.z); // single motion vector per particle add_vector(vel.x, vel.y, vel.z); } // uv coordinates miVector uvw; uvw.x = uvw.y = uvw.z = 0.0f; uvw.z = 123.0f; mi_api_vector_xyz_add( &uvw ); uvw.x = 1.0; mi_api_vector_xyz_add( &uvw ); uvw.y = 1.0; mi_api_vector_xyz_add( &uvw ); uvw.x = 0.0; mi_api_vector_xyz_add( &uvw ); // define vertices // depending on the attributes we have x vectors per vertex: // 0: pos1 // 1: pos2 // 2: pos3 // 3: pos4 // 4: vel // tex0 = numWrittenParticles * 5 - 4 // num done particles für rnd density int texIndex = numWrittenParticles * 5; for(int vtxId = 0; vtxId < numWrittenParticles; vtxId++) { int vertexIndex = vtxId * 5; int mvIndex = vtxId * 5 + 4; // add vertex definitions // e.g. v 0 n 8 t 32 m 46 mi_api_vertex_add(vertexIndex); mi_api_vertex_tex_add( texIndex, -1, -1); mi_api_vertex_motion_add(mvIndex); mi_api_vertex_add(vertexIndex + 1); mi_api_vertex_tex_add( texIndex + 1, -1, -1); mi_api_vertex_motion_add(mvIndex); mi_api_vertex_add(vertexIndex + 2); mi_api_vertex_tex_add( texIndex + 2, -1, -1); mi_api_vertex_motion_add(mvIndex); mi_api_vertex_add(vertexIndex + 3); mi_api_vertex_tex_add( texIndex + 3, -1, -1); mi_api_vertex_motion_add(mvIndex); } // add poly for every particle for( int pId = 0; pId < numWrittenParticles; pId++) { int vtxId = pId * 4; mi_api_poly_begin_tag(1, miNULLTAG); mi_api_poly_index_add(vtxId); mi_api_poly_index_add(vtxId + 1); mi_api_poly_index_add(vtxId + 2); mi_api_poly_index_add(vtxId + 3); mi_api_poly_end(); } miTag objTag = finishObject(); return objTag; }
/* #sit command */ int dosit() { static const char sit_message[] = "sit on the %s."; register struct trap *trap = t_at(u.ux, u.uy); register int typ = levl[u.ux][u.uy].typ; if (u.usteed) { You("are already sitting on %s.", mon_nam(u.usteed)); return 0; } if (u.uundetected && is_hider(youmonst.data) && u.umonnum != PM_TRAPPER) u.uundetected = 0; /* no longer on the ceiling */ if (!can_reach_floor(FALSE)) { if (u.uswallow) There("are no seats in here!"); else if (Levitation) You("tumble in place."); else You("are sitting on air."); return 0; } else if (u.ustuck && !sticks(youmonst.data)) { /* holding monster is next to hero rather than beneath, but hero is in no condition to actually sit at has/her own spot */ if (humanoid(u.ustuck->data)) pline("%s won't offer %s lap.", Monnam(u.ustuck), mhis(u.ustuck)); else pline("%s has no lap.", Monnam(u.ustuck)); return 0; } else if (is_pool(u.ux, u.uy) && !Underwater) { /* water walking */ goto in_water; } if (OBJ_AT(u.ux, u.uy) /* ensure we're not standing on the precipice */ && !uteetering_at_seen_pit(trap)) { register struct obj *obj; obj = level.objects[u.ux][u.uy]; if (youmonst.data->mlet == S_DRAGON && obj->oclass == COIN_CLASS) { You("coil up around your %shoard.", (obj->quan + money_cnt(invent) < u.ulevel * 1000) ? "meager " : ""); } else { You("sit on %s.", the(xname(obj))); if (!(Is_box(obj) || objects[obj->otyp].oc_material == CLOTH)) pline("It's not very comfortable..."); } } else if (trap != 0 || (u.utrap && (u.utraptype >= TT_LAVA))) { if (u.utrap) { exercise(A_WIS, FALSE); /* you're getting stuck longer */ if (u.utraptype == TT_BEARTRAP) { You_cant("sit down with your %s in the bear trap.", body_part(FOOT)); u.utrap++; } else if (u.utraptype == TT_PIT) { if (trap && trap->ttyp == SPIKED_PIT) { You("sit down on a spike. Ouch!"); losehp(Half_physical_damage ? rn2(2) : 1, "sitting on an iron spike", KILLED_BY); exercise(A_STR, FALSE); } else You("sit down in the pit."); u.utrap += rn2(5); } else if (u.utraptype == TT_WEB) { You("sit in the spider web and get entangled further!"); u.utrap += rn1(10, 5); } else if (u.utraptype == TT_LAVA) { /* Must have fire resistance or they'd be dead already */ You("sit in the lava!"); if (Slimed) burn_away_slime(); u.utrap += rnd(4); losehp(d(2, 10), "sitting in lava", KILLED_BY); /* lava damage */ } else if (u.utraptype == TT_INFLOOR || u.utraptype == TT_BURIEDBALL) { You_cant("maneuver to sit!"); u.utrap++; } } else { You("sit down."); dotrap(trap, 0); } } else if (Underwater || Is_waterlevel(&u.uz)) { if (Is_waterlevel(&u.uz)) There("are no cushions floating nearby."); else You("sit down on the muddy bottom."); } else if (is_pool(u.ux, u.uy)) { in_water: You("sit in the water."); if (!rn2(10) && uarm) (void) water_damage(uarm, "armor", TRUE); if (!rn2(10) && uarmf && uarmf->otyp != WATER_WALKING_BOOTS) (void) water_damage(uarm, "armor", TRUE); } else if (IS_SINK(typ)) { You(sit_message, defsyms[S_sink].explanation); Your("%s gets wet.", humanoid(youmonst.data) ? "rump" : "underside"); } else if (IS_ALTAR(typ)) { You(sit_message, defsyms[S_altar].explanation); altar_wrath(u.ux, u.uy); } else if (IS_GRAVE(typ)) { You(sit_message, defsyms[S_grave].explanation); } else if (typ == STAIRS) { You(sit_message, "stairs"); } else if (typ == LADDER) { You(sit_message, "ladder"); } else if (is_lava(u.ux, u.uy)) { /* must be WWalking */ You(sit_message, "lava"); burn_away_slime(); if (likes_lava(youmonst.data)) { pline_The("lava feels warm."); return 1; } pline_The("lava burns you!"); losehp(d((Fire_resistance ? 2 : 10), 10), /* lava damage */ "sitting on lava", KILLED_BY); } else if (is_ice(u.ux, u.uy)) { You(sit_message, defsyms[S_ice].explanation); if (!Cold_resistance) pline_The("ice feels cold."); } else if (typ == DRAWBRIDGE_DOWN) { You(sit_message, "drawbridge"); } else if (IS_THRONE(typ)) { You(sit_message, defsyms[S_throne].explanation); if (rnd(6) > 4) { switch (rnd(13)) { case 1: (void) adjattrib(rn2(A_MAX), -rn1(4, 3), FALSE); losehp(rnd(10), "cursed throne", KILLED_BY_AN); break; case 2: (void) adjattrib(rn2(A_MAX), 1, FALSE); break; case 3: pline("A%s electric shock shoots through your body!", (Shock_resistance) ? "n" : " massive"); losehp(Shock_resistance ? rnd(6) : rnd(30), "electric chair", KILLED_BY_AN); exercise(A_CON, FALSE); break; case 4: You_feel("much, much better!"); if (Upolyd) { if (u.mh >= (u.mhmax - 5)) u.mhmax += 4; u.mh = u.mhmax; } if (u.uhp >= (u.uhpmax - 5)) u.uhpmax += 4; u.uhp = u.uhpmax; make_blinded(0L, TRUE); make_sick(0L, (char *) 0, FALSE, SICK_ALL); heal_legs(); context.botl = 1; break; case 5: take_gold(); break; case 6: if (u.uluck + rn2(5) < 0) { You_feel("your luck is changing."); change_luck(1); } else makewish(); break; case 7: { int cnt = rnd(10); /* Magical voice not affected by deafness */ pline("A voice echoes:"); verbalize("Thy audience hath been summoned, %s!", flags.female ? "Dame" : "Sire"); while (cnt--) (void) makemon(courtmon(), u.ux, u.uy, NO_MM_FLAGS); break; } case 8: /* Magical voice not affected by deafness */ pline("A voice echoes:"); verbalize("By thine Imperious order, %s...", flags.female ? "Dame" : "Sire"); do_genocide(5); /* REALLY|ONTHRONE, see do_genocide() */ break; case 9: /* Magical voice not affected by deafness */ pline("A voice echoes:"); verbalize( "A curse upon thee for sitting upon this most holy throne!"); if (Luck > 0) { make_blinded(Blinded + rn1(100, 250), TRUE); } else rndcurse(); break; case 10: if (Luck < 0 || (HSee_invisible & INTRINSIC)) { if (level.flags.nommap) { pline("A terrible drone fills your head!"); make_confused((HConfusion & TIMEOUT) + (long) rnd(30), FALSE); } else { pline("An image forms in your mind."); do_mapping(); } } else { Your("vision becomes clear."); HSee_invisible |= FROMOUTSIDE; newsym(u.ux, u.uy); } break; case 11: if (Luck < 0) { You_feel("threatened."); aggravate(); } else { You_feel("a wrenching sensation."); tele(); /* teleport him */ } break; case 12: You("are granted an insight!"); if (invent) { /* rn2(5) agrees w/seffects() */ identify_pack(rn2(5), FALSE); } break; case 13: Your("mind turns into a pretzel!"); make_confused((HConfusion & TIMEOUT) + (long) rn1(7, 16), FALSE); break; default: impossible("throne effect"); break; } } else { if (is_prince(youmonst.data)) You_feel("very comfortable here."); else You_feel("somehow out of place..."); } if (!rn2(3) && IS_THRONE(levl[u.ux][u.uy].typ)) { /* may have teleported */ levl[u.ux][u.uy].typ = ROOM; pline_The("throne vanishes in a puff of logic."); newsym(u.ux, u.uy); } } else if (lays_eggs(youmonst.data)) { struct obj *uegg; if (!flags.female) { pline("%s can't lay eggs!", Hallucination ? "You may think you are a platypus, but a male still" : "Males"); return 0; } else if (u.uhunger < (int) objects[EGG].oc_nutrition) { You("don't have enough energy to lay an egg."); return 0; } uegg = mksobj(EGG, FALSE, FALSE); uegg->spe = 1; uegg->quan = 1L; uegg->owt = weight(uegg); /* this sets hatch timers if appropriate */ set_corpsenm(uegg, egg_type_from_parent(u.umonnum, FALSE)); uegg->known = uegg->dknown = 1; You("lay an egg."); dropy(uegg); stackobj(uegg); morehungry((int) objects[EGG].oc_nutrition); } else { pline("Having fun sitting on the %s?", surface(u.ux, u.uy)); } return 1; }
read_scroll() { register struct object *obj; register struct linked_list *item; register struct room *rp; register int i,j; register char ch, nch; register struct linked_list *titem; char buf[80]; item = get_item("run", SCROLL); if (item == NULL) return; obj = (struct object *) ldata(item); if (obj->o_type != SCROLL) { if (!terse) msg("There is no way to run it"); else msg("Nothing to run"); return; } msg("As you run the device, it self-destructs."); /* * Calculate the effect it has on the poor guy. */ if (obj == cur_weapon) cur_weapon = NULL; switch(obj->o_which) { when S_CONFUSE: /* * Scroll of monster confusion. Give him that power. */ msg("Your hands begin to glow red"); player.t_flags |= CANHUH; when S_LIGHT: s_know[S_LIGHT] = TRUE; if ((rp = roomin(&hero)) == NULL) msg("The corridor glows and then fades"); else { addmsg("The room is lit"); if (!terse) addmsg(" by a shimmering blue light."); endmsg(); rp->r_flags &= ~ISDARK; /* * Light the room and put the player back up */ light(&hero); mvwaddch(cw, hero.y, hero.x, PLAYER); } when S_ARMOR: if (cur_armor != NULL) { msg("Your armor glows faintly for a moment"); cur_armor->o_ac--; cur_armor->o_flags &= ~ISCURSED; } when S_HOLD: /* * Hold monster scroll. Stop all monsters within two spaces * from chasing after the hero. */ { register int x,y; register struct linked_list *mon; for (x = hero.x-2; x <= hero.x+2; x++) for (y = hero.y-2; y <= hero.y+2; y++) if (y > 0 && x > 0 && isupper(mvwinch(mw, y, x))) if ((mon = find_mons(y, x)) != NULL) { register struct thing *th; th = (struct thing *) ldata(mon); th->t_flags &= ~ISRUN; th->t_flags |= ISHELD; } } when S_SLEEP: /* * Scroll which makes you fall asleep */ s_know[S_SLEEP] = TRUE; msg("You fall asleep."); no_command += 4 + rnd(SLEEPTIME); when S_CREATE: /* * Create a monster * First look in a circle around him, next try his room * otherwise give up */ { register int x, y; register bool appear = 0; coord mp; /* * Search for an open place */ for (y = hero.y; y <= hero.y+1; y++) for (x = hero.x; x <= hero.x+1; x++) { /* * Don't put a monster in top of the player. */ if (y == hero.y && x == hero.x) continue; /* * Or anything else nasty */ if (step_ok(winat(y, x))) { if (rnd(++appear) == 0) { mp.y = y; mp.x = x; } } } if (appear) { titem = new_item(sizeof (struct thing)); new_monster(titem, randmonster(FALSE), &mp); } else msg("You hear a faint cry of anguish in the distance."); } when S_IDENT: /* * Identify, let the rogue figure something out */ msg("This nanodevice is an identify nanodevice"); s_know[S_IDENT] = TRUE; whatis(); when S_MAP: /* * Scroll of magic mapping. */ s_know[S_MAP] = TRUE; msg("Oh, now this nanodevice has a map on it."); overwrite(stdscr, hw); /* * Take all the things we want to keep hidden out of the window */ for (i = 0; i < lines(); i++) for (j = 0; j < cols(); j++) { switch (nch = ch = mvwinch(hw, i, j)) { case SECRETDOOR: mvaddch(i, j, nch = DOOR); case '-': case '|': case DOOR: case PASSAGE: case ' ': case STAIRS: if (mvwinch(mw, i, j) != ' ') { register struct thing *it; it = (struct thing *) ldata(find_mons(i, j)); if (it->t_oldch == ' ') it->t_oldch = nch; } break; default: nch = ' '; } if (nch != ch) waddch(hw, nch); } /* * Copy in what he has discovered */ overlay(cw, hw); /* * And set up for display */ overwrite(hw, cw); when S_GFIND: /* * Potion of gold detection */ { int gtotal = 0; wclear(hw); for (i = 0; i < MAXROOMS; i++) { gtotal += rooms[i].r_goldval; if (rooms[i].r_goldval != 0 && mvwinch(stdscr, rooms[i].r_gold.y, rooms[i].r_gold.x) == GOLD) mvwaddch(hw,rooms[i].r_gold.y,rooms[i].r_gold.x,GOLD); } if (gtotal) { s_know[S_GFIND] = TRUE; show_win(hw, "You connect to the Net and detect credits locations.--More--"); } else msg("You begin to feel a pull downward"); } when S_TELEP: /* * Scroll of teleportation: * Make him dissapear and reappear */ { int rm; struct room *cur_room; cur_room = roomin(&hero); rm = teleport(); if (cur_room != &rooms[rm]) s_know[S_TELEP] = TRUE; } when S_ENCH: if (cur_weapon == NULL) msg("You feel a strange sense of loss."); else { cur_weapon->o_flags &= ~ISCURSED; if (rnd(100) > 50) cur_weapon->o_hplus++; else cur_weapon->o_dplus++; msg("Your %s glows blue for a moment.", w_names[cur_weapon->o_which]); } when S_SCARE: /* * A monster will refuse to step on a scare monster scroll * if it is dropped. Thus reading it is a mistake and produces * laughter at the poor rogue's boo boo. */ msg("You hear maniacal laughter in the distance."); when S_REMOVE: if (cur_armor != NULL) cur_armor->o_flags &= ~ISCURSED; if (cur_weapon != NULL) cur_weapon->o_flags &= ~ISCURSED; if (cur_ring[LEFT] != NULL) cur_ring[LEFT]->o_flags &= ~ISCURSED; if (cur_ring[RIGHT] != NULL) cur_ring[RIGHT]->o_flags &= ~ISCURSED; msg("You feel as if somebody is watching over you."); when S_AGGR: /* * This scroll aggravates all the monsters on the current * level and sets them running towards the hero */ aggravate(); msg("You hear a high pitched humming noise."); when S_NOP: msg("This nanodevice seems to be empty."); when S_GENOCIDE: msg("You have been granted the boon of genocide"); genocide(); s_know[S_GENOCIDE] = TRUE; otherwise: msg("What a puzzling nanodevice!"); return; } look(TRUE); /* put the result of the scroll on the screen */ status(); if (s_know[obj->o_which] && s_guess[obj->o_which]) { cfree(s_guess[obj->o_which]); s_guess[obj->o_which] = NULL; } else if (!s_know[obj->o_which] && askme && s_guess[obj->o_which] == NULL) { msg(terse ? "Call it: " : "What do you want to call it? "); if (get_str(buf, cw) == NORM) { s_guess[obj->o_which] = malloc((unsigned int) strlen(buf) + 1); strcpy(s_guess[obj->o_which], buf); } } /* * Get rid of the thing */ inpack--; if (obj->o_count > 1) obj->o_count--; else { detach(pack, item); discard(item); } }
/* remove a random INTRINSIC ability */ void attrcurse() { switch (rnd(11)) { case 1: if (HFire_resistance & INTRINSIC) { HFire_resistance &= ~INTRINSIC; You_feel("warmer."); break; } case 2: if (HTeleportation & INTRINSIC) { HTeleportation &= ~INTRINSIC; You_feel("less jumpy."); break; } case 3: if (HPoison_resistance & INTRINSIC) { HPoison_resistance &= ~INTRINSIC; You_feel("a little sick!"); break; } case 4: if (HTelepat & INTRINSIC) { HTelepat &= ~INTRINSIC; if (Blind && !Blind_telepat) see_monsters(); /* Can't sense mons anymore! */ Your("senses fail!"); break; } case 5: if (HCold_resistance & INTRINSIC) { HCold_resistance &= ~INTRINSIC; You_feel("cooler."); break; } case 6: if (HInvis & INTRINSIC) { HInvis &= ~INTRINSIC; You_feel("paranoid."); break; } case 7: if (HSee_invisible & INTRINSIC) { HSee_invisible &= ~INTRINSIC; You("%s!", Hallucination ? "tawt you taw a puttie tat" : "thought you saw something"); break; } case 8: if (HFast & INTRINSIC) { HFast &= ~INTRINSIC; You_feel("slower."); break; } case 9: if (HStealth & INTRINSIC) { HStealth &= ~INTRINSIC; You_feel("clumsy."); break; } case 10: /* intrinsic protection is just disabled, not set back to 0 */ if (HProtection & INTRINSIC) { HProtection &= ~INTRINSIC; You_feel("vulnerable."); break; } case 11: if (HAggravate_monster & INTRINSIC) { HAggravate_monster &= ~INTRINSIC; You_feel("less attractive."); break; } default: break; } }
double snorm() { static double a[32]= { 0.0, 3.917609E-2, 7.841241E-2, 0.11777, 0.1573107, 0.1970991, 0.2372021, 0.2776904, 0.3186394, 0.36013, 0.4022501, 0.4450965, 0.4887764, 0.5334097, 0.5791322, 0.626099, 0.6744898, 0.7245144, 0.7764218, 0.8305109, 0.8871466, 0.9467818, 1.00999, 1.077516, 1.150349, 1.229859, 1.318011, 1.417797, 1.534121, 1.67594, 1.862732, 2.153875 }; static double d[31]= { 0.0, 0.0, 0.0, 0.0, 0.0, 0.2636843, 0.2425085, 0.2255674, 0.2116342, 0.1999243, 0.1899108, 0.1812252, 0.1736014, 0.1668419, 0.1607967, 0.1553497, 0.1504094, 0.1459026, 0.14177, 0.1379632, 0.1344418, 0.1311722, 0.128126, 0.1252791, 0.1226109, 0.1201036, 0.1177417, 0.1155119, 0.1134023, 0.1114027, 0.1095039 }; static double t[31]= { 7.673828E-4, 2.30687E-3, 3.860618E-3, 5.438454E-3, 7.0507E-3, 8.708396E-3, 1.042357E-2, 1.220953E-2, 1.408125E-2, 1.605579E-2, 1.81529E-2, 2.039573E-2, 2.281177E-2, 2.543407E-2, 2.830296E-2, 3.146822E-2, 3.499233E-2, 3.895483E-2, 4.345878E-2, 4.864035E-2, 5.468334E-2, 6.184222E-2, 7.047983E-2, 8.113195E-2, 9.462444E-2, 0.1123001, 0.136498, 0.1716886, 0.2276241, 0.330498, 0.5847031 }; static double h[31]= { 3.920617E-2, 3.932705E-2, 3.951E-2, 3.975703E-2, 4.007093E-2, 4.045533E-2, 4.091481E-2, 4.145507E-2, 4.208311E-2, 4.280748E-2, 4.363863E-2, 4.458932E-2, 4.567523E-2, 4.691571E-2, 4.833487E-2, 4.996298E-2, 5.183859E-2, 5.401138E-2, 5.654656E-2, 5.95313E-2, 6.308489E-2, 6.737503E-2, 7.264544E-2, 7.926471E-2, 8.781922E-2, 9.930398E-2, 0.11556, 0.1404344, 0.1836142, 0.2790016, 0.7010474 }; static long i; static double snorm, u, s, ustar, aa, w, y, tt; u=rnd(); s=0.0; if(u>0.5) s=1.0; u+=(u-s); u=32.0*u; i=(long) (u); if(i==32) i=31; if(i==0) goto S100; /* START CENTER */ ustar=u-(double)i; aa=*(a+i-1); S40: if(ustar<=*(t+i-1)) goto S60; w=(ustar-*(t+i-1))**(h+i-1); S50: /* EXIT (BOTH CASES) */ y=aa+w; snorm=y; if(s==1.0) snorm=-y; return snorm; S60: /* CENTER CONTINUED */ u=rnd(); w=u*(*(a+i)-aa); tt=(0.5*w+aa)*w; goto S80; S70: tt=u; ustar=rnd(); S80: if(ustar>tt) goto S50; u=rnd(); if(ustar>=u) goto S70; ustar=rnd(); goto S40; S100: /* START TAIL */ i=6; aa=*(a+31); goto S120; S110: aa+=*(d+i-1); i+=1; S120: u+=u; if(u<1.0) goto S110; u -=1.0; S140: w=u**(d+i-1); tt=(0.5*w+aa)*w; goto S160; S150: tt=u; S160: ustar=rnd(); if(ustar>tt) goto S50; u=rnd(); if(ustar>=u) goto S150; u=rnd(); goto S140; }
static void PE_ChangePitch(struct PEventQueue *peq,int doit){ float x; STime ntime,btime; struct Pitches *next; btime=PC_TimeToRelBlockStart(pc->end_time); if(btime>=peq->time2){ next=NextPitch(peq->nextpitch); peq->time1=peq->time2; peq->pitch=peq->nextpitch; peq->pitch->doit = peq->pitch->chance==0x100 || peq->pitch->chance > rnd(0x100); if(next==NULL){ peq->time2=Place2STime(peq->block,&peq->note->end); peq->TreatMe=PE_ChangePitchToEnd; PE_ChangePitchToEnd(peq,doit); }else{ peq->nextpitch=next; peq->time2=Place2STime(peq->block,&next->l.p); PE_ChangePitch(peq,doit); } return; } float pitch1,pitch2,logtype; if(peq->pitch==peq->nextpitch){ pitch1=peq->note->note; pitch2=peq->pitch->note; logtype=peq->note->pitch_first_logtype; }else{ pitch1=peq->pitch->note; pitch2=peq->nextpitch->note; logtype=peq->pitch->logtype; } ntime=PEQ_CalcNextPitchEvent( peq, peq->time1, btime, peq->time2, pitch1, &x, pitch2, logtype ); if(btime==ntime){ Pdebug("Samme, stopper, x: %d\n",x); return; } if(ntime>peq->time2) ntime=peq->time2; // Pdebug("Player vel->vel, Pitch: %d, ntime: %d, btime: %d, time1: %d, time2: %d\n",x,ntime,btime,peq->time1,peq->time2); if(doit){ SendPitchChange(x,peq); } PC_InsertElement(peq,0,ntime); return; }
/* actually returns something that fits in an int */ long somegold(void) { return( (u.ugold < 100) ? u.ugold : (u.ugold > 10000) ? rnd(10000) : rnd((int) u.ugold) ); }
enum DIRECTION GridAnt::chooseGrid() { double tmp_prob[8] = {0,0,0,0,0,0,0,0}; bool flag[8] = {false,false,false,false,false,false,false,false}; int flag_res = 0; double total = 0.0; if(abs(cur_x - end_x) <= 1 && abs(cur_y - end_y) <= 1) { direction = GOAL; return GOAL; } if (cur_x - 1 >= 0 && g_grid[cur_x - 1][cur_y] == 0 && travel[cur_x - 1][cur_y] == 0) //up { /*计算转移到其它城市概率,公式1*/ tmp_prob[0] = pow(grid_pher[cur_city][ENCODE(cur_x - 1,cur_y)],ALPHA)*pow(1.0/PIX,BETA); flag[0] = true; } if (cur_x + 1 < N_GRID && g_grid[cur_x + 1][cur_y] == 0 && travel[cur_x + 1][cur_y] == 0) //down { tmp_prob[1] = pow(grid_pher[cur_city][ENCODE(cur_x + 1,cur_y)],ALPHA)*pow(1.0/PIX,BETA); flag[1] = true; } if (cur_y - 1 >= 0 && g_grid[cur_x][cur_y - 1] == 0 && travel[cur_x][cur_y - 1] == 0) //left { tmp_prob[2] = pow(grid_pher[cur_city][ENCODE(cur_x,cur_y - 1)],ALPHA)*pow(1.0/PIX,BETA); flag[2] = true; } if (cur_y + 1 < N_GRID && g_grid[cur_x][cur_y + 1] == 0 && travel[cur_x][cur_y + 1] == 0) //right { tmp_prob[3] = pow(grid_pher[cur_city][ENCODE(cur_x,cur_y + 1)],ALPHA)*pow(1.0/PIX,BETA); flag[3] = true; } if (cur_x - 1 >= 0 && cur_y - 1 >= 0 && g_grid[cur_x - 1][cur_y - 1] == 0 && travel[cur_x - 1][cur_y - 1] == 0) //left-up { tmp_prob[4] = pow(grid_pher[cur_city][ENCODE(cur_x - 1,cur_y - 1)],ALPHA)*pow(1.0/ANG_PIX,BETA); flag[4] = true; } if (cur_x + 1 < N_GRID && cur_y - 1 >= 0 && g_grid[cur_x + 1][cur_y - 1] == 0 && travel[cur_x + 1][cur_y - 1] == 0) //left-down { tmp_prob[5] = pow(grid_pher[cur_city][ENCODE(cur_x + 1,cur_y - 1)],ALPHA)*pow(1.0/ANG_PIX,BETA); flag[5] = true; } if (cur_x - 1 >= 0 && cur_y + 1 < N_GRID && g_grid[cur_x - 1][cur_y + 1] == 0 && travel[cur_x - 1][cur_y + 1] == 0) //right-up { tmp_prob[6] = pow(grid_pher[cur_city][ENCODE(cur_x - 1,cur_y + 1)],ALPHA)*pow(1.0/ANG_PIX,BETA); flag[6] = true; } if (cur_x + 1 < N_GRID && cur_y + 1 < N_GRID && g_grid[cur_x + 1][cur_y + 1] == 0 && travel[cur_x + 1][cur_y + 1] == 0) //right-down { tmp_prob[7] = pow(grid_pher[cur_city][ENCODE(cur_x + 1,cur_y + 1)],ALPHA)*pow(1.0/ANG_PIX,BETA); flag[7] = true; } for (int i = 0; i < 8; ++i) { total += tmp_prob[i]; flag_res += flag[i]; } if(flag_res == 0) { direction = NOROAD; return NOROAD; } double rand_num = rnd(0.0,total); if (total > 0.0) { for (int i = 0; i < 8; ++i) { rand_num -= tmp_prob[i]; if (rand_num < 0.0) { direction = (DIRECTION)i; return (DIRECTION)i; } } } printf("total is too little!\n"); /*如果城市间的信息素非常小 ( 小到比double能够表示的最小的数字还要小 ) 那么由于浮点运算的误差原因,上面计算的概率总和可能为0 会出现经过上述操作,没有城市被选择出来 出现这种情况,就把第一个没去过的城市作为返回结果*/ int greed_choose = -1; for (int i = 0; i < 8; ++i) { if (tmp_prob[i] > greed_choose) { greed_choose = i; } } direction = (DIRECTION)greed_choose; return (DIRECTION)greed_choose; }
void asmb(void) { Prog *p; long t, etext; Optab *o; if(debug['v']) Bprint(&bso, "%5.2f asm\n", cputime()); Bflush(&bso); OFFSET = HEADR; seek(cout, OFFSET, 0); pc = INITTEXT; for(p = firstp; p != P; p = p->link) { if(p->as == ATEXT) { curtext = p; autosize = p->to.offset + 4; } if(p->pc != pc) { diag("phase error %lux sb %lux", p->pc, pc); if(!debug['a']) prasm(curp); pc = p->pc; } curp = p; o = oplook(p); /* could probably avoid this call */ asmout(p, o); pc += o->size; } if(debug['a']) Bprint(&bso, "\n"); Bflush(&bso); cflush(); /* output strings in text segment */ etext = INITTEXT + textsize; for(t = pc; t < etext; t += sizeof(buf)-100) { if(etext-t > sizeof(buf)-100) datblk(t, sizeof(buf)-100, 1); else datblk(t, etext-t, 1); } curtext = P; switch(HEADTYPE) { case 0: case 1: case 2: case 5: case 7: OFFSET = HEADR+textsize; seek(cout, OFFSET, 0); break; case 3: case 6: /* no header, padded segments */ OFFSET = rnd(HEADR+textsize, 4096); seek(cout, OFFSET, 0); break; } if(dlm){ char buf[8]; write(cout, buf, INITDAT-textsize); textsize = INITDAT; } for(t = 0; t < datsize; t += sizeof(buf)-100) { if(datsize-t > sizeof(buf)-100) datblk(t, sizeof(buf)-100, 0); else datblk(t, datsize-t, 0); } symsize = 0; lcsize = 0; if(!debug['s']) { if(debug['v']) Bprint(&bso, "%5.2f sym\n", cputime()); Bflush(&bso); switch(HEADTYPE) { case 0: case 1: case 4: case 5: debug['s'] = 1; break; case 2: OFFSET = HEADR+textsize+datsize; seek(cout, OFFSET, 0); break; case 3: case 6: /* no header, padded segments */ OFFSET += rnd(datsize, 4096); seek(cout, OFFSET, 0); break; case 7: break; } if(!debug['s']) asmsym(); if(debug['v']) Bprint(&bso, "%5.2f pc\n", cputime()); Bflush(&bso); if(!debug['s']) asmlc(); if(dlm) asmdyn(); cflush(); } else if(dlm){ seek(cout, HEADR+textsize+datsize, 0); asmdyn(); cflush(); } if(debug['v']) Bprint(&bso, "%5.2f header\n", cputime()); Bflush(&bso); OFFSET = 0; seek(cout, OFFSET, 0); switch(HEADTYPE) { case 0: /* no header */ case 6: /* no header, padded segments */ break; case 1: /* aif for risc os */ lputl(0xe1a00000); /* NOP - decompress code */ lputl(0xe1a00000); /* NOP - relocation code */ lputl(0xeb000000 + 12); /* BL - zero init code */ lputl(0xeb000000 + (entryvalue() - INITTEXT + HEADR - 12 - 8) / 4); /* BL - entry code */ lputl(0xef000011); /* SWI - exit code */ lputl(textsize+HEADR); /* text size */ lputl(datsize); /* data size */ lputl(0); /* sym size */ lputl(bsssize); /* bss size */ lputl(0); /* sym type */ lputl(INITTEXT-HEADR); /* text addr */ lputl(0); /* workspace - ignored */ lputl(32); /* addr mode / data addr flag */ lputl(0); /* data addr */ for(t=0; t<2; t++) lputl(0); /* reserved */ for(t=0; t<15; t++) lputl(0xe1a00000); /* NOP - zero init code */ lputl(0xe1a0f00e); /* B (R14) - zero init return */ break; case 2: /* plan 9 */ if(dlm) lput(0x80000000|0x647); /* magic */ else lput(0x647); /* magic */ lput(textsize); /* sizes */ lput(datsize); lput(bsssize); lput(symsize); /* nsyms */ lput(entryvalue()); /* va of entry */ lput(0L); lput(lcsize); break; case 3: /* boot for NetBSD */ lput((143<<16)|0413); /* magic */ lputl(rnd(HEADR+textsize, 4096)); lputl(rnd(datsize, 4096)); lputl(bsssize); lputl(symsize); /* nsyms */ lputl(entryvalue()); /* va of entry */ lputl(0L); lputl(0L); break; case 4: /* boot for IXP1200 */ break; case 5: /* boot for ipaq */ lputl(0xe3300000); /* nop */ lputl(0xe3300000); /* nop */ lputl(0xe3300000); /* nop */ lputl(0xe3300000); /* nop */ break; case 7: /* elf */ debug['S'] = 1; /* symbol table */ elf32(ARM, ELFDATA2LSB, 0, nil); break; } cflush(); }
void main() { float n=-4.55; printf("%d",rnd(n)); }
static void *test(mps_arena_t arena, mps_pool_class_t pool_class, size_t roots_count) { mps_fmt_t format; mps_chain_t chain; mps_root_t exactRoot, ambigRoot, bogusRoot; unsigned long objs; size_t i; mps_word_t collections, rampSwitch; mps_alloc_pattern_t ramp = mps_alloc_pattern_ramp(); int ramping; mps_ap_t busy_ap; mps_addr_t busy_init; die(EnsureHeaderFormat(&format, arena), "fmt_create"); die(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); die(mps_pool_create(&pool, arena, pool_class, format, chain), "pool_create(amc)"); die(mps_ap_create(&ap, pool, mps_rank_exact()), "BufferCreate"); die(mps_ap_create(&busy_ap, pool, mps_rank_exact()), "BufferCreate 2"); for(i = 0; i < exactRootsCOUNT; ++i) exactRoots[i] = objNULL; for(i = 0; i < ambigRootsCOUNT; ++i) ambigRoots[i] = rnd_addr(); die(mps_root_create_table_masked(&exactRoot, arena, mps_rank_exact(), (mps_rm_t)0, &exactRoots[0], exactRootsCOUNT, (mps_word_t)1), "root_create_table(exact)"); die(mps_root_create_table(&ambigRoot, arena, mps_rank_ambig(), (mps_rm_t)0, &ambigRoots[0], ambigRootsCOUNT), "root_create_table(ambig)"); die(mps_root_create_table(&bogusRoot, arena, mps_rank_ambig(), (mps_rm_t)0, &bogusRoots[0], bogusRootsCOUNT), "root_create_table(bogus)"); /* create an ap, and leave it busy */ die(mps_reserve(&busy_init, busy_ap, 64), "mps_reserve busy"); collections = 0; rampSwitch = rampSIZE; die(mps_ap_alloc_pattern_begin(ap, ramp), "pattern begin (ap)"); die(mps_ap_alloc_pattern_begin(busy_ap, ramp), "pattern begin (busy_ap)"); ramping = 1; objs = 0; while (collections < collectionsCOUNT) { mps_word_t c; size_t r; c = mps_collections(arena); if (collections != c) { collections = c; printf("\nCollection %"PRIuLONGEST", %lu objects.\n", (ulongest_t)c, objs); report(arena); for (r = 0; r < exactRootsCOUNT; ++r) { if (exactRoots[r] != objNULL) die(HeaderFormatCheck(exactRoots[r]), "wrapper check"); } if (collections == rampSwitch) { int begin_ramp = !ramping || /* Every other time, switch back immediately. */ (collections & 1); rampSwitch += rampSIZE; if (ramping) { die(mps_ap_alloc_pattern_end(ap, ramp), "pattern end (ap)"); die(mps_ap_alloc_pattern_end(busy_ap, ramp), "pattern end (busy_ap)"); ramping = 0; /* kill half of the roots */ for(i = 0; i < exactRootsCOUNT; i += 2) { if (exactRoots[i] != objNULL) { die(HeaderFormatCheck(exactRoots[i]), "ramp kill check"); exactRoots[i] = objNULL; } } } if (begin_ramp) { die(mps_ap_alloc_pattern_begin(ap, ramp), "pattern rebegin (ap)"); die(mps_ap_alloc_pattern_begin(busy_ap, ramp), "pattern rebegin (busy_ap)"); ramping = 1; } } /* fill bogusRoots with variations of a real pointer */ r = rnd() % exactRootsCOUNT; if (exactRoots[r] != objNULL) { char *p = (char*)exactRoots[r]; for(i = 0; i < bogusRootsCOUNT; ++i, ++p) bogusRoots[i] = (mps_addr_t)p; } } r = (size_t)rnd(); if (r & 1) { i = (r >> 1) % exactRootsCOUNT; if (exactRoots[i] != objNULL) die(HeaderFormatCheck(exactRoots[i]), "wrapper check"); exactRoots[i] = make(roots_count); if (exactRoots[(exactRootsCOUNT-1) - i] != objNULL) dylan_write(exactRoots[(exactRootsCOUNT-1) - i], exactRoots, exactRootsCOUNT); } else {
static int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_data *sd, unsigned int tick) { struct block_list *target = NULL; int master_dist, view_range, mode; nullpo_ret(ed); nullpo_ret(sd); if( ed->bl.prev == NULL || sd == NULL || sd->bl.prev == NULL ) return 0; // Check if caster can sustain the summoned elemental if( DIFF_TICK(tick,ed->last_spdrain_time) >= 10000 ) { // Drain SP every 10 seconds int sp = 5; switch(ed->vd->class_) { case ELEMENTALID_AGNI_M: case ELEMENTALID_AQUA_M: case ELEMENTALID_VENTUS_M: case ELEMENTALID_TERA_M: sp = 8; break; case ELEMENTALID_AGNI_L: case ELEMENTALID_AQUA_L: case ELEMENTALID_VENTUS_L: case ELEMENTALID_TERA_L: sp = 11; break; } if( status_get_sp(&sd->bl) < sp ) { // Can't sustain delete it. elemental_delete(sd->ed,0); return 0; } status_zap(&sd->bl,0,sp); ed->last_spdrain_time = tick; } if( DIFF_TICK(tick,ed->last_thinktime) < MIN_ELETHINKTIME ) return 0; ed->last_thinktime = tick; if( ed->ud.skilltimer != INVALID_TIMER ) return 0; if( ed->ud.walktimer != INVALID_TIMER && ed->ud.walkpath.path_pos <= 2 ) return 0; //No thinking when you just started to walk. if(ed->ud.walkpath.path_pos < ed->ud.walkpath.path_len && ed->ud.target == sd->bl.id) return 0; //No thinking until be near the master. if( ed->sc.count && ed->sc.data[SC_BLIND] ) view_range = 3; else view_range = ed->db->range2; mode = status_get_mode(&ed->bl); master_dist = distance_bl(&sd->bl, &ed->bl); if( master_dist > AREA_SIZE ) { // Master out of vision range. elemental_unlocktarget(ed); unit_warp(&ed->bl,sd->bl.m,sd->bl.x,sd->bl.y,CLR_TELEPORT); clif_elemental_updatestatus(sd,SP_HP); clif_elemental_updatestatus(sd,SP_SP); return 0; } else if( master_dist > MAX_ELEDISTANCE ) { // Master too far, chase. short x = sd->bl.x, y = sd->bl.y; if( ed->target_id ) elemental_unlocktarget(ed); if( ed->ud.walktimer != INVALID_TIMER && ed->ud.target == sd->bl.id ) return 0; //Already walking to him if( DIFF_TICK(tick, ed->ud.canmove_tick) < 0 ) return 0; //Can't move yet. if( map_search_freecell(&ed->bl, sd->bl.m, &x, &y, MIN_ELEDISTANCE, MIN_ELEDISTANCE, 1) && unit_walktoxy(&ed->bl, x, y, 0) ) return 0; } if( mode == EL_MODE_AGGRESSIVE ) { target = map_id2bl(ed->ud.target); if( !target ) map_foreachinrange(elemental_ai_sub_timer_activesearch, &ed->bl, view_range, BL_CHAR, ed, &target, status_get_mode(&ed->bl)); if( !target ) { //No targets available. elemental_unlocktarget(ed); return 1; } if( battle_check_range(&ed->bl,target,view_range) && rnd()%100 < 2 ) { // 2% chance to cast attack skill. if( elemental_action(ed,target,tick) ) return 1; } //Attempt to attack. //At this point we know the target is attackable, we just gotta check if the range matches. if( ed->ud.target == target->id && ed->ud.attacktimer != INVALID_TIMER ) //Already locked. return 1; if( battle_check_range(&ed->bl, target, ed->base_status.rhw.range) ) {//Target within range, engage unit_attack(&ed->bl,target->id,1); return 1; } //Follow up if possible. if( !unit_walktobl(&ed->bl, target, ed->base_status.rhw.range, 2) ) elemental_unlocktarget(ed); } return 0; }
float frnd(float range) { return (float)rnd(10000)/10000*range; }
void do_trap(trap_t *trap) // was dotrap { Short ttype = get_trap_type(trap->trap_info); nomul(0); if (get_trap_seen(trap->trap_info) && !rund(5) && ttype != PIT) { StrPrintF(ScratchBuffer, "You escape a%s.", traps[ttype]); message(ScratchBuffer); } else { trap->trap_info |= SEEN_TRAP; switch(ttype) { case SLP_GAS_TRAP: message("A cloud of gas puts you to sleep!"); nomul(-rnd(25)); break; case BEAR_TRAP: if (Levitation) { message("You float over a bear trap."); break; } you.utrap = 4 + rund(4); you.utraptype = TT_BEARTRAP; message("A bear trap closes on your foot!"); break; case PIERC: deltrap(trap); if (makemon(PM_PIERCER, you.ux, you.uy)) { message("A piercer suddenly drops from the ceiling!"); if (uarmh) message("Its blow glances off your helmet."); else thing_hit_you(3, dice(4,6), "falling piercer"); } break; case ARROW_TRAP: message("An arrow shoots out at you!"); if (!thing_hit_you(8, rnd(6), "arrow")){ mksobj_at(ARROW, you.ux, you.uy); fobj->quantity = 1; } break; case TRAPDOOR: if (!xdnstair) { message("A trap door in the ceiling opens and a rock falls on your head!"); if (uarmh) message("Fortunately, you are wearing a helmet!"); losehp((uarmh ? 2 : dice(2,10)), "falling rock"); mksobj_at(ROCK, you.ux, you.uy); fobj->quantity = 1; stackobj(fobj); if (Invisible) newsym(you.ux, you.uy); } else { Short newlevel = dlevel + 1; while (!rund(4) && newlevel < 29) newlevel++; message("A trap door opens up under you!"); if (Levitation || you.ustuck) { message("For some reason you don't fall in."); break; } goto_level(newlevel, false); } break; case DART_TRAP: message("A little dart shoots out at you!"); if (thing_hit_you(7, rnd(3), "little dart")) { if (!rund(6)) poisoned("dart", "poison dart"); } else { mksobj_at(DART, you.ux, you.uy); fobj->quantity = 1; } break; case TELEP_TRAP: map_mode_teleport = TELE_TRAP; if (get_trap_once(trap->trap_info)) { deltrap(trap); newsym(you.ux,you.uy); vtele(); } else { newsym(you.ux,you.uy); tele(); } break; case PIT: if (Levitation) { message("A pit opens up under you!"); message("You don't fall in!"); break; } message("You fall into a pit!"); you.utrap = rund(6) + 2; you.utraptype = TT_PIT; losehp(rnd(6),"fall into a pit"); selftouch("Falling, you"); break; default: StrPrintF(ScratchBuffer, "BUG: You hit a trap with info=%u", trap->trap_info); message(ScratchBuffer); } } }
/* curse a few inventory items at random! */ void rndcurse() { int nobj = 0; int cnt, onum; struct obj *otmp; static const char mal_aura[] = "feel a malignant aura surround %s."; if (uwep && (uwep->oartifact == ART_MAGICBANE) && rn2(20)) { You(mal_aura, "the magic-absorbing blade"); return; } if (Antimagic) { shieldeff(u.ux, u.uy); You(mal_aura, "you"); } for (otmp = invent; otmp; otmp = otmp->nobj) { /* gold isn't subject to being cursed or blessed */ if (otmp->oclass == COIN_CLASS) continue; nobj++; } if (nobj) { for (cnt = rnd(6 / ((!!Antimagic) + (!!Half_spell_damage) + 1)); cnt > 0; cnt--) { onum = rnd(nobj); for (otmp = invent; otmp; otmp = otmp->nobj) { /* as above */ if (otmp->oclass == COIN_CLASS) continue; if (--onum == 0) break; /* found the target */ } /* the !otmp case should never happen; picking an already cursed item happens--avoid "resists" message in that case */ if (!otmp || otmp->cursed) continue; /* next target */ if (otmp->oartifact && spec_ability(otmp, SPFX_INTEL) && rn2(10) < 8) { pline("%s!", Tobjnam(otmp, "resist")); continue; } if (otmp->blessed) unbless(otmp); else curse(otmp); } update_inventory(); } /* treat steed's saddle as extended part of hero's inventory */ if (u.usteed && !rn2(4) && (otmp = which_armor(u.usteed, W_SADDLE)) != 0 && !otmp->cursed) { /* skip if already cursed */ if (otmp->blessed) unbless(otmp); else curse(otmp); if (!Blind) { pline("%s %s.", Yobjnam2(otmp, "glow"), hcolor(otmp->cursed ? NH_BLACK : (const char *) "brown")); otmp->bknown = TRUE; } } }
//Does party loot. first_charid holds the charid of the player who has time priority to take the item int party_share_loot(struct party_data *p, struct map_session_data *sd, struct item *item, int first_charid) { TBL_PC *target = NULL; int i; if (p && (p->party.item&2) && (first_charid || !(battle_config.party_share_type&1))) { //Item distribution to party members if (battle_config.party_share_type&2) { //Round Robin TBL_PC *psd; i = p->itemc; do { i++; if (i >= MAX_PARTY) i = 0; //Reset counter to 1st person in party so it'll stop when it reaches "itemc" if ((psd = p->data[i].sd) == NULL || sd->bl.m != psd->bl.m || pc_isdead(psd) || (battle_config.idle_no_share && pc_isidle(psd))) continue; if (pc_additem(psd,item,item->amount,LOG_TYPE_PICKDROP_PLAYER)) continue; //Chosen char can't pick up loot //Successful pick p->itemc = i; target = psd; break; } while (i != p->itemc); } else { //Random pick TBL_PC *psd[MAX_PARTY]; int count = 0; //Collect pick candidates for (i = 0; i < MAX_PARTY; i++) { if ((psd[count] = p->data[i].sd) == NULL || psd[count]->bl.m != sd->bl.m || pc_isdead(psd[count]) || (battle_config.idle_no_share && pc_isidle(psd[count]))) continue; count++; } while (count > 0) { //Pick a random member i = rnd()%count; if (pc_additem(psd[i],item,item->amount,LOG_TYPE_PICKDROP_PLAYER)) { //Discard this receiver psd[i] = psd[count-1]; count--; } else { //Successful pick target = psd[i]; break; } } } } if (!target) { target = sd; //Give it to the char that picked it up if ((i = pc_additem(sd,item,item->amount,LOG_TYPE_PICKDROP_PLAYER))) return i; } if (p && battle_config.party_show_share_picker && battle_config.show_picker_item_type&(1<<itemdb_type(item->nameid))) clif_party_show_picker(target,item); return 0; }
void AddPoisonFog(EERIE_3D * pos, float power) { int iDiv = 2; if (pMenuConfig) { iDiv += 2 - pMenuConfig->iLevelOfDetails; } float flDiv = ARX_CLEAN_WARN_CAST_FLOAT(1 << iDiv); ARX_CHECK_LONG(FrameDiff / flDiv); long count = ARX_CLEAN_WARN_CAST_LONG(FrameDiff / flDiv); if (count < 1) count = 1; while (count) { count--; long j = ARX_PARTICLES_GetFree(); if ((j != -1) && (!ARXPausedTimer) && (rnd() * 2000.f < power)) { ParticleCount++; particle[j].special = FADE_IN_AND_OUT | ROTATING | MODULATE_ROTATION | DISSIPATING; particle[j].exist = true; particle[j].zdec = 0; particle[j].ov.x = pos->x + 100.f - 200.f * rnd(); particle[j].ov.y = pos->y + 100.f - 200.f * rnd(); particle[j].ov.z = pos->z + 100.f - 200.f * rnd(); float speed = 1.f; float fval = speed * DIV5; particle[j].scale.x = particle[j].scale.y = particle[j].scale.z = 10.f; particle[j].move.x = (speed - rnd()) * fval; particle[j].move.y = (speed - speed * rnd()) * DIV15; particle[j].move.z = (speed - rnd()) * fval; particle[j].scale.x = particle[j].scale.y = 8; particle[j].timcreation = ARX_CLEAN_WARN_CAST_LONG(ARX_TIME_Get()); particle[j].tolive = 4500 + (unsigned long)(rnd() * 4500); particle[j].tc = TC_smoke; particle[j].siz = (80 + rnd() * 80 * 2.f) * DIV3; particle[j].r = rnd() * DIV3; particle[j].g = 1.f; particle[j].b = rnd() * DIV10; particle[j].fparam = 0.001f; } } }