Warband Refined & Enhanced Compiler Kit (v1.0.0 @ Mar 01, 2015)

Users who are viewing this thread

Suggestion: add optional script parameters.
Example:
Our "test_script" will accept two parameters, one being optional. It should look something like this:
Code:
("test_script",[
    (store_script_param_1, ":first_parameter"),
    (store_script_param_2, ":optional_parameter", <default_value>),
    #or
    (store_script_param, ":optional_parameter", 2, <default_value>),

    <rest of the code>
]),
And when we call our function:
Code:
(call_script, "script_test_script", 819263),  # the compiler will insert the second parameter as <default_value>
or
(call_script, "script_test_script", 819263, 10),

The compiler should replace "(call_script, "script_test_script", 819263), " with "(call_script, "script_test_script", 819263, <default_value>), ".

There are some special cases:
1. if the <script_id> param of call_script is not a value (it is a variable or a register), then do nothing.
2. if there are more "store_script_param_"(that stores the same parameter) then if one of them has a <default_value>, mark the parameter as optional and store the first <default_value> occurence
3. the <default_param> can also be a global variable or a game register (not only a value).
 
Detection of situations when (call_script) is used with less parameters than required by script is already in the plans. However I'm going to auto-fill the (call_script) operation with zeroes, replicating engine's behavior when using regular operations (technically, all parameters for all Warband operations are optional, defaulting to zero).
 
I am converting/writing my plugins for VC (Viking Conquest) using WRECK.

I will release the code in the VC forum, but in case you find it useful I can post it here too. Example: plugin with logging helper:

Code:
from compiler import *
register_plugin()

# Any utility methods
# 1) create the method: def name_my_new_operation(destination, var1, var2, *argl):
# 2) return a list [] of commands
# 3) use extend_syntax(name_my_new_operation)

debug_string = s65
debug_register = reg65
color_red = 0xFF0000
color_green = 0x006600
color_blue = 0x0000FF

def warning(text, value=None, *argl):
	return __form_debug_message__(text, value, 'Warn', color_blue)

def info(text, value=None, *argl):
	return __form_debug_message__(text, value, 'Info', color_green)

def error(text, value=None, *argl):
	return __form_debug_message__(text, value, 'Error', color_red)


extend_syntax(warning)			# (warning, <string text>),
								# debug message for warning messages
extend_syntax(info)        		# (info, <string text>),
								# debug message for general information
extend_syntax(error)        	# (error, <string text>),      
								# debug message for errors


def __form_debug_message__(text, value=None, type='Warn', color=color_red, *argl):
	result = [
		(try_begin),
			(is_edit_mode_enabled),
			#(gt, g.cheat_mode, 0), #edit mode, not ingame cheat menu
			(str_clear, debug_string),
			(str_store_string, debug_string, text),
	]

	if value is not None:
		result.extend([
			(assign, debug_register, value),
			(str_store_string, debug_string, "@{!}   #%s: {s65} {reg65}"%type),
		])
	else:
		result.extend([			
			(str_store_string, debug_string, "@{!}   #%s: {s65}"%type),
		])				

	result.extend([
			(display_log_message, debug_string, color),		    
		(try_end),
	])

	return result

Using it (snippet):

(info, "@Char picture for npc = {s0}, id = ", l.npc),
(error, "@too many xxxxxx"),

Feedback is also welcome! Its my first week writing real code with WRECK extended compiler  so still exploring possibilities  :cool:

 
Whenever I declare this
Code:
display_gold,

In multiplayer_dm, multiplayer_tdm, or multiplayer_bt in mission_templates it gives me this:
Capture_zpsmsoqrgy4.png~original


I've done this before, but I don't know why it gives me that error now.
 
Nord Champion said:
Whenever I declare this
Code:
display_gold,

In multiplayer_dm, multiplayer_tdm, or multiplayer_bt in mission_templates it gives me this:
Capture_zpsmsoqrgy4.png~original

I've done this before, but I don't know why it gives me that error now.

It seens your second parameter (the message color) is inside a []. Check your code if that is the case, or even remove that (its optional) just so you can compile the code to a quick test.

(display_message, "@Gold: {reg0}", [color_red]),

to

(display_message, "@Gold: {reg0}"),

If that is not the case, copy and paste your script/code here using the CODE tag so Lav can check if it is the compiler.
 
Nord Champion said:
kalarhan said:

Oh, ok. When I looked at module_operations, it showed a "[]" in that spot so I figured I had to have them.

Thanks!

that means it is a optional parameter, so you can leave it blank to use default (in this case, the color BLACK).

Code:
display_message                     = 1106  # (display_message, <string_id>,[hex_colour_code]),
                                            # Display a string message using provided color (hex-coded 0xRRGGBB).
 
I'm assuming you used a python script to convert all static ID references in to dynamic ones? Could you share that with us so we can use WRECK with newer warband versions? I'd rather not have to write my own script to do it :3

Code:
if ('error' in sys.argv) or ('warnings' in sys.argv): error_reporting_level = 2

'error' should be 'warning' I think.

 
I've been using WRECK since February and am thankful for your work.
It is very touchy and sometimes will not compile a file after I change something then change it back to exactly as it was before.
Too Unexpected spacing errors.

Anyways, I'm trying to in stall the new version with all the code snippets.
I removed process.py files and added this on the top of all module files that imported something:
# >>>>> code snippet WRECK<<<<< #
from compiler import *

I can't get this to work; I get various errors at each compile.
Here is the latest example:
*** Warband Refined & Enhanced Compiler Kit (W.R.E.C.K.) version 1.0.0 ***
Please report errors, problems and suggestions at http://lav.lomskih.net/wreck/

Loading module... FAILED.
MODULE `scripts` ERROR:
Traceback (most recent call last):
  File "compile.py", line 109, in <module>
    from module_scripts import *
  File "C:\Program Files (x86)\Steam\SteamApps\common\MountBlade Warband\_modsextra\MODULESYSTEM1157
GDWBWWORKING 1.41\module_scripts.py", line 17, in <module>
    from module_items import items
  File "C:\Program Files (x86)\Steam\SteamApps\common\MountBlade Warband\_modsextra\MODULESYSTEM1157
GDWBWWORKING 1.41\module_items.py", line 3477, in <module>
    modmerge(var_set)
  File "C:\Program Files (x86)\Steam\SteamApps\common\MountBlade Warband\_modsextra\MODULESYSTEM1157
GDWBWWORKING 1.41\module_items.py", line 3447, in modmerge
    add_item = deepcopy(orig_items)
  File "C:\Python27\Lib\copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "C:\Python27\Lib\copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "C:\Python27\Lib\copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "C:\Python27\Lib\copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "C:\Python27\Lib\copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "C:\Python27\Lib\copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "C:\Python27\Lib\copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "C:\Python27\Lib\copy.py", line 237, in _deepcopy_tuple
    y.append(deepcopy(a, memo))
  File "C:\Python27\Lib\copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "C:\Python27\Lib\copy.py", line 230, in _deepcopy_list
    y.append(deepcopy(a, memo))
  File "C:\Python27\Lib\copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "C:\Python27\Lib\copy.py", line 237, in _deepcopy_tuple
    y.append(deepcopy(a, memo))
  File "C:\Python27\Lib\copy.py", line 190, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "C:\Python27\Lib\copy.py", line 334, in _reconstruct
    state = deepcopy(state, memo)
  File "C:\Python27\Lib\copy.py", line 163, in deepcopy
    y = copier(x, memo)
  File "C:\Python27\Lib\copy.py", line 257, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "C:\Python27\Lib\copy.py", line 174, in deepcopy
    y = copier(memo)
TypeError: __call__() takes exactly 4 arguments (2 given)


COMPILATION FAILED.

Press any key to continue . . .
 
Note that I didn't add the snipped to module_variables, modules_strings or module_infopages because none of those had import statements.

The compiler at level 2 won't work unless I remove this section (>>>>) from the end of module_constants:
>>>>        if not from_value <= to_value:
            raise Exception("ERROR, condition %s <= %s failed [not true that %s <= %s]" % (from_key, to_key, str(from_value), str(to_value)))
        elif verbose:
            print "%s <= %s [%s <= %s]" % (from_key, to_key, str(from_value), str(to_value))

#Automatically run this on module import, so errors are detected
#during building.
>>>>_validate_constants(verbose=(__name__=="__main__"))
##diplomacy end+
 
gdwitt said:
Too Unexpected spacing errors.

Python is based on spaces/tabs instead of {} like other languages. If you break identation it wont compile.

And if you miss a "," or a closing tuple ")" it will also give a error... those are from syntax.
 
Hey there,

when modding a big problem for me is that module_scripts gets big and unorganized real fast. Would it be a possibility to be able to split up module_scripts into smaller ones?
 
Arch3r said:
Hey there,

when modding a big problem for me is that module_scripts gets big and unorganized real fast. Would it be a possibility to be able to split up module_scripts into smaller ones?

you can do that without any tool. Just break the scripts in files and use Python import to merge them.

Something like:

scripts_base.py  (base file, has all the stuff that you need to put there for the engine)
scripts_battle_formation.py
scripts_diplomacy.py
scripts_xxxx.py

You do not need to write 100 codes of line in a script, presentation, trigger... nor have a 40000 lines file.

Give a look at ModMerge for plugins. And of course WRECK (that does alot more than plugins).

Cheers
 
Ah thanks! I always suspected it would be possible, but never really knew how.

Code:
# -*- coding: cp1254 -*-
from header_common import *
from header_operations import *
from module_constants import *
from module_constants import *
from header_parties import *
from header_skills import *
from header_mission_templates import *
from header_items import *
from header_triggers import *
from header_terrain_types import *
from header_music import *
from header_map_icons import *
from ID_animations import *
from module_scripts_extra import *


####################################################################################################################
# scripts is a list of script records.
# Each script record contns the following two fields:
# 1) Script id: The prefix "script_" will be inserted when referencing scripts.
# 2) Operation block: This must be a valid operation block. See header_operations.py for reference.
####################################################################################################################

scripts = [

**actual scripts here **
] + scripts_extra

Code:
# -*- coding: cp1254 -*-
from header_common import *
from header_operations import *
from module_constants import *
from module_constants import *
from header_parties import *
from header_skills import *
from header_mission_templates import *
from header_items import *
from header_triggers import *
from header_terrain_types import *
from header_music import *
from header_map_icons import *
from ID_animations import *


####################################################################################################################
# scripts is a list of script records.
# Each script record contns the following two fields:
# 1) Script id: The prefix "script_" will be inserted when referencing scripts.
# 2) Operation block: This must be a valid operation block. See header_operations.py for reference.
####################################################################################################################

scripts_extra = [

**actual scripts here **
]

would that setup work?
 
Arch3r said:
would that setup work?

yeap, that is the most basic way of doing it. You should check WRECK plugin feature to improve over it later.

Also you should consider using folders to organize your code. Then a program (like a .bat, or a .sh) that copies all files to a temp folder:

\Project
  \Source
      \Main
      \Stuff
      \Stuff2
  \Build

Look at Floris for a example.
 
Hi Kalarhan and Lav,
I would like to get the full version of WRECK working since I use it so often.
See on the prior page:
Anyways, I'm trying to in stall the new version with all the code snippets.
I removed process.py files and added this on the top of all module files that imported something:
# >>>>> code snippet WRECK<<<<< #
from compiler import *

Why can't I seem to get wreck to work with these snippets and the process files removed?
My modules folder is enormous.
 
gdwitt said:
Why can't I seem to get wreck to work with these snippets and the process files removed?
My modules folder is enormous.

read Lav's install guide
start with the basic form: copy_and_forget -> copy your module_xxxx.py, header_xxx.py, ID_xxxx.py there. Do not copy your module_info.py
configure module_info.py
compile

once that works you can go to the full installation
remove all imports and replace with Lav's on the module_xxx.py files only
put files in the right folders
compile
 
Back
Top Bottom