void SelectionWidget::UpdateAvailableScripts()
{
	//FIXME: lua ai's should be handled in AIScriptHandler.cpp, too respecting the selected game and map
	// maybe also merge it with StartScriptGen.cpp

	availableScripts.clear();
	// load selected archives to get lua ais
	AddArchive(userMod);
	AddArchive(userMap);

	std::vector< std::vector<InfoItem> > luaAIInfos = luaAIImplHandler.LoadInfos();
	for(int i=0; i<luaAIInfos.size(); i++) {
		for (int j=0; j<luaAIInfos[i].size(); j++) {
			if (luaAIInfos[i][j].key==SKIRMISH_AI_PROPERTY_SHORT_NAME)
				availableScripts.push_back(info_getValueAsString(&luaAIInfos[i][j]));
		}
	}

	// close archives
	RemoveArchive(userMap);
	RemoveArchive(userMod);

	// add sandbox script to list
	availableScripts.push_back(SandboxAI);

	// add native ai's to the list, too (but second, lua ai's are prefered)
	CAIScriptHandler::ScriptList scriptList = CAIScriptHandler::Instance().GetScriptList();
	for (CAIScriptHandler::ScriptList::iterator it = scriptList.begin(); it != scriptList.end(); ++it) {
		availableScripts.push_back(*it);
	}
	
	for (std::string &scriptName: availableScripts) {
		if (scriptName == userScript) {
			return;
		}
	}
	SelectScript(SelectionWidget::NoScriptSelect);
}
示例#2
0
CPreGame::CPreGame(bool server, const string& demo, const std::string& save)
    : showList(0),
      server(server),
      state(UNKNOWN),
      saveAddress(true),
      hasDemo(!demo.empty()),
      hasSave(!save.empty()),
      savefile(NULL)
{
    demoFile = gameSetup? gameSetup->demoName : demo;

    infoConsole = SAFE_NEW CInfoConsole;

    pregame = this; // prevent crashes if Select* is called from ctor
    net = SAFE_NEW CNetProtocol();

    //hpiHandler=SAFE_NEW CHpiHandler();

    activeController=this;

    if(!gameSetup) {
        for(int a=0; a<gs->activeTeams; a++) {
            for(int b=0; b<4; ++b) {
                gs->Team(a)->color[b]=palette.teamColor[a][b];
            }
        }
    }

    if(server) {
        net->InitLocalClient(gameSetup ? gameSetup->myPlayerNum : 0);
        if(gameSetup) {
            CScriptHandler::SelectScript(gameSetup->scriptName);
            SelectScript(gameSetup->scriptName);
            if (!gameSetup->saveName.empty()) {
                savefile = new CLoadSaveHandler();
                savefile->LoadGameStartInfo(savefile->FindSaveFile(gameSetup->saveName.c_str()));
            }
            SelectMap(gameSetup->mapName);
            SelectMod(gameSetup->baseMod);
            state = WAIT_CONNECTING;
        } else if (hasSave) {
            savefile = new CLoadSaveHandler();
            savefile->LoadGameStartInfo(savefile->FindSaveFile(save.c_str()));
            CScriptHandler::SelectScript("Commanders");
            SelectScript("Commanders");
            SelectMap(savefile->mapName);
            SelectMod(savefile->modName);
            state = WAIT_CONNECTING;
        } else {
            ShowScriptList();
            state = WAIT_ON_SCRIPT;
        }
    } else {
        if(gameSetup) {
            PrintLoadMsg("Connecting to server");
            net->InitClient(gameSetup->hostip.c_str(),gameSetup->hostport,gameSetup->sourceport, gameSetup->myPlayerNum);
            CScriptHandler::SelectScript(gameSetup->scriptName);
            SelectScript(gameSetup->scriptName);
            SelectMap(gameSetup->mapName);
            SelectMod(gameSetup->baseMod);
            state = WAIT_CONNECTING;
        } else {
            if (hasDemo) {
                net->localDemoPlayback = true;
                state = WAIT_CONNECTING;
                ReadDataFromDemo(demoFile);
                net->InitLocalClient(0);
                if (gameSetup) {	// we read a gameSetup from the demofiles
                    logOutput.Print("Read GameSetup from Demofile");
                    SelectMap(gameSetup->mapName);
                    SelectMod(gameSetup->baseMod);
                    CScriptHandler::SelectScript(gameSetup->scriptName);
                    SelectScript(gameSetup->scriptName);
                }
                else	// we dont read a GameSetup from demofile (this code was copied from CDemoReader)
                {
                    logOutput.Print("Demo file does not contain GameSetup data");
                    // Didn't get a CGameSetup script
                    // FIXME: duplicated in Main.cpp
                    const string luaGaiaStr  = configHandler.GetString("LuaGaia",  "1");
                    const string luaRulesStr = configHandler.GetString("LuaRules", "1");
                    gs->useLuaGaia  = CLuaGaia::SetConfigString(luaGaiaStr);
                    gs->useLuaRules = CLuaRules::SetConfigString(luaRulesStr);
                    if (gs->useLuaGaia) {
                        gs->gaiaTeamID = gs->activeTeams;
                        gs->gaiaAllyTeamID = gs->activeAllyTeams;
                        gs->activeTeams++;
                        gs->activeAllyTeams++;
                        CTeam* team = gs->Team(gs->gaiaTeamID);
                        team->color[0] = 255;
                        team->color[1] = 255;
                        team->color[2] = 255;
                        team->color[3] = 255;
                        team->gaia = true;
                        gs->SetAllyTeam(gs->gaiaTeamID, gs->gaiaAllyTeamID);
                    }
                }

                /*
                We want to watch a demo local, so we dont know script, map and mod yet and we have to start a server which should send us the required data
                Default settings: spectating
                */
                gu->spectating           = true;
                gu->spectatingFullView   = true;
                gu->spectatingFullSelect = true;
            }
            else {
                userInput=configHandler.GetString("address","");
                writingPos = userInput.length();
                userPrompt = "Enter server address: ";
                state = WAIT_ON_ADDRESS;
                userWriting = true;
            }
        }
    }
    assert(state != UNKNOWN);
}
WorldObjectWidget::WorldObjectWidget(QWidget *parent) :
  QWidget(parent),
  ui(new Ui::WorldObjectWidget)
{
  ui->setupUi(this);
  selection.object = 0;
  selection_type   = 0;
  UnsetSelection();

  ui->actionsButton->setMenu(&action_menu);

  connect(ui->objectName, SIGNAL(textChanged(QString)), this, SLOT(UpdateName(QString)));

  // Geometry
  connect(ui->objectPosX,        SIGNAL(valueChanged(double)), this, SLOT(UpdateGeometry()));
  connect(ui->objectPosY,        SIGNAL(valueChanged(double)), this, SLOT(UpdateGeometry()));
  connect(ui->objectPosZ,        SIGNAL(valueChanged(double)), this, SLOT(UpdateGeometry()));
  connect(ui->objectRotationX,   SIGNAL(valueChanged(double)), this, SLOT(UpdateGeometry()));
  connect(ui->objectRotationY,   SIGNAL(valueChanged(double)), this, SLOT(UpdateGeometry()));
  connect(ui->objectRotationZ,   SIGNAL(valueChanged(double)), this, SLOT(UpdateGeometry()));
  connect(ui->objectScaleX,      SIGNAL(valueChanged(double)), this, SLOT(UpdateGeometry()));
  connect(ui->objectScaleY,      SIGNAL(valueChanged(double)), this, SLOT(UpdateGeometry()));
  connect(ui->objectScaleZ,      SIGNAL(valueChanged(double)), this, SLOT(UpdateGeometry()));
  connect(ui->objectFloor,       SIGNAL(valueChanged(int)),    this, SLOT(UpdateFloor()));
  connect(ui->inheritsFloor,     SIGNAL(toggled(bool)),        this, SLOT(UpdateFloor()));

  // Collider
  connect(ui->displayColliders,  SIGNAL(toggled(bool)),            this, SLOT(UpdateColliderDisplay()));
  connect(ui->collider_type,     SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateColliderType()));
  connect(ui->collider_pos_x,    SIGNAL(valueChanged(double)),     this, SLOT(UpdateColliderGeometry()));
  connect(ui->collider_pos_y,    SIGNAL(valueChanged(double)),     this, SLOT(UpdateColliderGeometry()));
  connect(ui->collider_pos_z,    SIGNAL(valueChanged(double)),     this, SLOT(UpdateColliderGeometry()));
  connect(ui->collider_hpr_x,    SIGNAL(valueChanged(double)),     this, SLOT(UpdateColliderGeometry()));
  connect(ui->collider_hpr_y,    SIGNAL(valueChanged(double)),     this, SLOT(UpdateColliderGeometry()));
  connect(ui->collider_hpr_z,    SIGNAL(valueChanged(double)),     this, SLOT(UpdateColliderGeometry()));
  connect(ui->collider_scale_x,  SIGNAL(valueChanged(double)),     this, SLOT(UpdateColliderGeometry()));
  connect(ui->collider_scale_y,  SIGNAL(valueChanged(double)),     this, SLOT(UpdateColliderGeometry()));
  connect(ui->collider_scale_z,  SIGNAL(valueChanged(double)),     this, SLOT(UpdateColliderGeometry()));

  // Light
  connect(ui->lightSetEnabled,   SIGNAL(toggled(bool)),         this, SLOT(LightSetEnabled(bool)));
  connect(ui->lightSetDisabled,  SIGNAL(toggled(bool)),         this, SLOT(LightSetDisabled(bool)));
  connect(ui->lightColorR,       SIGNAL(valueChanged(double)),  this, SLOT(UpdateLightColor()));
  connect(ui->lightColorG,       SIGNAL(valueChanged(double)),  this, SLOT(UpdateLightColor()));
  connect(ui->lightColorB,       SIGNAL(valueChanged(double)),  this, SLOT(UpdateLightColor()));
  connect(ui->lightAttenuationA, SIGNAL(valueChanged(double)),  this, SLOT(UpdateLightAttenuation()));
  connect(ui->lightAttenuationB, SIGNAL(valueChanged(double)),  this, SLOT(UpdateLightAttenuation()));
  connect(ui->lightAttenuationC, SIGNAL(valueChanged(double)),  this, SLOT(UpdateLightAttenuation()));
  connect(ui->lightTypesList,    SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateLightType()));
  connect(ui->lightCompile,      SIGNAL(clicked()),             this, SLOT(LightCompile()));
  connect(ui->lightPriority,     SIGNAL(valueChanged(int)),     this, SLOT(UpdateLightPriority()));
  connect(ui->addLightTarget,    SIGNAL(clicked()),             this, SLOT(AddEnlightenedObject()));
  connect(ui->deleteLightTarget, SIGNAL(clicked()),             this, SLOT(DeleteEnlightenedObject()));
  connect(ui->showFrustum,       SIGNAL(toggled(bool)),         this, SLOT(LightShowFrustum(bool)));
  connect(ui->lightTargets,      SIGNAL(updatedPriority()),     this, SLOT(UpdateEnlightenedObject()));
  connect(ui->lightTargets,      SIGNAL(updatedPropagation()),  this, SLOT(UpdateEnlightenedObject()));

  // Light -> Shadow caster
  connect(ui->shadowFilmSize,    SIGNAL(valueChanged(int)),     this, SLOT(UpdateShadowCaster()));
  connect(ui->shadowNear,        SIGNAL(valueChanged(int)),     this, SLOT(UpdateShadowCaster()));
  connect(ui->shadowFar,         SIGNAL(valueChanged(int)),     this, SLOT(UpdateShadowCaster()));
  connect(ui->shadowBufferSizeX, SIGNAL(valueChanged(int)),     this, SLOT(UpdateShadowCaster()));
  connect(ui->shadowBufferSizeY, SIGNAL(valueChanged(int)),     this, SLOT(UpdateShadowCaster()));

  // Render
  connect(ui->selectModel,   SIGNAL(clicked()), this, SLOT(PickModel()));
  connect(ui->selectTexture, SIGNAL(clicked()), this, SLOT(PickTexture()));
  connect(ui->objectModel,   SIGNAL(textChanged(QString)), this, SLOT(UpdateRender()));
  connect(ui->objectTexture, SIGNAL(textChanged(QString)), this, SLOT(UpdateRender()));
  connect(ui->objectFocus,   SIGNAL(clicked()), this, SLOT(FocusCurrentObject()));
  connect(ui->useTexture,    SIGNAL(toggled(bool)), this, SLOT(UpdateRender()));
  connect(ui->useColor,      SIGNAL(toggled(bool)), this, SLOT(UpdateRender()));
  connect(ui->useOpacity,    SIGNAL(toggled(bool)), this, SLOT(UpdateRender()));
  connect(ui->colorRed,      SIGNAL(valueChanged(double)), SLOT(UpdateRender()));
  connect(ui->colorGreen,    SIGNAL(valueChanged(double)), SLOT(UpdateRender()));
  connect(ui->colorBlue,     SIGNAL(valueChanged(double)), SLOT(UpdateRender()));
  connect(ui->opacity,       SIGNAL(valueChanged(double)), SLOT(UpdateRender()));
  connect(ui->objectToggleVisibility, SIGNAL(clicked()), this, SLOT(ToogleCurrentObject()));

  // Waypoint
  connect(ui->setCurrentWaypoint, SIGNAL(clicked()), this, SLOT(SetCurrentWaypoint()));
  connect(ui->selectCurrentWaypoint, SIGNAL(clicked()), this, SLOT(SelectCurrentWaypoint()));

  // Behaviour
  connect(ui->objectTypeList,       SIGNAL(currentIndexChanged(int)), this, SLOT(UpdateBehaviour()));
  connect(ui->character,            SIGNAL(textChanged(QString)),     this, SLOT(UpdateBehaviour()));
  connect(ui->dialog,               SIGNAL(textChanged(QString)),     this, SLOT(UpdateBehaviour()));
  connect(ui->script,               SIGNAL(textChanged(QString)),     this, SLOT(UpdateBehaviour()));
  connect(ui->doorLocked,           SIGNAL(toggled(bool)),            this, SLOT(UpdateBehaviour()));
  connect(ui->key,                  SIGNAL(textChanged(QString)),     this, SLOT(UpdateBehaviour()));
  connect(ui->interactionUse,       SIGNAL(toggled(bool)),            this, SLOT(UpdateBehaviour()));
  connect(ui->interactionUseSkill,  SIGNAL(toggled(bool)),            this, SLOT(UpdateBehaviour()));
  connect(ui->interactionUseSpell,  SIGNAL(toggled(bool)),            this, SLOT(UpdateBehaviour()));
  connect(ui->interactionUseObject, SIGNAL(toggled(bool)),            this, SLOT(UpdateBehaviour()));
  connect(ui->interactionLookAt,    SIGNAL(toggled(bool)),            this, SLOT(UpdateBehaviour()));
  connect(ui->interactionTalkTo,    SIGNAL(toggled(bool)),            this, SLOT(UpdateBehaviour()));
  connect(ui->selectCharacter,      SIGNAL(clicked()),                this, SLOT(SelectCharacter()));
  connect(ui->selectItem,           SIGNAL(clicked()),                this, SLOT(SelectItem()));
  connect(ui->selectKey,            SIGNAL(clicked()),                this, SLOT(SelectKey()));
  connect(ui->selectScript,         SIGNAL(clicked()),                this, SLOT(SelectScript()));
  connect(ui->selectDialog,         SIGNAL(clicked()),                this, SLOT(SelectDialog()));

  // Render Particles
  connect(ui->particleEffectName,   SIGNAL(textChanged(QString)), this, SLOT(UpdateParticleEffect()));
  connect(ui->showParticleEffect,   SIGNAL(clicked()),            this, SLOT(RestartParticleEffect()));
  connect(ui->selectParticleEffect, SIGNAL(clicked()),            this, SLOT(SelectParticleEffect()));

  ui->actionsButton->setMenu(&action_menu);
  action_menu.addAction("Copy",  this, SIGNAL(CopyRequested()),  QKeySequence::Copy);
  action_menu.addAction("Paste", this, SIGNAL(PasteRequested()), QKeySequence::Paste);
}
示例#4
0
void CPreGame::UpdateClientNet()
{
    if (!net->IsActiveConnection())
    {
        logOutput.Print("Server not reachable");
        globalQuit = true;
        return;
    }

    RawPacket* packet = 0;
    while ( (packet = net->GetData()) )
    {
        const unsigned char* inbuf = packet->data;
        switch (inbuf[0]) {
        case NETMSG_SCRIPT: {
            if (!gameSetup) {
                CScriptHandler::SelectScript((char*) (inbuf+2));
                SelectScript((char*) (inbuf+2));
            }

            if (mapName.empty()) {
                state = WAIT_ON_MAP;
            } else if (modName.empty()) {
                state = WAIT_ON_MOD;
            } else {
                state = WAIT_CONNECTING;
            }
        }
        break;

        case NETMSG_MAPNAME: {
            if (!gameSetup) {
                SelectMap((char*) (inbuf + 6));
            }
            archiveScanner->CheckMap(mapName, *(unsigned*) (inbuf + 2));

            if (!CScriptHandler::Instance().chosenScript) {
                state = WAIT_ON_SCRIPT;
            } else if (modName.empty()) {
                state = WAIT_ON_MOD;
            } else {
                state = WAIT_CONNECTING;
            }
        }
        break;

        case NETMSG_MODNAME: {
            if (!gameSetup) {
                SelectMod((char*) (inbuf + 6));
            }
            archiveScanner->CheckMod(modArchive, *(unsigned*) (inbuf + 2));

            if (!CScriptHandler::Instance().chosenScript) {
                state = WAIT_ON_SCRIPT;
            } else if (mapName.empty()) {
                state = WAIT_ON_MAP;
            } else {
                state = WAIT_CONNECTING;
            }
        }
        break;

        case NETMSG_MAPDRAW: {
        } break;


        case NETMSG_SYSTEMMSG:
        case NETMSG_CHAT: {
            // int player = inbuf[inbufpos + 2];
            string s = (char*) (inbuf + 3);
            logOutput.Print(s);
        }
        break;

        case NETMSG_STARTPOS: {
            // copied from CGame
            // unsigned player = inbuf[1];
            int team = inbuf[2];
            if(team>=gs->activeTeams || team<0 || !gameSetup) {
                logOutput.Print("Got invalid team num %i in startpos msg",team);
            } else {
                if(inbuf[3]!=2)
                    gameSetup->readyTeams[team]=!!inbuf[3];
                gs->Team(team)->startPos.x=*(float*)&inbuf[4];
                gs->Team(team)->startPos.y=*(float*)&inbuf[8];
                gs->Team(team)->startPos.z=*(float*)&inbuf[12];
            }
            break;
        }

        case NETMSG_SETPLAYERNUM: {
            gu->myPlayerNum = inbuf[1];
            logOutput.Print("Became player %i", gu->myPlayerNum);
        }
        break;

        case NETMSG_PLAYERNAME: {
            gs->players[inbuf[2]]->playerName = (char*) (inbuf + 3);
            gs->players[inbuf[2]]->readyToStart = true;
            gs->players[inbuf[2]]->active = true;
            if (net->GetDemoRecorder())
                net->GetDemoRecorder()->SetMaxPlayerNum(inbuf[2]);
        }
        break;

        case NETMSG_QUIT: {
            globalQuit = true;
            break;
        }

        case NETMSG_USER_SPEED: {
        } break;
        case NETMSG_INTERNAL_SPEED: {
        } break;

        case NETMSG_SENDPLAYERSTAT: {
        } break;

        case NETMSG_PAUSE: {
            // these can get into the network stream here -- Kloot
            int playerNum = (int) inbuf[1];
            bool paused = !!inbuf[2];
            logOutput.Print(paused? "player %i paused the game": "player %i unpaused the game", playerNum);
        }
        break;

        case NETMSG_PLAYERINFO:
            break;

        default: {
            logOutput.Print("Unknown net-msg recieved from CPreGame: %i", int(inbuf[0]));
            break;
        }
        }
        delete packet;
    }
}