Exemplo n.º 1
0
bool AISujiang::useSkillOrNot(sgs::ConstData::HeroSkill skillType,
		sgs::DataType::Player * player) {
	printDebug(
			"AISujiang::useSkillOrNot: start, AI's seat = "
					+ QString::number(mySeat()));
	bool returnValue = true;
	printDebug("AISujiang::useSkillOrNot: over");
	return returnValue;
}
Exemplo n.º 2
0
bool AIDaqiao::useSkillOrNot(sgs::ConstData::HeroSkill /*skillType*/, sgs::DataType::Player * /*player*/)
{
	printDebug("AIDaqiao::useSkillOrNot: start, AI's seat = " + QString::number(mySeat()));
	printDebug("<font color=red><b>Warning: </b></font>"
			   "AIDaqiao::useSkillOrNot: "
			   "shouldn't be called becase daqiao has no passive skill (note: liuli is canceled by getLiuli)");
	bool returnValue = true;
	printDebug("AIDaqiao::useSkillOrNot: over, return " + QString(returnValue ? "true" : "false"));
	return returnValue;
}
Exemplo n.º 3
0
bool AIXiahoudun::useSkillOrNot(sgs::ConstData::HeroSkill /*skillType*/,
		sgs::DataType::Player * /*player*/) {
	printDebug(
			"AIXiahoudun::useSkillOrNot: start, AI's seat = "
					+ QString::number(mySeat()));
	bool returnValue = true;
	printDebug(
			"AIXiahoudun::useSkillOrNot: over, return "
					+ QString(returnValue ? "true" : "false"));
	return returnValue;
}
Exemplo n.º 4
0
sgs::DataType::Message * AIGuanyu::useCardResponse() {
	sgs::Derive::MSkill * wusheng = useWushengInUsecard();
	if (wusheng) {
		printDebug(sgsui::messageInterpret(wusheng));
		printDebug(
				"AIGuanyu::useCardResponse: use wusheng, AI's seat = "
						+ QString::number(mySeat()));
		return wusheng;
	}
	return AICommon::useCardResponse();
}
Exemplo n.º 5
0
sgs::DataType::Message * AIGuanyu::shaOrNot(sgs::DataType::Player * from,
		const sgs::DataType::Card * card) {
	sgs::Derive::MSkill * wusheng = useWushengInShaOrNot();
	if (wusheng) {
		printDebug(sgsui::messageInterpret(wusheng));
		printDebug(
				"AIGuanyu::shaOrNot: use wusheng, AI's seat = "
						+ QString::number(mySeat()));
		return wusheng;
	}
	return AICommon::shaOrNot(from, card);
}
Exemplo n.º 6
0
bool AILvbu::useSkillOrNot(sgs::ConstData::HeroSkill, sgs::DataType::Player *) {
	printDebug(
			"AILvbu::useSkillOrNot: start, AI's seat = "
					+ QString::number(mySeat()));
	printDebug(
			"<font color=red><b>Warning: </b></font>AILvbu::useSkillOrNot: shouldn't be called becase lvbu has no passive skill");

	bool returnValue = true;
	printDebug(
			"AILvbu::useSkillOrNot: over, return "
					+ QString(returnValue ? "true" : "false"));
	return returnValue;
}
Exemplo n.º 7
0
Arquivo: main.cpp Projeto: nyorain/iro
int main()
{
    char buffer[64];

    //logStream.rdbuf()->pubsetbuf(buffer, sizeof(buffer));
    logStream.rdbuf()->pubsetbuf(nullptr, 0);
    logStream.open("log.txt");
    //try
    {

        ny::logLogger().stream = &logStream;
        ny::warningLogger().stream = &logStream;
        ny::errorLogger().stream = &logStream;

        ny::sendLog("Started Iro Desktop");

        iro::Compositor myCompositor;
        iro::Seat mySeat(myCompositor);
        iro::ForkHandler myForkHandler(myCompositor);

        std::unique_ptr<iro::DBusHandler> myDBusHandler = nullptr;
        std::unique_ptr<iro::LogindHandler> myLogindHandler = nullptr;
        std::unique_ptr<iro::DeviceHandler> myDeviceHandler = nullptr;
        std::unique_ptr<iro::Backend> myBackend = nullptr;
        std::unique_ptr<iro::TerminalHandler> myTerminalHandler = nullptr;
        std::unique_ptr<iro::UDevHandler> myUDevHandler = nullptr;
        std::unique_ptr<iro::InputHandler> myInputHandler = nullptr;

        if(iro::X11Backend::available())
        {
            iro::X11Backend* xbcknd = new iro::X11Backend(myCompositor, mySeat);
            myBackend.reset(xbcknd);
            xbcknd->createOutput();
        }
        else
        {
            myDBusHandler.reset(new iro::DBusHandler(myCompositor));
            myLogindHandler.reset(new iro::LogindHandler(*myDBusHandler));
            myDeviceHandler.reset(new iro::DeviceHandler(*myDBusHandler, *myLogindHandler));
            myTerminalHandler.reset(new iro::TerminalHandler(myCompositor));
            myBackend.reset(new iro::KmsBackend(myCompositor, *myDeviceHandler));
            myUDevHandler.reset(new iro::UDevHandler(myCompositor));
            myInputHandler.reset(new iro::InputHandler(myCompositor, mySeat,
                                 *myUDevHandler, *myDeviceHandler));

            static_cast<iro::KmsBackend*>(myBackend.get())->setCallbacks(*myTerminalHandler);
            myLogindHandler->onActive([&](bool b)
            {
                ny::sendLog("active: ", b);
                if(b)
                {
                    myInputHandler->resume();
                    //myTerminalHandler->activate(myTerminalHandler->number());
                    //myTerminalHandler->waitActive(myTerminalHandler->number());
                }
                else
                {
                    myInputHandler->suspend();
                }
            });

            std::cout << (int)mySeat.keyboard()->modifiers() << "\n";
            std::cout << (int)(iro::Keyboard::Modifier::ctrl | iro::Keyboard::Modifier::alt) << "\n";

            if(mySeat.keyboard())
            {
                mySeat.keyboard()->onKey([&](unsigned int key, bool pressed)
                {
                    if(!pressed) return;

                    if(mySeat.keyboard()->modifiers() !=
                            (iro::Keyboard::Modifier::ctrl | iro::Keyboard::Modifier::alt))
                        return;

                    if(key == KEY_Q)
                    {
                        idleSwitchSource = wl_event_loop_add_idle(&myCompositor.wlEventLoop(),
                                           idleSwitch, myTerminalHandler.get());
                        vtSwitchTo = myTerminalHandler->number() - 1;
                    }
                    else if(key == KEY_E)
                    {
                        idleSwitchSource = wl_event_loop_add_idle(&myCompositor.wlEventLoop(),
                                           idleSwitch, myTerminalHandler.get());
                        vtSwitchTo = myTerminalHandler->number() + 1;
                    }
                });
            }
        }

        if(mySeat.keyboard())
        {

            mySeat.keyboard()->onKey([&](unsigned int key, bool pressed)
            {
                if(mySeat.keyboard()->modifiers() != iro::Keyboard::Modifier::alt) return;
                if(pressed && key == KEY_T)
                {
                    ny::sendLog("starting weston terminal");
                    myForkHandler.exec("weston-terminal", {"--shell=/bin/bash"});
                }
            });
        }

        ny::sendLog("finished backend setup");


        ny::sendLog("set up x window manager");

        if(!myBackend)
        {
            ny::sendError("no valid backend found");
            return 0;
        }

        myCompositor.backend(*myBackend);

        auto* myShell = loadShell("libiro-shell.so");
        if(!myShell)
        {
            ny::sendError("failed to load shell module");
            return 0;
        }
        myShell->init(myCompositor, mySeat);
        myCompositor.shell(*myShell);


        for(auto* outp : myBackend->outputs())
            outp->onDraw(nytl::memberCallback(&iro::ShellModule::render, myShell));

        auto xwm = std::make_unique<iro::XWindowManager>(myCompositor, mySeat);

        ny::sendLog("starting main loop");
        myCompositor.run(nytl::seconds(60));
        //myCompositor.run();
        ny::sendLog("Finished Iro Desktop");
        *ny::logLogger().stream << std::flush;

    }
    //catch(const std::exception& err)
    //{
    //	ny::sendLog("Caught Exception: ", err.what());
    //}

    *ny::logLogger().stream << "iro main extited normally. " << std::flush;
    return 1;
}
Exemplo n.º 8
0
sgs::Derive::MSkill * AIGuanyu::useWushengInUsecard() {
	sgs::Derive::MWuSheng * returnWusheng = 0;
	if (!canUseSha())
		return returnWusheng;

	const CardVec& redShoupaiFound = redShoupai();
	if (redShoupaiFound.empty()) {
		printDebug("AIGuanyu::useWusheng: no red card");
		return returnWusheng;
	}

	PlayerVec attackTargetVec = shaTarget();
	if (attackTargetVec.empty()) {
		for (CardVec::const_iterator cardIter = redShoupaiFound.begin();
				cardIter != redShoupaiFound.end(); ++cardIter) {

			if (canUseFangtian() && attackTargetVec.size() > 1) {
				printDebug("AIGuanyu::useWusheng: using fangtian");
				returnWusheng = new sgs::Derive::MWuSheng(myPlayer(),
						sgs::ConstData::PHAND, (*cardIter).second);

				// push in the fisrt 3 enemies;
				int j = 0;
				PlayerVec arrangedTargets;
				for (PlayerVec::iterator iter = attackTargetVec.begin();
						iter != attackTargetVec.end() && j < 3; ++iter, ++j) {
					arrangedTargets.push_back(*iter);
				}

				// sort the targets by seat;
				sgsui::PlayerSort arrangeSeat(mySeat(), sgsui::BySeat);
				std::sort(arrangedTargets.begin(), arrangedTargets.end(),
						arrangeSeat);
				for (PlayerVec::iterator iter = arrangedTargets.begin();
						iter != arrangedTargets.end(); ++iter) {
					returnWusheng->addto(*iter);
				}
			} else {
				printDebug("AIGuanyu::useWusheng: not using fangtian");

				// Do not use black Sha to Renwang
				// try each player in range
				for (PlayerVec::reverse_iterator riter =
						attackTargetVec.rbegin();
						riter != attackTargetVec.rend(); ++riter) {
					sgs::DataType::Player * target = *riter;

					returnWusheng = new sgs::Derive::MWuSheng(myPlayer(),
							sgs::ConstData::PHAND, (*cardIter).second, target);
					printDebug(
							"AIGuanyu::useWusheng: will attack player "
									+ QString::number(target->seat())
									+ ", break and stop searching for target");
					break;
				}
			}
			return returnWusheng;
		}
	}
	return returnWusheng;
}