Implements helper functions for random number generation.
Implemented using C++11 <random> library.
Exported Lua Functions:
- seedRNG(seed)
- rollInt(min, max)
- rollDouble(min, max)
- rollNormal(mean, std_deviation)
- rollBool(chance_for_true)
- resetIndexRolls(string, array_length) --String identifies the instance of SimpleNumDistribution to reset
- rollIndex(string, array_length) --String identifies the instance of SimpleNumDistribution to use
--(Shuffles a vector of indices, Next() increments through then reshuffles when end() is reached)
On branch cxxrandom-rel
Changes to be committed:
modified: plugins/CMakeLists.txt
new file: plugins/cxxrandom.cpp
new file: plugins/lua/cxxrandom.lua
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Squashed commit of the following:
commit 3a7ef70d45f3e0c2fe367141dd0349dddaaff60d
Merge: fd9f1982 7aa0608c
Author: Josh Cooper <cooper.s.josh@gmail.com>
Date: Fri Dec 22 22:17:27 2017 -0800
Merge remote-tracking branch 'origin/temp' into cxxrandom
commit 7aa0608cb85dcf82686193db7a6e9d1318f5f2a5
Author: Josh Cooper <cooper.s.josh@gmail.com>
Date: Thu Dec 21 21:43:35 2017 -0800
Revises cxxrandom plugin
New functions:
- seedRNG(ushort seed)
--lua exported
- GetDistribContainer()
--internal singleton
- RNG()
--internal singleton
Summary:
- Removed class CXXRNG
--Refactored functions that used CXXRNG
Changes to be committed:
modified: plugins/cxxrandom.cpp
commit b42979818a01c1121eace7b1ac14676f5ad5d8b2
Author: Josh Cooper <cooper.s.josh@gmail.com>
Date: Wed Dec 20 13:21:49 2017 -0800
Fixes plugin_init()
Misread the lines indicated by lethosor to be excluded, had broken the plugin in the process.
Changes to be committed:
modified: plugins/cxxrandom.cpp
commit 753a00a14d9e6519d299638e014abf30509940af
Author: Josh Cooper <cooper.s.josh@gmail.com>
Date: Wed Dec 20 12:36:17 2017 -0800
Cleans up cxxrandom.cpp
DFHack contributions specifies:
-spaces instead of tabs, so tabs were converted.
-C++ headers before dfhack stuff, so it was done
*Also added author name, creation date, and last updated date.
Changes to be committed:
modified: plugins/cxxrandom.cpp
commit 498ebe4b8fdccc01ac1f169269f3093c830a8a10
Author: Josh Cooper <cooper.s.josh@gmail.com>
Date: Tue Dec 19 22:51:58 2017 -0800
Updates cxxrandom, fixes instance leak
deleted header
moved definition to cpp file #lethosor
fixed singleton instance, no longer a pointer
commented out dfhack commands, now only init/shutdown and exported lua functions
modified: cxxrandom.cpp
deleted: cxxrandom.h
commit 821044bef2a0201d0d74192e445c7b29766b42a1
Author: Josh Cooper <cooper.s.josh@gmail.com>
Date: Sun Dec 17 04:01:11 2017 -0800
Fixes RollIndex and Renames RollNormal
Renamed the Normal Distribution RNG function to fit the standard.
Now named RollNormal(m,s)
Fixed some wonky white space in the lua macro export block.
Fixed a stupid mistake with the RollIndex output. (it was outputting 0's)
Updated usage details.
Changes to be committed:
modified: plugins/cxxrandom.cpp
commit 1536f43d137b6bc55d55759b43bdccf6ff429b33
Author: Josh Cooper <cooper.s.josh@gmail.com>
Date: Fri Dec 15 08:50:08 2017 -0800
Fixes/Improves cxxrandom
Modified return types
Corrected index distribution code
commit 8629c7e1509522cb0cc4b649914b90d033cb4763
Author: Josh Cooper <cooper.s.josh@gmail.com>
Date: Thu Dec 14 19:02:29 2017 -0800
Implements SimpleNumDistribution
Exported additional functions to lua.
Functions allow the generation of random 0-N index values.
Generation promises all unique values [0,N] will be returned once each when generation is run N times.
On branch cxxrandom
Changes to be committed:
modified: plugins/cxxrandom.cpp
modified: plugins/cxxrandom.h
commit f035f3d20415790542cf83e5e696261661d911f3
Author: Josh Cooper <cooper.s.josh@gmail.com>
Date: Wed Dec 13 23:55:39 2017 -0800
Implements cxxrandom
cxxrandom was implemented using a singleton.
This singleton provides an interface for generating uniform numbers, or numbers in a normal distribution, and also booleans(given the probability for the true outcome)
The singleton interface is wrapped in functions which are exposed for lua usage.
Integrated into plugins/CMakeLists.txt
On branch dev
Changes to be committed:
modified: CMakeLists.txt
new file: cxxrandom.cpp
new file: cxxrandom.h
new file: lua/cxxrandom.lua
It should not try to do that if e.g. showing buildingitems. Maybe later we will have more valid focus strings (e.g. custom item view for some buildings) but for now just use vanilla (or callback function not a class)
The manager can now specify each type of craft individually, as well as in general.
There may be a better justification for not allowing pearl and shell scepters, though.
Mostly, instruments and their pieces are made through generated custom reactions, instead of as tools.
Depends on df-structures commit e551233 for full potency.
This should make resolving future issues easier, although implementing
new confirmations in lua isn't possible yet (each one requires a line
in confirm.cpp).
This also resolves an issue with note-delete and route-delete, with
dfhack/df-structures@1bc4f61
It's been four years since meaningful updates, and in that time
alternatives have emerged to almost everything. Any remaining
functionality to replace is on the issue tracker.
Simpler is better, for users and developers, and removing a legacy
system makes it easier to understand how DFHack works.
Previously, it was possible to save outside of the stocksettings
directory or fail to save in a nonexistent subdirectory (e.g. when
a stockpile name had slashes in it).
Resolves#621
Widget positions and a few other options (e.g. date formats) can be
specified in dfhack-config/dwarfmonitor.json on a per-instance basis.
Related changes:
* Fixed an issue loading JSON files from Lua
* JSON files in dfhack-config (only dwarfmonitor.json currently) are
no longer copied into the DF directory when building DFHack. This
keeps developers' personal settings intact, but will require
copying over changes made to DFHack's copies manually.
* Fixed incorrect config path in dwarfmonitor help
Makes workflow understand "seeds of any plant", "thread of any plant",
"drink of any plant", "powder of any plant", and "liquid of any plant"
when counting items.
Changes workflow's handling of the built-in plant reactions to
understand that they always produce plant products, and that they also
produce seeds.
This means that you can set a target for, for example, "powder of any
plant", and workflow will use a milling job to produce that.
Fixed buildings not consuming correct value of power. Added way to ignore unpowered state. Added setPower/getPower to change how much power building uses on the fly.
For the most part, mismatches should only happen if the reaction list has changed between world loads, which means either the raw files or the plugin files have been changed. For now, such entries are ignored, though in some cases it might be possible to recover a new order number by searching through the reaction list.
- Duplicate definition of a function now in uicommon.h
- Assertion failure due to missing core suspend claim.
- Incorrect way of accessing the civ entity.
- Accessing nil objects in the lua module if filter matches nothing.
- Lua module breaking on reload('plugins.stockflow').
Now frees manager_order objects in the reaction_list when the plugin is disabled or the world unloaded. However, there may still be orders leaked elsewhere.
Specifically, any "if (verbose) { Core::printerr("blah") }" kind
of stuff definitely doesn't belong in the common API functions.
Also, ref->getUnit() is very expensive.
On the other hand, checks for crash-inducing conflicts with the
ui should be in the core api, and not in client plugins.
- To ensure reload safety functions have to be wrapped. Every call
checks the loaded state and locks a mutex in Plugin. If the plugin
is unloaded, calling its functions throws a lua error. Therefore,
plugins may not create closures or export yieldable functions.
- The set of function argument and return types supported by
LuaWrapper is severely limited when compared to being compiled
inside the main library.
Currently supported types: numbers, bool, std::string, df::foo,
df::foo*, std::vector<bool>, std::vector<df::foo*>.
- To facilitate postponing initialization until after all plugins
have been loaded, the core sends a SC_CORE_INITIALIZED event.
- As an example, the burrows plugin now exports its functions.