Example #1
0
void UnitFactory::produceAndRegisterMapObject(const std::string& objectType, int owner, const MPoint& pos) {
    MapObject* object;
    MapObjectView* view;
    std::vector<UnitModel*> units;
    std::vector<int> actions;
    int image = 0;
    int layer = 0;
    
    if (objectType == "village") {
        image = 4; layer = MapLayer::BUILDING;
        object = new MapObject(MapObjectCategory::CITY, pos, owner, actions);
    } else if (objectType == "dungeon") {
        image = 5; layer = MapLayer::BUILDING;
        object = new MapObject(MapObjectCategory::DUNGEON, pos, owner, actions);
    } else if (objectType == "party") {
        layer = MapLayer::UNIT;
        if (owner == 1) {
            image = 1;
        } else {
            image = 6;
        }
        
        actions.push_back(ActionNS::AACTION_MOVE); actions.push_back(ActionNS::AACTION_FIGHT);
        actions.push_back(ActionNS::AACTION_SHOP); actions.push_back(ActionNS::AACTION_ENTERDUNGEON);
        actions.push_back(ActionNS::AACTION_INVENTORY);
        units.push_back(produceUnit("swordsman", owner, MPointMake(1,1)));
        units.push_back(produceUnit("channeler", owner, MPointMake(1,0)));
        object = new PartyModel(MapObjectCategory::PARTY, pos, owner, actions, units);
    } else {
        return;
    }
    
    view = new MapObjectView(object, 64.0f, 64.0f, image, layer);
    object->addObserver(view);
    
    ModelManager::instance()->addMapObject(object);
    ViewControllerManager::instance()->add(view);
}