static int side_set(lua_State *L) { side_t *side = *((side_t **)luaL_checkudata(L, 1, META_SIDE)); enum side_e field = luaL_checkoption(L, 2, side_opt[0], side_opt); if (!side) { if (field == side_valid) { lua_pushboolean(L, 0); return 1; } return luaL_error(L, "accessed side_t doesn't exist anymore."); } switch(field) { case side_valid: // valid case side_sector: case side_special: case side_text: default: return luaL_error(L, "side_t field " LUA_QS " cannot be set.", side_opt[field]); case side_textureoffset: side->textureoffset = luaL_checkfixed(L, 3); break; case side_rowoffset: side->rowoffset = luaL_checkfixed(L, 3); break; case side_toptexture: side->toptexture = luaL_checkinteger(L, 3); break; case side_bottomtexture: side->bottomtexture = luaL_checkinteger(L, 3); break; case side_midtexture: side->midtexture = luaL_checkinteger(L, 3); break; case side_repeatcnt: side->repeatcnt = luaL_checkinteger(L, 3); break; } return 0; }
// The searchBlockmap function // arguments: searchBlockmap(searchtype, function, mobj, [x1, x2, y1, y2]) // return value: // true = search completely uninteruppted, // false = searching of at least one block stopped mid-way (including if the whole search was stopped) static int lib_searchBlockmap(lua_State *L) { int searchtype = luaL_checkoption(L, 1, "objects", search_opt); int n; mobj_t *mobj; INT32 xl, xh, yl, yh, bx, by; fixed_t x1, x2, y1, y2; boolean retval = true; UINT8 funcret = 0; blockmap_func searchFunc; lua_remove(L, 1); // remove searchtype, stack is now function, mobj, [x1, x2, y1, y2] luaL_checktype(L, 1, LUA_TFUNCTION); switch (searchtype) { case 0: // "objects" default: searchFunc = lib_searchBlockmap_Objects; break; case 1: // "lines" searchFunc = lib_searchBlockmap_Lines; break; } // the mobj we are searching around, the "calling" mobj we could say mobj = *((mobj_t **)luaL_checkudata(L, 2, META_MOBJ)); if (!mobj) return LUA_ErrInvalid(L, "mobj_t"); n = lua_gettop(L); if (n > 2) // specific x/y ranges have been supplied { if (n < 6) return luaL_error(L, "arguments 4 to 6 not all given (expected 4 fixed-point integers)"); x1 = luaL_checkfixed(L, 3); x2 = luaL_checkfixed(L, 4); y1 = luaL_checkfixed(L, 5); y2 = luaL_checkfixed(L, 6); } else // mobj and function only - search around mobj's radius by default { fixed_t radius = mobj->radius + MAXRADIUS; x1 = mobj->x - radius; x2 = mobj->x + radius; y1 = mobj->y - radius; y2 = mobj->y + radius; } lua_settop(L, 2); // pop everything except function, mobj xl = (unsigned)(x1 - bmaporgx)>>MAPBLOCKSHIFT; xh = (unsigned)(x2 - bmaporgx)>>MAPBLOCKSHIFT; yl = (unsigned)(y1 - bmaporgy)>>MAPBLOCKSHIFT; yh = (unsigned)(y2 - bmaporgy)>>MAPBLOCKSHIFT; BMBOUNDFIX(xl, xh, yl, yh); blockfuncerror = false; // reset validcount++; for (bx = xl; bx <= xh; bx++) for (by = yl; by <= yh; by++) { funcret = searchFunc(L, bx, by, mobj); // return value of searchFunc determines searchFunc's return value and/or when to stop if (funcret == 2){ // stop whole search lua_pushboolean(L, false); // return false return 1; } else if (funcret == 1) // search was interrupted for this block retval = false; // this changes the return value, but doesn't stop the whole search // else don't do anything, continue as normal if (P_MobjWasRemoved(mobj)){ // ...unless the original object was removed lua_pushboolean(L, false); // in which case we have to stop now regardless return 1; } } lua_pushboolean(L, retval); return 1; }
static int player_set(lua_State *L) { player_t *plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); const char *field = luaL_checkstring(L, 2); if (!plr) return LUA_ErrInvalid(L, "player_t"); if (hud_running) return luaL_error(L, "Do not alter player_t in HUD rendering code!"); if (fastcmp(field,"mo")) { mobj_t *newmo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); plr->mo->player = NULL; // remove player pointer from old mobj (newmo->player = plr)->mo = newmo; // set player pointer for new mobj, and set new mobj as the player's mobj } else if (fastcmp(field,"cmd")) return NOSET; else if (fastcmp(field,"playerstate")) plr->playerstate = luaL_checkinteger(L, 3); else if (fastcmp(field,"viewz")) plr->viewz = luaL_checkfixed(L, 3); else if (fastcmp(field,"viewheight")) plr->viewheight = luaL_checkfixed(L, 3); else if (fastcmp(field,"deltaviewheight")) plr->deltaviewheight = luaL_checkfixed(L, 3); else if (fastcmp(field,"bob")) plr->bob = luaL_checkfixed(L, 3); else if (fastcmp(field,"aiming")) { plr->aiming = luaL_checkangle(L, 3); if (plr == &players[consoleplayer]) localaiming = plr->aiming; else if (plr == &players[secondarydisplayplayer]) localaiming2 = plr->aiming; } else if (fastcmp(field,"health")) plr->health = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"pity")) plr->pity = (SINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"currentweapon")) plr->currentweapon = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"ringweapons")) plr->ringweapons = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"powers")) return NOSET; else if (fastcmp(field,"pflags")) plr->pflags = luaL_checkinteger(L, 3); else if (fastcmp(field,"panim")) plr->panim = luaL_checkinteger(L, 3); else if (fastcmp(field,"flashcount")) plr->flashcount = (UINT16)luaL_checkinteger(L, 3); else if (fastcmp(field,"flashpal")) plr->flashpal = (UINT16)luaL_checkinteger(L, 3); else if (fastcmp(field,"skincolor")) { UINT8 newcolor = (UINT8)luaL_checkinteger(L,3); if (newcolor >= MAXSKINCOLORS) return luaL_error(L, "player.skincolor %d out of range (0 - %d).", newcolor, MAXSKINCOLORS-1); plr->skincolor = newcolor; } else if (fastcmp(field,"score")) plr->score = (UINT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"dashspeed")) plr->dashspeed = luaL_checkfixed(L, 3); else if (fastcmp(field,"dashtime")) plr->dashtime = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"normalspeed")) plr->normalspeed = luaL_checkfixed(L, 3); else if (fastcmp(field,"runspeed")) plr->runspeed = luaL_checkfixed(L, 3); else if (fastcmp(field,"thrustfactor")) plr->thrustfactor = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"accelstart")) plr->accelstart = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"acceleration")) plr->acceleration = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"charability")) plr->charability = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"charability2")) plr->charability2 = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"charflags")) plr->charflags = (UINT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"thokitem")) plr->thokitem = luaL_checkinteger(L, 3); else if (fastcmp(field,"spinitem")) plr->spinitem = luaL_checkinteger(L, 3); else if (fastcmp(field,"revitem")) plr->revitem = luaL_checkinteger(L, 3); else if (fastcmp(field,"actionspd")) plr->actionspd = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"mindash")) plr->mindash = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"maxdash")) plr->maxdash = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"jumpfactor")) plr->jumpfactor = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"lives")) plr->lives = (SINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"continues")) plr->continues = (SINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"xtralife")) plr->xtralife = (SINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"gotcontinue")) plr->gotcontinue = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"speed")) plr->speed = luaL_checkfixed(L, 3); else if (fastcmp(field,"jumping")) plr->jumping = luaL_checkboolean(L, 3); else if (fastcmp(field,"secondjump")) plr->secondjump = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"fly1")) plr->fly1 = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"scoreadd")) plr->scoreadd = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"glidetime")) plr->glidetime = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"climbing")) plr->climbing = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"deadtimer")) plr->deadtimer = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"exiting")) plr->exiting = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"homing")) plr->homing = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"skidtime")) plr->skidtime = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"cmomx")) plr->cmomx = luaL_checkfixed(L, 3); else if (fastcmp(field,"cmomy")) plr->cmomy = luaL_checkfixed(L, 3); else if (fastcmp(field,"rmomx")) plr->rmomx = luaL_checkfixed(L, 3); else if (fastcmp(field,"rmomy")) plr->rmomy = luaL_checkfixed(L, 3); else if (fastcmp(field,"numboxes")) plr->numboxes = (INT16)luaL_checkinteger(L, 3); else if (fastcmp(field,"totalring")) plr->totalring = (INT16)luaL_checkinteger(L, 3); else if (fastcmp(field,"realtime")) plr->realtime = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"laps")) plr->laps = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"ctfteam")) plr->ctfteam = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"gotflag")) plr->gotflag = (UINT16)luaL_checkinteger(L, 3); else if (fastcmp(field,"weapondelay")) plr->weapondelay = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"tossdelay")) plr->tossdelay = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"starpostx")) plr->starpostx = (INT16)luaL_checkinteger(L, 3); else if (fastcmp(field,"starposty")) plr->starposty = (INT16)luaL_checkinteger(L, 3); else if (fastcmp(field,"starpostz")) plr->starpostz = (INT16)luaL_checkinteger(L, 3); else if (fastcmp(field,"starpostnum")) plr->starpostnum = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"starposttime")) plr->starposttime = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"starpostangle")) plr->starpostangle = luaL_checkangle(L, 3); else if (fastcmp(field,"angle_pos")) plr->angle_pos = luaL_checkangle(L, 3); else if (fastcmp(field,"old_angle_pos")) plr->old_angle_pos = luaL_checkangle(L, 3); else if (fastcmp(field,"axis1")) P_SetTarget(&plr->axis1, *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ))); else if (fastcmp(field,"axis2")) P_SetTarget(&plr->axis2, *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ))); else if (fastcmp(field,"bumpertime")) plr->bumpertime = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"flyangle")) plr->flyangle = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"drilltimer")) plr->drilltimer = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"linkcount")) plr->linkcount = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"linktimer")) plr->linktimer = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"anotherflyangle")) plr->anotherflyangle = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"nightstime")) plr->nightstime = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"drillmeter")) plr->drillmeter = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"drilldelay")) plr->drilldelay = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"bonustime")) plr->bonustime = luaL_checkboolean(L, 3); else if (fastcmp(field,"capsule")) { mobj_t *mo = NULL; if (!lua_isnil(L, 3)) mo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); P_SetTarget(&plr->capsule, mo); } else if (fastcmp(field,"mare")) plr->mare = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"marebegunat")) plr->marebegunat = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"startedtime")) plr->startedtime = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"finishedtime")) plr->finishedtime = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"finishedrings")) plr->finishedrings = (INT16)luaL_checkinteger(L, 3); else if (fastcmp(field,"marescore")) plr->marescore = (UINT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"lastmarescore")) plr->lastmarescore = (UINT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"lastmare")) plr->lastmare = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"maxlink")) plr->maxlink = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"texttimer")) plr->texttimer = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"textvar")) plr->textvar = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"lastsidehit")) plr->lastsidehit = (INT16)luaL_checkinteger(L, 3); else if (fastcmp(field,"lastlinehit")) plr->lastlinehit = (INT16)luaL_checkinteger(L, 3); else if (fastcmp(field,"losstime")) plr->losstime = (tic_t)luaL_checkinteger(L, 3); else if (fastcmp(field,"timeshit")) plr->timeshit = (UINT8)luaL_checkinteger(L, 3); else if (fastcmp(field,"onconveyor")) plr->onconveyor = (INT32)luaL_checkinteger(L, 3); else if (fastcmp(field,"awayviewmobj")) { mobj_t *mo = NULL; if (!lua_isnil(L, 3)) mo = *((mobj_t **)luaL_checkudata(L, 3, META_MOBJ)); P_SetTarget(&plr->awayviewmobj, mo); } else if (fastcmp(field,"awayviewtics")) { plr->awayviewtics = (INT32)luaL_checkinteger(L, 3); if (plr->awayviewtics && !plr->awayviewmobj) // awayviewtics must ALWAYS have an awayviewmobj set!! P_SetTarget(&plr->awayviewmobj, plr->mo); // but since the script might set awayviewmobj immediately AFTER setting awayviewtics, use player mobj as filler for now. } else if (fastcmp(field,"awayviewaiming")) plr->awayviewaiming = luaL_checkangle(L, 3); else if (fastcmp(field,"spectator")) plr->spectator = lua_toboolean(L, 3); else if (fastcmp(field,"bot")) return NOSET; else if (fastcmp(field,"jointime")) plr->jointime = (tic_t)luaL_checkinteger(L, 3); #ifdef HWRENDER else if (fastcmp(field,"fovadd")) plr->fovadd = luaL_checkfixed(L, 3); #endif else { lua_getfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS); I_Assert(lua_istable(L, -1)); lua_pushlightuserdata(L, plr); lua_rawget(L, -2); if (lua_isnil(L, -1)) { // This index doesn't have a table for extra values yet, let's make one. lua_pop(L, 1); CONS_Debug(DBG_LUA, M_GetText("'%s' has no field named '%s'; adding it as Lua data.\n"), "player_t", field); lua_newtable(L); lua_pushlightuserdata(L, plr); lua_pushvalue(L, -2); // ext value table lua_rawset(L, -4); // LREG_EXTVARS table } lua_pushvalue(L, 3); // value to store lua_setfield(L, -2, field); lua_pop(L, 2); } return 0; }
static int sector_set(lua_State *L) { sector_t *sector = *((sector_t **)luaL_checkudata(L, 1, META_SECTOR)); enum sector_e field = luaL_checkoption(L, 2, sector_opt[0], sector_opt); if (!sector) return luaL_error(L, "accessed sector_t doesn't exist anymore."); if (hud_running) return luaL_error(L, "Do not alter sector_t in HUD rendering code!"); switch(field) { case sector_valid: // valid case sector_thinglist: // thinglist case sector_heightsec: // heightsec case sector_camsec: // camsec case sector_ffloors: // ffloors default: return luaL_error(L, "sector_t field " LUA_QS " cannot be set.", sector_opt[field]); case sector_floorheight: { // floorheight boolean flag; mobj_t *ptmthing = tmthing; fixed_t lastpos = sector->floorheight; sector->floorheight = luaL_checkfixed(L, 3); flag = P_CheckSector(sector, true); if (flag && sector->numattached) { sector->floorheight = lastpos; P_CheckSector(sector, true); } P_SetTarget(&tmthing, ptmthing); break; } case sector_ceilingheight: { // ceilingheight boolean flag; mobj_t *ptmthing = tmthing; fixed_t lastpos = sector->ceilingheight; sector->ceilingheight = luaL_checkfixed(L, 3); flag = P_CheckSector(sector, true); if (flag && sector->numattached) { sector->ceilingheight = lastpos; P_CheckSector(sector, true); } P_SetTarget(&tmthing, ptmthing); break; } case sector_floorpic: sector->floorpic = P_AddLevelFlatRuntime(luaL_checkstring(L, 3)); break; case sector_ceilingpic: sector->ceilingpic = P_AddLevelFlatRuntime(luaL_checkstring(L, 3)); break; case sector_lightlevel: sector->lightlevel = (INT16)luaL_checkinteger(L, 3); break; case sector_special: sector->special = (INT16)luaL_checkinteger(L, 3); break; case sector_tag: P_ChangeSectorTag((UINT32)(sector - sectors), (INT16)luaL_checkinteger(L, 3)); break; } return 0; }
static int ffloor_set(lua_State *L) { ffloor_t *ffloor = *((ffloor_t **)luaL_checkudata(L, 1, META_FFLOOR)); enum ffloor_e field = luaL_checkoption(L, 2, ffloor_opt[0], ffloor_opt); if (!ffloor) return luaL_error(L, "accessed ffloor_t doesn't exist anymore."); if (hud_running) return luaL_error(L, "Do not alter ffloor_t in HUD rendering code!"); switch(field) { case ffloor_valid: // valid case ffloor_sector: // sector case ffloor_master: // master case ffloor_target: // target case ffloor_next: // next case ffloor_prev: // prev default: return luaL_error(L, "ffloor_t field " LUA_QS " cannot be set.", ffloor_opt[field]); case ffloor_topheight: { // topheight boolean flag; fixed_t lastpos = *ffloor->topheight; mobj_t *ptmthing = tmthing; sector_t *sector = §ors[ffloor->secnum]; sector->ceilingheight = luaL_checkfixed(L, 3); flag = P_CheckSector(sector, true); if (flag && sector->numattached) { *ffloor->topheight = lastpos; P_CheckSector(sector, true); } P_SetTarget(&tmthing, ptmthing); break; } case ffloor_toppic: *ffloor->toppic = P_AddLevelFlatRuntime(luaL_checkstring(L, 3)); break; case ffloor_toplightlevel: *ffloor->toplightlevel = (INT16)luaL_checkinteger(L, 3); break; case ffloor_bottomheight: { // bottomheight boolean flag; fixed_t lastpos = *ffloor->bottomheight; mobj_t *ptmthing = tmthing; sector_t *sector = §ors[ffloor->secnum]; sector->floorheight = luaL_checkfixed(L, 3); flag = P_CheckSector(sector, true); if (flag && sector->numattached) { *ffloor->bottomheight = lastpos; P_CheckSector(sector, true); } P_SetTarget(&tmthing, ptmthing); break; } case ffloor_bottompic: *ffloor->bottompic = P_AddLevelFlatRuntime(luaL_checkstring(L, 3)); break; case ffloor_flags: { ffloortype_e oldflags = ffloor->flags; // store FOF's old flags ffloor->flags = luaL_checkinteger(L, 3); if (ffloor->flags != oldflags) ffloor->target->moved = true; // reset target sector's lightlist break; } case ffloor_alpha: ffloor->alpha = (INT32)luaL_checkinteger(L, 3); break; } return 0; }