Skip to content

Commit

Permalink
Interface: Extract function
Browse files Browse the repository at this point in the history
  • Loading branch information
dscharrer committed Jan 10, 2018
1 parent df7bec1 commit 6f65820
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
9 changes: 0 additions & 9 deletions src/game/Player.cpp
Expand Up @@ -215,15 +215,6 @@ void ARX_KEYRING_Add(const std::string & key) {
g_playerKeyring.push_back(key);
}

//! Sends COMBINE event to "io" for each keyring entry
void ARX_KEYRING_Combine(Entity * keyring, Entity * entity) {
for(size_t i = 0; i < g_playerKeyring.size(); i++) {
if(SendIOScriptEvent(keyring, entity, SM_COMBINE, g_playerKeyring[i]) == REFUSE) {
return;
}
}
}

/*!
* \return player "front pos" for sound purpose
*/
Expand Down
1 change: 0 additions & 1 deletion src/game/Player.h
Expand Up @@ -437,7 +437,6 @@ bool ARX_PLAYER_CanStealItem(Entity * item);

void ARX_KEYRING_Init();
void ARX_KEYRING_Add(const std::string & key);
void ARX_KEYRING_Combine(Entity * keyring, Entity * entity);

void ARX_PLAYER_Reset_Fall();
void ARX_PLAYER_KillTorch();
Expand Down
32 changes: 24 additions & 8 deletions src/gui/Interface.cpp
Expand Up @@ -503,6 +503,28 @@ void ResetPlayerInterface() {
SLID_START = g_platformTime.frameStart();
}

static ScriptResult combineEntities(Entity * source, Entity * target) {

arx_assert(source != NULL);

ScriptParameters parameters(source->idString());

if(boost::starts_with(source->className(), "keyring")) {

for(size_t i = 0; i < g_playerKeyring.size(); i++) {
parameters[0] = g_playerKeyring[i];
ScriptResult ret = SendIOScriptEvent(source, target, SM_COMBINE, parameters);
if(ret == REFUSE || ret == DESTRUCTIVE) {
return ret;
}
}

return ACCEPT;
}

return SendIOScriptEvent(source, target, SM_COMBINE, parameters);
}

static void ReleaseInfosCombine() {

arx_assert(player.bag >= 0);
Expand Down Expand Up @@ -2056,14 +2078,8 @@ void ArxGame::manageEditorControls() {
if(io) {
if(COMBINEGOLD) {
SendIOScriptEvent(NULL, io, SM_COMBINE, "gold_coin");
} else {
if(io != COMBINE) {
if(boost::starts_with(COMBINE->className(), "keyring")) {
ARX_KEYRING_Combine(COMBINE, io);
} else {
SendIOScriptEvent(COMBINE, io, SM_COMBINE, COMBINE->idString());
}
}
} else if(io != COMBINE) {
combineEntities(COMBINE, io);
}
} else { // GLights
float fMaxdist = player.m_telekinesis ? 850 : 300;
Expand Down

0 comments on commit 6f65820

Please sign in to comment.