![]() |
SE4 Scripting in Python (templatizer again)
This might not sound very impressive, but I just wrote a program that can negate a number... http://forum.shrapnelgames.com/image...s/rolleyes.gif
Why'd you do that, you might ask? Well, I'm working on an expression evaluator. OK, you ask again, why are you doing THAT? Well, this expression evaluator is going to be used in a sort of Uber-Tech-Gridder program which combines the flexibility of editing text files (ask Gandalf Parker or any other Linux junkie http://forum.shrapnelgames.com/images/icons/icon12.gif ) with the power of something like Krsqk's Component Generator. OK, it won't generate tech *grids* - it will only work in one dimension - but there will be a lot of flexibility; basically you will be able to do what Aaron's promised for SE5 with the SE4 data files - something like this: </font><blockquote><font size="1" face="sans-serif, arial, verdana">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">Start Level := 1 End Level := 12 Name := Anti - Proton Beam [level] Description := Focused energy beam used as a medium range weapon. Pic Num := 18 Tonnage Space Taken := 30 Tonnage Structure := 30 Cost Minerals := [50 + 25 * level] Cost Organics := 0 Cost Radioactives := [10 + 10 * level] Vehicle Type := Ship\Base\Sat\WeapPlat\Drone Supply Amount Used := 5 Restrictions := None General Group := Weapons Family := 2000 Roman Numeral := [level] Custom Group := 0 Number of Tech Req := 1 Tech Area Req 1 := Energy Stream Weapons Tech Level Req 1 := [level] Number of Abilities := 0 Weapon Type := Direct Fire Weapon Target := Ships\Planets\Ftr\Sat\Drone Weapon Damage At Rng := [max(15 + level * 5 - range * 10, 0)] Weapon Damage Type := Normal Weapon Reload Rate := 1 Weapon Display Type := Beam Weapon Display := 1 Weapon Modifier := 0 Weapon Sound := apbeam.wav Weapon Family := 1</pre><hr /></blockquote><font size="2" face="sans-serif, arial, verdana">And the beauty of my approach is that it will apply not only to Components.txt, but also to Facility.txt and anything else you might want to have leveled items! http://forum.shrapnelgames.com/images/smilies/cool.gif" src="images/icons/cool.gif" /> Now I know that I'm not easily motivated to work on something past the first night, but I know that this program is something that the SE4 community would greatly appreciate (at least I'd think you would!) so please keep bugging me to finish it! (Or at least release the code so someone else can http://forum.shrapnelgames.com/images/icons/tongue.gif ) edit: changed topic from "Semi-OT: I just negated a number! (Really, this is interesting! ;-)" to "Math parser ready (not the data file generator - yet!)" changed topic to "SE4 Templatizer Ready for Download!" edit: changed topic to "Templatizer 3 is HERE!!!!!" [ July 25, 2004, 05:52: Message edited by: Ed Kolis ] |
Re: SE4 Templatizer Ready for Download!
I just program in basic. I hear binary is easy too, but is owned by Microsoft so that is ruled out.
|
Re: SE4 Templatizer Ready for Download!
Negate a number? As far as I know, a number is an imaginary creation designed to represent Groups or singles of something. ??
|
Re: SE4 Templatizer Ready for Download!
Will it support all sorts of funky math? Exponents, sin, custom user defined functions, etc.?
|
Re: SE4 Templatizer Ready for Download!
I'm hoping to basically put in anything that's in the .NET math library, so exponents and sines should be in. As for user-defined functions, I wasn't planning for them, but if you want to add functions, the program is designed to be extensible so you can code them yourself if you know a .NET language such as C# http://forum.shrapnelgames.com/images/icons/icon10.gif Basically, I have an Expression class with subclasses for all the different types of expressions there can be (unary operations, constants, functions, etc.) and to add a function you'd have to derive a class from one of my base classes and implement its Value property which does the actual computation.
If I ever get this working I'll post it on www.codeproject.com; my main problem is to get the input string parsed out into an expression tree... but I've read about converting to Reverse Polish Notation and that should prove helpful with everything except the functions... and the (non-user-defined) functions shouldn't be too much after that, it's just a matter of getting them to take multiple parameters... |
Re: SE4 Templatizer Ready for Download!
User defined functions are necessary to prevent having to put the same formula code in 700 entries... http://forum.shrapnelgames.com/images/icons/icon12.gif
|
Re: SE4 Templatizer Ready for Download!
Hmm, that might be doable if I just had a separate functions.txt listing all the functions and what they evaluate to; they'd just be evaluated Last in the precedence order, I guess...
|
Re: SE4 Templatizer Ready for Download!
no offense, but that's kinda like my program, i woulda posted it up, but i couldn't, here's the link to the topic:
http://www.shrapnelgames.com/cgi-bin...=011057#000000 btw, only works for non-weap components (i got bored making it, so i stopped) |
Re: SE4 Templatizer Ready for Download!
Quote:
|
Re: SE4 Templatizer Ready for Download!
Negating a number means turning 5 into -5, or -3 into 3, or whatever - basically subtracting it from zero.
|
Re: SE4 Templatizer Ready for Download!
Negate: 1. To render ineffective or void; nullify. 2. To deny; contradict; rule out.
Well, I suppose it fits under contradict. http://forum.shrapnelgames.com/images/icons/icon7.gif |
Re: SE4 Templatizer Ready for Download!
The negative of a number nullifies it. To negate a number, to nullify it. The null number is 0.
[ July 14, 2004, 21:05: Message edited by: Imperator Fyron ] |
Re: SE4 Templatizer Ready for Download!
True, but the described operation is 0 - n, where n is the number. The operation you describe is n + (0 - n).
|
Re: SE4 Templatizer Ready for Download!
This works too. How about the operation -1*n where n is the number
|
Re: SE4 Templatizer Ready for Download!
Time for a progress report! http://forum.shrapnelgames.com/images/icons/icon10.gif
The calculator part of the application is coming along great; currently, it can negate, add, subtract, multiply, divide, exponentiate, and take modulos, exponents, percentages, and factorials! http://forum.shrapnelgames.com/images/icons/shock.gif What's left to do: -Add in variables -Add in mathematical functions (sin, log, sqrt, and stuff like that) -Add in user defined functions (if I can - Fyron wants 'em and it shouldn't be TOO hard, just string replacement http://forum.shrapnelgames.com/images/icons/icon12.gif ) -Add in functions that return strings, not just numbers (if I can - would be useful for generating Roman numerals for components) -Finally, write the application that parses the SE4 data file templates and generates the actual data files! http://forum.shrapnelgames.com/images/icons/shock.gif |
Re: SE4 Templatizer Ready for Download!
Oops, forgot to mention that I needed to add parentheses... Well, I just finished adding those! http://forum.shrapnelgames.com/images/icons/icon10.gif
BTW, will anyone be needing functions that take multiple parameters? I could easily implement single-parameter functions as unary operators and not write proper functions, and that would save me a bit of time with the parsing of parameters, but if you really want them... http://forum.shrapnelgames.com/images/icons/icon12.gif |
Re: SE4 Templatizer Ready for Download!
Quote:
But if it's too time consiming (multiparam functions)...don't bother with it now. Save it for future Versions http://forum.shrapnelgames.com/images/icons/icon7.gif |
Re: SE4 Templatizer Ready for Download!
I'll see what I can do then http://forum.shrapnelgames.com/images/icons/icon12.gif
BTW, I just added 4 more operators: The "to" operator generates random numbers in a specified range, so 1to6 simulates rolling a normal six-sided die. The "d" operator acts like in many roleplaying games, rolling multiple dice; 3d6 rolls up a number from 3 to 18 with most values in the 8 to 12 range. http://forum.shrapnelgames.com/images/icons/icon6.gif Note that these random generators will NOT allow you to generate random damage for weapons in SE4; it will just generate random numbers in the data files. Which might at least be good for a surprise game if you can keep yourself from peeking at the tech tree http://forum.shrapnelgames.com/images/icons/icon12.gif The other two are really statistical operators, but I figured I'd throw them in because I'd already done factorials - the "P" operator calculates permutations while the "C" operator calculates combinations, if you happen to know (or care) what those are... http://forum.shrapnelgames.com/image...s/rolleyes.gif |
Re: SE4 Templatizer Ready for Download!
Time for another progress report! http://forum.shrapnelgames.com/images/icons/icon10.gif
I added variables today - actually, they're really just named constants, as the program can't perform symbolic manipulations on them. (Though I wonder how hard that would be given what I've set up so far... http://forum.shrapnelgames.com/images/icons/icon12.gif ) I added 3 built-in variables: pi, e, and c (the speed of light). Any more you might want? I also added the "E" operator, which does scientific notation, e.g. 3E6 means 3 million. All that's left now is those pesky functions (and those aren't really even crucial, as long as I can do the single-parameter ones as unary operators) and then I can start incorporating the SE4 files into a client program for this app! http://forum.shrapnelgames.com/images/icons/icon6.gif |
Re: SE4 Templatizer Ready for Download!
Almost there... these functions are just getting annoying because I have to basically copy and paste my wrapper classes for one standard math library function to the next... http://forum.shrapnelgames.com/image...s/rolleyes.gif
|
Re: SE4 Templatizer Ready for Download!
Ed, what's ETA for release?
Edit: feature requests 1. bit of OOP http://forum.shrapnelgames.com/images/icons/icon7.gif 2. Conditions. 3. Comment sign. Together it could look like this: if (Cost Minerals.Antiproton Beam (level-1))>1500 // do something else exec format c: I can't imagine any application of these features, probably they're completely useless here http://forum.shrapnelgames.com/images/icons/icon7.gif (except comments), but nevertheless it's cool http://forum.shrapnelgames.com/images/icons/icon12.gif [ July 23, 2004, 06:46: Message edited by: aiken ] |
Re: SE4 Templatizer Ready for Download!
ETA for release? Probably sometime early next week, or sooner if I feel especially motivated... I've just got two more functions to add to the parser (assuming I don't think up more! http://forum.shrapnelgames.com/images/icons/icon10.gif ) and after that I have to make it integrate with the SE4 files, but I already have some code that loads SE4 files, so that shouldn't be too hard...
OOP, conditionals, and comments? Hmm, that's a bit beyond the scope of what I was planning - all I really was going to do was have something that's basically identical to the SE4 data files (in fact you could pass in an SE4 data file and it would output it right back, not that that would be useful http://forum.shrapnelgames.com/images/icons/tongue.gif ) but with a few extra fields - Min Level, Max Level, Weapon Min Range, and Weapon Max Range come to mind. Then in most of the fields you could put in equations in square brackets and they would be substituted for you and based on the Min Level and Max Level, you'd get multiple SE4 data entries for each entry you supply to my program. I guess conditionals might be possible if I put in boolean operations, but right now I have everything set up as type double, which might have been a mistake - if I ever want to make it more generic (say, so I can add a function to generate the components' Roman numerals instead of having to use Arabic numerals in their place), I'd have to change everything to type object, and I have hundreds of places where I'm referencing type double - not to mention all the type conVersions I'd have to add, and error checking to make sure you don't pass a string to a function that's expecting a number! http://forum.shrapnelgames.com/images/icons/shock.gif But you will be glad to see the HUGE array of functions, etc. that will be supported: Prefix operators: + (identity) - (negation) Infix operators: + (addition) - (subtraction) * (multiplication) / (division) ^ (exponentiation) \ (integer division) % (modulo or remainder) to (random; 3to6 generates a random integer from 3 to 6 inclusive) d (dice; 3d6 generates a random integer as would be generated by rolling 3 six-sided dice) P (permutations; 4P2 returns the number of permutations of 4 objects in Groups of 2) C (combinations; 4C2 returns the number of combinations of 4 objects in Groups of 2) E (exponential notation; 3E6 returns 3.0*10^6 or 3000000) Postfix operators: ! (factorial) % (percentage) Built-in variables: pi (ratio of circumference of circle to its diameter) e (base of the natural logarithms) c (speed of light, in meters per second) Functions: sin (sine) cos (cosine) tan (tangent) asin (arcsine) acos (arccosine) atan (arctangent) sinh (hyperbolic sine) cosh (hyperbolic cosine) tanh (hyperbolic tangent) dtor (degrees to radians) rtod (radians to degrees) log (logarithm, base 10, or a specified base as the second parameter) ln (logarithm, base e) sqrt (square root) curt (cube root) root (returns x^(1/y) where x and y are the 2 arguments. Useful in place of the exponentiation operator if you want to take odd roots of negative numbers.) abs (absolute value) floor (largest integer below or equal) ceiling (smallest integer above or equal) int (integer part) dec (decimal part) round (rounds to nearest integer, or number of significant digits as specified by a second parameter) fib (Fibonacci series) poly (evaluates a polynomial in x; takes 2 or more arguments where the first argument is the value of x and later arguments are the coefficients of the polynomial in the order they are normally written, i.e. by descending order of power) ftoc (Fahrenheit to Celsius) ctof (Celsius to Fahrenheit) min (finds minimum of all its arguments) max (finds maximum of all its arguments) avg (finds mean of all its arguments) stdev (finds standard deviation of all its arguments) median (finds median of all its arguments) And any more I can think of! http://forum.shrapnelgames.com/images/icons/icon10.gif |
Re: SE4 Templatizer Ready for Download!
No SE4 data file integration yet, but why not play around with my math parser and let me know what you think?
http://home.fuse.net/koliset/Programming/EEE.rar |
Re: SE4 Templatizer Ready for Download!
*trying to launch Evil Ed's Exterminator once again*
Do I need .NET Framework? I got errors about missing dlls when tried to work with it. [ July 24, 2004, 13:52: Message edited by: aiken ] |
Re: SE4 Templatizer Ready for Download!
ETA next week.. Darned, you'll beat my eta for the companion http://forum.shrapnelgames.com/images/icons/tongue.gif
(Don't really understand what this does but have nothing to do and wants to post) Impressive amount of functions though! To bad it wasn't a zip archive, I dont feel up to download an unrar proggie here at work, only have zip support. Will have to try it when I get home. [ July 24, 2004, 14:03: Message edited by: Ruatha ] |
Re: SE4 Templatizer Ready for Download!
Hmm. This perfectly sums up my understanding of your program, Ed, and therefore I will unlikely able to provide any kind of feedback. http://forum.shrapnelgames.com/images/icons/icon12.gif
Before you threaten to totemise me: does this program allow modders to plug in various formulas ruling any value in the SEIV files? For example, is the purpose of this program to automatise a geometrical suit ruling the cost of devices? (Such as what SJ seems to have done for his latest mod) If so, I can indeed see its usefulness for modders (well, as long as they can understand the whole array of mathematical functions better than I do; I flunked maths at kindergarten after all). If I am wholly mistaken, I guess it is simply too complicated for my poor mind. http://forum.shrapnelgames.com/images/icons/icon12.gif |
Re: SE4 Templatizer Ready for Download!
Quote:
|
Re: SE4 Templatizer Ready for Download!
Quote:
Quote:
Quote:
|
Re: SE4 Templatizer Ready for Download!
http://forum.shrapnelgames.com/images/icons/shock.gif 25 Mb? Good god! Nice size for a set of libraries.
Burn the .NET!!! http://forum.shrapnelgames.com/images/icons/icon8.gif |
Re: SE4 Templatizer Ready for Download!
Sorry about that... hope you download them anyway, because you will need them to run the program http://forum.shrapnelgames.com/images/icons/icon9.gif
(Hey, think of it this way - it's about the same size as the Java libraries, and nobody complains about Java, do they? http://forum.shrapnelgames.com/images/icons/icon12.gif ) edit: judging from your sig, you might be interested in this: www.go-mono.com It's the GNU Version of .NET and allows you to run .NET applications on Linux as well as Windows - as long as they're compiled for Mono and not the regular .NET. Mine isn't but it should be able to be compiled for Mono - I think... [ July 24, 2004, 20:51: Message edited by: Ed Kolis ] |
Re: SE4 Templatizer Ready for Download!
The SE4 Templatizer is ready for download, ahead of schedule! http://forum.shrapnelgames.com/images/icons/icon6.gif http://forum.shrapnelgames.com/images/icons/icon6.gif http://forum.shrapnelgames.com/images/icons/icon6.gif
http://home.fuse.net/koliset/SE4/SE4_Templatizer.rar You'll need the .NET Framework ( http://forum.shrapnelgames.com/images/icons/icon9.gif ), EEE (as mentioned in previous Posts), and a RAR extractor to use this program. Try it out - it's pretty darn cool! http://forum.shrapnelgames.com/images/icons/icon6.gif |
Re: SE4 Templatizer Ready for Download!
Quote:
[ July 25, 2004, 17:26: Message edited by: Yimboli ] |
Re: SE4 Templatizer Ready for Download!
Now I have a reverse task: I have a numerical values for damage (ex.: 0 5 10 45 120 390 0 0.. or such) and I like to find the approximation function for this sequence. Can someone suggest a tool to do it?
|
Re: SE4 Templatizer Ready for Download!
SE4 Templatizer updated to Version 1.0.1!
What's new: -Fixed bug where roman numeral IV showed up as IIII http://forum.shrapnelgames.com/image...s/rolleyes.gif -Fixed bug where an extra newline was inserted between entry families |
Re: SE4 Templatizer Ready for Download!
(bump)
C'mon, this is an interesting tool! Hard to use maybe, but very useful! http://forum.shrapnelgames.com/images/icons/icon12.gif |
Re: SE4 Templatizer Ready for Download!
Don't panic, where's at least 1 user of your SE4_templatizer - me (going to use it in my own project after I'll figure out how the hell pyScintilla works) http://forum.shrapnelgames.com/images/icons/icon7.gif
*to do: test Templatizer for i18n* |
Re: SE4 Templatizer Ready for Download!
New Version of the expression evaluator that the Templatizer uses - get it at my website!
What's new: interpolation functions (handy for damage calculations http://forum.shrapnelgames.com/images/icons/icon12.gif ) and bug fixes! |
Re: SE4 Templatizer Ready for Download!
Templatizer update: you can now use metric suffixes (such as 1K = 1E3), and a bug fixed which required you to add a newline to the generated files before using them in SE4 http://forum.shrapnelgames.com/image...s/rolleyes.gif
|
Re: SE4 Templatizer Ready for Download!
Is it possible for you to write a graphic UI for the templatizer or the EEE?
For us not so fluent in evaluation thingies! I've tried to start it but it goes Zoooooooooom way past me!! It's finished before I have even the slightest idea what I'm doing, (It's not that it finishes by itself its just that it would propably take several years for me to understand it). I've tried both the Templatizer and the EEE and I belive I've got some tiny notion as to what it does but that's about it and I might be way wrong! |
Re: SE4 Templatizer Ready for Download!
Yeah, I could probably put together a GUI for the programs... the real meat of the app is in the expression parser library anyway, so it shouldn't take long to make a GUI for the templatizer, at least... I personally don't see much point in making a GUI for the calculator part, because that would have to be changed every time I added a function or operator, and it would be *quite* cluttered with all the functions I've added - unless all you want is a text box where you type in equations, but then how's that better than a command line anyway? http://forum.shrapnelgames.com/images/icons/tongue.gif
Of course, when you say a GUI for the templatizer, do you just mean something where you can select an input text file and select an output text file and hit "generate"? Or do you want to be able to fully configure the various data files in the GUI? I think there's a PropertyList control which might be of some use, if I can figure out how to manipulate it to add and remove abilities, tech reqs, etc. the way I want... Oh, and BTW, there's another bugfix release out now - was having some more problems with parentheses, those pesky things http://forum.shrapnelgames.com/images/icons/tongue.gif |
Re: SE4 Templatizer Ready for Download!
Hmm, I don't know what I mean, I just thought it'd be easier to see what it does....
|
Re: SE4 Templatizer Ready for Download!
Well, the GUI, whatever that may be, is probably a ways off... I'm still trying to work out the Last of these stupid order-of-operations bugs that ruin any expression with multiple levels of parentheses! http://forum.shrapnelgames.com/images/icons/icon8.gif
(Though with the wide variety of functions I've provided, there will be little need to use multiple levels of parentheses, no? http://forum.shrapnelgames.com/images/icons/icon12.gif ) |
Re: SE4 Templatizer Ready for Download!
Well, I got those parentheses bugs fixed (at least I hope... http://forum.shrapnelgames.com/image...s/rolleyes.gif ) - anyone else want to try it out? I've generated a few MOO2 components with the program, but those are pretty trivial compared to what the program can do http://forum.shrapnelgames.com/images/icons/icon12.gif
|
Re: SE4 Templatizer Ready for Download!
Grrr, I found another bug... http://forum.shrapnelgames.com/images/icons/icon8.gif
It seems you can't call a function that takes multiple parameters from inside another function, because the outer function counts all the commas inside its parameter list and spits back an error saying "too many parameters"... so I'll have to tell it to ignore any commas that are inside parentheses in a parameter list, I guess... Also, the templatizer is rather slow, seeing as it redoes the whole calculation each time it runs an equation, even if all that's changed is the value of a variable... I'll probably have to Cache the results of all my expressions until they fall out of scope, I guess... Finally, I'd better make it display any errors that are thrown by the various functions and such... http://forum.shrapnelgames.com/image...s/rolleyes.gif |
Re: SE4 Templatizer Ready for Download!
Fixed those bugs... still haven't done anything about the slowness; that will probably require adding a property to one of my upper-level classes and overloading it in a lot of lower-level ones... ugh http://forum.shrapnelgames.com/images/icons/tongue.gif
Unless I can figure out this attributes thing that .NET has... then I could just tag the expression type classes I want to be "nonCacheable" with a special attribute tag, and check for that tag when I go to do the caching... |
Re: SE4 Templatizer Ready for Download!
1 Attachment(s)
I've started work on a GUI Version of the Templatizer... here's a general idea of what it will look like (assuming this newfangled file attachment thing works properly http://forum.shrapnelgames.com/images/smilies/wink.gif)
Anyone interested, or should I go back and try to speed up the expression parser by making it Cache known equation results? |
Re: SE4 Templatizer Ready for Download!
Files can only be attached in the Scenarios/Mods forum Category. You can upload the file there, then use the URL in your post here.
|
Re: SE4 Templatizer Ready for Download!
Well it WORKED... http://forum.shrapnelgames.com/image...ies/tongue.gif
Is there a rule against it? http://forum.shrapnelgames.com/image...es/redface.gif |
Re: SE4 Templatizer Ready for Download!
Yes. From the message at the top of the forums:
Quote:
|
Re: SE4 Templatizer Ready for Download!
Now even I can understand it!
|
All times are GMT -4. The time now is 01:28 AM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.