예제 #1
0
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);
		}
	}
}
예제 #2
0
파일: beds.cpp 프로젝트: AhmedWaly/CastOnly
BedItem* BedItem::getNextBedItem()
{
	if(Tile* tile = g_game.getTile(getNextPosition(Item::items[getID()].bedPartnerDir, getPosition())))
		return tile->getBedItem();

	return NULL;
}
예제 #3
0
bool Npc::canWalkTo(const Position& fromPos, Direction dir) const
{
	if (masterRadius == 0) {
		return false;
	}

	Position toPos = getNextPosition(dir, fromPos);
	if (!Spawns::getInstance()->isInZone(masterPos, masterRadius, toPos)) {
		return false;
	}

	Tile* tile = g_game.getTile(toPos.x, toPos.y, toPos.z);
	if (!tile || tile->__queryAdd(0, this, 1, 0) != RETURNVALUE_NOERROR) {
		return false;
	}

	if (!floorChange && (tile->floorChange() || tile->getTeleportItem())) {
		return false;
	}

	if (!ignoreHeight && tile->hasHeight(1)) {
		return false;
	}

	return true;
}
예제 #4
0
bool Npc::canWalkTo(const Position& fromPos, Direction dir) const
{
	if (masterRadius == 0) {
		return false;
	}

	Position toPos = getNextPosition(dir, fromPos);
	if (!Spawns::isInZone(masterPos, masterRadius, toPos)) {
		return false;
	}

	Tile* tile = g_game.map.getTile(toPos);
	if (!tile || tile->queryAdd(0, *this, 1, 0) != RETURNVALUE_NOERROR) {
		return false;
	}

	if (!floorChange && (tile->hasFlag(TILESTATE_FLOORCHANGE) || tile->getTeleportItem())) {
		return false;
	}

	if (!ignoreHeight && tile->hasHeight(1)) {
		return false;
	}

	return true;
}
예제 #5
0
파일: main.c 프로젝트: damys/c-lab
/**
 *  将小人向指定方向移动
 *  @param dir 指定的方向
 */
void movePerson(char dir){
    // 1. 拿到小人的下1个坐标,根据小人的前进方向而不同,如:根据小人当前的坐标和前进方向计算出小人的下个坐标
    int personNextRow = 0;
    int personNextCol = 0;
    //基准坐标为:小人的坐标
    getNextPosition(dir, personCurrentRow, personCurrentCol, &personNextRow, &personNextCol);
    
    // 2. 判断小人的下1个坐标是1个什么物品, 如果是空格就移动小人
    if(map[personNextRow][personNextCol] == ' ')
    {
        map[personNextRow][personNextCol] = '0';        //移动后将当前1坐标设置为小人
        map[personCurrentRow][personCurrentCol] = ' ';  //移动后将小人之前1坐标设置为空
        
        //推完之后,改小人的位置
        personCurrentRow = personNextRow;
        personCurrentCol = personNextCol;
        
    }
    else if(map[personNextRow][personNextCol] == 'X')   //如果是箱子,就开始推箱子了
    {
        // 要判断箱子能不推,就要拿到这个箱子的下1个坐标,而箱子的坐标是personNextRow, personNextCol
        int boxNextRow = 0;
        int boxNextCol = 0;
        
        // 这段代码就是根据箱子现在的坐标,算出箱子下1个坐标: 基准坐标为:personNextRow, personNextCol
        getNextPosition(dir, personNextRow, personNextCol, &boxNextRow, &boxNextCol);
        
        // 继续判断箱子的下1个坐标是路
        if(map[boxNextRow][boxNextCol] == ' '){
            map[boxNextRow][boxNextCol] = 'X';
            
            // 把当有箱子的位置设置为小人
            map[personNextRow][personNextCol] = '0';
            
            // 把小人的位置设置为这空格
            map[personCurrentRow][personCurrentCol] = ' ';
            
            //推完之后,改小人的位置
            personCurrentRow = personNextRow;
            personCurrentCol = personNextCol;
        }
        
    }

}
예제 #6
0
ofxW2DSlider & ofxWFrame::add2DSlider(const string & title, float xvalue, float yvalue, float xmin, float xmax, float ymin, float ymax, string controlName, const string & _style){
	controlName=getControlName(controlName,title);
	ofxW2DSlider * slider = new ofxW2DSlider(controlName);
	slider->init(title,xvalue,yvalue,xmin,xmax,ymin,ymax,_style==""?style:_style);

	slider->setPosition(getNextPosition());


	addWidget(slider,controlName);
	return *slider;
}
예제 #7
0
ofxWButton & ofxWFrame::addButton(const string & title, string controlName, string _style){
	controlName=getControlName(controlName,title);
	ofxWButton * button = new ofxWButton(controlName);
	button->init(title,_style==""?style:_style);

	button->setPosition(getNextPosition());


	addWidget(button,controlName);
	return *button;
}
예제 #8
0
파일: bed.cpp 프로젝트: JoseEduardo/mtcb
BedItem* BedItem::getNextBedItem() const
{
	Direction dir = Item::items[id].bedPartnerDir;
	Position targetPos = getNextPosition(dir, getPosition());

	Tile* tile = g_game.getTile(targetPos);
	if (!tile) {
		return nullptr;
	}
	return tile->getBedItem();
}
예제 #9
0
ofxWToggle & ofxWFrame::addToggle(const string & title, string controlName, string _style){
	controlName=getControlName(controlName,title);
	ofxWToggle * toggle = new ofxWToggle(controlName);
	toggle->init(title,_style==""?style:_style);

	toggle->setPosition(getNextPosition());


	addWidget(toggle,controlName);
	return *toggle;
}
예제 #10
0
ofxWSpinSlider & ofxWFrame::addSpinSlider(const string & title, float value, float min, float max, float step,  string controlName, const string & _style){
	controlName=getControlName(controlName,title);
	ofxWSpinSlider * slider = new ofxWSpinSlider(controlName);
	slider->init(title,value,min,max,step,_style==""?style:_style);

	slider->setPosition(getNextPosition());


	addWidget(slider,controlName);
	return *slider;
}
예제 #11
0
ofxWTextBox & ofxWFrame::addTextBox(const string & title, string text, string controlName, string _style){
	controlName=getControlName(controlName,title);
	ofxWTextBox * textBox = new ofxWTextBox(controlName);
	textBox->init(title,_style==""?style:_style);

	textBox->setPosition(getNextPosition());
	textBox->setText(text);


	addWidget(textBox,controlName);
	return *textBox;
}
예제 #12
0
BedItem* BedItem::getNextBedItem()
{
	Direction dir = Item::items[getID()].bedPartnerDir;
	Position targetPos = getNextPosition(dir, getPosition());

	Tile* tile = g_game.getMap()->getTile(targetPos);

	if (tile) {
		return tile->getBedItem();
	}

	return NULL;
}
예제 #13
0
void Commands::buyHouse(Player* player, const std::string& cmd, const std::string& param)
{
	if (!player->isPremium()) {
		player->sendCancelMessage(RET_YOUNEEDPREMIUMACCOUNT);
		return;
	}

	Position pos = player->getPosition();
	pos = getNextPosition(player->direction, pos);

	Tile* tile = g_game.getTile(pos.x, pos.y, pos.z);

	if (!tile) {
		player->sendCancel("You have to be looking at the door of the house you would like to buy.");
		return;
	}

	HouseTile* houseTile = dynamic_cast<HouseTile*>(tile);
	if (!houseTile) {
		player->sendCancel("You have to be looking at the door of the house you would like to buy.");
		return;
	}

	House* house = houseTile->getHouse();
	if (!house || !house->getDoorByPosition(pos)) {
		player->sendCancel("You have to be looking at the door of the house you would like to buy.");
		return;
	}

	if (house->getHouseOwner()) {
		player->sendCancel("This house alreadly has an owner.");
		return;
	}

	for (const auto& it : Houses::getInstance().getHouses()) {
		if (it.second->getHouseOwner() == player->guid) {
			player->sendCancel("You are already the owner of a house.");
			return;
		}
	}

	uint64_t price = house->getHouseTiles().size() * g_config.getNumber(ConfigManager::HOUSE_PRICE);
	if (!g_game.removeMoney(player, price)) {
		player->sendCancel("You do not have enough money.");
		return;
	}

	house->setHouseOwner(player->guid);
	player->sendTextMessage(MSG_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in the bank.");
}
예제 #14
0
void ofxWFrame::addLoadButton(const string & filename, const string & xml_root){
	ofxWButton * button = new ofxWButton("save_" + name);
	button->init("load from xml",style);

	button->setPosition(getNextPosition());

	addWidget(button,"LOAD");
	//controls.push_back(button);

	this->filename = filename;
	this->xml_root = xml_root;

	ofAddListener(button->intEvent,this,&ofxWFrame::onLoad);
}
예제 #15
0
bool Monster::canWalkTo(Position pos, Direction direction) const
{
	pos = getNextPosition(direction, pos);
	if (isInSpawnRange(pos)) {
		if (getWalkCache(pos) == 0) {
			return false;
		}

		Tile* tile = g_game.map.getTile(pos);
		if (tile && tile->getTopVisibleCreature(this) == nullptr && tile->queryAdd(0, *this, 1, FLAG_PATHFINDING) == RETURNVALUE_NOERROR) {
			return true;
		}
	}
	return false;
}
예제 #16
0
glm::mat4 Spline::getTransformMatrix(float u)
{
    auto t = getPositionAt(u);

    auto z = glm::normalize(-getNextPosition(u));
    auto y = vec3(0,1,0); //glm::normalize(getUpPosition(u));
    auto x = glm::normalize(glm::cross(y,z));
    y = glm::normalize(glm::cross(z,x));


    glm::mat4 mat = {x.x,x.y,x.z,0,
                     y.x,y.y,y.z,0,
                     z.x,z.y,z.z,0,
                     t.x,t.y,t.z,1.0f};
    return mat;
}
예제 #17
0
AudioFrame * AudioHeader::getNextFrame(){
    buffer->lock();
    if(pctHasChanged && buffer->size()){
        pct=CLAMP(pct,0,1);
        //cout << "vheader pct: "<< pct<< "\n";
        currentPos=pct*(buffer->size()-1);
        positionTS.update();
        position=buffer->getTotalFrames()-(buffer->size()-currentPos);
        pctHasChanged=false;
    }else{
        currentPos=getNextPosition();
        pct=(float)currentPos/(float)buffer->size();
    }
    AudioFrame * frame = buffer->getAudioFrame(currentPos);
    buffer->unlock();
    return frame;
}
예제 #18
0
ofxWidgetFps & ofxWFrame::addFps(string controlName){
	controlName=getControlName(controlName,"fps");
	ofxWidgetFps * fps = new ofxWidgetFps(controlName);

	/*fps->setEnabledStyle(buttonStyle);
	fps->setDisabledStyle(buttonStyle);
	fps->setFocusedStyle(buttonFocusedStyle);
	fps->setPressedStyle(buttonPressedStyle);
	fps->setOutStyle(buttonPressedStyle);*/


	fps->setPosition(getNextPosition());


	addWidget(fps,controlName);
	return *fps;
}
예제 #19
0
  void Camera::handleQueuedEvent(std::shared_ptr<Events::Event> event) { 
    switch(event->getEventType()) {
      case Events::EventType::SPRITE_MOVE: {
        free_camera = false;
        auto casted_event = std::static_pointer_cast<Game::SpriteMoveEvent>(event);

        if(casted_event->getVelocity().x > 0.0) {
          if(casted_event->getNextPosition().x > getTransform()->getAbsoluteTranslation().x + viewport_width / 2.0 - screen_padding_in_tiles) {
            velocity = casted_event->getVelocity();
            target_position = glm::vec2(getTransform()->getAbsoluteTranslation()) + glm::vec2(1.0, 0.0);
          }
        }
        else if(casted_event->getVelocity().x < 0.0) {
          if(casted_event->getNextPosition().x < getTransform()->getAbsoluteTranslation().x - viewport_width / 2.0 + screen_padding_in_tiles) {
            velocity = casted_event->getVelocity();
            target_position = glm::vec2(getTransform()->getAbsoluteTranslation()) + glm::vec2(-1.0, 0.0);
          }
        }
        else if(casted_event->getVelocity().y > 0.0) {
          if(casted_event->getNextPosition().y > getTransform()->getAbsoluteTranslation().y + viewport_height / 2.0 - screen_padding_in_tiles) {
            velocity = casted_event->getVelocity();
            target_position = glm::vec2(getTransform()->getAbsoluteTranslation()) + glm::vec2(0.0, 1.0);
          }
        }
        else if(casted_event->getVelocity().y < 0.0) {
          if(casted_event->getNextPosition().y < getTransform()->getAbsoluteTranslation().y - viewport_height / 2.0 + screen_padding_in_tiles) {
            velocity = casted_event->getVelocity();
            target_position = glm::vec2(getTransform()->getAbsoluteTranslation()) + glm::vec2(0.0, -1.0);
          }
        }
        break;
      }
      case Events::EventType::KEY_DOWN: {
        free_camera = true;
        auto casted_event = std::static_pointer_cast<Input::KeyDownEvent>(event);
        if(casted_event->getKey() == GLFW_KEY_W) {
          velocity = glm::vec2(velocity.x, free_camera_speed);
        }
        else if(casted_event->getKey() == GLFW_KEY_A) {
          velocity = glm::vec2(-free_camera_speed, velocity.y);
        }
        else if(casted_event->getKey() == GLFW_KEY_S) {
          velocity = glm::vec2(velocity.x, -free_camera_speed);
        }
        else if(casted_event->getKey() == GLFW_KEY_D) {
          velocity = glm::vec2(free_camera_speed, velocity.y);
        }
        break;
      }
      case Events::EventType::KEY_REPEAT: {
        auto casted_event = std::static_pointer_cast<Input::KeyRepeatEvent>(event);
        if(casted_event->getKey() == GLFW_KEY_W) {
          velocity = glm::vec2(velocity.x, free_camera_speed);
        }
        else if(casted_event->getKey() == GLFW_KEY_A) {
          velocity = glm::vec2(-free_camera_speed, velocity.y);
        }
        else if(casted_event->getKey() == GLFW_KEY_S) {
          velocity = glm::vec2(velocity.x, -free_camera_speed);
        }
        else if(casted_event->getKey() == GLFW_KEY_D) {
          velocity = glm::vec2(free_camera_speed, velocity.y);
        }
        break;
      }
      case Events::EventType::KEY_UP: {
        auto casted_event = std::static_pointer_cast<Input::KeyUpEvent>(event);
        if(casted_event->getKey() == GLFW_KEY_W) {
          velocity = glm::vec2(velocity.x, 0.0);
        }
        else if(casted_event->getKey() == GLFW_KEY_A) {
          velocity = glm::vec2(0.0, velocity.y);
        }
        else if(casted_event->getKey() == GLFW_KEY_S) {
          velocity = glm::vec2(velocity.x, 0.0);
        }
        else if(casted_event->getKey() == GLFW_KEY_D) {
          velocity = glm::vec2(0.0, velocity.y);
        }
        break;
      }

      default:
        Component::handleQueuedEvent(event);
    }
  }
예제 #20
0
void Monster::onCreatureMove(Creature* creature, const Tile* newTile, const Position& newPos,
                             const Tile* oldTile, const Position& oldPos, bool teleport)
{
	Creature::onCreatureMove(creature, newTile, newPos, oldTile, oldPos, teleport);

	if (mType->info.creatureMoveEvent != -1) {
		// onCreatureMove(self, creature, oldPosition, newPosition)
		LuaScriptInterface* scriptInterface = mType->info.scriptInterface;
		if (!scriptInterface->reserveScriptEnv()) {
			std::cout << "[Error - Monster::onCreatureMove] Call stack overflow" << std::endl;
			return;
		}

		ScriptEnvironment* env = scriptInterface->getScriptEnv();
		env->setScriptId(mType->info.creatureMoveEvent, scriptInterface);

		lua_State* L = scriptInterface->getLuaState();
		scriptInterface->pushFunction(mType->info.creatureMoveEvent);

		LuaScriptInterface::pushUserdata<Monster>(L, this);
		LuaScriptInterface::setMetatable(L, -1, "Monster");

		LuaScriptInterface::pushUserdata<Creature>(L, creature);
		LuaScriptInterface::setCreatureMetatable(L, -1, creature);

		LuaScriptInterface::pushPosition(L, oldPos);
		LuaScriptInterface::pushPosition(L, newPos);

		if (scriptInterface->callFunction(4)) {
			return;
		}
	}

	if (creature == this) {
		if (isSummon()) {
			isMasterInRange = canSee(getMaster()->getPosition());
		}

		updateTargetList();
		updateIdleStatus();
	} else {
		bool canSeeNewPos = canSee(newPos);
		bool canSeeOldPos = canSee(oldPos);

		if (canSeeNewPos && !canSeeOldPos) {
			onCreatureEnter(creature);
		} else if (!canSeeNewPos && canSeeOldPos) {
			onCreatureLeave(creature);
		}

		if (canSeeNewPos && isSummon() && getMaster() == creature) {
			isMasterInRange = true;    //Follow master again
		}

		updateIdleStatus();

		if (!isSummon()) {
			if (followCreature) {
				const Position& followPosition = followCreature->getPosition();
				const Position& position = getPosition();

				int32_t offset_x = Position::getDistanceX(followPosition, position);
				int32_t offset_y = Position::getDistanceY(followPosition, position);
				if ((offset_x > 1 || offset_y > 1) && mType->info.changeTargetChance > 0) {
					Direction dir = getDirectionTo(position, followPosition);
					const Position& checkPosition = getNextPosition(dir, position);

					Tile* tile = g_game.map.getTile(checkPosition);
					if (tile) {
						Creature* topCreature = tile->getTopCreature();
						if (topCreature && followCreature != topCreature && isOpponent(topCreature)) {
							selectTarget(topCreature);
						}
					}
				}
			} else if (isOpponent(creature)) {
				//we have no target lets try pick this one
				selectTarget(creature);
			}
		}
	}
}
void ControlLoopSTEPPER::update() {

  // -------------------------------
  //
  //  for timing / testing:
  //
  // -------------------------------

  digitalWriteFast(TP_INT_CLOCK,HIGH);

#ifdef INVERTED_PINS

  digitalWriteFast(pin_STEP_A, HIGH);

#else

  digitalWriteFast(pin_STEP_A, LOW);

#endif

  // -------------------------------
  //
  // do the bresenham's:
  //
  // -------------------------------

  if (A_theD > 0) {

    // do a step!

#ifdef INVERTED_PINS

  digitalWriteFast(pin_STEP_A, LOW);

#else

  digitalWriteFast(pin_STEP_A, HIGH);

#endif

    
    
    A_theD += A_twoDy_twoDx;

    /* ---- Keep track of position ---- */
    
    if (currentDirection) {
      currentPosition ++;
    } else {
      currentPosition --;
    }

    /* ---- check for home sensor ---- */
    
    if (digitalReadFast(HOME_SENSOR_SIGNAL) != homeSensorState) {
      if (!homeSensorState) {

        // sensor going high so record position
      
        homeSensorState = true;
        homeSensorPosition = currentPosition;
      
      } else {
        homeSensorState = false;
      }
    }
    
  
  } else {
  
    A_theD += A_twoDy;
  
  }


  // -------------------------------
  //
  //  Prepare for next time round
  //
  // -------------------------------




   // are we at the end of this subframe?
  currentStep--;
  if (currentStep == 0) {

    // yes, so get next deltas and calc Bres coefficients

    // for testing:
    digitalWriteFast(TP_GETNEXT, HIGH);

    // channel A:
    nextPosition = getNextPosition();
    nextDelta_A = nextPosition - currentPosition;
    
    if (nextDelta_A < 0) {
      // direction positive
      digitalWrite(pin_DIR_A,HIGH);
      currentDirection = false;
      nextDelta_A = -nextDelta_A;
    } 
    else {
      // direction negative
      digitalWrite(pin_DIR_A,LOW);
      currentDirection = true;
    }
    A_twoDy = 2 * nextDelta_A;
    A_twoDy_twoDx = A_twoDy - (INNERS_PER_OUTER * 2);
    A_theD = A_twoDy_twoDx + INNERS_PER_OUTER;

    // tidy up:
    nextDelta_A = 0;
    currentStep = INNERS_PER_OUTER;

    digitalWriteFast(TP_GETNEXT, LOW);

  } 

  // for timing testing:
  digitalWriteFast(TP_INT_CLOCK,LOW);
  
}
예제 #22
0
void main() {
// the matrix must be included as a modifier of gl_Position
	if (initiallized==false) { init(); initiallized=true; }\
	gl_Position = getNextPosition() * uMVPMatrix;
	gl_PointSize = 2.0;
}
예제 #23
0
bool Commands::buyHouse(Creature* creature, const std::string& cmd, const std::string& param)
{
	Player* player = creature->getPlayer();
	if (player) {
		Position pos = player->getPosition();
		pos = getNextPosition(player->direction, pos);
		for(HouseMap::iterator it = Houses::getInstance().getHouseBegin(); it != Houses::getInstance().getHouseEnd(); it++)
		{
			if (it->second->getHouseOwner() == player->guid) {
				player->sendCancel("You are already the owner of a house.");
				return false;
			}
		}
		if (Tile* tile = g_game.getTile(pos.x, pos.y, pos.z)) {
			if (HouseTile* houseTile = dynamic_cast<HouseTile*>(tile)) {
				if (House* house = houseTile->getHouse()) {
					if (house->getDoorByPosition(pos)) {
						if (!house->getHouseOwner()) {
							if (player->isPremium()) {
								uint32_t price = 0;
								for (HouseTileList::iterator it = house->getHouseTileBegin(); it != house->getHouseTileEnd(); it++) {
									price += g_config.getNumber(ConfigManager::HOUSE_PRICE);
								}
								if (price) {
									uint32_t money = g_game.getMoney(player);
									if (money >= price && g_game.removeMoney(player, price)) {
										house->setHouseOwner(player->guid);
										player->sendTextMessage(MSG_INFO_DESCR, "You have successfully bought this house, be sure to have the money for the rent in your depot of this city.");
										return true;
									}
									else {
										player->sendCancel("You do not have enough money.");
									}
								}
								else {
									player->sendCancel("That house doesn't contain any house tile.");
								}
							}
							else {
								player->sendCancelMessage(RET_YOUNEEDPREMIUMACCOUNT);
							}
						}
						else {
							player->sendCancel("This house already has an owner.");
						}
					}
					else {
						player->sendCancel("You have to be in front of door of the house you would like to buy.");
					}
				}
				else {
					player->sendCancel("You have to be in front of door of the house you would like to buy.");
				}
			}
			else
				player->sendCancel("You have to be in front of door of the house you would like to buy.");
		}
		else {
			player->sendCancel("You have to be in front of door of the house you would like to buy.");
		}
	}
	return false;
}
예제 #24
0
MaIterator &MaIterator::operator ++() {
    SAFE_POINT(hasNext(), "Out of boundaries", *this);
    position = getNextPosition();
    SAFE_POINT(isInRange(position), "Out of boundaries", *this);
    return *this;
}
예제 #25
0
Position Spells::getCasterPosition(Creature* creature, Direction dir)
{
	return getNextPosition(dir, creature->getPosition());
}