Commit Graph
271 Commits
Author SHA1 Message Date
ac-stef b650fca2ca persistidents cleanup
Restore the old persistidents system from AC 1.0, since it's working as
intended - if used properly.

As a reminder:

  * aliases created by "const" and "tempalias" are never persistent
  * aliases created or altered by "alias" or "=" become persistent, if
    the persistidents flag is set during that operation
  * persistidents if false during the execution of almost all config files
    during game start - those files can create aliases with default values
    which will not be persistent (until changed later while the flag is
    set)
  * before saved.cfg is executed, the flag is set and stays set all
    throughout the game - which means, that all changes (from menus, for
    example) will change the altered alias to "persistent"
  * exceptions for map or model config files are unnecessary, since those
    run restricted and can't create aliases anyway
  * exceptions are necessary for "late run" config files like those in
    config/opt/

The new command "persistidents" may be used to manually set or clear the
flag. It also returns the current state of the flag. If used in a config
file, the flag is restored to its original value when the file ends
execution.

In short: only late-run config files (meaning: run after saved.cfg was
restored) may need to manually set/reset the flag. Use const and tempalias
where appropriate and clear persistidents before creating an alias with a
not-to-save default value that may be changed and made persistent later.

DOCREF persistidents
2017-05-05 15:50:59 +02:00
ac-stef 967fd62077 cleanup 2017-04-26 16:14:39 +02:00
gy_beandac-stef 9820e59adb Fix local hitsound priority
Local hitsounds (/hitsound 2) work by running CubeScript
command `sound`, passing hitsound sound number and
priority (highest). However, `sound` command doesn't actually
take the second priority argument and always uses default normal
priority.

This commit adds the second prioity argument to `sound`.
It accepts numeric priority levels as well as string names.

Also use highest priority for server hitsounds (to be consistent with
local hitsounds).

(was pull request #164)

DOCREF sound
2017-04-20 13:53:55 +02:00
ac-stef 701d33af55 fix "no snprintf on VS" 2016-10-16 14:37:08 +02:00
ac-stef 1b5877e3fc treat CR as LF in cubescript
this hopefully doesn't break too much stuff...
2016-10-16 13:38:34 +02:00
ac-stef 925645ecb3 new custom arch prefab editor
The menu lists all prefab arches and allows to edit them with sliders.
Arches can be saved and restored.

"archvertex" now returns the old value of the vertex, and if the vertex
argument is omitted, doesn't change it.

enumalias prefix

  Lists all persistent aliases that start with prefix. Returns a table
  with two entries per alias: 1) full name and 2) name without prefix

DOCREF archvertex enumalias
2016-09-17 01:01:40 +02:00
ac-stef 397c441fed more verbose error messages for disabled commands 2016-09-16 17:35:47 +02:00
ac-stef a6bffc1858 new command looplisti
same as looplist, but it automatically counts the loops in "i", starting
with 0.

Example:

  a = [u v w] ; b = [x y z]
  looplisti $a m [echo $m (at $b $i) $i]

  u x 0
  v y 1
  w z 2

DOCREF looplisti
2016-09-02 21:58:39 +02:00
ac-stef bfb8158069 add cubescript commands for binary arithmetic
The commands &b, |b, ^b and !b perform the operations and, or, xor and not
using binary arithmetic on integer values.

Please keep in mind, that integer values are 32-bit signed values, so
"echo (!b 1)" returns "-2", of course.

The new command "h0 precision value" is modeled after the existing "l0"
command and returns the given value as string of hexadecimal digits,
padded with leading zeros to a given minimum length ("precision").

Examples:

  echo (h0 2 1024)       ->  "400"
  echo (h0 4 1024)       ->  "0400"
  echo (h0 6 1024)       ->  "000400"
  echo (h0 0 (&b 0xe 0x3))  ->  "2"
  echo (h0 0 (|b 0xe 0x3))  ->  "f"
  echo (h0 0 (^b 0xe 0x3))  ->  "d"
  echo (h0 0 (!b 0xe))   ->  "fffffff1"
  echo (h0 0 (* -1 0xe))  ->  "fffffff2"  (for comparison)

Also, the commands for addition and multiplication of integer and float
values have been modified to accept more than two arguments.

Examples:

  echo (* 3 5)   -> "15"
  echo (* 3 5 2)   -> "30"
  echo (* 3 5 2 -1)   -> "-30"
  echo (* 3)   -> "0"  (for compatibility reasons)
  echo (+ 3 5)   -> "8"
  echo (+ 3 5 2)   -> "10"
  echo (+ 3 5 2 -1)   -> "9"
  echo (+f 3.0 5 1.9 -1)   -> "-28.5"
  echo (*f 3.0 5 1.9 -1)   -> "8.9"

DOCREF + * +f *f &b |b ^b !b h0
2016-09-01 15:47:09 +02:00
ac-stef f0dfe2d1a3 pass arguments to and deliver results from script files
When a script file is executed, any additional arguments are passed
as execarg1..execargX to the script. The number of arguments is in
execnumargs and if the script in the file sets the value of execresult,
the exec command returns that value.

Example:

If there is a file testscript.cfg with this content:

  execresult = (* $execarg1 $execarg2)

then the command

  echo (exec testscript.cfg 6 7)

will output "42".

DOCREF exec
2016-08-31 18:53:58 +02:00
ac-stef 4b2767a96d cleanup
* removed convertcase
  use toupper (concat A B C D ....) instead

* moved several COMMAND macros to their function bodies

* cleaned up screenshot extension handling

* prefix screenshot argument with "screenshot/" and add correct extension
2016-08-31 17:20:28 +02:00
ac-stef 1310516c14 keep track of map load errors
Collect warnings during load_world() and issue a warning at the end. Most,
but not all warnings already printed a message - which usually scrolls out
of the console quite fast.

The collected value is also given back by the loadmap command, which
allows batch editing scripts for maps stop at problematic maps.

Mapsound errors are not detected, if soundvol is zero. Missing textures are
not flagged, if notexture is set.

The error code is ored together from those elements:

0x0000001  entity attribute overflow
  One or more map entities had attribute values, that are no longer
  supported with map format 10. Rework manually.

0x0000010  map decoder error
  Indicates a damaged map file.

0x0000100  world error -1
  Map is completely solid. Very funny.

0x0000200  world error -2
  Map border is not solid. Fix manually.

0x0001000  missing skymap texture files
0x0002000  missing world texture files (only if no notexture is set)
0x0004000  missing mapmodel files
0x0008000  missing mapsound files

0x0010000  bad mapsound command in map config
0x0020000  bad mapmodel command in map config
0x0040000  bad texture command in map config
0x0080000  bad loadnotexture command in map config

0x0100000  error during loading of mapmodels (see earlier console output)

0x1000000  out of range integer value in map config (for example, "fog 0")
0x2000000  out of range float value in map config
0x4000000  generic cubescript error in map config

The command loadmap is now also available for non-debug builds.

DOCREF loadmap
2016-08-30 20:56:58 +02:00
ac-stef 41fa9e1b34 add command for raw scripted editing
selectionwalk action beginsel endsel

  The command iterates over all cubes in all selections and executes
  "action" for each cube. The cubes of every selection are framed by
  executions of "beginsel" and "endsel". The action script is allowed
  to make changes to cube attributes, and if it does, an undo point is
  automatically added. "beginsel" and "endsel" are optional.

  While the scripts are executed, several aliases provide further info:

  sw_cursel
    Position and size of the current selection. Valid in all three
    scripts. Holds four integer values for x, y, xs, ys. See command
    "selection" for details.

  (all following aliases are only valid during the execution of the action
   script and provide the attributes of one cube of the map)

  sw_abs_x
  sw_abs_y
  sw_rel_x
  sw_rel_y
    Absolute and relative (within the current selection) coordinates of
    the current cube. Read-only values.

  sw_type
    Type of the current cube. Can be 0..4 for SOLID, CORNER, FHF, CHF and
    SPACE. May be changed to other numerical value or keyword.

  sw_floor
  sw_ceil
    Floor and ceiling heights of the current cube. Range -128..127

  sw_wtex
  sw_ftex
  sw_ctex
  sw_utex
    Texture slot indices for wall, floor, ceiling and upper wall of the
    current cube.

  sw_vdelta
  sw_tag
    Vdelta and tag values of current cube.

  sw_r
  sw_g
  sw_b
    Current light values of current cube. Can be edited, but only with
    temporary effect. Will be reset with the next light recalc.

The command is mostly useful for statistics scripts (like counting cubes
with certain attributes), but is can also be used for scripted editing,
as the following (useless) example shows:

  selectionwalk [ += sw_floor (rnd 2) ]

Further changes:

  The command listoptions now also can return the names of cube types:

    echo (listoptions cubetypes)

  The command countwalls is now implemented as a script instead of a
  builtin command. The script works better, because it doesn't create
  unnecessary undo points.

DOCREF selectionwalk listoptions countwalls
2016-08-27 21:58:02 +02:00
ac-stef 422b407e79 misc VS warning fixes 2016-08-27 12:03:23 +02:00
ac-stef daae49273d remove __fontsetting
instead, "curfont" returns name of current font

DOCREF __fontsetting curfont
2016-08-26 14:30:29 +02:00
ac-stef 4a9ae84613 add hashes for map files on server 2016-08-26 14:28:54 +02:00
ac-stef 71132e3d35 escape dollar chars in strings
not escape the char, but trigger the quotes, actually
2016-08-22 15:08:20 +02:00
ac-stef 59d4f4d847 add embedded license information to all official maps
also add script to generate a summary map license file

new (undocumented) debug commands:
  loadmap <mapname>
    loads a map directly, easy to use from scripts

  debugline <filename> <text>
    writes text to file (no path names allowed)
2016-07-30 01:47:30 +02:00
ac-stef 98d01d1f34 fix some errors and warnings for GCC 6
* do not use std::abs() because math.h includes one, that converts ints
  to double. Use own iabs(), which directly uses labs() instead.
* don't use the word "gamma" as name for variables
* don't use a homebrew round() function
2016-02-27 22:50:06 +01:00
gy_be 5d1a9cac19 Fix a memory leak in command.cpp
Do not forget to free command name and its arguments if
it's not allowed in current execution context.
2015-11-09 10:20:24 +03:00
ac-stef 917df65a51 remove all instances of round()
VS2008 doesn't have round() in math.h and the old inline function (removed
in 50d1413d, had problems in newer compilers). Now floor() or straight
casting to int is used. Let's see, which MS compiler will trip on that...
2015-09-24 19:51:50 +02:00
ac-stef 532453b9f8 tweak command completion
If the fragment is also a full command, skip that command during the first
round of TAB completions.
2015-09-08 21:03:06 +02:00
ac-stef 396eae3ee0 fix #131
although I doubt, that anyone ever fell for that

(the fix prevents, that nickname completion can change the first char of
the console string to a slash, which would change the line from chat to
command)
2015-09-08 20:22:07 +02:00
ac-stef 816aed4ba6 rewire zip packages inside the virtual filesystem
* change priority of zip packages from "highest" to "just below home dir"
* strict naming rules for zip packages
* require all zips to be below directory "mods/"
* only allow zips to intoduce files below "packages/" (or with a special
  zip package name also below "config/")
* make zip package config persistent (saved to init.cfg)

WARNING: intermediate commit - autodownload system defunct!

DOCREF (removed) addzip removezip
2015-09-07 14:53:56 +02:00
aurhat 3a4edff826 Cleanup
Among other things it fixes masterserver compiling.
2015-08-16 16:44:18 +02:00
ac-stef 38c563dfd6 add command getvarrange
getvarrange <what> <varname>
  Gets range attribute <what> for builtin variable <varname>.

  what
    one of "min", "max" or "default"

  varname
    name of any builtin variable (integer or float)

DOCREF getvarrange
2015-06-13 22:16:52 +02:00
ac-stef 148719c0f7 add script command for menu items with alternate fonts
Also: add '\a' to the list of escaped characters and remove storage of
  unneeded "filename".

mitemaltfont <altfont> <text> <action> <hoveraction> <desc>
  Displays a menu line with a text which may contain chars from an
  alternate font.

  altfont
    Name of the alternate font.

  text
    Content of menu line. Chars from the alternate font have to be marked
    with "\a". Alternate font chars have no width and are just rendered
    above the following text. Use spaces to counter that.

  action, hoveraction, desc
    Same function as with other menu lines.

DOCREF menuitemaltfont
2015-06-10 14:12:43 +02:00
ac-stef 1b2e944754 add script commands to support texture and sound config menus
textureslotusagelist <what>
  Return a list of 256 numbers representing the number of uses for every
  texture slot. If <what> is "onlygeometry", uses as map model skin do
  not count. If <what> is "onlymodels", the uses in map geometry do not
  count.

gettextureorigin <path>
  Returns the location where the texture actually can be found. The
  possibilities are:
    "official": texture was found in the working directory, which
                indicates an official texture.
    "custom":   texture was found in the profile directory, which means,
                the texture is either manually installed or downloaded.
    "package dir #x": texture was found in a mod directory.
    "<file not found>": that.

textureslotbyname <texture path>
  Returns the list of numbers of all texture slots which use that texture
  file.

edittexturestack <floor|wall|ceiling> <texture slot number>
  Puts a texture slot in a "last used" list up front. The first
  parameter picks the list, the second parameter is the texture
  slot number to be used for the next edit

getautomapconfig
  Returns "1" if automapconfig is already enabled, "0" otherwise.

getmapsoundorigin <path>
  Returns the location where the map sound file actually can be found. The
  possibilities are:
    "official": the sound file was found in the working directory, which
                indicates an official mapsound.
    "custom":   the file was found in the profile directory, which means,
                the mapsound is either manually installed or downloaded.
    "package dir #x": mapsound was found in a mod directory.
    "<file not found>": that.

mapsoundslotbyname <mapsound path>
  Returns the list of numbers of all mapsound slots which use that texture
  file.

getmapsoundlist
  Returns a list of all *.wav and *.ogg files below packages/audio/ambient.

DOCREF textureslotusagelist gettextureorigin textureslotbyname
DOCREF edittexturestack getautomapconfig
DOCREF getmapsoundorigin mapsoundslotbyname getmapsoundlist
2015-06-05 16:00:02 +02:00
ac-stef 07facdfcc2 fix: no snprintf on VS 2015-05-27 15:47:04 +02:00
ac-stef c4e1155dcc option to write floats as ints when possible
omit the ".0" in values like "3.0"
2015-05-18 14:59:41 +02:00
ac-stef e5fc8b35a2 be extremely pedantic with setvar and getvar in debug mode
This will exit the program, if code tries to access a non-existing
variable or an existing variable of the wrong type.
2015-05-18 14:59:41 +02:00
ac-stef 03bcae1918 make sure that COMMAND arguments are always in a writeable segment
Casting a string constant to "char *" causes segfaults if a command tries
to write to it. Now, empty strings are rarely written to, but it is
inconsistent, if command arguments change memory segments depending on the
argument value.
2015-05-18 14:46:03 +02:00
ac-stef 03f974b2bc additional text attributes for mapmodels
This adds a means to store additional attributes for mapmodels, including
a caching mechanism, so the mapmodels don't have to be loaded to access
the information. The goal is, to provide fully automatic mapmodel menus
for map editing who also add information about downloaded mapmodels.

Model attributes are extracted everytime, when a model is loaded. At game
end, all available data is written to config/mapmodelattributes.cfg and
restored at next startup. On release, a file with all (but only) official
models should be included. Since autodownloaded models are usually "loaded"
after download, those are automatically added to the database. If someone
adds models manually to the directories (media pack, w/e), the command
"loadallmapmodels" can be used to try to find all available models. The
only way to delete something from the database, is to delete the file
config/mapmodelattributes.cfg when the game is closed.

The current list of attributes is:

keywords
  List of one or more menu topics to list the model under. Check
  config/menus_edit.cfg for available keywords. Unknown keywords will
  be listed separately.

desc
  Short name or description of the model. Will be used as menu entry.

usage
  Important information for how to use that specific model.

author
  Who created the mapmodel. If it's a derivative of another model, state
  the author of the mod (refer to the original author under "license", if
  you like). Always use the exact same spelling for the same author, to
  allow menus to automatically group models by author.

license
  Free-text attribute for license info or info about additional
  contributors (or original authors for derivated works).

distribution
  One of "official", "autodownload" or "manual". Other values default to
  "manual". This is used to determine, if a map contains only original
  media or media that can be download automatically.

version
  Single numerical value to separate older from newer versions. Defaults
  to zero. Higher numbers mean "newer". Maybe someone manages to implement
  a versioning system for custom media in the future...

New commands:

mdlattribute <attr> <value>
  To be used in model config files. Adds a value for a specified
  attribute to the model.

mapmodelregister <modelpath> <attr1> <attr2> ...
  Adds values for all attributes to a specific mapmodel. This is used to
  restore the cached values from config/mapmodelattributes.cfg during
  game start. Does not actually verify of load the model.

mapmodelattributes <modelpath> <attr>
  Returns the value of a specific attribute of a mapmodel. If modelpath
  is a number, it is interpreted as index for the list of models in the
  current map config. If no attribute name is specified, all attributes
  are printed to the console instead.

getmapmodelattributes <list of attribute names>
  Returns a table of all known mapmodels. Each model is listed with the
  modelpath and the values for the requested attributes. To be used
  instead of a fixed table in menu_edit.cfg. In addition to attribute
  names, the function also allows the keywords "explodekeywords" and
  "sortby:" as arguments. If "explodekeywords" is given, all mapmodels
  with more than one keyword are listed multiple times, once for each
  keyword. If an attribute name is preceeded by "sortby:" the list will
  be sorted by this table column. If "sortby:" is used several times,
  this first sort will have highest priority. The list is always sorted
  by path by default.

  example:
    getmapmodelattributes sortby: author sortby: desc explodekeywords

loadallmapmodels
  Tries to load mapmodels from /all/ paths below packages/models/mapmodels.
  Will throw a lot of error messages, because not all directories contain
  models to load. This command can be used to build or rebuild the
  complete list of all available mapmodels. It is only necessary, if models
  are added manually to the directories, since every mapmodel gets added
  to the list when it is loaded - which takes care of all automatically
  downloaded models.

DOCREF mdlattribute mapmodelregister mapmodelattributes
DOCREF getmapmodelattributes loadallmapmodels
2015-05-17 00:24:38 +02:00
ac-stef f86e2c1f4a fix loadcrosshair script in saved.cfg
"c" is already used as "const" and therefore is not allowed as temporary
alias...
2015-05-17 00:24:38 +02:00
ac-stef d55dbb47f4 output error message when temporary alias can not be created 2015-05-17 00:24:38 +02:00
ac-stef 3e84f11630 cleanup 2015-05-17 00:24:38 +02:00
aurhat b2da592d6e Save skin choice on quit 2015-05-07 18:58:34 +02:00
ac-stef 1f6cd99408 fix CR-handling for looplist 2015-04-18 14:07:45 +02:00
ac-stef f511889731 customisable sort order for file lists in menus 2015-04-12 18:09:36 +02:00
ac-stef 453c79ee6d minor fixes to get master to compile again 2015-04-06 10:37:13 +02:00
ac-stef 5bf27f802c fix memory leak in execdir 2015-03-24 02:06:19 +01:00
ac-stef b4b1c0bf91 add debug warning for unknown argument keywords
"weapon asault" will now print a warning to console.
2015-03-24 02:06:19 +01:00
ac-stef 7b607a6c43 allow comments inside cubescript lists
like this:
  alias listwiththreeelements [
    first   // first element
    second  // second element
    third   // third element
  ]

"echo $listwiththreeelements" will print everything, including comments,
but "echo (listlen $listwiththreeelements)" will print "3", and
"echo (at $listwiththreeelements 1)" will print "second".
2015-03-24 02:06:18 +01:00
ac-stef 5619fb2e7e allow multiple arguments for "pop"
instead of "pop var_a ; pop var_b" you can write "pop var_a var_b"

Also, "pop" will now give back the removed value of the first alias from
the argument list. This allows using the pop'd value one last time.

DOCREF pop
2015-03-06 19:36:29 +01:00
ac-stef 1c402a7d93 omit empty aliases from command completion
Some operations, like pop or looplist, leave empty aliases behind. Mostly,
this is without consequence - but before this commit, they showed up
during command completion.
2015-03-06 14:37:42 +01:00
ac-stef 0f8dbf69aa introduce temporary aliases
An alias, that was at least once used with the new "tempalias" will not be
written to saved.cfg.

So, now there are four ways to create aliases:

1) alias (or "=")
  General alias, who's value gets saved at game exit in saved.cfg, and
  restored at the next restart - unless the alias was created at a time,
  where persistidents was zero (usually during execution of the game's own
  config files during startup).

2) const
  Creates an alias, that can not be changed. Makes it harder for users
  to destroy their config.

3) push
  Reassigns an alias with a new value. After "pop", the old value is
  restored. Allows the use of "local" aliases in scripts. Also avoids
  name conflicts.

4) tempalias
  Like "alias", but the value will not be written to saved.cfg.

The commit also changes aliases, written by the engine itself, to "temp":
gametimestart, __getmaprevisions

DOCREF tempalias
2015-03-06 14:17:08 +01:00
ac-stef 32db3e5e88 new options for saved.cfg
Defaults to omitting variables from saved.cfg, that are still at default
value. By setting omitunchangeddefaults to zero, those variables get
written, but commented out. The variable "groupvariables" sets the number
of variables with similar names, that can be grouped on one line. Setting
it to zero will additionally write min, max and default values and a
short description of the variable to file.

In general, variables, that are still at default value, will not be
restored from saved.cfg, so when the default in the game is changed, all
clients will use that new default. This way, testers don't have to erase
their saved.cfg as often.

DOCREF omitunchangeddefaults groupvariables
2015-03-06 14:01:52 +01:00
ac-stef a013148305 save original aliases instead of local ones
If an alias has a local value assigned (by "push"), this change will write
the original value to saved.cfg instead of the last local value.

This has the additional effect, that aliases, that were created by "push",
will not be written to saved.cfg, since the original value was empty.
2015-03-06 13:46:13 +01:00
ac-stef d9b7e0e159 clean up saved.cfg
* combine all weapon attributes in a table
* sort variables and aliases
* group variables
* implement curname as SVAR
* implement cmdbuf as temporary alias
2015-02-23 20:17:43 +01:00
ac-stef 8153813c14 fix string escaping for SVARs
* avoid double richtext conversion for mspmsg
* fix minor memleak in pushident()
* always escape strings for the command buffer
2015-02-23 20:12:47 +01:00