Ejemplo n.º 1
0
	void PropExplosion::Evolve(const std::vector<InputState>& /*iInputs*/, Uint32 iTimestamp, const MapConstPtr &iPresentMap, const MapPtr &iFutureMap) const
	{
		if (iTimestamp < _timeout) 
		{
			auto explosion = std::make_shared<PropExplosion>(*this);
			explosion->active = true;
		  	iFutureMap->SetEntity(explosion);
		}
		else
		{
			if (_stage == 0)
			{
				if (_willPropagate)
				{
					Propagate(iTimestamp, iPresentMap, iFutureMap);
				}
			}
			
			if (_stage < 4)
			{
				auto explosion = std::make_shared<PropExplosion>(*this);
				explosion->active = true;
				explosion->_timeout = iTimestamp + kExplosionTimer;
				explosion->_stage = explosion->_stage + 1;
				iFutureMap->SetEntity(explosion);
			}
		}
	}
Ejemplo n.º 2
0
std::vector<ColoredString> Engine::getActorsBenethPlayersFeet()
{
    std::vector< ColoredString > items;
    MapPtr map = getWorld().getCurrentMap();

    if ( map )
    {
        std::function<bool(amarlon::ActorPtr)> filterFun = [&](ActorPtr a) -> bool
        {
            return a != Actor::Player;
        };

        std::vector<ActorPtr> actorsOnTile = map->getActors(Actor::Player->getX(), Actor::Player->getY(), &filterFun);

        for ( ActorPtr actor : actorsOnTile )
        {
            std::string msg = actor->getName();

            PickablePtr pickable = actor->getFeature<Pickable>();
            if ( pickable && pickable->getAmount() > 1 )
            {
                msg = msg + " (" + std::to_string(pickable->getAmount()) + ")";
            }

            items.push_back( ColoredString( msg, TCODColor::darkLime ) );
        }
    }

    return items;
}
Ejemplo n.º 3
0
int CmdCast::execute()
{
  int turns = 0;
  SpellPtr spell = getSpell();

  Engine::instance().render();
  Engine::instance().flush();
  ActorPtr player = Engine::instance().getPlayer();

  if ( spell )
  {
     TargetSelectorPtr selector( TargetSelector::create( spell->getTargetType() ) );
     if ( selector )
     {
       selector->setRange( spell->getRange() );
       selector->setRadius( spell->getRadius() );
       MapPtr map = Engine::instance().getWorld().getCurrentMap();
       Target target = selector->select([&](ActorPtr a){ return map->isInFov(a->getX(), a->getY()); });

       if ( player->performAction( new CastAction(spell, target) ) != ActorActionResult::Ok )
       {
         gui::msgBox("Failed to cast spell!", gui::MsgType::Warning);
       }
     }
     ++turns;
  }
  return turns;
}
Ejemplo n.º 4
0
void Engine::render()
{
    TCODConsole::root->clear();
    MapPtr map = getWorld().getCurrentMap();

    if ( map )
    {
        map->computeFov(Actor::Player->getX(), Actor::Player->getY(), FovRadius);
        map->render(TCODConsole::root);
    }

    if (_gui)
    {
        _gui->setPlayerName(Actor::Player->getName());

        if ( Actor::Player->isAlive() )
            _gui->setHpBar(Actor::Player->getFeature<Character>()->getHitPoints(), Actor::Player->getFeature<Character>()->getMaxHitPoints());

        _gui->setViewList(getActorsBenethPlayersFeet());
        _gui->render();
    }

    TCODConsole::root->putChar(Actor::Player->getX(), Actor::Player->getY(), Actor::Player->getChar());
    TCODConsole::root->setCharForeground(Actor::Player->getX(), Actor::Player->getY(), Actor::Player->getColor());
}
Ejemplo n.º 5
0
    void fill()
    {
        order.clear();

        MapPtr nodes = ::root_map->get( "Nodes" );
        
        Map::iterator i = nodes->begin();
        Map::iterator iend = nodes->end();
        while( i != iend )
        {
            NodeLayerPtr node = nodes->get( i );
            BooleanPtr enabled( node->get( "enabled" ) );

            if( node->asyncRecallOrder() && enabled->get() )
            {
                size_t neurons = node->numNeurons();

                for( size_t i = 0; i < neurons; ++i )
                {
                    order.push_back( NodeNeuron( node, i ) );
                }
            }

            i++;
        }
    }
Ejemplo n.º 6
0
int CmdUseSkill::execute()
{
  int turns(0);

  if ( SkillPtr skill = getSkill() )
  {
    Engine::instance().render();
    Engine::instance().flush();
    ActorPtr player = Engine::instance().getPlayer();

    TargetSelectorPtr selector( TargetSelector::create( skill->getTargetType() ) );
    if ( selector )
    {
      selector->setRadius( skill->getRadius() );
      MapPtr map = Engine::instance().getWorld().getCurrentMap();
      ActorActionPtr action(
            new UseSkillAction(skill, selector->select([&](ActorPtr a){
                                 return map->isInFov(a->getX(), a->getY());
                               })) );
      if ( player->performAction( action ) != ActorActionResult::Ok )
      {
        gui::msgBox(skill->getName() + " failed!", gui::MsgType::Warning);
      }
      ++turns;
    }
  }

  return turns;
}
Ejemplo n.º 7
0
Archivo: map.hpp Proyecto: CruzR/wc3lib
inline bool Map::isW3x() const
{
	if (m_map.get() == 0)
		return false;

	return typeid(*m_map.get()) == typeid(map::W3x);
}
Ejemplo n.º 8
0
void CmdPick::execute()
{
  int x( Actor::Player->getX() );
  int y( Actor::Player->getY() );

  MapPtr map = Actor::Player->getMap();
  if ( map )
  {
    ContainerPtr container = map->getActorsContainer(x, y);

    auto afterPickupAction =
    [](const std::string& item, int amount)
    {
      Messenger::message()->actorPicked(Actor::Player->getName(), item, amount);
    };

    auto inventoryFullAction =
    [](const std::string& item)
    {
      gui::msgBox("Cannot pickup "+item+":\nInventory is full!", gui::MsgType::Error);
    };

    Engine::instance().windowManager()
                      .getWindow<gui::PickUpWindow>()
                      .setPicker(Actor::Player)
                      .setContainer(container)
                      .setFilterFunction( [](ActorPtr a){ return a->getFeature<Pickable>() != nullptr; } )
                      .setAfterPickupAction( afterPickupAction )
                      .setInventoryFullAction( inventoryFullAction )
                      .show();
  }

}
Ejemplo n.º 9
0
void DieAction::dropOnGround(ActorPtr item)
{
  MapPtr map = _performer->getMap();
  if ( map != nullptr )
  {
    item->setPosition( _performer->getX(), _performer->getY() );
    map->addActor(item);
  }
}
Ejemplo n.º 10
0
TEST(MapGatewayTest, fetchExistingMap_givesMap)
{
  MapGateway gateway;
  gateway.load("data/maps.xml");
  MapPtr map (gateway.fetch(MapId::GameStart));

  ASSERT_TRUE(map != nullptr);
  ASSERT_EQ(map->getId(), MapId::GameStart );
}
Ejemplo n.º 11
0
int TarsAnalyzer::readMap(MapPtr pPtr, int expectTag, bool isRequire)
{

    int type;
    AnalyzerDataHead h;
    h.readFrom(*this);
    
    uint8_t tag = h.getTag();
    
    int ret = compareTag(tag, expectTag,isRequire);
    if (ret != eOK)
    {
        return 0;
    }
    switch (h.getType())
    {
    case AnalyzerDataHead::eMap:
        {
            int size;
            uint8_t t = 0;
            read(size, t, type);
            
            cout << "read " << " map size:" << size << endl;
            if (size < 0|| size > 10 * 1024 * 1024)
            {
                cout<< getTab() << "ERROR, invalid size " << size << endl;
                cout << getTab() << " _cur:" << _cur << " _last_pos:" << _last_pos ;
                exit(-1);
            }
            //addTab(7);
            cout << getTab()<< "{ //tag:" << (int)tag << endl;
            for (int i = 0; i < size; ++i)
            {
            
            cout  << getTab() << " index:" << i << " first:";
                readType(pPtr->getLeftTypePtr(), 0,  isRequire);
                cout<< getTab()<< " index:" << i << " second:" ;
                readType(pPtr->getRightTypePtr(), 1,  isRequire);

            }
            
            cout << getTab()<< "} //tag:" << (int)tag << endl;
            //eraseTab(7);
        }
        break;
    default:
        {
            cout << "ERROR, read map type mismatch, tag:" <<  (int)tag <<"get type " << h.tostrType(h.getType() )<< endl;
            cout << getTab() << " _cur:" << _cur << " _last_pos:" << _last_pos << endl;;
            exit(-1);
        }
    }
    
    return 0;

}
Ejemplo n.º 12
0
string transform(const string& src, MapPtr& rule)
{
	auto des = rule->find(src);
	if (des != rule->end())
	{
		return des->second;
	}
	else
		return src;
}
Ejemplo n.º 13
0
void nnet::learn() 
{
	if( ::exec_map->empty() ) 
    {
        // train synchronous layers first
        {
            MapPtr nodes = ::root_map->get( "Nodes" );

            Map::iterator i = nodes->begin();
            Map::iterator iend = nodes->end();
            while( i != iend )
            {
                NodeLayerPtr node = nodes->get( i );
                BooleanPtr enabled( node->get( "enabled" ) );

                if( !node->asyncRecallOrder() && enabled->get() )
                {
                    learn( node );
                }
                i++;
            }
        }
        // then train async layers
        {
            RecallOrder::iterator i = recall_order.order.begin();
            RecallOrder::iterator iend = recall_order.order.end();
            while( i != iend )
            {
                i->node->learn( i->neuron );
                i++;
            }
        }
	} 
    else 
    {
        try 
        {
            ExecEnginePtr exec( ::exec_map->first() );
            exec->learn();
        }
        catch( std::exception& e ) 
        {
            LOG_EXCEPTION_E( e );
            error::std_exception( "nnet::Learn() running ExecEngine", e.what() );
            return;
        }
        catch( ... )
        {
            LOG_EXCEPTION;
            error::alert( "Critical exception in ExecEngine!" );
        }
	}
	
    nnet::global::learn_signal();
}
Ejemplo n.º 14
0
TEST_F(MapTest, addActor)
{
  MapPtr map = mapGateway.fetch(MapId::GameStart);
  ActorPtr actor = Actor::create(ActorType::HealthPotion,1,1);

  map->addActor(actor);
  auto actors = map->getActors(1,1);

  EXPECT_EQ(actors.size(), (size_t)1);
  EXPECT_TRUE( actors.front().get() == actor.get() );
}
Ejemplo n.º 15
0
int CustomerData::query(const std::string& customer, const std::string& stock) const
{
    MapPtr data = getData();
    Map::const_iterator entries = data->find(customer);
    std::cout << "CustomerData::query " << customer << ", " << stock << std::endl;
    if(entries != data->end())
    {
        return findEntry(entries->second, stock);
    }
    else
        return -1;
}
Ejemplo n.º 16
0
void CustomerData::update(const std::string& customer, const EntryList& entries)
{
    std::lock_guard<std::mutex> lock(mutex_);
    if (!data_.unique())
    {
        MapPtr newData(new Map(*data_));
        data_.swap(newData);
    }
    assert(data_.unique());
    (*data_)[customer] = entries;

}
Ejemplo n.º 17
0
 void reader_thread()
 {
     while(1)
     {
         MapPtr data = getData();
         readCount_ ++;
         printf("reader thread[%ld] : read one\n", this_thread::tid());
         if(data->size() > test_max_loop)
         {
             break;
         }
     }
 }
Ejemplo n.º 18
0
string TarsAnalyzer::tostrMap(const MapPtr &pPtr, bool bNew)
{
    string s = Builtin::builtinTable[Builtin::KindMap] + string("<") + tostr(pPtr->getLeftTypePtr()) + ", " + tostr(pPtr->getRightTypePtr());
    if(MapPtr::dynamicCast(pPtr->getRightTypePtr()) || VectorPtr::dynamicCast(pPtr->getRightTypePtr()))
    {
        s += " >";
    }
    else
    {
        s += ">";
    }
    return s;
}
Ejemplo n.º 19
0
TEST(MapGatewayTest, mapHasValidTiles2)
{
  Configuration cfg;
  ASSERT_TRUE( cfg.load("config.cfg") );

  Engine::instance().prologue(&cfg);

  MapGateway gateway;
  gateway.load("data/maps.xml");
  MapPtr map ( gateway.fetch(MapId::GameStart) );

  ASSERT_EQ(map->getChar(1,1), Engine::instance().getTileDB().getChar(TileType::Tree));
}
Ejemplo n.º 20
0
bool MoveAction::patchIsBlocked()
{
  bool blocked = false;  
  MapPtr map = _performer->getMap();
  if ( map )
  {    
    int targetX = _performer->getX() + _dx;
    int targetY = _performer->getY() + _dy;
    blocked = map->isBlocked(targetX, targetY);
  }

  return blocked;
}
Ejemplo n.º 21
0
void Engine::updateAis()
{
    MapPtr map = getWorld().getCurrentMap();
    if ( map )
    {
        std::function<bool(ActorPtr)> filter = [](ActorPtr a)->bool{ return a->hasFeature<Ai>();};
        auto ais = map->getActors( &filter );
        for ( ActorPtr actor : ais )
        {
            actor->getFeature<Ai>()->update();
        }
    }
}
Ejemplo n.º 22
0
 void reader_thread()
 {
     while(1)
     {
         // data 一旦拿到,就不再需要锁了。取数据的时候只有getData()内部有锁,多线程并发读的性能很好。
         MapPtr data = getData();
         readCount_ ++;
         printf("reader thread[%ld] : read one\n", this_thread::tid());
         if(data->size() > test_max_loop)
         {
             break;
         }
     }
 }
Ejemplo n.º 23
0
void Destroyable::dropOnGround(ActorPtr item)
{
  ActorPtr owner = getOwner().lock();
  if (owner)
  {
    MapPtr map = owner->getMap();
    if ( map != nullptr )
    {
      item->setMap(nullptr);
      item->setPosition( owner->getX(), owner->getY() );
      map->addActor(item);
    }
  }
}
Ejemplo n.º 24
0
void MapGateway::parseMaps(vector<char>& buf)
{
  xml_document<> doc;
  doc.parse<0>(&buf[0]);

  xml_node<>* maps = doc.first_node("Maps");
  xml_node<>* mapNode = maps ? maps->first_node("Map") : nullptr;

  while(mapNode != nullptr)
  {
    _mapParser.setSource( mapNode );
    MapPtr map = _mapParser.parse();
    if ( map ) _maps[ map->getId() ] = map;

    mapNode = mapNode->next_sibling();
  }
}
Ejemplo n.º 25
0
	void Bomb::Evolve(const std::vector<InputState>& /*iInputs*/, uint32_t iTimestamp, const MapConstPtr &iPresentMap, const MapPtr &iFutureMap) const
	{
		if (iTimestamp >= _timeout || _detonating) 
		{
			auto umpire = std::static_pointer_cast<Umpire>(iFutureMap->GetEntity(constants::UMPIRE));
			umpire->DecrementBombCount(_playerId);

			// center
			auto blast = Explosion::Create(iTimestamp, Explosion::IsoTropic);
			blast->x = x;
			blast->y = y;
			iFutureMap->SetEntity(blast);

			// outwards
			SetBlast(_strength, x, y, Explosion::Horizontal, iTimestamp, iPresentMap, iFutureMap,
				[](int i, int* x, int* y) { *x -= i; });
			SetBlast(_strength, x, y, Explosion::Vertical, iTimestamp, iPresentMap, iFutureMap,
				[](int i, int* x, int* y) { *y -= i; });
			SetBlast(_strength, x, y, Explosion::Horizontal, iTimestamp, iPresentMap, iFutureMap,
				[](int i, int* x, int* y) { *x += i; });
			SetBlast(_strength, x, y, Explosion::Vertical, iTimestamp, iPresentMap, iFutureMap,
				[](int i, int* x, int* y) { *y += i; });

			if (Mix_PlayChannel(-1, _explosionSound.get(), 0) == -1)
			{
				printlog("Mix_PlayChannel: %s\n",Mix_GetError());
			}
		}
		else
		{
			auto bomb = std::make_shared<Bomb>(*this);

			if (_nextFrameDueTime < iTimestamp)
			{
				bomb->_frameId++;
				bomb->_frameId %= 3;
				bomb->_nextFrameDueTime = iTimestamp + constants::BOMB_FRAME_UPDATE_DELAY;
			}

			iFutureMap->SetEntity(bomb);
		}
	}
Ejemplo n.º 26
0
bool NoteRenameDialog::on_notes_model_foreach_iter_accumulate(
                         const Gtk::TreeIter & iter,
                         const MapPtr & notes) const
{
  ModelColumnRecord model_column_record;
  const Gtk::TreeModel::Row row = *iter;

  notes->insert(std::make_pair(
                  row[model_column_record.get_column_note()],
                  row[model_column_record.get_column_selected()]));
  return false;
}
Ejemplo n.º 27
0
Target SingleNeighbourSelector::select(std::function<bool (amarlon::ActorPtr)>* filterFun)
{
  Engine::instance().gui().setStatusMessage( _selectionMessage );
  TCODConsole::root->flush();
  MapPtr map = Actor::Player->getMap();
  ActorPtr player = Actor::Player;

  int dx(0), dy(0);

  DirectionSelector dSelector;
  dSelector.select(dx, dy);

  Engine::instance().gui().clearStatusMessage();
  Engine::instance().render();

  assert( map != nullptr );

  return Target(map->getActors(player->getX()+dx, player->getY()+dy, filterFun),
                player->getX()+dx,
                player->getY()+dy);
}
Ejemplo n.º 28
0
bool CloseAction::perform(ActorPtr performer)
{
  bool closed = false;

  if ( _toClose )
  {
    OpenablePtr openable = _toClose->getFeature<Openable>();
    if ( openable )
    {
      if ( openable->close(performer) )
      {
        MapPtr map = _toClose->getMap();
        if ( map )
        {
          map->updateTile( _toClose->getX(), _toClose->getY() );
        }
        closed = true;
      }
    }
  }

  return closed;
}
Ejemplo n.º 29
0
void CustomerData::updateMap(const std::string& customer, const std::string& stock, int value)
{

    std::lock_guard<std::mutex> lock(mutex_);
    if (!data_.unique())
    {
        MapPtr newData(new Map(*data_));
        data_.swap(newData);
    }
    EntryList::iterator it = (*data_)[customer].begin();
    while (it != (*data_)[customer].end())
    {
        if (it->first == stock)
        {
            it->second = value;
            return;
        }
        ++it;
    }
    (*data_)[customer].push_back(std::pair<std::string, int>(stock, value));
    std::cout << "CustomerData::updateMap: " << customer << ", " << stock << ", " << value << std::endl;

}
Ejemplo n.º 30
0
	void Explosion::Evolve(const std::vector<InputState>& /*iInputs*/, Uint32 iTimestamp, const MapConstPtr &iPresentMap, const MapPtr &iFutureMap) const
	{
		auto explosion = std::make_shared<Explosion>(*this);
		if (iTimestamp > _timeout) 
		{
			explosion->_stage++;
			explosion->_timeout = iTimestamp + kExplosionTimer;
		}

		if (_stage < 4)
		{
			explosion->active = true;
			iFutureMap->SetEntity(explosion);
		}
	}