Index: class.doc ================================================================== --- class.doc +++ class.doc @@ -1900,10 +1900,18 @@ ,Rel ( obj dir -- dir ) Resolves a relative direction to an absolute direction, using the direction of the specified object as the base. If zero is specified instead of a valid object, then the result is the same as the input. +Replace ( class x y image dir -- obj ) ** + Similar to Create, except that it also destroys any objects in the + target location with any matching CollisionLayers bits, and clears the + Bizarro flag of the created object. You may also specify an object + instead of a class; in this case, it moves that object, but otherwise + acts like above. In the case of an existing object, it will update the + Image and Dir (which can now be relative) if the movement is successful. + ret ( -- ) Exit the current subroutine. If this is a message block, it must either leave the stack as it is, or leave it but with one extra value pushed which will be the return value from the message call. (This is implied at the end of a code block.) For a user defined function call, or a Index: exec.c ================================================================== --- exec.c +++ exec.c @@ -1730,14 +1730,64 @@ } static inline Value v_create(Uint32 from,Value cl,Value x,Value y,Value im,Value d) { Uint32 n; if(!cl.t && !cl.u) return NVALUE(0); - if(cl.t!=TY_CLASS || x.t || x.t || y.t || im.t || d.t) Throw("Type mismatch"); + if(cl.t!=TY_CLASS || x.t || y.t || im.t || d.t) Throw("Type mismatch"); n=create(from,cl.u,x.u,y.u,im.u,d.u); return OVALUE(n); } + +static inline Value v_replace(Uint32 from,Value cl,Value x,Value y,Value im,Value d) { + Uint8 c; + Uint32 n; + Object*o; + if(!cl.t && !cl.u) return NVALUE(0); + if(x.t || y.t || im.t || d.t) Throw("Type mismatch"); + if(x.u<1 || y.u<1 || x.u>pfwidth || y.u>pfheight) return NVALUE(0); + if(cl.t==TY_CLASS) { + if(c=classes[cl.u]->collisionLayers) { + n=playfield[x.u+y.u*64-65]; + while(n!=VOIDLINK) { + if(!(objects[n]->oflags&OF_DESTROYED) && (classes[objects[n]->class]->collisionLayers&c)) destroy(VOIDLINK,n,3); + n=objects[n]->up; + } + } + n=create(from,cl.u,x.u,y.u,im.u,d.u); + set_bizarro(n,0); + return OVALUE(n); + } else if(cl.t>TY_MAXTYPE) { + o=objects[n=v_object(cl)]; + if(o->oflags&OF_DESTROYED) return NVALUE(0); + if(o->x==x.u && o->y==y.u && !(o->oflags&OF_BIZARRO)) { + o->oflags&=~OF_MOVING; + o->image=im.u; + o->dir=resolve_dir(n,d.u); + return cl; + } + if(c=classes[o->class]->collisionLayers) { + n=playfield[x.u+y.u*64-65]; + while(n!=VOIDLINK) { + if(!(objects[n]->oflags&OF_DESTROYED) && (classes[objects[n]->class]->collisionLayers&c)) destroy(cl.u,n,3); + n=objects[n]->up; + } + n=v_object(cl); + } + move_to(from,n,x.u,y.u); + if(o->x==x.u && o->y==y.u && !(o->oflags&OF_DESTROYED)) { + o->oflags&=~OF_MOVING; + o->image=im.u; + o->dir=resolve_dir(n,d.u); + set_bizarro(n,0); + return OVALUE(n); + } else { + return NVALUE(0); + } + } else { + Throw("Type mismatch"); + } +} static int v_for(Uint16*code,int ptr,Value v,Value xv,Value yv) { int k=code[ptr]; Uint32 n; if(xv.t || yv.t) Throw("Type mismatch"); @@ -3196,10 +3246,12 @@ case OP_QOZ: StackReq(1,1); t1=Pop(); NotSound(t1); if(t1.t>TY_MAXTYPE || (t1.t==TY_NUMBER && !t1.u)) Push(NVALUE(1)); else Push(NVALUE(0)); break; case OP_QS: StackReq(1,1); t1=Pop(); NotSound(t1); if(t1.t==TY_STRING || t1.t==TY_LEVELSTRING) Push(NVALUE(1)); else Push(NVALUE(0)); break; case OP_QUEEN: StackReq(0,1); Numeric(msgvars.arg1); i="\x06\x01\x07\x05\x03\x04\x02\x00"[msgvars.arg1.u&7]; Push(NVALUE(i)); break; case OP_REL: StackReq(1,1); t1=Pop(); Numeric(t1); i=resolve_dir(obj,t1.u); Push(NVALUE(i)); break; case OP_REL_C: StackReq(2,1); t2=Pop(); Numeric(t2); t1=Pop(); i=v_object(t1); i=(i==VOIDLINK?t2.u:resolve_dir(i,t2.u)); Push(NVALUE(i)); break; + case OP_REPLACE: NoIgnore(); StackReq(5,1); t5=Pop(); t4=Pop(); t3=Pop(); t2=Pop(); t1=Pop(); Push(v_replace(obj,t1,t2,t3,t4,t5)); break; + case OP_REPLACE_D: NoIgnore(); StackReq(5,0); t5=Pop(); t4=Pop(); t3=Pop(); t2=Pop(); t1=Pop(); v_replace(obj,t1,t2,t3,t4,t5); break; case OP_RET: return; case OP_ROT: StackReq(3,3); t3=Pop(); t2=Pop(); t1=Pop(); Push(t2); Push(t3); Push(t1); break; case OP_ROTBACK: StackReq(3,3); t3=Pop(); t2=Pop(); t1=Pop(); Push(t3); Push(t1); Push(t2); break; case OP_RSH: StackReq(2,1); t2=Pop(); Numeric(t2); t1=Pop(); Numeric(t1); Push(NVALUE(t2.u&~31?0:t1.u>>t2.u)); break; case OP_RSH_C: StackReq(2,1); t2=Pop(); Numeric(t2); t1=Pop(); Numeric(t1); Push(NVALUE(t2.u&~31?(t1.s<0?-1:0):t1.s>>t2.u)); break; Index: instruc ================================================================== --- instruc +++ instruc @@ -276,10 +276,11 @@ ObjMovingTo ObjTopAt PopUp *PopUpArgs ; for (PopUp [number]) ,Rel +.Replace ,Seek .,Send .,SendEx ; send with three arguments SetInventory Sound Index: instruc.h ================================================================== --- instruc.h +++ instruc.h @@ -412,96 +412,98 @@ #define OP_OBJTOPAT 32971 #define OP_POPUP 32972 #define OP_POPUPARGS 32973 #define OP_REL 32974 #define OP_REL_C 35022 -#define OP_SEEK 32975 -#define OP_SEEK_C 35023 -#define OP_SEND 32976 -#define OP_SEND_C 35024 -#define OP_SEND_D 41168 -#define OP_SEND_CD 43216 -#define OP_SENDEX 32977 -#define OP_SENDEX_C 35025 -#define OP_SENDEX_D 41169 -#define OP_SENDEX_CD 43217 -#define OP_SETINVENTORY 32978 -#define OP_SOUND 32979 -#define OP_SWEEP 32980 -#define OP_SWEEPEX 32981 -#define OP_SYNCHRONIZE 32982 -#define OP_TARGET 32983 -#define OP_TARGET_C 35031 -#define OP_TRACE 32984 -#define OP_TRACESTACK 32985 -#define OP_TRACESTACK_C 35033 -#define OP_TRIGGER 32986 -#define OP_TRIGGERAT 32987 -#define OP_VOLUMEAT 32988 -#define OP_WALKABLE 32989 -#define OP_WALKABLE_C 35037 -#define OP_WINLEVEL 32990 -#define OP_WINLEVEL_C 35038 -#define OP_XDIR 32991 -#define OP_XDIR_C 35039 -#define OP_XSTEP 32992 -#define OP_XSTEP_C 35040 -#define OP_XYDIR 32993 -#define OP_YDIR 32994 -#define OP_YDIR_C 35042 -#define OP_YSTEP 32995 -#define OP_YSTEP_C 35043 -#define OP_MARK 32996 -#define OP_TMARK 32997 -#define OP_IN 32998 -#define OP_NIN 32999 -#define OP_MBEGIN 33000 -#define OP_FLIP 33001 -#define OP_COUNT 33002 -#define OP_CLEAR 33003 -#define OP_UNIQ 33004 -#define OP_ARRAY 33005 -#define OP_GETARRAY 33006 -#define OP_GETARRAY_C 35054 -#define OP_INITARRAY 33007 -#define OP_SETARRAY 33008 -#define OP_SETARRAY_C 35056 -#define OP_ARRAYCELL 33009 -#define OP_ARRAYCELL_C 35057 -#define OP_ARRAYSLICE 33010 -#define OP_COPYARRAY 33011 -#define OP_DOTPRODUCT 33012 -#define OP_PATTERN 33013 -#define OP_PATTERN_C 35061 -#define OP_PATTERN_E 37109 -#define OP_PATTERN_EC 39157 -#define OP_PATTERNS 33014 -#define OP_PATTERNS_C 35062 -#define OP_PATTERNS_E 37110 -#define OP_PATTERNS_EC 39158 -#define OP_ROOK 33015 -#define OP_BISHOP 33016 -#define OP_QUEEN 33017 -#define OP_CUT 33018 -#define OP_BIZARRO 33019 -#define OP_BIZARRO_C 35067 -#define OP_BIZARRO_E 37115 -#define OP_BIZARRO_EC 39163 -#define OP_BIZARROSWAP 33020 -#define OP_BIZARROSWAP_D 41212 -#define OP_SWAPWORLD 33021 -#define OP_ABSTRACT 33022 -#define OP_SUPER 33023 -#define OP_SUPER_C 35071 -#define OP_FUNCTION 33024 -#define OP_LOCAL 33025 -#define OP_LABEL 33026 -#define OP_STRING 33027 -#define OP_INT16 33028 -#define OP_INT32 33029 -#define OP_DISPATCH 33030 -#define OP_USERFLAG 33031 +#define OP_REPLACE 32975 +#define OP_REPLACE_D 41167 +#define OP_SEEK 32976 +#define OP_SEEK_C 35024 +#define OP_SEND 32977 +#define OP_SEND_C 35025 +#define OP_SEND_D 41169 +#define OP_SEND_CD 43217 +#define OP_SENDEX 32978 +#define OP_SENDEX_C 35026 +#define OP_SENDEX_D 41170 +#define OP_SENDEX_CD 43218 +#define OP_SETINVENTORY 32979 +#define OP_SOUND 32980 +#define OP_SWEEP 32981 +#define OP_SWEEPEX 32982 +#define OP_SYNCHRONIZE 32983 +#define OP_TARGET 32984 +#define OP_TARGET_C 35032 +#define OP_TRACE 32985 +#define OP_TRACESTACK 32986 +#define OP_TRACESTACK_C 35034 +#define OP_TRIGGER 32987 +#define OP_TRIGGERAT 32988 +#define OP_VOLUMEAT 32989 +#define OP_WALKABLE 32990 +#define OP_WALKABLE_C 35038 +#define OP_WINLEVEL 32991 +#define OP_WINLEVEL_C 35039 +#define OP_XDIR 32992 +#define OP_XDIR_C 35040 +#define OP_XSTEP 32993 +#define OP_XSTEP_C 35041 +#define OP_XYDIR 32994 +#define OP_YDIR 32995 +#define OP_YDIR_C 35043 +#define OP_YSTEP 32996 +#define OP_YSTEP_C 35044 +#define OP_MARK 32997 +#define OP_TMARK 32998 +#define OP_IN 32999 +#define OP_NIN 33000 +#define OP_MBEGIN 33001 +#define OP_FLIP 33002 +#define OP_COUNT 33003 +#define OP_CLEAR 33004 +#define OP_UNIQ 33005 +#define OP_ARRAY 33006 +#define OP_GETARRAY 33007 +#define OP_GETARRAY_C 35055 +#define OP_INITARRAY 33008 +#define OP_SETARRAY 33009 +#define OP_SETARRAY_C 35057 +#define OP_ARRAYCELL 33010 +#define OP_ARRAYCELL_C 35058 +#define OP_ARRAYSLICE 33011 +#define OP_COPYARRAY 33012 +#define OP_DOTPRODUCT 33013 +#define OP_PATTERN 33014 +#define OP_PATTERN_C 35062 +#define OP_PATTERN_E 37110 +#define OP_PATTERN_EC 39158 +#define OP_PATTERNS 33015 +#define OP_PATTERNS_C 35063 +#define OP_PATTERNS_E 37111 +#define OP_PATTERNS_EC 39159 +#define OP_ROOK 33016 +#define OP_BISHOP 33017 +#define OP_QUEEN 33018 +#define OP_CUT 33019 +#define OP_BIZARRO 33020 +#define OP_BIZARRO_C 35068 +#define OP_BIZARRO_E 37116 +#define OP_BIZARRO_EC 39164 +#define OP_BIZARROSWAP 33021 +#define OP_BIZARROSWAP_D 41213 +#define OP_SWAPWORLD 33022 +#define OP_ABSTRACT 33023 +#define OP_SUPER 33024 +#define OP_SUPER_C 35072 +#define OP_FUNCTION 33025 +#define OP_LOCAL 33026 +#define OP_LABEL 33027 +#define OP_STRING 33028 +#define OP_INT16 33029 +#define OP_INT32 33030 +#define OP_DISPATCH 33031 +#define OP_USERFLAG 33032 #ifdef HEROMESH_CLASS static const Op_Names op_names[]={ {"*",8486943}, {"+",8421405}, {"+Move",10584255}, @@ -511,19 +513,19 @@ {".",10518528}, {"/",8486944}, {"/mod",8486946}, {"ANHH",8389393}, {"ARRIVED",8389124}, -{"Abstract",8683774}, +{"Abstract",8683775}, {"Animate",8552599}, {"AnimateDead",8552600}, {"Arg1",8552578}, {"Arg2",8552579}, {"Arg3",8552580}, -{"Array",8683757}, -{"ArrayCell",8487153}, -{"ArraySlice",8421618}, +{"Array",8683758}, +{"ArrayCell",8487154}, +{"ArraySlice",8421619}, {"Arrivals",8618093}, {"Arrived",8618091}, {"Assassinate",8487065}, {"B",9437196}, {"BANG",8389380}, @@ -536,13 +538,13 @@ {"BRRREEET",8389395}, {"BRRRT",8389394}, {"BUZZER",8389419}, {"BWEEP",8389396}, {"Background",8683657}, -{"Bishop",8683768}, -{"Bizarro",8618235}, -{"BizarroSwap",10518780}, +{"Bishop",8683769}, +{"Bizarro",8618236}, +{"BizarroSwap",10518781}, {"Broadcast",10518682}, {"BroadcastAnd",8421531}, {"BroadcastAndEx",8421532}, {"BroadcastEx",10518686}, {"BroadcastList",8421535}, @@ -568,11 +570,11 @@ {"Coloc",8487077}, {"Compatible",8487036}, {"Connect",8487078}, {"Connection",8618105}, {"Control",8421516}, -{"CopyArray",8421619}, +{"CopyArray",8421620}, {"Create",10518695}, {"Crush",8618110}, {"DEEP_POP",8389416}, {"DEPARTED",8389125}, {"DESTROY",8389122}, @@ -591,11 +593,11 @@ {"Destroy",10584235}, {"Destroyed",8487034}, {"Dir",8618055}, {"Distance",9142347}, {"Done",8618104}, -{"DotProduct",8421620}, +{"DotProduct",8421621}, {"E",9437184}, {"END_TURN",8389139}, {"EditorHelp",8683668}, {"F",9437192}, {"FAROUT",8389420}, @@ -608,11 +610,11 @@ {"FlushClass",8421550}, {"FlushObj",8487087}, {"From",8421505}, {"GLASS",8389379}, {"GLISSANT",8389418}, -{"GetArray",8487150}, +{"GetArray",8487151}, {"GetInventory",8421552}, {"HAWK",8389424}, {"HEARTBEAT",8389406}, {"HIT",8389134}, {"HITBY",8389135}, @@ -624,11 +626,11 @@ {"INIT",8389120}, {"IgnoreKey",8421555}, {"Image",8618056}, {"InPlace",8683665}, {"Inertia",9142345}, -{"InitArray",8421615}, +{"InitArray",8421616}, {"Input",8683663}, {"InputXY",8683662}, {"IntMove",10584244}, {"Invisible",8618096}, {"JAYAYAYNG",8389415}, @@ -689,89 +691,90 @@ {"ObjLayerAt",8421577}, {"ObjMovingTo",8421578}, {"ObjTopAt",8421579}, {"Order",8683659}, {"Others",8683669}, -{"P",8880373}, -{"P*",8880374}, +{"P",8880374}, +{"P*",8880375}, {"PLAYERMOVING",8389133}, {"POSTINIT",8389138}, {"POUR",8389377}, {"POWER",8389386}, {"Player",8487035}, {"PopUp",8421580}, -{"Queen",8683769}, +{"Queen",8683770}, {"Quiz",8683664}, {"R",9437198}, {"RATCHET1",8389417}, {"RATCHET2",8389411}, {"RATTLE",8389402}, {"RB",9437197}, {"RF",9437199}, {"Rel",8487118}, -{"Rook",8683767}, +{"Replace",10518735}, +{"Rook",8683768}, {"S",9437190}, {"SE",9437191}, {"SMALL_POP",8389388}, {"SPLASH",8389376}, {"STEAM",8389423}, {"STOP",8388608}, {"SUBS",8683670}, {"SUNK",8389131}, {"SW",9437189}, -{"Seek",8487119}, +{"Seek",8487120}, {"Self",8421503}, -{"Send",10584272}, -{"SendEx",10584273}, -{"SetArray",8487152}, -{"SetInventory",8421586}, +{"Send",10584273}, +{"SendEx",10584274}, +{"SetArray",8487153}, +{"SetInventory",8421587}, {"Shape",8618052}, {"ShapeDir",8618075}, {"Sharp",8618074}, {"Shovable",8618076}, -{"Sound",8421587}, +{"Sound",8421588}, {"Stealthy",8618101}, {"Strength",9142359}, -{"Super",8487167}, -{"SwapWorld",8421629}, -{"Sweep",8421588}, -{"SweepEx",8421589}, -{"Synchronize",8421590}, +{"Super",8487168}, +{"SwapWorld",8421630}, +{"Sweep",8421589}, +{"SweepEx",8421590}, +{"Synchronize",8421591}, {"TAHTASHH",8389408}, {"THMP_thmp",8389404}, {"THWIT",8389384}, {"TICK",8389390}, -{"Target",8487127}, +{"Target",8487128}, {"Temperature",9142338}, -{"Trace",8421592}, -{"TraceStack",8487129}, -{"Trigger",8421594}, -{"TriggerAt",8421595}, +{"Trace",8421593}, +{"TraceStack",8487130}, +{"Trigger",8421595}, +{"TriggerAt",8421596}, {"UH_OH",8389382}, {"UNCORK",8389413}, {"UNHH",8389381}, {"UserSignal",8618098}, {"UserState",8618099}, {"VACUUM",8389410}, {"VisualOnly",8618100}, {"Volume",9142351}, -{"VolumeAt",8421596}, +{"VolumeAt",8421597}, {"W",9437188}, {"WAHOO",8389399}, {"WHACK",8389422}, -{"Walkable",8487133}, +{"Walkable",8487134}, {"Weight",9142353}, -{"WinLevel",8487134}, -{"XDir",8487135}, -{"XStep",8487136}, -{"XYDir",8421601}, +{"WinLevel",8487135}, +{"XDir",8487136}, +{"XStep",8487137}, +{"XYDir",8421602}, {"Xloc",8486981}, -{"YDir",8487138}, +{"YDir",8487139}, {"YEEHAW",8389400}, -{"YStep",8487139}, +{"YStep",8487140}, {"Yloc",8486982}, -{"_",8421604}, +{"_",8421605}, {"a?",8421440}, {"again",8683533}, {"and",8683544}, {"band",8421416}, {"begin",8683532}, @@ -812,26 +815,26 @@ {"bor",8421417}, {"bxor",8421418}, {"c?",8421434}, {"case",8683542}, {"chain",8421539}, -{"clear",8421611}, -{"count",8421610}, -{"cut",8683770}, +{"clear",8421612}, +{"count",8421611}, +{"cut",8683771}, {"cz?",8421435}, {"dup",8421377}, {"else",8683530}, {"eq",8421425}, {"eq2",8421426}, {"exec",8486940}, -{"flip",8421609}, +{"flip",8421610}, {"for",8683537}, {"fork",8683545}, {"ge",8486966}, {"gt",8486964}, {"if",8683529}, -{"in",8421606}, +{"in",8421607}, {"is",8421432}, {"land",8421421}, {"le",8486967}, {"link",8683547}, {"lnot",8421424}, @@ -839,18 +842,18 @@ {"lsh",8421414}, {"lt",8486965}, {"lxor",8421423}, {"m?",8421436}, {"max",8486949}, -{"mbegin",8683752}, +{"mbegin",8683753}, {"min",8486948}, {"mod",8486945}, {"n?",8421433}, {"ne",8421427}, {"neg",8421411}, {"next",8683538}, -{"nin",8421607}, +{"nin",8421608}, {"nip",8421379}, {"o?",8421438}, {"or",8683543}, {"over",8421384}, {"oz?",8421439}, @@ -861,13 +864,13 @@ {"rsh",8486951}, {"rtn",8683546}, {"s?",8421437}, {"swap",8421378}, {"then",8683531}, -{"tmark",8421605}, +{"tmark",8421606}, {"tuck",8421380}, -{"uniq",8421612}, +{"uniq",8421613}, {"until",8683534}, {"while",8683535}, }; -#define N_OP_NAMES 366 +#define N_OP_NAMES 367 #endif