Generating the first slime

This is going to be interesting. It's pretty complex, lots of moving bits and pieces. I think it would be wise to break this down into individual functions so I can see what breaks and why a little easier, plus DRY.

Lots of DB queries will be fired for this as well. Gotta look up a lot of info. I could keep it in memory but if I change something in the DB while the server is running I would like it to be reflected. I could write a hook that calls the server and tells it to update it's cache but for now, since it is early and there is a lot to test it's probably better to avoid adding any extra complexity.

I wrote a color generator that is completely random right now, I may add some complexity later but for now it's fine. There's a few algorithms I am aware of to make things a little nicer if it comes out kinda screwy.

http://devmag.org.za/2012/07/29/how-to-choose-colours-procedurally-algorithms/

Color difference - Wikipedia
How to Generate Random Colors Programmatically
Creating random colors is actually more difficult than it seems. The randomness itself is easy, but aesthetically pleasing randomness is more difficult. For a little project at work I needed to automatically generate multiple background colors with the following properties: Text over the colored bac…
iWantHue

I built a little portable arcade on my lunch break. Still need to take a shower, though... before I do I am going to do a little more outlining on my generator. This thing scares me, it's bound to be buggy.

I also might take time to work on another project now and then, this project is very long term and I know I will burn out if I spend every day on it. Plus I have some stuff I really need to redesign and some other stuff that's in need of updating. I will document my work on those projects here as well, this is after all; my project log.

Anyway, shower time.

Alright, back to generating slimes. I need to generate each part individually, some parts may have color locks or alpha locks so I need to account for that in the generator.

There's a lot of ways I can handle the alpha, though I suppose the best way is to write an alpha into the color generator and pass it in. I have my min/max alpha 0-255 in the database and will need to convert it to a float and then into a hex. I could store it in the DB as a float and skip a conversion but the Color object should not have a problem handling it.

Color
Color in RGBA format using floats on the range of 0 to 1. Description: A color represented by red, green, blue, and alpha (RGBA) components. The alpha component is often used for opacity. Values ar...

Now that I have colors worked out (for the time being) I need to figure out how I will handle rarity. Rarity is a number between 0 and 1000, the higher the number the more rare the marking should be.

I could write a function that takes a marking array (from the db) and compares it's rarity against a dice roll, then return the result... but that would leave us with blank markings instead of picking a different one and rolling again.

I could use a recursive function called from a function I call to pick the marking, recurse until something is generated... but what if there's no markings? Need to make sure it doesn't run or we'll infinite loop. Also it would be pretty heavy on the server to have to do this for every marking.

I knew this would be complicated quick.

Another way I could solve it would be build an array of pointers to all the available markings, more entries for more common ones and less for rarer, then select one. Also pretty heavy on the server, though...

Screw it we'll go with a while loop that will terminate if it fails 3 times in a row and return nothing. Better than recursive insanity and less likely to get no marking.

If we get no marking returned we'll use a continue inside that iteration and set the marking to null. Man, it's going to suck to debug all this when it inevitably goes terribly wrong.

I think I am trying to hold way too much in my head right now, everything is really hard to hold on to and I feel like I am screwing up a lot but I managed this;

func roll_for_marking(markings):
	# Choose from available markings, roll dice against their rarity, return null if failing three times.
	var marking = markings[randi() % (markings.size() -1)]
	if marking[14] > 0:
		var roll_counter = 3
		while roll_counter > 0:
			if randi() % 1000 > marking[14]:
				return marking
			roll_counter -= 1
            marking = markings[randi() % (markings.size() -1)]
	else:
		return marking
	return null

Now that I have a giant mound of code to debug with the markings, on to ears. (While I probably should have devised a way to test all this stuff bit by bit... I am going to take the low road and suffer.)

I've marked out the indexes on the slime table's fields... oh boy.

Very complex little creatures.

I still have a long way to go here. A long, long way. It's the end of the day already and I feel like I didn't even dent this thing. Looks like I was right thinking this would take all week.

I still have to test the visual generation, probably rework one part of the model, instead of having markingX_showing make fields for showing_marking_1,2,3,4,5. Then have the non-showing markings be in the markings field. This will keep the colors from being able to drift if I start messing with the database and I can't imagine we'll want to show more than 5 markings anyway. If we do I will deal with it later.

Which means that whole index I did up there is going to have to be rebuilt =D Fuck.

This is the nature of the beast.

Anyway, I will modify the model before I clock out, it's 4:45 now so I better go fast.

id | name  | level | experience | strength | agility | constitution | intellect | wisdom | charisma | current_health | max_health | current_sp | max_sp | current_weapon_skillpoints | max_weapon_skillpoints | short_blade | short_blade_xp | long_blade | long_blade_xp | axe | axe_xp | projectile | projectile_xp | thrown | thrown_xp | spear | spear_xp | face_sprite | hand_sprite | color | color2 | color3 | color4 | color5 | body_sprite | head_slot_id | main_hand_slot_id | off_hand_slot_id | care_logs | neglect_logs | owner_id | attention | aura_color | aura_showing | body_color | discipline | ear_color | ears_showing | energy | exercise | fun | hand_color | happiness | health | heat | hunger | hygiene | knowledge | moisture | tail_color | tail_showing | thirst | trust | wing_color | wings_showing | aura_id | body_id | ears_id | hands_id | tail_id | wings_id | shown_marking_1_id | shown_marking_2_id | shown_marking_3_id | shown_marking_4_id | shown_marking_5_id 

Welp, guess I will sort through and redo the index I made tomorrow and then work on the DB side of the generator.

Time to make some food.