Skip to content

Commit

Permalink
Scripting|libdoomsday: Added the "commonlib" module
Browse files Browse the repository at this point in the history
libdoomsday has a script module called "commonlib" for common game-related functions.

commonlib defines the following methods:
- World.Thing.info()
- World.Thing.dropItem()
  • Loading branch information
skyjake committed Dec 21, 2019
1 parent 02f9f16 commit 33d6ea6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
@@ -1,5 +1,5 @@
# DOOMSDAY CLIENT BOOTSTRAP
#
#
# This script is executed after the client application has been fully
# initialized, immediately after subsystems are all ready. No game is
# loaded at this stage, although all plugins have been enumerated.
Expand All @@ -26,7 +26,7 @@ def runLegacySavegameConversion(newGame)
end

def runPluginLoadHooks(newGame)
if newGame == 'null-game': return
if newGame == 'null-game': return
try
gameConf = Config.plugin[App.gamePlugin()]
for func in gameConf.onNextLoad: func()
Expand All @@ -42,12 +42,12 @@ end
def addOnLoadHookForAllGames(function)
for plug in subrecords(Config.plugin).values()
plug.onNextLoad += [function]
end
end
end

def cleanPackageFolders()
# Config.resource.iwadFolder was used previously for IWADs
# (non-recursive), but now everything can be put in
# (non-recursive), but now everything can be put in
# Config.resource.packageFolder and recursing is specified
# separately.
try
Expand All @@ -73,23 +73,23 @@ end

def upgradeMaintenance()
if not 'OLD_VERSION' in Version: return

# Ensure that the default Tilde binding is present when upgrading
# from an older version.
if isUpgradedToBuild(920)
# Register a single-shot hook that ensures the binding is present
# after a game has been loaded the next time. This must be done
# per-plugin as the bindings are stored separately for each.
# Config is persistent so these will be remembered even after
# Config is persistent so these will be remembered even after
# shutting down the app.
addOnLoadHookForAllGames(bindDefaultConsoleTildeKey)
end

# Add the default Menu key bindings.
if isUpgradedToBuild(1479)
addOnLoadHookForAllGames(bindWindowsMenuKey)
end

cleanPackageFolders()
end

Expand Down Expand Up @@ -121,3 +121,4 @@ App.audienceForGameAddition += [runLegacySavegameConversion]
App.audienceForGameChange += [runPluginLoadHooks]

import controllers
import commonlib # from net.dengine.base
@@ -0,0 +1,28 @@
# Additional functions for games

import World, Math, Defs

def World.Thing.info()
return Defs.things.order[self.type()]
end

def World.Thing.dropItem(type, force=1.0, lift=0.0, height=0.5, prob=1.0)
# Spawns an item at the position of the thing.
# - type: Thing ID of the dropped item (Text).
# - force: XY momentum of the dropped item (random direction).
# - lift: Z momentum of the dropped item.
# - height: spawn position Z offset.
# - prob: chance of dropping (1.0 is 100% certainty).
# Returns the dropped item, or None.
if Math.random() > prob: return None
pos = self.pos()
pos[2] = pos[2] + height * self.height()
item = World.spawnThing(type, pos)
if item
# Throw the item a little bit.
angle = 2 * Pi * Math.random()
mom = [force * Math.cos(angle), force * Math.sin(angle), lift]
item.addMom(mom)
end
return item
end
3 changes: 3 additions & 0 deletions doomsday/apps/server/src/serverapp.cpp
Expand Up @@ -35,6 +35,7 @@
#include <de/LogBuffer>
#include <de/PackageFeed>
#include <de/PackageLoader>
#include <de/ScriptSystem>
#include <de/c_wrapper.h>

#include "serverapp.h"
Expand Down Expand Up @@ -274,6 +275,8 @@ void ServerApp::initialize()

plugins().loadAll();

scriptSystem().importModule("commonlib"); // from net.dengine.base

DD_FinishInitializationAfterWindowReady();
}

Expand Down

0 comments on commit 33d6ea6

Please sign in to comment.