本文整理汇总了C++中Thing类的典型用法代码示例。如果您正苦于以下问题:C++ Thing类的具体用法?C++ Thing怎么用?C++ Thing使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Thing类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: popNumber
int NpcScriptInterface::luagetDistanceTo(lua_State *L)
{
//getDistanceTo(uid)
uint32_t uid = popNumber(L);
ScriptEnviroment* env = getScriptEnv();
Npc* npc = env->getNpc();
Thing* thing = env->getThingByUID(uid);
if(thing && npc){
Position thing_pos = thing->getPosition();
Position npc_pos = npc->getPosition();
if(npc_pos.z != thing_pos.z){
lua_pushnumber(L, -1);
}
else{
int32_t dist = std::max(std::abs(npc_pos.x - thing_pos.x), std::abs(npc_pos.y - thing_pos.y));
lua_pushnumber(L, dist);
}
}
else{
reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
lua_pushnil(L);
}
return 1;
}
示例2: getNextPosition
void Commands::removeThing(Player* player, const std::string& cmd, const std::string& param)
{
Position pos = player->getPosition();
pos = getNextPosition(player->direction, pos);
Tile* removeTile = g_game.getMap()->getTile(pos);
if (!removeTile) {
player->sendTextMessage(MSG_STATUS_SMALL, "Tile not found.");
g_game.addMagicEffect(pos, NM_ME_POFF);
return;
}
Thing* thing = removeTile->getTopVisibleThing(player);
if (!thing) {
player->sendTextMessage(MSG_STATUS_SMALL, "Object not found.");
g_game.addMagicEffect(pos, NM_ME_POFF);
return;
}
if (Creature* creature = thing->getCreature()) {
g_game.removeCreature(creature, true);
} else {
Item* item = thing->getItem();
if (item) {
if (item->isGroundTile()) {
player->sendTextMessage(MSG_STATUS_SMALL, "You may not remove a ground tile.");
g_game.addMagicEffect(pos, NM_ME_POFF);
return;
}
g_game.internalRemoveItem(item, std::max<int32_t>(1, std::min<int32_t>(atoi(param.c_str()), item->getItemCount())));
g_game.addMagicEffect(pos, NM_ME_MAGIC_BLOOD);
}
}
}
示例3: getScriptEnv
int NpcScriptInterface::luagetDistanceTo(lua_State* L)
{
//getDistanceTo(uid)
ScriptEnvironment* env = getScriptEnv();
Npc* npc = env->getNpc();
if (!npc) {
reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
lua_pushnil(L);
return 1;
}
uint32_t uid = getNumber<uint32_t>(L, -1);
Thing* thing = env->getThingByUID(uid);
if (!thing) {
reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND));
lua_pushnil(L);
return 1;
}
const Position& thingPos = thing->getPosition();
const Position& npcPos = npc->getPosition();
if (npcPos.z != thingPos.z) {
lua_pushnumber(L, -1);
} else {
int32_t dist = std::max<int32_t>(Position::getDistanceX(npcPos, thingPos), Position::getDistanceY(npcPos, thingPos));
lua_pushnumber(L, dist);
}
return 1;
}
示例4: collect_garbage
void WebThings::collect_garbage()
{
if (stale_count) {
// mark all nodes reachable from the roots
for (Thing *t = things; t; t = (Thing *)t->next)
t->reachable(gc_phase);
/*
for (Proxy *proxy = proxies; proxy; proxy = (Proxy *)proxy->next) {
reachable(proxy->properties);
reachable(proxy->proxies);
}
*/
// now sweep through the nodes reachable from the stale list
// and delete the ones that aren't reachable from the roots
for (unsigned int i = 0; i < stale_count; ++i) {
JSON *json = get_json(stale[i]);
if (!json->marked(gc_phase)) {
json->sweep(gc_phase);
for (unsigned int j = i; j < stale_count - 1; ++j)
stale[j] = stale[j+1];
--stale_count;
}
}
gc_phase = !gc_phase;
JSON::set_gc_phase(gc_phase); // to ensure new nodes are marked correctly
}
}
示例5: main
// -------------------------------------------------------------
// Main Program
// -------------------------------------------------------------
int
main(int argc, char **argv)
{
Thing thing;
thing.message();
return 0;
}
示例6: getEvent
uint32_t MoveEvents::onCreatureMove(Creature* creature, Tile* tile, bool isIn)
{
MoveEvent_t eventType;
if(isIn){
eventType = MOVE_EVENT_STEP_IN;
}
else{
eventType = MOVE_EVENT_STEP_OUT;
}
uint32_t ret = 1;
MoveEvent* moveEvent = getEvent(tile, eventType);
if(moveEvent){
ret = ret & moveEvent->fireStepEvent(creature, NULL, tile->getPosition());
}
int32_t j = tile->__getLastIndex();
Item* tileItem = NULL;
for(int32_t i = tile->__getFirstIndex(); i < j; ++i){
Thing* thing = tile->__getThing(i);
if(thing && (tileItem = thing->getItem())){
moveEvent = getEvent(tileItem, eventType);
if(moveEvent){
ret = ret & moveEvent->fireStepEvent(creature, tileItem, tile->getPosition());
}
}
}
return ret;
}
示例7: menuWindow
void Kernel::handleMotionNotify(XMotionEvent *event) {
Menu *menu = menuWindow(event->window);
if (menu) {
menu->handleMotionNotify(event);
}
Bar *bar = barWindow(event->window);
if (bar) {
bar->handleMotionNotify(event);
return;
}
Thing *thing = thingWindow(event->window);
if (thing) {
if (!thing->isFocused() && isSloppyMode_) {
Workspace *workspace = focusedMonitor()->focused();
workspace->focus(thing, false);
}
thing->handleMotionNotify(event);
}
// focusses the monitor if multihead
isRootWindow(event->root);
}
示例8: getEvent
uint32_t MoveEvents::onCreatureMove(Creature* creature, const Tile* tile, bool isIn)
{
MoveEvent_t eventType;
if (isIn) {
eventType = MOVE_EVENT_STEP_IN;
} else {
eventType = MOVE_EVENT_STEP_OUT;
}
Position pos = tile->getPosition();
uint32_t ret = 1;
MoveEvent* moveEvent = getEvent(tile, eventType);
if (moveEvent) {
ret = ret & moveEvent->fireStepEvent(creature, nullptr, pos);
}
for (int32_t i = tile->__getFirstIndex(), j = tile->__getLastIndex(); i < j; ++i) {
Thing* thing = tile->__getThing(i);
if (thing) {
Item* tileItem = thing->getItem();
if (tileItem) {
moveEvent = getEvent(tileItem, eventType);
if (moveEvent) {
ret = ret & moveEvent->fireStepEvent(creature, tileItem, pos);
}
}
}
}
return ret;
}
示例9: lua_gettop
int LuaThing::getAliases(lua_State *L) {
int n = lua_gettop(L);
if (1 != n) {
return luaL_error(L, "takes no arguments");
}
Thing *t = checkThing(L, -1);
if (0 == t) {
return luaL_error(L, "not a Thing!");
}
LuaArray luaAliases;
vector<string> aliases = t->getAliases();
for (vector<string>::const_iterator i = aliases.begin(); i != aliases.end(); i++) {
LuaValue v;
v.type = LUA_TYPE_STRING;
v.value = *i;
luaAliases.insert(luaAliases.end(), v);
}
LuaState::pushArray(L, luaAliases);
return 1;
}
示例10: getEvent
uint32_t MoveEvents::onCreatureMove(Creature* creature, const Tile* tile, const Position& fromPos, MoveEvent_t eventType)
{
const Position& pos = tile->getPosition();
uint32_t ret = 1;
MoveEvent* moveEvent = getEvent(tile, eventType);
if (moveEvent) {
ret &= moveEvent->fireStepEvent(creature, nullptr, pos, fromPos);
}
for (size_t i = tile->getFirstIndex(), j = tile->getLastIndex(); i < j; ++i) {
Thing* thing = tile->getThing(i);
if (!thing) {
continue;
}
Item* tileItem = thing->getItem();
if (!tileItem) {
continue;
}
moveEvent = getEvent(tileItem, eventType);
if (moveEvent) {
ret &= moveEvent->fireStepEvent(creature, tileItem, pos, fromPos);
}
}
return ret;
}
示例11: MultiLockUnsafeThread
void * MultiLockUnsafeThread( void * p )
{
const unsigned int value = reinterpret_cast< unsigned int >( p );
Thing * thing = nullptr;
unsigned int jj = 0;
unsigned int tests = 0;
unsigned int fails = 0;
unsigned int randomIndex = 0;
try
{
for ( unsigned int ii = 0; ii < thingCount; ++ii )
{
for ( jj = 0; jj < thingCount; ++jj )
{
thing = const_cast< Thing * >( Thing::GetFromPool( jj ) );
assert( nullptr != thing );
thing->SetValue( value );
}
::GoToSleep( 2 );
if ( WillRedoSingleTests() )
{
SingleThreadSimpleTest();
SingleThreadReentrantTest();
SingleThreadSimpleMultiLockTest();
SingleThreadComplexMultiLockTest( false );
SingleThreadExceptionTest();
}
thing = const_cast< Thing * >( Thing::GetFromPool( ii ) );
assert( nullptr != thing );
thing->Print( value, ii, 7 );
randomIndex = ( ::rand() % thingCount );
thing = const_cast< Thing * >( Thing::GetFromPool( randomIndex ) );
assert( nullptr != thing );
thing->Print( value, ii, 7 );
for ( jj = 0; jj < thingCount; ++jj )
{
thing = const_cast< Thing * >( Thing::GetFromPool( jj ) );
assert( nullptr != thing );
if ( thing->GetValue() != value )
fails++;
tests++;
}
::GoToSleep( 2 );
}
}
catch ( ... )
{
assert( false );
}
TestResults::GetIt()->SetResult( value, tests, fails );
return nullptr;
}
示例12: getParent
Container* Container::getParentContainer()
{
Thing* thing = getParent();
if (!thing) {
return nullptr;
}
return thing->getContainer();
}
示例13: getParent
Container* Container::getParentContainer()
{
Thing* thing = getParent();
if (thing) {
return thing->getContainer();
}
return NULL;
}
示例14: getTilePosition
Cylinder* Tile::__queryDestination(int32_t& index, const Thing* thing, Item** destItem,
uint32_t& flags)
{
Tile* destTile = NULL;
*destItem = NULL;
if(floorChangeDown()){
int dx = getTilePosition().x;
int dy = getTilePosition().y;
int dz = getTilePosition().z + 1;
Tile* downTile = g_game.getTile(dx, dy, dz);
if(downTile){
if(downTile->floorChange(NORTH))
dy += 1;
if(downTile->floorChange(SOUTH))
dy -= 1;
if(downTile->floorChange(EAST))
dx -= 1;
if(downTile->floorChange(WEST))
dx += 1;
destTile = g_game.getTile(dx, dy, dz);
}
}
else if(floorChange()){
int dx = getTilePosition().x;
int dy = getTilePosition().y;
int dz = getTilePosition().z - 1;
if(floorChange(NORTH))
dy -= 1;
if(floorChange(SOUTH))
dy += 1;
if(floorChange(EAST))
dx += 1;
if(floorChange(WEST))
dx -= 1;
destTile = g_game.getTile(dx, dy, dz);
}
if(destTile == NULL){
destTile = this;
}
else{
flags |= FLAG_NOLIMIT; //Will ignore that there is blocking items/creatures
}
if(destTile){
Thing* destThing = destTile->getTopDownItem();
if(destThing)
*destItem = destThing->getItem();
}
return destTile;
}
示例15: collidesWith
bool Thing::collidesWith(Thing &thing)
{
if(this->hp == 0 || thing.hp == 0)
return false;
return this->_collissionCheck(
this->x, this->y, this->x + this->width(), this->y + this->height(),
thing.x, thing.y, thing.x + thing.width(), thing.y + thing.height()
);
}