AtomMerge Reference

If you have any questions, suggestions, or problems for AtomMerge please email me at shadowdarke@hotmail.com or post a message at http://shadowdarke.byond.com/forum/forum.cgi?forum=libraries


Contents

Updates
Version 4
Version 3
Library
Using AtomMerge
AtomMerge Icons
Global
sd_EnableMerging var (global)
sd_DelayMerge proc (global)
sd_Merge proc (global)
Atom Extensions
sd_MrgSet var (atom)
sd_EdgeMrg var (atom)
sd_Adjacent proc (atom)
sd_MergeMatch proc (atom)
Demo Program


Updates

Version 4

Updated the test.dm to demonstrate the new sd_MergeMatch proc. Purple objs and green mobs now merge with each other in the demo program.

back to Contents

Version 3

I've provided the sd_MergeMatch() proc to give programmers greater control over how atoms merge. General porpuse users need not worry about it.

back to Contents

Library

The AtomMerge library allows any atoms (except areas) automatically merge graphically with neighboring atoms of the same type. The most obvious use for AtomMerge is to make auto-merging walls, rivers, and other turf types. However, AtomMerge works with objs, mobs, and custom atom types as well. The demo provides examples.

back to Contents

Using AtomMerge

AtomMerge is very easy to use. Just include it in your project, draw an icon with the required icon states, and assign sd_MrgSet and sd_EdgeMrg. Atoms that automerge after moving will require a little extra code. There is an example method in test.dm.

back to Contents

AtomMerge Icons

AtomMerge requires very specific icon states to function properly. The icon states are numbers from "0" to "255". Depending on the sd_MrgSet of the atom, certain states might not be required. sd_MrgSet 1 only requires "0" to "15", sd_MrgSet 2 requires 47 specific icon states, and sd_MrgSet 3 requires all 256 icon states. See sd_MrgSet var (atom) for more details on merging styles.

You may examine the included icon files for the icon states needed. The number suffix reminds you how many icon_states are used for that icon. For example, 'blue16.dmi' is for sd_MrgSet 1 and only has the basic 16 icon states. 'yellow256.dmi' has all 256 icon states.

The icon state is comprised of 8 bits, one for each direction from the atom. If there is a mathing atom in the corresponding direction, the bit is set. The bits from least significant bit to most significant bit are NORTH, SOUTH, EAST, WEST, NORTHEAST, SOUTHEAST, NORTHWEST, SOUTHWEST.

back to Contents

sd_EnableMerging var (global)

See Also:
sd_Merge proc (global)
sd_DelayMerge proc (global)
Default Value:
0 during world boot up. 1 after the world has finished booting.
If sd_EnableMerging is set, AtomMerge will automatically merge atoms as they are created and deleted. sd_EnableMerging defaults to 0 to prevent merging during world boot up, but is automatically set to 1 after world/New() is finished.

back to Contents

sd_DelayMerge proc (global)

See Also:
sd_EnableMerging var (global)
sd_Merge proc (global)
Format:
sd_DelayMerge(List)
Args:
List:
List of atoms to merge

sd_DelayMerge spawns an sd_Merge() in one tick. If sd_EnableMerging = 1, sd_DelayMerge() is automatically called whenever an atom is deleted.

back to Contents

sd_Merge proc (global)

See Also:
sd_EnableMerging var (global)
sd_DelayMerge proc (global)
Format:
sd_Merge(var/list/List)
Args:
List:
List of atoms to merge

sd_Merge() recalculates the icon_state to automatically merge atoms in the List to neighboring atoms of the same type. If sd_EnableMerging = 1, sd_Merge() is automatically called whenever a new atom is created.

back to Contents

Atom Extensions

AtomMerge expands existing atoms to include the following vars and proc.
vars
sd_MrgSet
sd_EdgeMrg
procs
sd_Adjacent
sd_MergeMatch

back to Contents

sd_MrgSet var (atom)

Default Value:
0 (no automatic merging)
Valid values:
sd_MrgSet value merge style # of icon states
0 no merging
(default value)
NA
1 4 adjacent squares only
(NORTH, SOUTH, EAST, and WEST)
16
2 4 adjacent + inner corners 47
3 all 8 directions 256
sd_MrgSet determines how the atom merges with other atoms of the same type. There are 4 styles of icon merging supperted by AtomMerge.

The first style, denoted by sd_MrgSet = 0, does not merge with neighboring atoms. No additional icon states are required.

The style denoted by sd_MrgSet = 1 merges with atoms of the same type at each cardinal direction, north, south, east, and west. It requires 16 icon states labeled "0" to "15".

The style denoted by sd_MrgSet = 2 merges with atoms of the same type at each cardinal direction and at inner corners. For example, if a block that merges north and west will also check to see if there is a block to the northwest, but would not check northeast. It requires 47 icon states.

The style denoted by sd_MrgSet = 3 merges with atoms in any of the eight directions,north, south, east, west, northeast, northwest, southeast, and southwest. It requires 256 icon states labeled "0" to "15".

back to Contents

sd_EdgeMrg var (atom)

See also:
sd_DelayMerge proc (global)
Default value:
sd_EdgeMrg = 0
If sd_EdgeMrg is set for an atom, it will merge with the map edges.

back to Contents

sd_Adjacent proc (atom)

See Also:
sd_MrgSet var (atom)
Format:
sd_Adjacent()
Returns:
A list of adjacent atoms relevant to the atom's sd_MrgSet.

back to Contents

sd_MergeMatch proc (atom)

See Also:
sd_Merge proc (global)
sd_EdgeMrg var (atom)
Format:
sd_MergeMatch(direction)
Args:
direction:
a BYOND direction
Returns:
1 if the atom should merge in direction. 0 if not.
Default:
Returns 1 if an instance of an exactly matching type is found in direction, or if the edge direction is off the edge of the map and sd_EdgeMrg is set. For example, a /turf/wall will not merge with a /turf/wall/brick.
The sd_MergeMatch proc is provided so programmers may override the default merge behavior in specialized cases. For instance, to make all types of /turf/wall merge with each other, you may include this snippet of code:
/turf/wall
	sd_MergeMatch(direction)
		var/turf/T = get_step(src,direction)
		if(!T)
			return sd_EdgeMrg
		else
			if(istype(T,/turf/wall)) return 1

back to Contents

Demo Program

AtomMerge comes with a small world to demonstrate the library in action. In the demo world, you assume the role of a smiley. Moving the smiley will draw or erase greens or purples in the space you move to, depending on your movemode. Use the movemode command to change movemode. You may click any turf to cycle it through the three turf types, plain, blue, or yellow.

There are 4 automerging atom types in the demo world:
Color Type sd_MrgSet sd_EdgeMrg
Blue turf 1 0
Blue turfs only merge in 4 directions and do not merge with the map edges. Blues are created by clicking a plain empty turf.
Purple obj 2 0
Purple objs merge in the 4 basic directions and interior angles. Purples are created by moving your smiley when your movemode is set to "Drawing Purples".
Green mob 2 0
Green mobs merge in the 4 basic direction and intereior angles. They have also been modified to automerge after moving. Greens are created by moving your smiley when your movemode is set to "Drawing Greens".
Yellow turf 3 1
Yellow turfs merge in all 8 directions and do merge with the map edges. Yellows are created by clicking a blue turf.

back to Contents