dinscurge

c/programming in general..

20 posts in this topic

im sure its been asked but i figure gonna post anyways just to make some traffic lol..

 

    the question is. do you have any tips for creating your own "format(s)" other than the obvious.. writing/typing out literally every thing it needs to have as far as data?

 

    now the specifics would be that im working on a project in c where im basically making dnd as a 'shell' if you want to call it that.. in that its a text game which you just type in what you want to do like.. can just type in balance, and then it runs some stuff to do a balance check, can type in the other program names since i haven't added them as functions at this point as its dnd so there's already like 60+ of them so not sure what all i would need as far as pointers to move all the variables.. also speeds up the compiling when i make these new functions as i don't have to compile the entire program..

    

    none of that is really needed to know but.. making a quest/job 'engine' i guess you could call it.. so instead of having the jobs/quests compiled into the program it seems more useful to have them external and have it just gather the data from those files.. so i need to make a 'format' for which this data will be stored, instructing the program what type of job/quest it is to use the appropriate loops/sections of the program  because different ones will need different calculations/have different amounts of text.

 

    a very simple example would be.. guy offers you to move boxes into store room from a cart out front. so the string for that offer, if you accept then you moving the boxes, then a string for when you tell him you have finished of him paying you/saying whatever. where if this had been some bandits ransacking a town, you may have also had to talk to the bandits during the confrontation and being that that's a fight/battle would require a lot more calculations/variables than the earlier box example.

 

    so at this point there is no program to model the files after, nor the files to model the program since its a fairly specific job which i want to use the least amount of data i can figure out how to get away with. so the tips would be for a entirely new thing, not expanding on anything already existing or what have you..

 

and yes i know terrible grammar etc.. lol

0

Share this post


Link to post
Share on other sites

Sounds pretty cool. Any game where there is fighting off bandits is awesome in my book.

 

I don't really do much in C. But expat can parse XML in C? Maybe write a function for move boxes. Then have all the characteristics for that function in an XML file?  As well as XML files with characteristics the shop owner, you're moving boxing for? So.. if like: the user types "move boxes", but is talking to a bandit, it checks an XML file for "bandits" and they don't understand "move boxes" (its not listed in the XML as something a bandit would know). They shoot, or even ask, "Where are these boxes and what is in them?".

 

You could even like synonyms files for different objects. When the bandits here an action followed by "gold", "boxes", "money", etc... they could respond with "What (goldIboxes|money)?". 

 

Just an idea. Sounds like an interesting project.

0

Share this post


Link to post
Share on other sites

Look into JSON (JavaScript Object Notation), I'd imagine there are parsing libraries available for your chosen C and platform. Many parsers can produce higher level data structures from JSON (automatic serialization/deserialization of maps, trees, lists, et c.). It's a super-simple format so you could write your own parser as an academic exercise without too much trouble.

0

Share this post


Link to post
Share on other sites

^^^ What he said. I hate parsing XML. Neither Perl or PHP are fun, so C would probably be a pain in arse. 

0

Share this post


Link to post
Share on other sites

Free the Ukraine! :-P

0

Share this post


Link to post
Share on other sites

    well for my project specifically its currently entirely ansi to make it easier for porting which dont have the current version on linux since i just havent grabbed the files and recompiled.. but till this point ive just been using specific files with 1 variable per line.

    so loosely my idea is just 1 file describing the database as currently the quests/jobs are launched thru another program/will be a part of that program, which has options like.. around town different towns have different things available(like, a port for example). so theres currently 18 variables for the entirety of the different places the quests could be from including the first for town wide, which could be jobs not relating to a specific business/building/person.. like visiting a farm could give jobs working around a farm. but also the farmer is a person so could give jobs about the bandits everyone in town knows about, or personal business such as checking on family/friends what have you..

    so im thinking first 18 lines just being the current number of quests/jobs in each category.  which would leave the file names for the files in the database to be just be like.. first number the 1-18qj(number for quest).(whichever extension i choose if has any and the qj bit earlier just to separate the numbers and stands for quest/jobs i guess..) then that file specifying first few lines the data needed to choose which part of the program/how many dialogs whatever.. could also have the text with special characters/phrases to signify beginning/end of the text(for each part)

    at least that's the idea so far lol..

 

edit: i guess to give insight on the parts of the program id be broken up into like.. moving boxes would be part of a single calculation loop which i could just change the text/read it from files if needed which the job would just be talk to them at beginning if you accept do it, which would just be a single task like move boxes, unload/load ship, plant seeds. etc. which is just you enter your roll/it rolls for you depending on a configuration file. could even use this example for like gathering things like herbs/crops atleast when you know the locations of those things.. etc.. and then you talk to the person to turn in the job and your done. then somethings could be more complex like requiring you to say throw a line for fishing then you would also need to try to pull the fish in where its two actions instead of the simpler one action job. and then ones that have a battle would have to have a whole other level of loop. like.. if you use melle only, you have to defeat all the melle guys to get back to the rangers in the back.

    i all ready ahve all these functions available in separate programs as part of the normal shell like part of it, just trying to combine them at this point into the questing/job engine for the player that hasn't decided what they want to do specifically. to give some sense of direction instead of staring at a screen that says "dnd: " for you to type in fishing or whatever..

Edited by dinscurge
0

Share this post


Link to post
Share on other sites

    well for my project specifically...........

 

Personally, for what you are doing, I'd choose XML. Maybe just because I'm a little more comfortable with creating more complex objects with XML -vs- JSON. JSON would be your best choice if you wanted to pull objects over http. For example a MUD type thing: where objects are requested over HTTP. Locally, I'd choose XML for more complex objects. Again, that's just me. I'm not saying XML is better. XML, for sure is much more difficult to parse and is more complex. 

 

You can use a database for the same thing. But it's really not practical. Since the database needs to queried all the time. Where XML objects can be loaded into memory. Again, you could do the same thing with a database. But it's gonna be slower and more complicated... 

As far as parsing; I don't really think creating your own parser might the best idea. There are plenty out there for XML and JSON in C. Each are already averrable, and have been tweaked for performance and elegance. Making a decent parser (depending on the complexity), can be a project in-and-of itself.

0

Share this post


Link to post
Share on other sites

nah for my use its entirely offline, id just check the index file for the current total numbers and then generate a number/pick the quest/job from the available ones.

 

edit: to be more specific the project goals are to maintain as much simplicity as possible/use entirely only standard ansi libraries/instructions if at all possible. mostly for the challenge and then for porting for most every program i didn't have to do anything just recompiled it on linux with gcc, should run on basically any operating system/architecture that supports c. currently still fits on a floppy with everything compiled and the source code was like 2.5-2.6mb should still fit on the floppy whenever i get around to finishing the quest/job thing.

Edited by dinscurge
0

Share this post


Link to post
Share on other sites

floppy? I'll have to visit a museum to get one of those. 8"- 5" - or 3"?  Double density? 

 

Haha! Sorry couldn't help myself with that. :-P

0

Share this post


Link to post
Share on other sites

the 3.5in 2.88mb been thinking about picking some up actually :P is obfuscation at this point eventhough the usb drives/disks are still available

1

Share this post


Link to post
Share on other sites

think gonna start working on it finally now that holiday stuff is gone, probably the programs by how many calculations need to be made and then just import the text from the database file for the quest/job. so the moving boxes example would import the text "moving boxes" or similar, and id say something like "enter your roll to move the boxes" if you had it set up for you to roll. where an example of a multiple calculation would be like, your making food at the inn, so you do first roll to search for ingredients in the store room, then a roll to prepare, a roll to cook whatever.. and just import the text/calculation parameters from the file.

0

Share this post


Link to post
Share on other sites

post-15812-0-62370300-1430108587_thumb.p

just for fun i guess :P

 

(besides the 2 screened the wrong file that had a 2 where the other did not have a 2 as a way to tell which one as it generates randomly to select the 'quest'. that aside is the same for all the data/text)

 

the left is like running thru the quest, the right being the database file that it was generated from. but thats what i came up with i guess

 

edit: oh yeah there was a typo at that point but not rescreening for the 2 so w.e. XD

Edited by dinscurge
1

Share this post


Link to post
Share on other sites

bump

 

+added a 'pack' system,

and how it manages the database is basically:

    the main index, consists of 38 numbers, each number corresponding to the directories in sequential order, the number itself being the actual number of files in that directory all being in sequential order, say the 5th number is 100, in the directory '5', there would exist 1-100.txt.

    then there's a usermade index, which consists of the exact path/name to the file that they edited/created with the program to make quests/import/export etc.. from this list i can populate another folder in the pack directory in the database' main directory (same as the other 38 directories and the main index/usermadeindex, and a couple example files) that they name, and then makes another index in that folder the same as the main index, but for the database in that directory.

    then added a index into the pack directory which is a list of the 'packs' that are installed, the management of the 'packs' is that it prints the list currently installed(base being the base databse/backup), and the rest of the ones if they added any, to the screen, then you can type in a name, if its on the list it removes it from list, if its not on the list, it will check for an index in that folder, if that doesn't exist it will print an error message doesn't exist, then you can enter 'pack' and it blanks the main database and installs all the database/packs that you marked, and does this because, the index/database does not contain enough information to determine which files are from which pack, and the way that it selects the quest from the database is pseudorandom number generation, so they have to be sequential with no holes as to avoid errors from selecting non existing files. and this being the simplest way i came up with to reliably guarantee that it would always be properly managed

    the main drawback being at somepoint i'll have to add that it checks usermadeindex, and backs that up to a pack, then reinstalls that pack and then edits the usermadeindex to the new file names, the current work around being you just export the files to a pack and then import them thru that pack

 

edit: also added couple things to the actual running of the quests/options you can do with the quest,

a character that will input a pause like "press enter to continue" adds in a getchar,

a commenting system a character that makes it stop printing anything till the same character is repeated

and another step which can ask a yes or no, a or b question, which will let you skip any number of steps following, or you can have it generate a number and if its over some other number, then it auto does the skipping, or even just force the skip. so thru that you can add quests that have multiple endings/parts.

no limitation on the number/order of any of the 3 types of steps, other than the limit of only up to 25 total steps in one quest

 

edit2: something curious happened when reporting to linux. apparently im going to have to maintain 2 different versions now, a bsd/windows one, and a linux/solaris. how might this be you might ask?. 'fflush(stdin);' is in bsd4.4> also works with mingw apparently. linux does not work with this and instead uses the solaris derived '__fpurge(Stdin);' using these as i wanted something more reliable then a trailing 'getchar();' between scanning information/reading user input, as using say fgetc to read in from stdin, does not clear the buffer next time scan comes up, it will have returned before you have been able to read the prompt and print the prompt twice>

Edited by dinscurge
0

Share this post


Link to post
Share on other sites

interesting thought, could install the 'game' into the same portable directory with multiple target os, using the same configuration/user/database files, that the user configuration/quests/everything would remain the same on linux, windows, bsd, solaris, mac, whatever i had compiled/ported it to, you would just run a different shortcut. and then it would be smaller than having all the versions separately, as the added benefit of the same configuration on any of those systems comes at only having the one same set of configuration/user files. instead of 2+

0

Share this post


Link to post
Share on other sites

post-15812-0-18431200-1439245370_thumb.p

 

added some hud/graphics options, the small window probably will make somewhat smaller in width,(don't want to small since the top line with character name is longer than the rest so the name doesn't wrap down, probably just scan the char string len and then shorten it in the display to fit. this one since i made it, starts up auto if you have it set to, auto shuts down if you quit the main program. the other ones can start up auto, but not really looked into shutting them down, since not really a good way in c doesn't seem, and using system commands generated from c, would probably be hard to scan pid table for the program and then if they had other window open/didn't want that one closed would be probably harder to check what those programs had open to kill only the ones that were spawned.(used system commands to start the extra windows, as c not having any basis for multi threading that is standard would not be portable anyways, but would be more difficult than the basic system commands to start a program/run a new shell, as far as portability. i.e.. change 1 line instead of using different libraries for different formats for spawning and managing and closing threads.)

 

also a updater program that backs up configuration/ then restores after install, and then adds any missing files to any character directories(new features sometimes new files for more configuration/data storage, so can add them to older characters that don't have them in the default configuration as to adhere to format/required data to prevent errors from trying to scan non existing data, so instead of having to have all the programs check/confirm the configuration, its generated in a working configuration when you make a character or install a newer version(update))

 

probably going to make an option to force rebuild all default configuration besides the actual sheet file just in case there's a crash/computer crashes or something during a write, or if the user modifies files and breaks something, instead of just scanning for each file, and if isn't there then placing the default.

 

edit: oh yeah the little window updates after a sleep(1); unless it cant open the file then it waits a second and tries again. changed the battle/encounter(generates traps sometimes)/gototown programs so the file is updated every time you lose/gain health immediately instead of when the program closes. if you login someone else/change name/stats rescans everything every time

Edited by dinscurge
1

Share this post


Link to post
Share on other sites

post-15812-0-59901300-1439608546_thumb.p

ended up just redoing the graphics of it, as making it smaller ended up with the top bar just being the icon on the left opening a menu and the minimize/maximize/close buttons, making it impossible to move without right clicking and selecting move, added a, 'no char' if you logout or whatever, and a 'file busy' if it just cant open the file also.

1

Share this post


Link to post
Share on other sites

Pretty awesome Dins! 

0

Share this post


Link to post
Share on other sites
On 7/23/2016 at 4:19 PM, tekio said:

Pretty awesome Dins! 

 

lol i guess :P

 

made some changes to the quest engine, battle system, and added a general purpose engine to replace most of the smaller precompiled binaries which were basically just 1 of 4 programs or so, with different text, and some numbers.

 

basically.. chopping wood, or smelting ore, besides using different  stat/ability modifiers and skills is the same basic, ask a question, how many logs do you want to chop, or how many pounds of ore do you want to smelt, or ingots do you want to pour whatever text. then you generate how many rolls based on that number or parameters to generate from that number, say 3-5 per 1 they enter so 3 would be between 9 and 15. so loop to take in rolls, and have a delay so they cant enter them all willy nilly, print text if they succeed or fail, and when they finish one of those sections of the 3, and then when they finish all of the work and then return.

 

but also added multiple success levels, different text along with that. say they roll a 1 on a d20, could have it that they failed so hard they have to do even more work, roll even more, or if they get a really high number it takes the place of 2 rolls maybe. also settings and stuff to over ride it for people that want more specific style of play.

 

 

 

the 1 at the start of the lines of text was just for testing so i knew which function/file it was running before i had it printing the ascii banner. the other types being, one has a divide function, for when it asks how many to divide that by a number, say to climb a cliff face you could enter in feet how far you want to climb, so you could roll 5 or 10 times instead of 100 for 100feet or whatever its setup for, also a timer function, timer and divide, a single loop one where it doesnt ask how many you just do 1, a timer version of that one etc..

for the basic crafting, actions, whatever.

gpengtest1.png

0

Share this post


Link to post
Share on other sites

made a couple other things after figured out some of the stuff lol :p. one being a program which creates/manages html redirection pages, as if i registered pages to emails, i could change all the pages that was registered to that email, or if you got a take down notice from 5-0 about bad stuff you could ban all their registered pages, you could update email for all or just one site, change url for the redirections etc.

 

on the basis sort of like.. the opposite approach to freenet, in that just anyone could have a 'dns' but not sure how to go about automation being.. the point is to not use icann or any other gate keepers so.. doing ssl/tls will give certificate errors for most all users, but having a first come first served policy, where you just have a page with 3 forms say, one for desired name, the url/path to whatever file, and the email they wish to register it to. the data shouldnt be transmitted till they press go and the only attack i could forsee is if you were to sniff the traffic and be able to inject your own before theirs got there to steal their page before they got it, other than being able to see who registered the redirection and where it would point to. that.. probably would be made with lighthttpd or something to get it as a single package but not sure if its really worth it lol.

 

but in the current state its just manual configuration just a utility that asks name, then it asks url if its not registered, otherwise pops up the email its registered to so you could confirm if you were going to use one of the options to ban/edit etc, then would ask the email after url if it wasnt registered and then id drop back to asking name but might remake it as individual tools to add/edit ban etc and just have both versions. so if they wanted to change they would email an email you setup to recieve this traffic. for the webserver, in manual configuration id just be any web server basically, and point it to the provided index or make your own, where it has a search bar where you type the name which redirects to the redirection page or have the webserver print your custom 404 saying its not been registered if they want to register follow these steps etc.so you could load say stankdawg.fap on the index 'search bar' or you could go the url to that domain whatever, if you have it registered or your ip/stankdawg.fap if you wanted to directly access the file stankdawg.fap.html

 

so basically a make your own tinyurl where they get to pick the names. but its just static html redirections so as long as the path is available it doesnt matter if its local, intranet or internet figure might be useful for something likes.. set up a network at a college have your own knock off versions of Qoogle where you can get the low down all the clubs and classes and student activities

 

edit: oh a random multiple one time pad thing, and some other dumb stuff lol

Edited by dinscurge
added text
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now