Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
NumPowder: The Powder Toy on the calculator
Mason Chenbc6bc290c46d
diff --git a/Makefile b/Makefileindex 6cbae376..809ad845 100644--- a/Makefile+++ b/Makefile@@ -24,7 +24,7 @@ RAM_LIMIT = 148928# custom builds of Epsilon 25.2's source give apps less: 133652 bytes; every game fits there too, in NumPlay and on# its own (their big buffers are on the stack, 32 KB apart from that RAM, or in the RAM the software has left)CUSTOM_RAM = 133652-BIG_APPS = Celeste HollowKnight ChampionIsland FinalEarth2 NumBlocks NumDrive+BIG_APPS = Celeste HollowKnight ChampionIsland FinalEarth2 NumPowder NumBlocks NumDrive# the calculator's space for installed apps (0x90200000 to 0x903F0000 in its flash)APP_SPACE = 2031616# Upsilon, the N0110 and N0115's custom software, gives .nwa apps less RAM: NumPlay-Upsilon.nwa has@@ -206,6 +206,7 @@ APP_celeste = games/celeste/output/celeste.nwa:Celeste.nwaAPP_championisland = games/championisland/output/championisland.nwa:ChampionIsland.nwaAPP_hollowknight = games/hollowknight/output/hollowknight.nwa:HollowKnight.nwaAPP_finalearth2 = games/finalearth2/output/finalearth2.nwa:FinalEarth2.nwa+APP_numpowder = games/numpowder/output/numpowder.nwa:NumPowder.nwaapps: | $(B)$(MAKE) -C games/numdash build NWLINK="node node_modules/nwlink/bin/nwlink"@@ -220,6 +221,7 @@ apps: | $(B)$(MAKE) -C games/championisland build NWLINK="$(NWLINK)"$(MAKE) -C games/hollowknight build NWLINK="$(NWLINK)"$(MAKE) -C games/finalearth2 build NWLINK="$(NWLINK)"+ $(MAKE) -C games/numpowder build NWLINK="$(NWLINK)"cd games/tetris/tetris && NWLINK="$(NWLINK)" $(CARGO) build --release --quietcp $(word 1,$(subst :, ,$(APP_numdash))) $(B)/apps/$(word 2,$(subst :, ,$(APP_numdash)))cp $(word 1,$(subst :, ,$(APP_crossyroad))) $(B)/apps/$(word 2,$(subst :, ,$(APP_crossyroad)))@@ -234,6 +236,7 @@ apps: | $(B)cp $(word 1,$(subst :, ,$(APP_championisland))) $(B)/apps/$(word 2,$(subst :, ,$(APP_championisland)))cp $(word 1,$(subst :, ,$(APP_hollowknight))) $(B)/apps/$(word 2,$(subst :, ,$(APP_hollowknight)))cp $(word 1,$(subst :, ,$(APP_finalearth2))) $(B)/apps/$(word 2,$(subst :, ,$(APP_finalearth2)))+ cp $(word 1,$(subst :, ,$(APP_numpowder))) $(B)/apps/$(word 2,$(subst :, ,$(APP_numpowder)))arm-none-eabi-strip --strip-unneeded $(B)/apps/Tetris.nwaSTD_APPS = $(foreach g,$(STD_GAMES),$(B)/apps/$(NWA_$(g)))@@ -289,5 +292,6 @@ clean:-$(MAKE) -C games/championisland clean-$(MAKE) -C games/hollowknight clean-$(MAKE) -C games/finalearth2 clean+ -$(MAKE) -C games/numpowder clean-cd games/tetris/tetris && $(CARGO) clean-$(foreach g,$(STD_GAMES),$(MAKE) -C games/$(g) clean;)diff --git a/README.md b/README.mdindex eb9e8cc5..5507ece8 100644--- a/README.md+++ b/README.md@@ -6,7 +6,7 @@<p align="center"><b>17 free games for your NumWorks calculator, in one app.</b><br>- Plus <b>The Final Earth 2</b>, <b>Hollow Knight</b>, <b>Celeste</b> and <b>Champion Island</b>, four big games that come as apps of their own.<br>+ Plus <b>NumPowder</b>, <b>The Final Earth 2</b>, <b>Hollow Knight</b>, <b>Celeste</b> and <b>Champion Island</b>, five big games that come as apps of their own.<br>For the N0110, N0115 and N0120, in English, <a href="#in-french-and-chinese">French and Chinese</a>, and for <a href="#on-upsilon">Upsilon</a>.</p>@@ -29,7 +29,7 @@</p><p align="center">- <b>New: <a href="#new-the-final-earth-2">The Final Earth 2</a></b>, a city on floating islands in space. <b>And <a href="#new-hollow-knight">Hollow Knight</a></b>, from King's Pass to Hornet in Greenpath.+ <b>New: <a href="#new-numpowder">NumPowder</a></b>, The Powder Toy on the calculator. <b>And <a href="#new-the-final-earth-2">The Final Earth 2</a></b>, a city on floating islands in space.</p><p align="center">@@ -42,6 +42,29 @@ NumPlay is open source and completely free, and it took a lot of work to make. IWant a game that isn't here? I'm open to requests: email me at [[email protected]](mailto:[email protected]).+## New: NumPowder++<p align="center">+ <img src="docs/media/numpowder.gif" width="640" alt="NumPowder: sand poured on a metal shelf, then water, then lava that melts the ice and boils the water">+</p>++The Powder Toy, right on your calculator: draw sand, water, fire and 175 other materials and watch them react.++- **Things react:** sand sinks in water, fire burns wood, lava melts ice and boils water, acid eats most things.+- **Heat, air and electricity:** things melt, boil and freeze, explosions push the air, and sparks run along metal and silicon.+- **Walls, tools and views:** 17 kinds of walls, tools to heat and cool, and the original's display modes.+- **Easy on a keypad:** the bottom of the screen always says what the keys do, and How to play is in the menu.++<p align="center">+ <a href="https://github.com/Mason363/NumPlay/releases/latest/download/NumPowder.nwa"><img src="https://img.shields.io/badge/Download-NumPowder.nwa-C8A040?style=for-the-badge" alt="Download NumPowder.nwa"></a>+</p>++<p align="center">+ It's too big to fit next to NumPlay, so it comes on its own. <a href="games/numpowder/README.md"><b>More about NumPowder</b></a> · <a href="docs/play.md#numpowder"><b>How to play</b></a>+</p>+++## New: The Final Earth 2<p align="center">@@ -214,6 +237,10 @@ Click a file to download it. Not sure which one? Take the first.<td width="120" align="center"><img src="docs/media/thumb_hollowknight.png" width="112" alt="Hollow Knight"></td><td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/HollowKnight.nwa">HollowKnight.nwa</a><br>Hollow Knight: from King's Pass to Hornet in Greenpath. It fills the calculator's app space, so it comes on its own, not inside NumPlay (<a href="games/hollowknight/README.md">more</a>)</td></tr>+ <tr>+ <td width="120" align="center"><img src="docs/media/thumb_numpowder.png" width="112" alt="NumPowder"></td>+ <td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/NumPowder.nwa">NumPowder.nwa</a><br>NumPowder: The Powder Toy on the calculator, sand, water, fire, acid, electricity and 175 materials. It's too big to fit next to NumPlay, so it comes on its own (<a href="games/numpowder/README.md">more</a>)</td>+ </tr><tr><td width="120" align="center"><img src="docs/media/thumb_finalearth2.png" width="112" alt="The Final Earth 2"></td><td><a href="https://github.com/Mason363/NumPlay/releases/latest/download/FinalEarth2.nwa">FinalEarth2.nwa</a><br>The Final Earth 2: build a city on floating islands in space. It's too big to fit next to NumPlay, so it comes on its own (<a href="games/finalearth2/README.md">more</a>)</td>@@ -309,9 +336,9 @@ You need your calculator, its USB cable, and a computer with **Google Chrome** o| Calculator | Software | What runs || --- | --- | --- || N0120 | Epsilon 23.2 or newer (the calculator's own software) | Everything |-| N0110, N0115 | Epsilon 23.2 or newer | Everything. These models are about 2.5 times slower, so the big games (The Final Earth 2, Hollow Knight, Celeste, NumDrive, NumBlocks, Champion Island) show fewer frames per second, but they keep their speed. |+| N0110, N0115 | Epsilon 23.2 or newer | Everything. These models are about 2.5 times slower, so the big games (NumPowder, The Final Earth 2, Hollow Knight, Celeste, NumDrive, NumBlocks, Champion Island) show fewer frames per second, but they keep their speed. || N0110, N0115 | Upsilon | NumPlay-Upsilon.nwa: 13 games. See [On Upsilon](#on-upsilon). |-| Any | Custom software built from Epsilon 25.2's source | Everything, The Final Earth 2, Celeste, Hollow Knight and Champion Island too. These builds can give apps less memory (133 KB): on one that gives even less, a game that needs more than there is says how much on its card. |+| Any | Custom software built from Epsilon 25.2's source | Everything, NumPowder, The Final Earth 2, Celeste, Hollow Knight and Champion Island too. These builds can give apps less memory (133 KB): on one that gives even less, a game that needs more than there is says how much on its card. |To see your calculator's model and software, open **Settings**, then **About**. To update the software, go to [my.numworks.com](https://my.numworks.com) with the calculator plugged in.@@ -319,7 +346,7 @@ To see your calculator's model and software, open **Settings**, then **About**.**NumPlay-French.nwa** and **NumPlay-Chinese.nwa** are NumPlay with every game in French or in Chinese (simplified). Install them like NumPlay.nwa, instead of it. Your progress is the same in every language.-A few things stay in English: logos and words drawn into pictures, level names, the calculator's key names, NumBlocks' commands, and Portal Returns' chamber stories. The Final Earth 2, Celeste, Hollow Knight and Champion Island come in English only.+A few things stay in English: logos and words drawn into pictures, level names, the calculator's key names, NumBlocks' commands, and Portal Returns' chamber stories. NumPowder, The Final Earth 2, Celeste, Hollow Knight and Champion Island come in English only.### On Upsilon@@ -344,7 +371,7 @@ Upsilon support is new. If it doesn't work on your calculator, please [email me]- **The calculator restarts once after installing**: it shows the NumWorks logo, then asks for your language. That's normal. Your apps are at the end of the home screen after that.- **Celeste, Hollow Knight and Champion Island each fill the whole space for apps.** Install one of them alone, without NumPlay and without each other: if you pick more than fits, they don't install.-- **The Final Earth 2 doesn't fit next to NumPlay.** Install it without NumPlay.+- **NumPowder and The Final Earth 2 don't fit next to NumPlay.** Install them without NumPlay.- **Installing replaces the apps you installed before.** To keep one, add it again with the new one.- Check your calculator's software is **Epsilon 23.2 or newer** (Settings, then About), and update it at [my.numworks.com](https://my.numworks.com) if not.@@ -367,6 +394,10 @@ Upsilon support is new. If it doesn't work on your calculator, please [email me]<td><img src="docs/media/hollowknight.gif" alt="Hollow Knight: the Knight in King's Pass, against the False Knight and Hornet"></td><td><img src="games/hollowknight/docs/greenpath.png" width="100%" alt="Hollow Knight: Greenpath"></td></tr>+ <tr>+ <td><img src="docs/media/numpowder.gif" alt="NumPowder: sand poured on a metal shelf, then water, then lava that melts the ice and boils the water"></td>+ <td><img src="games/numpowder/docs/explosion.png" width="100%" alt="NumPowder: C-4 exploding under stone"></td>+ </tr><tr><td><img src="docs/media/finalearth2.gif" alt="The Final Earth 2: building a house on a city in free play, then its window and the happiness window"></td><td><img src="games/finalearth2/docs/night.png" width="100%" alt="The Final Earth 2: a city at night"></td>@@ -419,6 +450,7 @@ Upsilon support is new. If it doesn't work on your calculator, please [email me]- **Minecraft** by Mojang inspired NumBlocks, which uses Minecraft 1.8.8's textures, font and screens and makes its worlds the way Minecraft 1.8.8 does.- **Celeste** inspired NumPlay's Celeste, which uses the game's own pictures, maps, texts and fonts. Not affiliated with Maddy Makes Games.- **Hollow Knight** inspired NumPlay's Hollow Knight, which uses the game's own pictures, animations, maps, texts and fonts. Not affiliated with Team Cherry.+- **[The Powder Toy](https://powdertoy.co.uk)** inspired NumPowder, which ports its materials' behaviour, its font and its icons from [its source code](https://github.com/The-Powder-Toy/The-Powder-Toy) (GNU GPL v3.0), by Stanislaw K Skowronek, Simon Robertshaw and its contributors. Not affiliated with them.- **[The Final Earth 2](https://store.steampowered.com/app/1180130/The_Final_Earth_2/)** by [Florian van Strien](https://florianvanstrien.nl) inspired NumPlay's The Final Earth 2, which uses the game's own pictures, fonts and texts, with additional sprites by LukXD99. Not affiliated with him.- **Buckshot Roulette** by Mike Klubnika inspired NumPlay's Buckshot Roulette, whose scenes are rendered from the game through the Open Buckshot Roulette project (1503Dev). Fonts: Fake Receipt by Ray Larabie and Dot Matrix by Dionaea.- The **Doodle Champion Island Games** (2021) inspired Champion Island, which uses the doodle's own pictures, maps and texts from the [Google-Doodle-Champion-Island](https://github.com/potherca-blog/Google-Doodle-Champion-Island) archive by potherca-blog, and the **PixelMplus** font by Itou Hiroki ([license](LICENSES/PixelMplus.txt)).@@ -436,4 +468,4 @@ NumPlay is licensed under the [GNU General Public License v3.0](LICENSE). CopyriCode and fonts from others keep their own licenses: the `UNLICENSE` files in the games' folders and the [LICENSES](LICENSES) folder. The names, artwork and music of the games NumPlay is inspired by belong to their makers and are not covered by it.-<sub>Unofficial fan games, not affiliated with NumWorks, RobTop Games (Geometry Dash), Hipster Whale (Crossy Road), the makers of Drive Mad, LocalThunk or Playstack (Balatro), Mike Klubnika or Critical Reflex (Buckshot Roulette), Mojang or Microsoft (Minecraft), Maddy Makes Games (Celeste), Team Cherry (Hollow Knight), Florian van Strien (The Final Earth 2), MateoConLechuga (Portal Returns), Valve (Portal), .GEARS (Flappy Bird), Bandai Namco (Pac-Man), Hasbro (Connect Four), Google (Snake, Solitaire, Block Breaker, Doodle Champion Island Games), STUDIO4°C or Microsoft (Minesweeper). Tetris is a trademark of The Tetris Company, Minecraft of Mojang Synergies AB, Pac-Man of Bandai Namco and Connect Four of Hasbro.</sub>+<sub>Unofficial fan games, not affiliated with NumWorks, RobTop Games (Geometry Dash), Hipster Whale (Crossy Road), the makers of Drive Mad, LocalThunk or Playstack (Balatro), Mike Klubnika or Critical Reflex (Buckshot Roulette), Mojang or Microsoft (Minecraft), Maddy Makes Games (Celeste), Team Cherry (Hollow Knight), Florian van Strien (The Final Earth 2), The Powder Toy's developers (The Powder Toy), MateoConLechuga (Portal Returns), Valve (Portal), .GEARS (Flappy Bird), Bandai Namco (Pac-Man), Hasbro (Connect Four), Google (Snake, Solitaire, Block Breaker, Doodle Champion Island Games), STUDIO4°C or Microsoft (Minesweeper). Tetris is a trademark of The Tetris Company, Minecraft of Mojang Synergies AB, Pac-Man of Bandai Namco and Connect Four of Hasbro.</sub>diff --git a/docs/media/numpowder.gif b/docs/media/numpowder.gifnew file mode 100644index 00000000..24429ddbBinary files /dev/null and b/docs/media/numpowder.gif differdiff --git a/docs/media/thumb_numpowder.png b/docs/media/thumb_numpowder.pngnew file mode 100644index 00000000..64dcf641Binary files /dev/null and b/docs/media/thumb_numpowder.png differdiff --git a/docs/play.md b/docs/play.mdindex 38acf3cc..24e9101d 100644--- a/docs/play.md+++ b/docs/play.md@@ -116,6 +116,29 @@ Choose Climb, then a chapter, then Start. Madeline can dash once in the air (twi<br clear="right">+## NumPowder++<img src="media/numpowder.gif" width="320" align="right" alt="NumPowder: sand, water and lava">++NumPowder comes as its own app, `NumPowder.nwa`: it is too big to share the calculator with NumPlay.++| Key | What it does |+| --- | --- |+| **Arrows** | Move the brush (**shift**: 4 at a time) |+| **OK** | Draw with the OK material |+| **Back** | Draw with the Back tool (ERASE at first) |+| **toolbox** | The materials: left and right pick, up and down change category, **OK** takes it, **shift**+**OK** for Back |+| **var** | The menu: How to play, keys, save, load, clear, display, settings, credits |+| **+** and **-** | The brush's size (**shift**: its shape) |+| **shift**+**OK** | Draw a line; **⌫** switches to a box or a fill |+| **⌫** | Take the material under the brush |+| **alpha** | Pause (**shift**+**alpha**: one frame) |+| **Home** | Save and quit |++Pick a material with **toolbox**, then hold **OK** to draw it. The bar at the bottom always shows what **OK** and **Back** draw with, and the line under it says what the keys do right now. Try sand on water, fire on wood, lava on ice, or draw metal (METL) and touch it with a spark (SPRK). How to play, in the **var** menu, has more ideas. Home saves, and four save slots keep more; they are also copied into `numpowder_saves.py`, so installing the app again doesn't erase them.++<br clear="right">+## The Final Earth 2<img src="media/finalearth2.gif" width="320" align="right" alt="The Final Earth 2: building a house on a city in free play">diff --git a/games/numpowder/.gitignore b/games/numpowder/.gitignorenew file mode 100644index 00000000..342d9dda--- /dev/null+++ b/games/numpowder/.gitignore@@ -0,0 +1,2 @@+output/+build/diff --git a/games/numpowder/Makefile b/games/numpowder/Makefilenew file mode 100644index 00000000..240f339b--- /dev/null+++ b/games/numpowder/Makefile@@ -0,0 +1,82 @@+# NumPowder: The Powder Toy on the NumWorks calculator.+# make output/numpowder.nwa+# make check link it like the calculator does (output/numpowder.bin)+# make host build/play: the game on a computer, for tests and screenshots+# make test the simulation, checked on a computer (with the sanitizers)+# make gen src/elements.h, src/elements_data.c and the font from the original's source+# (TPT=its folder, Python)+Q ?= @+# the ARM toolchain on the PATH, or in TOOLCHAIN=<its bin folder>+TOOLCHAIN ?=+BIN = $(if $(TOOLCHAIN),$(TOOLCHAIN)/)+CC = $(BIN)arm-none-eabi-gcc+NWLINK ?= npx --yes -- [email protected]+STRIP ?= $(BIN)arm-none-eabi-strip --strip-unneeded+SIZE = $(BIN)arm-none-eabi-size+BUILD_DIR = output+TPT ?=++# the simulation and the drawing run every frame at -O2; the rest is small at -Os+HOT = $(filter $(wildcard src/sim*.c src/air.c src/render*.c src/el_*.c),$(wildcard src/*.c))+COLD = $(filter-out $(HOT) src/plat_host.c src/plat_eadk.c,$(wildcard src/*.c))+COLD_OBJ = $(patsubst src/%.c,$(BUILD_DIR)/cold/%.o,$(COLD))+HEADERS = $(wildcard src/*.h) ../common/epsilon_app.h ../common/epsilon_files.h++CFLAGS = -std=gnu11 $(shell $(NWLINK) eadk-cflags-device)+CFLAGS += -O2 -Wall -Wextra -Wno-unused-parameter -fno-math-errno -fsingle-precision-constant+CFLAGS += -fno-tree-loop-distribute-patterns -flto -fno-fat-lto-objects -fwhole-program -fvisibility=internal+CFLAGS += -ffunction-sections -fdata-sections $(EXTRA)+LDFLAGS = -Wl,--relocatable -nostartfiles --specs=nano.specs+LDFLAGS += -Wl,-e,main -Wl,-u,eadk_app_name -Wl,-u,eadk_app_icon -Wl,-u,eadk_api_level+LDFLAGS += -Wl,--gc-sections -flinker-output=nolto-rel++.PHONY: build check clean host test gen+build: $(BUILD_DIR)/numpowder.nwa++# apps get 133652 bytes of RAM on custom builds of Epsilon 25.2 (148928 or more on official ones)+check: $(BUILD_DIR)/numpowder.nwa+ $(Q) $(NWLINK) nwa-bin --ram-length 133652 $< $(BUILD_DIR)/numpowder.bin+ @echo "BIN $(BUILD_DIR)/numpowder.bin: $$(wc -c < $(BUILD_DIR)/numpowder.bin) bytes"++$(BUILD_DIR)/cold/%.o: src/%.c $(HEADERS)+ @mkdir -p $(@D)+ $(Q) $(CC) $(CFLAGS) -Os -c $< -o $@++$(BUILD_DIR)/numpowder.nwa: $(HOT) src/plat_eadk.c $(COLD_OBJ) $(HEADERS) $(BUILD_DIR)/icon.o+ @echo "LD $@"+ $(Q) $(CC) $(CFLAGS) $(LDFLAGS) $(HOT) src/plat_eadk.c $(COLD_OBJ) $(BUILD_DIR)/icon.o -lm -o $@+ $(Q) $(STRIP) $@+ $(Q) $(SIZE) $@++$(BUILD_DIR)/icon.o: src/icon.png | $(BUILD_DIR)+ @echo "ICON $<"+ $(Q) $(NWLINK) png-icon-o $< $@++$(BUILD_DIR):+ $(Q) mkdir -p $@++# on a computer: tests/play.c plays it with scripted keys and saves screenshots+HOST_FLAGS = -std=gnu11 -O1 -g -Wall -Wextra -Wno-unused-parameter -Isrc -DHOST+HOST_SAN = -fsanitize=address,undefined -fno-sanitize-recover=undefined+HOST_SRC = $(filter-out src/plat_eadk.c,$(wildcard src/*.c))+host: build/play+build/play: $(HOST_SRC) tests/play.c $(HEADERS)+ $(Q) mkdir -p $(dir $@)+ $(Q) cc $(HOST_FLAGS) $(HOST_SAN) $(HOST_SRC) tests/play.c -lm -o $@+ @echo "HOST $@"++# the simulation without the interface (tests/simtest.c)+TEST_SRC = $(filter-out src/plat_eadk.c src/main.c $(wildcard src/ui*.c),$(wildcard src/*.c))+test: build/simtest+ $(Q) ./build/simtest+build/simtest: $(TEST_SRC) tests/simtest.c $(HEADERS)+ $(Q) mkdir -p $(dir $@)+ $(Q) cc $(HOST_FLAGS) $(HOST_SAN) $(TEST_SRC) tests/simtest.c -lm -o $@++gen:+ @test -n "$(TPT)" || { echo "make gen TPT=<the folder of The Powder Toy's source>"; exit 1; }+ python3 -I tools/gen_elements.py $(TPT)+ python3 -I tools/gen_font.py $(TPT)++clean:+ $(Q) rm -rf $(BUILD_DIR) builddiff --git a/games/numpowder/README.md b/games/numpowder/README.mdnew file mode 100644index 00000000..e5fc3a4b--- /dev/null+++ b/games/numpowder/README.md@@ -0,0 +1,89 @@+> **NumPowder is a [NumPlay](../../README.md) game that comes on its own.** It is too big to fit next to NumPlay on the calculator. Get `NumPowder.nwa` from the [latest release](https://github.com/Mason363/NumPlay/releases/latest).++<p align="center">+ <img src="src/icon.png" width="84" alt="The NumPowder icon">+</p>++<h1 align="center">NumPowder</h1>++<p align="center">+ <b>The Powder Toy on the NumWorks calculator.</b><br>+ Sand, water, fire, acid, electricity and 175 materials to mix, melt, burn and blow up.+</p>++<p align="center">+ <a href="https://github.com/Mason363/NumPlay/releases/latest/download/NumPowder.nwa"><b>Download NumPowder.nwa</b></a>+ · <a href="#controls">Controls</a>+</p>++<p align="center">+ <img src="../../docs/media/numpowder.gif" width="640" alt="NumPowder: sand poured on a metal shelf, then water, then lava that melts the ice and boils the water">+</p>++## Highlights++* **The Powder Toy's materials:** 175 of them, from sand, water and wood to metal, silicon, acid, lava, nitroglycerin, plutonium, clone, black holes and the Game of Life, each with its behaviour from the original's code.+* **Things react:** sand sinks in water, fire burns wood, lava melts ice and boils water, acid eats through most things.+* **Heat and air:** everything has a temperature, so things melt, boil and freeze; explosions push the air around them.+* **Electricity:** sparks run along metal, silicon makes switches and logic, batteries keep things powered.+* **Walls, tools and views:** 17 kinds of walls, tools to heat, cool and push air, and the original's display modes, from fire to heat and pressure.+* **Keep your creations:** four save slots and an autosave when you press Home, copied into `numpowder_saves.py` so installing the app again doesn't erase them.++<table>+ <tr>+ <td align="center"><img src="docs/welcome.png" width="390" alt="The welcome card"><br><sub>The welcome card shows the four keys you need</sub></td>+ <td align="center"><img src="docs/menu.png" width="390" alt="The material menu"><br><sub>toolbox opens the materials, by category</sub></td>+ </tr>+ <tr>+ <td align="center"><img src="docs/sand_water.png" width="390" alt="Sand and water"><br><sub>Sand piles up and water flows around it</sub></td>+ <td align="center"><img src="docs/lava.png" width="390" alt="Lava boiling water into steam"><br><sub>Lava melts the ice and boils the water</sub></td>+ </tr>+ <tr>+ <td align="center"><img src="docs/electricity.png" width="390" alt="Sparks running along metal"><br><sub>A battery sends sparks along metal</sub></td>+ <td align="center"><img src="docs/explosion.png" width="390" alt="C-4 exploding under stone"><br><sub>C-4 throws the stone around</sub></td>+ </tr>+ <tr>+ <td align="center"><img src="docs/heat.png" width="390" alt="The heat display"><br><sub>The heat display shows every temperature</sub></td>+ <td align="center"><img src="docs/help.png" width="390" alt="A How to play page"><br><sub>How to play, in the menu</sub></td>+ </tr>+</table>++## How to play++Pick a material and draw with it. Press **toolbox** to open the materials: left and right pick one, up and down change the category, and **OK** takes it. Then move the brush with the arrows and hold **OK** to draw, or **Back** to erase. The bar at the bottom always shows what **OK** and **Back** draw with, and the line under it says what the keys do right now.++Try things together: sand on water, fire on wood, lava on ice, acid on anything. For electricity, draw metal (METL), then touch it with a spark (SPRK). **How to play**, in the menu (**var**), has more ideas.++## Controls++| Key | What it does |+| --- | --- |+| Arrows | Move the brush (shift: 4 at a time) |+| OK | Draw with the OK material |+| Back | Draw with the Back tool (ERASE at first) |+| toolbox | The materials: left and right pick, up and down change category, OK takes it, shift+OK for Back |+| var | The menu: How to play, keys, save, load, clear, display, settings, credits |+| + and - | The brush's size (shift: its shape) |+| shift+OK | Draw a line, a box (⌫) or fill |+| ⌫ | Take the material under the brush |+| alpha | Pause (shift+alpha: one frame) |+| Home | Save and quit |++## Good to know++* **On its own:** NumPowder is too big to fit next to NumPlay. Installing it from the NumWorks website swaps out NumPlay and the other apps, and installing NumPlay again swaps it back out. Your saves in each one are kept.+* **A smaller world:** the play area is 100 by 64 particles, each 3 pixels wide, and holds up to about 4,400 particles at once (about 3,600 on custom builds of the calculator's software, which give apps less memory).+* **The edges are solid:** things stop at the screen's edges. In Settings, Edges can make them fall out instead, as in the original, or come back on the other side.+* **Left out:** decorations (painting colours over particles), signs, and custom Game of Life rules. There is no sound.++## Credits++Inspired by [The Powder Toy](https://powdertoy.co.uk), not affiliated with its developers.++* The materials' behaviour, the font and the icons are ported from [The Powder Toy's source code](https://github.com/The-Powder-Toy/The-Powder-Toy) (GNU General Public License v3.0), by Stanislaw K Skowronek, Simon Robertshaw and its many contributors.++Made by Mason Chen as part of NumPlay.++## License++NumPowder's code is licensed under the GNU General Public License v3.0, like The Powder Toy it is ported from: see the `LICENSE` file at the root of the repository.diff --git a/games/numpowder/docs/electricity.png b/games/numpowder/docs/electricity.pngnew file mode 100644index 00000000..25bceb64Binary files /dev/null and b/games/numpowder/docs/electricity.png differdiff --git a/games/numpowder/docs/explosion.png b/games/numpowder/docs/explosion.pngnew file mode 100644index 00000000..7e6eea52Binary files /dev/null and b/games/numpowder/docs/explosion.png differdiff --git a/games/numpowder/docs/heat.png b/games/numpowder/docs/heat.pngnew file mode 100644index 00000000..776c3870Binary files /dev/null and b/games/numpowder/docs/heat.png differdiff --git a/games/numpowder/docs/help.png b/games/numpowder/docs/help.pngnew file mode 100644index 00000000..9d8810d4Binary files /dev/null and b/games/numpowder/docs/help.png differdiff --git a/games/numpowder/docs/lava.png b/games/numpowder/docs/lava.pngnew file mode 100644index 00000000..b3ce7f1cBinary files /dev/null and b/games/numpowder/docs/lava.png differdiff --git a/games/numpowder/docs/menu.png b/games/numpowder/docs/menu.pngnew file mode 100644index 00000000..3800dcbfBinary files /dev/null and b/games/numpowder/docs/menu.png differdiff --git a/games/numpowder/docs/sand_water.png b/games/numpowder/docs/sand_water.pngnew file mode 100644index 00000000..517fc747Binary files /dev/null and b/games/numpowder/docs/sand_water.png differdiff --git a/games/numpowder/docs/welcome.png b/games/numpowder/docs/welcome.pngnew file mode 100644index 00000000..a5064bb4Binary files /dev/null and b/games/numpowder/docs/welcome.png differdiff --git a/games/numpowder/src/air.c b/games/numpowder/src/air.cnew file mode 100644index 00000000..be850795--- /dev/null+++ b/games/numpowder/src/air.c@@ -0,0 +1,370 @@+/* NumPowder: The Powder Toy's air (Air.cpp): pressure and velocity, ambient heat, the edges, walls blocking air+ * and fans. Air cells are ACELL particles wide, as the original's; a wall cell is WCELL, so an air cell is+ * blocked when any of its wall cells blocks (and has a fan when any of them is one). */+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("O3") /* (a hot path: a few KB of flash for speed) */+#endif+#include "simpriv.h"++float pv[YACELLS][XACELLS], vx[YACELLS][XACELLS], vy[YACELLS][XACELLS], hv[YACELLS][XACELLS];+uint8_t bmap_blockair[YACELLS][XACELLS], bmap_blockairh[YACELLS][XACELLS];+float ambientAirTemp = R_TEMP + 273.15f, edgePressure, edgeVelocityX, edgeVelocityY, vorticityCoeff = 0.1f;+int airMode = AIR_ON, convectionMode = AIRC_BOUSSINESQ;+static float kernel[9];++#define WPA (ACELL / WCELL) /* wall cells across an air cell */++void air_make_kernel(void) { /* used for velocity */+ float s = 0.0f;+ for (int j = -1; j < 2; j++)+ for (int i = -1; i < 2; i++) {+ kernel[(i + 1) + 3 * (j + 1)] = expf(-2.0f * (i * i + j * j));+ s += kernel[(i + 1) + 3 * (j + 1)];+ }+ s = 1.0f / s;+ for (int j = -1; j < 2; j++)+ for (int i = -1; i < 2; i++) kernel[(i + 1) + 3 * (j + 1)] *= s;+}++/* vorticity that takes bmap_blockair into account (old velocities: ovx, ovy) */+static float vorticityBmap(float (*ovx)[XACELLS], float (*ovy)[XACELLS], int y, int x) {+ if (x > 1 && x < XACELLS - 2 && y > 1 && y < YACELLS - 2) {+ float dvydx = (bmap_blockair[y][x] || bmap_blockair[y][x + 1] || bmap_blockair[y][x - 1]) ? 0.0f : ovy[y][x + 1] - ovy[y][x - 1];+ float dvxdy = (bmap_blockair[y][x] || bmap_blockair[y + 1][x] || bmap_blockair[y - 1][x]) ? 0.0f : ovx[y + 1][x] - ovx[y - 1][x];+ return (dvydx - dvxdy) * 0.5f;+ }+ return 0.0f;+}++void air_clear(void) {+ for (int y = 0; y < YACELLS; y++)+ for (int x = 0; x < XACELLS; x++) pv[y][x] = edgePressure, vx[y][x] = edgeVelocityX, vy[y][x] = edgeVelocityY;+}+void air_clear_heat(void) {+ for (int y = 0; y < YACELLS; y++)+ for (int x = 0; x < XACELLS; x++) hv[y][x] = ambientAirTemp;+}+void air_invert(void) {+ for (int y = 0; y < YACELLS; y++)+ for (int x = 0; x < XACELLS; x++) pv[y][x] = -pv[y][x], vx[y][x] = -vx[y][x], vy[y][x] = -vy[y][x];+}++static inline bool InCellBounds(int x, int y) { return x >= 0 && y >= 0 && x < XACELLS && y < YACELLS; }+static const float advDistanceMult = 0.7f; /* when taking temperature or velocity from far away */++void air_update_heat(void) {+ float (*ohv)[XACELLS] = (float (*)[XACELLS])(void *)sim_scratch;+ for (int i = 0; i < YACELLS; i++) /* the edges' air temperature, every frame */+ hv[i][0] = hv[i][1] = hv[i][XACELLS - 2] = hv[i][XACELLS - 1] = ambientAirTemp;+ for (int i = 0; i < XACELLS; i++)+ hv[0][i] = hv[1][i] = hv[YACELLS - 2][i] = hv[YACELLS - 1][i] = ambientAirTemp;+ for (int y = 0; y < YACELLS; y++)+ for (int x = 0; x < XACELLS; x++) {+ float dh = 0.0f, dx = 0.0f, dy = 0.0f;+ for (int j = -1; j <= 1; j++)+ for (int i = -1; i <= 1; i++) {+ float f = kernel[i + 1 + (j + 1) * 3];+ if (y + j > 0 && y + j < YACELLS - 1 && x + i > 0 && x + i < XACELLS - 1 && !(bmap_blockairh[y + j][x + i] & 0x8)) {+ dh += hv[y + j][x + i] * f;+ dx += vx[y + j][x + i] * f;+ dy += vy[y + j][x + i] * f;+ } else {+ dh += hv[y][x] * f;+ dx += vx[y][x] * f;+ dy += vy[y][x] * f;+ }+ }+ /* air temperature from far away, as the velocity in air_update */+ float tx = x - dx * advDistanceMult, ty = y - dy * advDistanceMult;+ if ((fabsf(dx * advDistanceMult) > 1.0f || fabsf(dy * advDistanceMult) > 1.0f) && (tx >= 2 && tx < XACELLS - 2 && ty >= 2 && ty < YACELLS - 2)) {+ float stepX, stepY;+ int stepLimit;+ if (fabsf(dx) > fabsf(dy)) {+ stepX = (dx < 0.0f) ? 1.f : -1.f;+ stepY = -dy / fabsf(dx);+ stepLimit = (int)(fabsf(dx * advDistanceMult));+ } else {+ stepY = (dy < 0.0f) ? 1.f : -1.f;+ stepX = -dx / fabsf(dy);+ stepLimit = (int)(fabsf(dy * advDistanceMult));+ }+ tx = (float)x;+ ty = (float)y;+ int step = 0;+ for (; step < stepLimit; ++step) {+ tx += stepX;+ ty += stepY;+ if (!InCellBounds((int)(tx + 0.5f), (int)(ty + 0.5f)) || bmap_blockairh[(int)(ty + 0.5f)][(int)(tx + 0.5f)] & 0x8) {+ tx -= stepX;+ ty -= stepY;+ break;+ }+ }+ if (step == stepLimit) { /* no wall found */+ tx = x - dx * advDistanceMult;+ ty = y - dy * advDistanceMult;+ }+ }+ int i = (int)tx, j = (int)ty;+ tx -= i;+ ty -= j;+ if (!(bmap_blockairh[y][x] & 0x8) && i >= 0 && i < XACELLS - 1 && j >= 0 && j < YACELLS - 1 && tx >= 0.0f && ty >= 0.0f) {+ float odh = dh;+ dh *= 1.0f - AIR_VADV;+ dh += AIR_VADV * (1.0f - tx) * (1.0f - ty) * ((bmap_blockairh[j][i] & 0x8) ? odh : hv[j][i]);+ dh += AIR_VADV * tx * (1.0f - ty) * ((bmap_blockairh[j][i + 1] & 0x8) ? odh : hv[j][i + 1]);+ dh += AIR_VADV * (1.0f - tx) * ty * ((bmap_blockairh[j + 1][i] & 0x8) ? odh : hv[j + 1][i]);+ dh += AIR_VADV * tx * ty * ((bmap_blockairh[j + 1][i + 1] & 0x8) ? odh : hv[j + 1][i + 1]);+ }+ if (bmap_blockairh[y][x] & 0x8) dh = hv[y][x]; /* a cell that blocks ambient heat doesn't change */+ if (dh > MAX_TEMP) dh = MAX_TEMP;+ if (dh < MIN_TEMP) dh = MIN_TEMP;+ ohv[y][x] = dh;++ /* air convection (the velocities change in place, as in the original) */+ float dvx = vx[y][x], dvy = vy[y][x];+ if (x >= 2 && x < XACELLS - 2 && y >= 2 && y < YACELLS - 2) {+ float convGravX, convGravY;+ GetGravityField(x * ACELL, y * ACELL, -1.0f, -1.0f, &convGravX, &convGravY);+ switch (convectionMode) {+ case AIRC_LEGACY: { /* before 99.0 */+ float weight = ((hv[y][x] - hv[y][x - 1]) * convGravX + (hv[y][x] - hv[y - 1][x]) * convGravY) / 5000.0f;+ if (weight > 0 && !(bmap_blockairh[y - 1][x] & 0x8)) {+ dvx += weight * convGravX;+ dvy += weight * convGravY;+ }+ break;+ }+ case AIRC_BOUSSINESQ: {+ /* density changes only in the gravity term, linearly with the difference to the ambient temperature */+ float gravMagn = sqrtf(convGravX * convGravX + convGravY * convGravY);+ if (gravMagn > 10.0f) { /* cap the gravity field */+ convGravX /= 0.1f * gravMagn;+ convGravY /= 0.1f * gravMagn;+ }+ float weight = (hv[y][x] - ambientAirTemp) / 10000.0f;+ if (weight > 0.01f) weight = 0.01f; /* best when the difference is small */+ dvx += weight * convGravX;+ dvy += weight * convGravY;+ break;+ }+ default:+ break;+ }+ }+ if (dvx > MAX_PRESSURE) dvx = MAX_PRESSURE;+ if (dvx < MIN_PRESSURE) dvx = MIN_PRESSURE;+ if (dvy > MAX_PRESSURE) dvy = MAX_PRESSURE;+ if (dvy < MIN_PRESSURE) dvy = MIN_PRESSURE;+ vx[y][x] = dvx;+ vy[y][x] = dvy;+ }+ memcpy(hv, ohv, sizeof hv);+}++static inline float Mix(float a, float b, float f) { return a + (b - a) * f; }++static bool fan_at(int y, int x) {+ for (int j = 0; j < WPA; j++)+ for (int i = 0; i < WPA; i++)+ if (bmap[y * WPA + j][x * WPA + i] == WL_FAN) return true;+ return false;+}++void air_update(void) {+ if (airMode == AIR_NOUPDATE) return;+ for (int i = 0; i < YACELLS; i++) { /* pressure and velocity fade on the edges every frame */+ pv[i][0] = Mix(edgePressure, pv[i][0], 0.8f);+ pv[i][1] = Mix(edgePressure, pv[i][1], 0.8f);+ pv[i][XACELLS - 2] = Mix(edgePressure, pv[i][XACELLS - 2], 0.8f);+ pv[i][XACELLS - 1] = Mix(edgePressure, pv[i][XACELLS - 1], 0.8f);+ vx[i][0] = Mix(edgeVelocityX, vx[i][0], 0.9f);+ vx[i][1] = Mix(edgeVelocityX, vx[i][1], 0.9f);+ vx[i][XACELLS - 2] = Mix(edgeVelocityX, vx[i][XACELLS - 2], 0.9f);+ vx[i][XACELLS - 1] = Mix(edgeVelocityX, vx[i][XACELLS - 1], 0.9f);+ vy[i][0] = Mix(edgeVelocityY, vy[i][0], 0.9f);+ vy[i][1] = Mix(edgeVelocityY, vy[i][1], 0.9f);+ vy[i][XACELLS - 2] = Mix(edgeVelocityY, vy[i][XACELLS - 2], 0.9f);+ vy[i][XACELLS - 1] = Mix(edgeVelocityY, vy[i][XACELLS - 1], 0.9f);+ }+ for (int i = 0; i < XACELLS; i++) {+ pv[0][i] = Mix(edgePressure, pv[0][i], 0.8f);+ pv[1][i] = Mix(edgePressure, pv[1][i], 0.8f);+ pv[YACELLS - 2][i] = Mix(edgePressure, pv[YACELLS - 2][i], 0.8f);+ pv[YACELLS - 1][i] = Mix(edgePressure, pv[YACELLS - 1][i], 0.8f);+ vx[0][i] = Mix(edgeVelocityX, vx[0][i], 0.9f);+ vx[1][i] = Mix(edgeVelocityX, vx[1][i], 0.9f);+ vx[YACELLS - 2][i] = Mix(edgeVelocityX, vx[YACELLS - 2][i], 0.9f);+ vx[YACELLS - 1][i] = Mix(edgeVelocityX, vx[YACELLS - 1][i], 0.9f);+ vy[0][i] = Mix(edgeVelocityY, vy[0][i], 0.9f);+ vy[1][i] = Mix(edgeVelocityY, vy[1][i], 0.9f);+ vy[YACELLS - 2][i] = Mix(edgeVelocityY, vy[YACELLS - 2][i], 0.9f);+ vy[YACELLS - 1][i] = Mix(edgeVelocityY, vy[YACELLS - 1][i], 0.9f);+ }+ for (int j = 1; j < YACELLS - 1; j++) /* no velocity near walls */+ for (int i = 1; i < XACELLS - 1; i++)+ if (bmap_blockair[j][i]) {+ vx[j][i] = vx[j][i - 1] = vx[j][i + 1] = 0.0f;+ vy[j][i] = vy[j - 1][i] = vy[j + 1][i] = 0.0f;+ }+ for (int y = 1; y < YACELLS - 1; y++) /* pressure from velocity */+ for (int x = 1; x < XACELLS - 1; x++) {+ float dp = 0.0f;+ dp += vx[y][x - 1] - vx[y][x + 1];+ dp += vy[y - 1][x] - vy[y + 1][x];+ pv[y][x] = Mix(edgePressure, pv[y][x], AIR_PLOSS);+ pv[y][x] += dp * AIR_TSTEPP * 0.5f;+ }+ for (int y = 1; y < YACELLS - 1; y++) /* velocity from pressure */+ for (int x = 1; x < XACELLS - 1; x++) {+ float dx = 0.0f, dy = 0.0f;+ dx += pv[y][x - 1] - pv[y][x + 1];+ dy += pv[y - 1][x] - pv[y + 1][x];+ vx[y][x] = Mix(edgeVelocityX, vx[y][x], AIR_VLOSS);+ vy[y][x] = Mix(edgeVelocityY, vy[y][x], AIR_VLOSS);+ vx[y][x] += dx * AIR_TSTEPV * 0.5f;+ vy[y][x] += dy * AIR_TSTEPV * 0.5f;+ if (bmap_blockair[y][x - 1] || bmap_blockair[y][x] || bmap_blockair[y][x + 1]) vx[y][x] = 0;+ if (bmap_blockair[y - 1][x] || bmap_blockair[y][x] || bmap_blockair[y + 1][x]) vy[y][x] = 0;+ }++ /* velocity and pressure: the next values of vx and vy go to the scratch RAM, those of pv to two rows there+ * (a row is written back once the next one no longer reads it) */+ float (*ovx)[XACELLS] = (float (*)[XACELLS])(void *)sim_scratch;+ float (*ovy)[XACELLS] = ovx + YACELLS;+ float (*opv)[XACELLS] = ovy + YACELLS; /* 2 rows */+ for (int y = 0; y < YACELLS; y++) {+ float *prow = opv[y & 1];+ for (int x = 0; x < XACELLS; x++) {+ float dx = 0.0f, dy = 0.0f, dp = 0.0f;+ for (int j = -1; j < 2; j++)+ for (int i = -1; i < 2; i++) {+ float f = kernel[i + 1 + (j + 1) * 3];+ if (y + j > 0 && y + j < YACELLS - 1 && x + i > 0 && x + i < XACELLS - 1 && !bmap_blockair[y + j][x + i]) {+ dx += vx[y + j][x + i] * f;+ dy += vy[y + j][x + i] * f;+ dp += pv[y + j][x + i] * f;+ } else {+ dx += vx[y][x] * f;+ dy += vy[y][x] * f;+ dp += pv[y][x] * f;+ }+ }+ float tx = x - dx * advDistanceMult, ty = y - dy * advDistanceMult;+ if ((fabsf(dx * advDistanceMult) > 1.0f || fabsf(dy * advDistanceMult) > 1.0f) && (tx >= 2 && tx < XACELLS - 2 && ty >= 2 && ty < YACELLS - 2)) {+ /* velocity from far away: look for a wall in the way, stepping a cell at a time along x or y */+ float stepX, stepY;+ int stepLimit;+ if (fabsf(dx) > fabsf(dy)) {+ stepX = (dx < 0.0f) ? 1.f : -1.f;+ stepY = -dy / fabsf(dx);+ stepLimit = (int)(fabsf(dx * advDistanceMult));+ } else {+ stepY = (dy < 0.0f) ? 1.f : -1.f;+ stepX = -dx / fabsf(dy);+ stepLimit = (int)(fabsf(dy * advDistanceMult));+ }+ tx = (float)x;+ ty = (float)y;+ int step = 0;+ for (; step < stepLimit; ++step) {+ tx += stepX;+ ty += stepY;+ if (!InCellBounds((int)(tx + 0.5f), (int)(ty + 0.5f)) || bmap_blockair[(int)(ty + 0.5f)][(int)(tx + 0.5f)]) {+ tx -= stepX;+ ty -= stepY;+ break;+ }+ }+ if (step == stepLimit) { /* no wall found */+ tx = x - dx * advDistanceMult;+ ty = y - dy * advDistanceMult;+ }+ }+ int i = (int)tx, j = (int)ty;+ tx -= i;+ ty -= j;+ if (!bmap_blockair[y][x] && i >= 2 && i < XACELLS - 3 && j >= 2 && j < YACELLS - 3 && tx >= 0.0f && ty >= 0.0f) {+ dx *= 1.0f - AIR_VADV;+ dy *= 1.0f - AIR_VADV;+ dx += AIR_VADV * (1.0f - tx) * (1.0f - ty) * vx[j][i];+ dy += AIR_VADV * (1.0f - tx) * (1.0f - ty) * vy[j][i];+ dx += AIR_VADV * tx * (1.0f - ty) * vx[j][i + 1];+ dy += AIR_VADV * tx * (1.0f - ty) * vy[j][i + 1];+ dx += AIR_VADV * (1.0f - tx) * ty * vx[j + 1][i];+ dy += AIR_VADV * (1.0f - tx) * ty * vy[j + 1][i];+ dx += AIR_VADV * tx * ty * vx[j + 1][i + 1];+ dy += AIR_VADV * tx * ty * vy[j + 1][i + 1];+ }+ /* vorticity confinement */+ if (vorticityCoeff > 0.0f && x > 1 && x < XACELLS - 2 && y > 1 && y < YACELLS - 2) {+ float dwx = (fabsf(vorticityBmap(vx, vy, y, x + 1)) - fabsf(vorticityBmap(vx, vy, y, x - 1))) * 0.5f;+ float dwy = (fabsf(vorticityBmap(vx, vy, y + 1, x)) - fabsf(vorticityBmap(vx, vy, y - 1, x))) * 0.5f;+ float norm = hypotf(dwx, dwy);+ float w = vorticityBmap(vx, vy, y, x);+ dx += vorticityCoeff / 5.0f * dwy / (norm + 0.001f) * w;+ dy += vorticityCoeff / 5.0f * (-dwx) / (norm + 0.001f) * w;+ }+ if (fan_at(y, x)) {+ dx += fvx[y][x];+ dy += fvy[y][x];+ }+ if (dp > MAX_PRESSURE) dp = MAX_PRESSURE;+ if (dp < MIN_PRESSURE) dp = MIN_PRESSURE;+ if (dx > MAX_PRESSURE) dx = MAX_PRESSURE;+ if (dx < MIN_PRESSURE) dx = MIN_PRESSURE;+ if (dy > MAX_PRESSURE) dy = MAX_PRESSURE;+ if (dy < MIN_PRESSURE) dy = MIN_PRESSURE;+ switch (airMode) {+ default:+ case AIR_ON: break;+ case AIR_PRESSUREOFF: dp = 0.0f; break;+ case AIR_VELOCITYOFF: dx = 0.0f, dy = 0.0f; break;+ case AIR_OFF: dx = 0.0f, dy = 0.0f, dp = 0.0f; break;+ case AIR_NOUPDATE: break;+ }+ ovx[y][x] = dx;+ ovy[y][x] = dy;+ prow[x] = dp;+ }+ if (y > 0) memcpy(pv[y - 1], opv[(y - 1) & 1], sizeof pv[0]);+ }+ memcpy(pv[YACELLS - 1], opv[(YACELLS - 1) & 1], sizeof pv[0]);+ memcpy(vx, ovx, sizeof vx);+ memcpy(vy, ovy, sizeof vy);+}++/* walls block air and ambient heat (BeforeSim, after the walls' electricity faded) */+void air_walls_block(void) {+ for (int y = 0; y < YACELLS; y++)+ for (int x = 0; x < XACELLS; x++) {+ uint8_t block = 0, grav = 0;+ for (int j = 0; j < WPA; j++)+ for (int i = 0; i < WPA; i++) {+ int b = bmap[y * WPA + j][x * WPA + i];+ block |= b == WL_WALL || b == WL_WALLELEC || b == WL_BLOCKAIR || (b == WL_EWALL && !emap[y * WPA + j][x * WPA + i]);+ grav |= b == WL_GRAV;+ }+ bmap_blockair[y][x] = block;+ bmap_blockairh[y][x] = (block || grav) ? 0x8 : 0;+ }+}++/* after loading a save, so that nothing "leaks" the first frame (ApproximateBlockAirMaps) */+void air_approximate_block_maps(void) {+ air_walls_block();+ for (int i = 0; i < parts_active; i++) {+ int type = parts[i].type;+ if (!type) continue;+ int x = ((parts[i].x + 32) / 64) / ACELL, y = ((parts[i].y + 32) / 64) / ACELL;+ if (!InCellBounds(x, y)) continue;+ /* real TTAN only blocks when there's enough, but blocking for a frame is fine */+ if (type == PT_TTAN || type == PT_RSSS) {+ bmap_blockair[y][x] = 1;+ bmap_blockairh[y][x] = 0x8;+ } else if (IsHeatInsulator(&parts[i]) || elements[type].HeatConduct <= (rng_u32() % 250)) {+ /* mostly accurate insulators (but GEL) */+ if (!(bmap_blockairh[y][x] & 0x8)) bmap_blockairh[y][x]++;+ }+ }+}diff --git a/games/numpowder/src/canmove_data.c b/games/numpowder/src/canmove_data.cnew file mode 100644index 00000000..3b2b2ef2--- /dev/null+++ b/games/numpowder/src/canmove_data.c@@ -0,0 +1,201 @@+/* NumPowder: The Powder Toy's can_move table (SimulationData::init_can_move), 2 bits a pair (generated by+ * tools/gen_elements.py: do not edit). can_move[moving][destination]: 0 bounce, 1 swap, 2 same place, 3 varies */+#include "simpriv.h"++const uint8_t can_move_table[PT_COUNT][CANMOVE_STRIDE] = {+ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x41,0x01,0x11,0x00,0x10,0x74,0x00,0x40,0x10,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x41,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x01,0x01,0x10,0x00,0x10,0x74,0x00,0x40,0x00,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x01,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x01,0x00,0x10,0x00,0x10,0x70,0x00,0x40,0x00,0x40,0x00,0x00,0x05,0x01,0x04,0x04,0x00,0x00,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x01,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x10,0x00,0x00,0x00},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x51,0x01,0x11,0x00,0x10,0x74,0x44,0x40,0x10,0x44,0x00,0x00,0x05,0x01,0x14,0x05,0x10,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x44,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x40,0x05,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x51,0x00,0x50,0x14},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x41,0x01,0x10,0x00,0x10,0x74,0x00,0x40,0x00,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x01,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x41,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x41,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},+ {0x51,0x11,0x11,0x00,0x10,0x74,0x44,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x05,0x10,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x44,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x41,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0xA1,0x00,0x60,0x09,0xA6,0x31,0x48,0x80,0x00,0x40,0x00,0x88,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x03,0x00,0x80,0x00,0x00,0x40,0x00,0x80,0x00,0x00,0x00,0x10,0x00,0x42,0x11,0x08,0x45,0x00,0x00,0x00,0x05,0x08,0x02,0x22,0x0A,0x00,0x80,0x22},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x41,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x01,0x10,0x00,0x10,0x70,0x00,0x40,0x00,0x40,0x00,0x00,0x05,0x01,0x04,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x01,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x10,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x44,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x05,0x10,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x41,0x01,0x11,0x00,0x10,0x74,0x00,0x40,0x10,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x41,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x44,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x05,0x10,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x51,0x01,0x11,0x00,0x00,0x74,0x04,0x40,0x10,0x44,0x00,0x00,0x05,0x01,0x14,0x05,0x00,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x44,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x40,0x04,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x51,0x00,0x50,0x04},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x21,0x00,0x08,0x00,0x20,0x30,0x88,0x80,0x00,0x40,0x00,0x88,0x00,0x30,0x00,0x00,0x20,0x00,0x20,0x00,0x00,0x03,0x00,0x08,0x00,0x80,0x8A,0x02,0x80,0x00,0x00,0x08,0x20,0x0A,0x02,0x00,0x80,0x04,0x0E,0x00,0x00,0x05,0x00,0x02,0x02,0x00,0x00,0x80,0x00},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x41,0x01,0x11,0x00,0x10,0x74,0x00,0x40,0x00,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x41,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x41,0x01,0x11,0x00,0x10,0x74,0x00,0x40,0x10,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x41,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x51,0x01,0x11,0x00,0x10,0x74,0x44,0x40,0x10,0x44,0x00,0x00,0x05,0x01,0x14,0x05,0x10,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x44,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x40,0x05,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x51,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0xA2,0x22,0x22,0x00,0x00,0xB8,0x88,0x00,0x20,0x48,0x20,0x00,0x08,0x02,0x28,0x0A,0x20,0x02,0x02,0x08,0x22,0x23,0x00,0x82,0x02,0x88,0x82,0xA0,0xC0,0x28,0x00,0x00,0x00,0x00,0x00,0x28,0x88,0x86,0x00,0x00,0x00,0x00,0x00,0x88,0x00,0xA0,0x00,0x80,0x08},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x01,0x01,0x10,0x00,0x10,0x74,0x00,0x40,0x00,0x40,0x00,0x00,0x05,0x01,0x04,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x01,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x50,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x41,0x01,0x11,0x00,0x10,0x74,0x00,0x40,0x10,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x41,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x05,0x10,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x05,0x10,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x51,0x01,0x11,0x00,0x10,0x74,0x44,0x40,0x10,0x44,0x00,0x00,0x05,0x01,0x14,0x05,0x00,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x44,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x40,0x05,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x51,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x00,0x10,0x00,0x10,0x70,0x00,0x40,0x00,0x40,0x00,0x00,0x05,0x01,0x04,0x04,0x00,0x00,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x01,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x10,0x00,0x00,0x00},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x44,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x05,0x10,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x44,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x05,0x10,0x05,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x41,0x01,0x11,0x00,0x00,0x74,0x00,0x40,0x10,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x41,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x51,0x55,0x55,0x75,0x54,0x54,0x55,0x55,0x55,0x55,0x55,0x15,0x55,0x55,0x55,0x55,0x45,0x55,0x55,0x57,0x51,0x51,0x55,0x55,0x55,0x55,0xD5,0x55,0x55,0x55,0x54,0x55,0x55,0x45,0x45,0x55,0x54,0x51,0x55,0x55,0x55,0x55,0x55,0x54,0x55,0x51,0x15},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x51,0x01,0x11,0x00,0x10,0x74,0x04,0x40,0x10,0x44,0x00,0x00,0x05,0x01,0x14,0x05,0x00,0x01,0x00,0x04,0x11,0x13,0x00,0x01,0x01,0x44,0x41,0x00,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x40,0x04,0x00,0x01,0x10,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x54,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x51,0x11,0x11,0x00,0x10,0x74,0x44,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x05,0x10,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x44,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x41,0x01,0x11,0x00,0x10,0x74,0x00,0x40,0x10,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x41,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x41,0x01,0x11,0x00,0x10,0x74,0x00,0x40,0x10,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x41,0x00,0xC0,0x00,0x00,0x08,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x08,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x41,0x01,0x11,0x00,0x00,0x74,0x00,0x40,0x00,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x01,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x51,0x01,0x11,0x00,0x10,0x74,0x04,0x40,0x10,0x44,0x00,0x00,0x05,0x01,0x14,0x05,0x00,0x01,0x00,0x04,0x11,0x13,0x00,0x01,0x01,0x44,0x41,0x00,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x40,0x04,0x00,0x01,0x10,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x11,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x15,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0xA2,0x22,0x22,0x00,0x00,0xB8,0x88,0x00,0x20,0x48,0x20,0x00,0x08,0x02,0x28,0x0A,0x20,0x02,0x02,0x08,0x22,0x23,0x00,0x82,0x02,0x88,0x82,0xA0,0xC0,0x28,0x00,0x00,0x00,0x00,0x00,0x28,0x88,0x86,0x00,0x00,0x00,0x00,0x00,0x88,0x00,0xA0,0x00,0x80,0x08},+ {0x41,0x01,0x11,0x00,0x10,0x74,0x00,0x40,0x10,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x41,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x50,0x00,0x10,0x04},+ {0x55,0x55,0x11,0x00,0x41,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x20,0x30,0x00,0x80,0x00,0x40,0x00,0x00,0x00,0x20,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x03,0x00,0x40,0x00,0x80,0x0A,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x08,0x04,0x00,0x00,0x00,0x05,0x00,0x02,0x02,0x00,0x00,0x80,0x02},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x41,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x41,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x51,0x01,0x11,0x00,0x00,0x74,0x04,0x40,0x10,0x44,0x00,0x00,0x05,0x01,0x14,0x05,0x00,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x44,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x40,0x04,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x51,0x00,0x50,0x04},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x17,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x51,0x11,0x11,0x00,0x10,0x74,0x44,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x05,0x10,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x44,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x40,0x05,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x51,0x00,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x51,0x01,0x11,0x00,0x00,0x74,0x04,0x40,0x10,0x44,0x00,0x00,0x05,0x01,0x14,0x05,0x00,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x44,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x40,0x04,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x51,0x00,0x50,0x04},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x44,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x05,0x10,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x41,0x01,0x11,0x00,0x10,0x74,0x00,0x40,0x10,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x41,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x50,0x00,0x10,0x04},+ {0xA2,0x22,0x22,0x00,0x00,0xB8,0x88,0x00,0x20,0x48,0x20,0x00,0x08,0x02,0x28,0x0A,0x20,0x02,0x02,0x08,0x22,0x23,0x00,0x82,0x02,0x88,0x82,0xA0,0xC0,0x28,0x00,0x00,0x00,0x00,0x00,0x28,0x88,0x86,0x00,0x00,0x00,0x00,0x00,0x88,0x00,0xA0,0x00,0x80,0x08},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x41,0x01,0x11,0x00,0x10,0x74,0x00,0x40,0x10,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x41,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x50,0x00,0x10,0x04},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x51,0x11,0x11,0x00,0x11,0x74,0x44,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x05,0x10,0x05,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x45,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x00,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0xAA,0xAA,0xAA,0xAA,0xAA,0xBA,0xAA,0xA8,0xAA,0x8A,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAB,0xAA,0xAA,0xAA,0xAA,0xAA,0x82,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xA5,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x2A},+ {0x51,0x01,0x11,0x00,0x10,0x74,0x04,0x40,0x10,0x44,0x00,0x00,0x05,0x01,0x14,0x05,0x00,0x01,0x00,0x04,0x11,0x13,0x00,0x01,0x01,0x44,0x41,0x00,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x40,0x04,0x00,0x01,0x10,0x00,0x00,0x41,0x01,0x51,0x00,0x10,0x04},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0xAA,0xAA,0xAA,0xAA,0xAA,0xBA,0xAA,0xA8,0xAA,0x8A,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAB,0xAA,0xAA,0xAA,0xAA,0xAA,0x82,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xA5,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x2A},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x01,0x10,0x00,0x10,0x74,0x00,0x40,0x00,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x01,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x50,0x00,0x10,0x04},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x01,0x00,0x00,0x00,0x10,0x30,0x00,0x40,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x00},+ {0x01,0x01,0x10,0x00,0x10,0x70,0x00,0x40,0x00,0x40,0x00,0x00,0x05,0x01,0x04,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x01,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x10,0x00,0x00,0x00},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x51,0x11,0x00,0x11,0x74,0x54,0x40,0x10,0x44,0x10,0x00,0x05,0x01,0x14,0x45,0x11,0x45,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x00,0x01,0x04,0x44,0x05,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x50,0x00,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x01,0x10,0x00,0x10,0x74,0x00,0x40,0x00,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x01,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x50,0x00,0x00,0x04},+ {0x51,0x01,0x11,0x00,0x10,0x74,0x04,0x40,0x10,0x44,0x00,0x00,0x05,0x01,0x14,0x05,0x00,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x44,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x40,0x04,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x51,0x00,0x10,0x04},+ {0x55,0x55,0x11,0x00,0x51,0x74,0x54,0x50,0x11,0x44,0x10,0x41,0x05,0x01,0x14,0x45,0x15,0x45,0x04,0x04,0x11,0x13,0x00,0x41,0x11,0x55,0x41,0x40,0xC4,0x01,0x00,0x00,0x44,0x44,0x01,0x04,0x44,0x45,0x10,0x01,0x10,0x04,0x00,0x45,0x01,0x55,0x10,0x50,0x14},+ {0x01,0x01,0x10,0x00,0x10,0x74,0x00,0x40,0x00,0x40,0x00,0x00,0x05,0x01,0x14,0x04,0x00,0x01,0x00,0x04,0x01,0x13,0x00,0x01,0x01,0x00,0x01,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x41,0x01,0x50,0x00,0x00,0x00},+ {0x51,0x01,0x11,0x00,0x10,0x74,0x44,0x40,0x10,0x44,0x00,0x00,0x05,0x01,0x14,0x05,0x00,0x01,0x00,0x04,0x11,0x13,0x00,0x41,0x01,0x44,0x41,0x40,0xC0,0x00,0x00,0x00,0x04,0x00,0x01,0x04,0x40,0x05,0x00,0x01,0x10,0x00,0x00,0x45,0x01,0x50,0x00,0x50,0x04},+};diff --git a/games/numpowder/src/el_elec.c b/games/numpowder/src/el_elec.cnew file mode 100644index 00000000..bc1cdcd2--- /dev/null+++ b/games/numpowder/src/el_elec.c@@ -0,0 +1,1515 @@+/* NumPowder: The Powder Toy's electronics and powered elements (their files in elements/), ported: SPRK, NTCT, PTCT,+ * ETRD, BTRY, SWCH, HSWC, PCLN, PBCN, LCRY, DLAY, STOR, PVOD, PUMP, GPMP, WIFI, WIRE, ARAY, CRAY, DRAY, TESC, EMP. */+#include "simpriv.h"++/* ---------------------------------------------------------------- SPRK */+/* the conduction rules from the sender (the element the spark is on) to the receiver (tryConduct) */+static bool SPRK_tryConduct(int i, int r, int receiver, int sender, int x, int y, int rx, int ry) {+ if (receiver==sender && receiver!=PT_INST && receiver!=PT_QRTZ) return true; //Everything conducts to itself, except INST.+ //Sender cases, where elements can have specific outputs+ switch (sender) {+ case PT_INST:+ if (receiver==PT_NSCN)+ return true;+ return false;+ case PT_SWCH:+ if (receiver==PT_PSCN||receiver==PT_NSCN||receiver==PT_WATR||receiver==PT_SLTW||receiver==PT_NTCT||receiver==PT_PTCT||receiver==PT_INWR)+ return false;+ break;+ case PT_ETRD:+ if (receiver==PT_METL||receiver==PT_BMTL||receiver==PT_BRMT||receiver==PT_LRBD||receiver==PT_RBDM||receiver==PT_PSCN||receiver==PT_NSCN)+ return true;+ return false;+ case PT_NTCT:+ if (receiver==PT_PSCN || (receiver==PT_NSCN && p_temp(&parts[i])>373.0f))+ return true;+ return false;+ case PT_PTCT:+ if (receiver==PT_PSCN || (receiver==PT_NSCN && p_temp(&parts[i])<373.0f))+ return true;+ return false;+ case PT_INWR:+ if (receiver==PT_NSCN || receiver==PT_PSCN)+ return true;+ return false;+ default:+ break;+ }+ //Receiving cases, where elements can have specific inputs+ switch (receiver) {+ case PT_QRTZ:+ if ((sender==PT_NSCN||sender==PT_METL||sender==PT_PSCN||sender==PT_QRTZ) && (p_temp(&parts[ID(r)])<173.15||pv[(y+ry)/ACELL][(x+rx)/ACELL]>8))+ return true;+ return false;+ case PT_NTCT:+ if (sender==PT_NSCN || (sender==PT_PSCN&&p_temp(&parts[ID(r)])>373.0f))+ return true;+ return false;+ case PT_PTCT:+ if (sender==PT_NSCN || (sender==PT_PSCN&&p_temp(&parts[ID(r)])<373.0f))+ return true;+ return false;+ case PT_INWR:+ if (sender==PT_NSCN || sender==PT_PSCN)+ return true;+ return false;+ case PT_INST:+ if (sender==PT_PSCN)+ return true;+ return false;+ case PT_NBLE:+ if (!(parts[i].tmp&0x1))+ return true;+ return false;+ case PT_PSCN:+ if (sender!=PT_NSCN)+ return true;+ return false;+ default:+ break;+ }+ return true;+}++int el_SPRK_update(UPDATE_FUNC_ARGS) {+ int ct = parts[i].ctype;+ Element_FIRE_update(UPDATE_FUNC_SUBCALL_ARGS);+ if (parts[i].life<=0) {+ if (ct==PT_WATR||ct==PT_SLTW||ct==PT_PSCN||ct==PT_NSCN||ct==PT_ETRD||ct==PT_INWR)+ p_set_temp(&parts[i], R_TEMP + 273.15f);+ if (ct<=0 || ct>=PT_NUM || !elements[parts[i].ctype].Enabled)+ ct = PT_METL;+ parts[i].ctype = PT_NONE;+ parts[i].life = 4;+ if (ct == PT_WATR)+ parts[i].life = 64;+ else if (ct == PT_SLTW)+ parts[i].life = 54;+ else if (ct == PT_SWCH)+ parts[i].life = 14;+ else if (ct == PT_RSST) { //RSST disappears at the end of its spark cycle+ kill_part(i);+ return 1;+ }+ if (part_change_type(i,x,y,ct))+ return 1;+ return 0;+ }+ //Some functions of SPRK based on ctype (what it is on)+ switch(ct) {+ case PT_SPRK:+ kill_part(i);+ return 1;+ case PT_NTCT:+ case PT_PTCT:+ Element_NTCT_update(UPDATE_FUNC_SUBCALL_ARGS);+ break;+ case PT_ETRD:+ if (parts[i].life==1) {+ int nearp = Element_ETRD_nearestSparkablePart(i);+ if (nearp == -1)+ break;+ int pavg = parts_avg(i, nearp, PT_INSL);+ if (pavg != PT_INSL && pavg != PT_RSSS) {+ //@ ETRD -> ETRD + PLSM+ CreateLine(x, y, (int)(p_x(&parts[nearp])+0.5f), (int)(p_y(&parts[nearp])+0.5f), PT_PLSM);+ parts[i].life = 20;+ part_change_type(i,x,y,ct);+ ct = parts[i].ctype = PT_NONE;+ part_change_type(nearp,(int)(p_x(&parts[nearp])+0.5f),(int)(p_y(&parts[nearp])+0.5f),PT_SPRK);+ parts[nearp].life = 9;+ parts[nearp].ctype = PT_ETRD;+ }+ }+ break;+ case PT_NBLE:+ if (parts[i].life<=1 && !(parts[i].tmp&0x1)) {+ //@ NBLE -> PLSM(NBLE)+ parts[i].life = rng_between(50, 199);+ part_change_type(i,x,y,PT_PLSM);+ parts[i].ctype = PT_NBLE;+ if (p_temp(&parts[i]) > 5273.15)+ parts[i].tmp |= 0x4;+ p_set_temp(&parts[i], 3500);+ pv[y/ACELL][x/ACELL] += 1;+ }+ break;+ case PT_TESC:+ if (parts[i].tmp>300)+ parts[i].tmp=300;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (r)+ continue;+ if (parts[i].tmp>4 && rng_chance(1, parts[i].tmp*parts[i].tmp/20+6)) {+ //@ TESC -> TESC + LIGH+ int p = create_part(-1, x+rx*2, y+ry*2, PT_LIGH, -1);+ if (p!=-1) {+ parts[p].life = rng_between(0, 2+parts[i].tmp/15) + parts[i].tmp/7;+ if (parts[i].life>60)+ parts[i].life=60;+ p_set_temp(&parts[p], parts[p].life*parts[i].tmp/2.5);+ parts[p].tmp2=1;+ parts[p].tmp=(int)(atan2f(-ry, (float)(rx))*360/NP_PI);+ p_set_temp(&parts[i], restrict_flt(p_temp(&parts[i]) - (parts[i].tmp * 2 + p_temp(&parts[i]) / 5), MIN_TEMP, MAX_TEMP)); // slight self-cooling+ if (fabsf(pv[y/ACELL][x/ACELL])!=0.0f) {+ if (fabsf(pv[y/ACELL][x/ACELL])<=0.5f)+ pv[y/ACELL][x/ACELL]=0;+ else+ pv[y/ACELL][x/ACELL]-=(pv[y/ACELL][x/ACELL]>0)?0.5:-0.5;+ }+ }+ }+ }+ }+ }+ break;+ case PT_IRON:+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_DSTW || TYP(r)==PT_SLTW || TYP(r)==PT_WATR) {+ int rndstore = rng_gen()%100;+ //@ IRON + DSTW/SLTW/WATR -> IRON + O2/H2+ if (!rndstore)+ part_change_type(ID(r),x+rx,y+ry,PT_O2);+ else if (3 > rndstore)+ part_change_type(ID(r),x+rx,y+ry,PT_H2);+ }+ }+ }+ }+ break;+ case PT_TUNG:+ if(p_temp(&parts[i]) < 3595.0){+ p_set_temp(&parts[i], p_temp(&parts[i]) + (rng_between(-4, 15)));+ }+ default:+ break;+ }+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int receiver = TYP(r);+ int sender = ct;+ int pavg = parts_avg(ID(r), i,PT_INSL);+ //receiver is the element SPRK is trying to conduct to+ //sender is the element the SPRK is on+ //First, some checks usually for (de)activation of elements+ switch (receiver) {+ case PT_SWCH:+ if (pavg!=PT_INSL && pavg!=PT_RSSS && parts[i].life<4) {+ if(sender==PT_PSCN && parts[ID(r)].life<10) {+ parts[ID(r)].life = 10;+ } else if (sender==PT_NSCN) {+ parts[ID(r)].ctype = PT_NONE;+ parts[ID(r)].life = 9;+ }+ }+ break;+ case PT_SPRK:+ if (pavg!=PT_INSL && pavg!=PT_RSSS && parts[i].life<4) {+ if (parts[ID(r)].ctype==PT_SWCH) {+ if (sender==PT_NSCN) {+ part_change_type(ID(r),x+rx,y+ry,PT_SWCH);+ parts[ID(r)].ctype = PT_NONE;+ parts[ID(r)].life = 9;+ }+ } else if(parts[ID(r)].ctype==PT_NTCT||parts[ID(r)].ctype==PT_PTCT)+ if (sender==PT_METL) {+ p_set_temp(&parts[ID(r)], 473.0f);+ }+ }+ continue;+ case PT_PUMP: case PT_GPMP: case PT_HSWC: case PT_PBCN:+ if (parts[i].life<4) { // PROP_PTOGGLE, Maybe? We seem to use 2 different methods for handling actived elements, this one seems better. Yes, use this one for new elements, PCLN is different for compatibility with existing saves+ if (sender==PT_PSCN) parts[ID(r)].life = 10;+ else if (sender==PT_NSCN && parts[ID(r)].life>=10) parts[ID(r)].life = 9;+ }+ continue;+ case PT_LCRY:+ if (abs(rx)<2&&abs(ry)<2 && parts[i].life<4) {+ if (sender==PT_PSCN && parts[ID(r)].tmp == 0) parts[ID(r)].tmp = 2;+ else if (sender==PT_NSCN && parts[ID(r)].tmp == 3) parts[ID(r)].tmp = 1;+ }+ continue;+ case PT_PPIP:+ if (parts[i].life == 3 && pavg!=PT_INSL && pavg!=PT_RSSS) {+ if (sender == PT_NSCN || sender == PT_PSCN || sender == PT_INST)+ Element_PPIP_flood_trigger(x+rx, y+ry, sender);+ }+ continue;+ case PT_NTCT: case PT_PTCT: case PT_INWR:+ if (sender==PT_METL && pavg!=PT_INSL && pavg!=PT_RSSS && parts[i].life<4) {+ p_set_temp(&parts[ID(r)], 473.0f);+ if (receiver==PT_NTCT||receiver==PT_PTCT)+ continue;+ }+ break;+ case PT_EMP:+ if (!parts[ID(r)].life && parts[i].life > 0 && parts[i].life < 4) {+ emp_trigger_count++;+ emp_decor += 3;+ if (emp_decor > 40)+ emp_decor = 40;+ parts[ID(r)].life = 220;+ }+ continue;+ }+ if ((pavg == PT_INSL) || (pavg == PT_RSSS)) continue; //Insulation blocks everything past here+ if (!((elements[receiver].Properties&PROP_CONDUCTS)||receiver==PT_INST||receiver==PT_QRTZ)) continue; //Stop non-conducting receivers, allow INST and QRTZ as special cases+ if (abs(rx)+abs(ry)>=4 &&sender!=PT_SWCH&&receiver!=PT_SWCH) continue; //Only switch conducts really far+ if (!SPRK_tryConduct(i, r, receiver, sender, x, y, rx, ry)) {+ continue;+ }+ //Yay, passed normal conduction rules, check a few last things and change receiver to spark+ if (receiver==PT_WATR||receiver==PT_SLTW) {+ if (parts[ID(r)].life==0 && parts[i].life<3) {+ part_change_type(ID(r),x+rx,y+ry,PT_SPRK);+ if (receiver==PT_WATR) parts[ID(r)].life = 6;+ else parts[ID(r)].life = 5;+ parts[ID(r)].ctype = receiver;+ }+ } else if (receiver==PT_INST) {+ if (parts[ID(r)].life==0 && parts[i].life<4) {+ FloodINST(x+rx,y+ry);//spark the wire+ }+ } else if (receiver==PT_RSST) {+ if (parts[ID(r)].life==0 && parts[i].life<4) {+ part_change_type(ID(r),x+rx,y+ry,PT_SPRK);+ parts[ID(r)].life = 5;+ parts[ID(r)].ctype = receiver;+ }+ } else if (parts[ID(r)].life==0 && parts[i].life<4) {+ parts[ID(r)].life = 4;+ parts[ID(r)].ctype = receiver;+ part_change_type(ID(r),x+rx,y+ry,PT_SPRK);+ if (p_temp(&parts[ID(r)])+10.0f<673.0f&&!legacy_enable&&(receiver==PT_METL||receiver==PT_BMTL||receiver==PT_BRMT||receiver==PT_PSCN||receiver==PT_NSCN||receiver==PT_ETRD||receiver==PT_NBLE||receiver==PT_IRON))+ p_set_temp(&parts[ID(r)], p_temp(&parts[ID(r)])+10.0f);+ } else if (!parts[ID(r)].life && sender==PT_ETRD && parts[i].life==5) { //ETRD is odd and conducts to others only at life 5, this could probably be somewhere else+ part_change_type(i,x,y,sender);+ parts[i].ctype = PT_NONE;+ parts[i].life = 20;+ parts[ID(r)].life = 4;+ parts[ID(r)].ctype = receiver;+ part_change_type(ID(r),x+rx,y+ry,PT_SPRK);+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- NTCT */+int Element_NTCT_update(UPDATE_FUNC_ARGS) {+ if (p_temp(&parts[i])>295.0f)+ p_set_temp(&parts[i], p_temp(&parts[i]) - (2.5f));+ return 0;+}++/* ---------------------------------------------------------------- PTCT */+int el_PTCT_update(UPDATE_FUNC_ARGS) {+ if (p_temp(&parts[i])>295.0f)+ p_set_temp(&parts[i], p_temp(&parts[i]) - (2.5f));+ return 0;+}++/* ---------------------------------------------------------------- ETRD */+void el_ETRD_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) {+ if (etrd_count_valid) {+ if (from == PT_ETRD && parts[i].life == 0)+ etrd_life0_count--;+ if (to == PT_ETRD && parts[i].life == 0)+ etrd_life0_count++;+ }+}+/* the places within 12 (|x| + |y|) and their distances, nearest first (ETRD's deltaPos, stably sorted) */+static const struct { int8_t x, y, length; } ETRD_deltaPos[313] = {+ {0, 0, 0}, {-1, -1, 1}, {0, -1, 1}, {1, -1, 1}, {-1, 0, 1}, {1, 0, 1}, {-1, 1, 1}, {0, 1, 1},+ {1, 1, 1}, {-2, -2, 2}, {-1, -2, 2}, {0, -2, 2}, {1, -2, 2}, {2, -2, 2}, {-2, -1, 2}, {2, -1, 2},+ {-2, 0, 2}, {2, 0, 2}, {-2, 1, 2}, {2, 1, 2}, {-2, 2, 2}, {-1, 2, 2}, {0, 2, 2}, {1, 2, 2},+ {2, 2, 2}, {-2, -3, 3}, {-1, -3, 3}, {0, -3, 3}, {1, -3, 3}, {2, -3, 3}, {-3, -2, 3}, {3, -2, 3},+ {-3, -1, 3}, {3, -1, 3}, {-3, 0, 3}, {3, 0, 3}, {-3, 1, 3}, {3, 1, 3}, {-3, 2, 3}, {3, 2, 3},+ {-2, 3, 3}, {-1, 3, 3}, {0, 3, 3}, {1, 3, 3}, {2, 3, 3}, {-2, -4, 4}, {-1, -4, 4}, {0, -4, 4},+ {1, -4, 4}, {2, -4, 4}, {-3, -3, 4}, {3, -3, 4}, {-4, -2, 4}, {4, -2, 4}, {-4, -1, 4}, {4, -1, 4},+ {-4, 0, 4}, {4, 0, 4}, {-4, 1, 4}, {4, 1, 4}, {-4, 2, 4}, {4, 2, 4}, {-3, 3, 4}, {3, 3, 4},+ {-2, 4, 4}, {-1, 4, 4}, {0, 4, 4}, {1, 4, 4}, {2, 4, 4}, {-3, -5, 5}, {-2, -5, 5}, {-1, -5, 5},+ {0, -5, 5}, {1, -5, 5}, {2, -5, 5}, {3, -5, 5}, {-4, -4, 5}, {-3, -4, 5}, {3, -4, 5}, {4, -4, 5},+ {-5, -3, 5}, {-4, -3, 5}, {4, -3, 5}, {5, -3, 5}, {-5, -2, 5}, {5, -2, 5}, {-5, -1, 5}, {5, -1, 5},+ {-5, 0, 5}, {5, 0, 5}, {-5, 1, 5}, {5, 1, 5}, {-5, 2, 5}, {5, 2, 5}, {-5, 3, 5}, {-4, 3, 5},+ {4, 3, 5}, {5, 3, 5}, {-4, 4, 5}, {-3, 4, 5}, {3, 4, 5}, {4, 4, 5}, {-3, 5, 5}, {-2, 5, 5},+ {-1, 5, 5}, {0, 5, 5}, {1, 5, 5}, {2, 5, 5}, {3, 5, 5}, {-3, -6, 6}, {-2, -6, 6}, {-1, -6, 6},+ {0, -6, 6}, {1, -6, 6}, {2, -6, 6}, {3, -6, 6}, {-4, -5, 6}, {4, -5, 6}, {-5, -4, 6}, {5, -4, 6},+ {-6, -3, 6}, {6, -3, 6}, {-6, -2, 6}, {6, -2, 6}, {-6, -1, 6}, {6, -1, 6}, {-6, 0, 6}, {6, 0, 6},+ {-6, 1, 6}, {6, 1, 6}, {-6, 2, 6}, {6, 2, 6}, {-6, 3, 6}, {6, 3, 6}, {-5, 4, 6}, {5, 4, 6},+ {-4, 5, 6}, {4, 5, 6}, {-3, 6, 6}, {-2, 6, 6}, {-1, 6, 6}, {0, 6, 6}, {1, 6, 6}, {2, 6, 6},+ {3, 6, 6}, {-3, -7, 7}, {-2, -7, 7}, {-1, -7, 7}, {0, -7, 7}, {1, -7, 7}, {2, -7, 7}, {3, -7, 7},+ {-5, -6, 7}, {-4, -6, 7}, {4, -6, 7}, {5, -6, 7}, {-6, -5, 7}, {-5, -5, 7}, {5, -5, 7}, {6, -5, 7},+ {-6, -4, 7}, {6, -4, 7}, {-7, -3, 7}, {7, -3, 7}, {-7, -2, 7}, {7, -2, 7}, {-7, -1, 7}, {7, -1, 7},+ {-7, 0, 7}, {7, 0, 7}, {-7, 1, 7}, {7, 1, 7}, {-7, 2, 7}, {7, 2, 7}, {-7, 3, 7}, {7, 3, 7},+ {-6, 4, 7}, {6, 4, 7}, {-6, 5, 7}, {-5, 5, 7}, {5, 5, 7}, {6, 5, 7}, {-5, 6, 7}, {-4, 6, 7},+ {4, 6, 7}, {5, 6, 7}, {-3, 7, 7}, {-2, 7, 7}, {-1, 7, 7}, {0, 7, 7}, {1, 7, 7}, {2, 7, 7},+ {3, 7, 7}, {-4, -8, 8}, {-3, -8, 8}, {-2, -8, 8}, {-1, -8, 8}, {0, -8, 8}, {1, -8, 8}, {2, -8, 8},+ {3, -8, 8}, {4, -8, 8}, {-5, -7, 8}, {-4, -7, 8}, {4, -7, 8}, {5, -7, 8}, {-6, -6, 8}, {6, -6, 8},+ {-7, -5, 8}, {7, -5, 8}, {-8, -4, 8}, {-7, -4, 8}, {7, -4, 8}, {8, -4, 8}, {-8, -3, 8}, {8, -3, 8},+ {-8, -2, 8}, {8, -2, 8}, {-8, -1, 8}, {8, -1, 8}, {-8, 0, 8}, {8, 0, 8}, {-8, 1, 8}, {8, 1, 8},+ {-8, 2, 8}, {8, 2, 8}, {-8, 3, 8}, {8, 3, 8}, {-8, 4, 8}, {-7, 4, 8}, {7, 4, 8}, {8, 4, 8},+ {-7, 5, 8}, {7, 5, 8}, {-6, 6, 8}, {6, 6, 8}, {-5, 7, 8}, {-4, 7, 8}, {4, 7, 8}, {5, 7, 8},+ {-4, 8, 8}, {-3, 8, 8}, {-2, 8, 8}, {-1, 8, 8}, {0, 8, 8}, {1, 8, 8}, {2, 8, 8}, {3, 8, 8},+ {4, 8, 8}, {-3, -9, 9}, {-2, -9, 9}, {-1, -9, 9}, {0, -9, 9}, {1, -9, 9}, {2, -9, 9}, {3, -9, 9},+ {-9, -3, 9}, {9, -3, 9}, {-9, -2, 9}, {9, -2, 9}, {-9, -1, 9}, {9, -1, 9}, {-9, 0, 9}, {9, 0, 9},+ {-9, 1, 9}, {9, 1, 9}, {-9, 2, 9}, {9, 2, 9}, {-9, 3, 9}, {9, 3, 9}, {-3, 9, 9}, {-2, 9, 9},+ {-1, 9, 9}, {0, 9, 9}, {1, 9, 9}, {2, 9, 9}, {3, 9, 9}, {-2, -10, 10}, {-1, -10, 10}, {0, -10, 10},+ {1, -10, 10}, {2, -10, 10}, {-10, -2, 10}, {10, -2, 10}, {-10, -1, 10}, {10, -1, 10}, {-10, 0, 10}, {10, 0, 10},+ {-10, 1, 10}, {10, 1, 10}, {-10, 2, 10}, {10, 2, 10}, {-2, 10, 10}, {-1, 10, 10}, {0, 10, 10}, {1, 10, 10},+ {2, 10, 10}, {-1, -11, 11}, {0, -11, 11}, {1, -11, 11}, {-11, -1, 11}, {11, -1, 11}, {-11, 0, 11}, {11, 0, 11},+ {-11, 1, 11}, {11, 1, 11}, {-1, 11, 11}, {0, 11, 11}, {1, 11, 11}, {0, -12, 12}, {-12, 0, 12}, {12, 0, 12},+ {0, 12, 12},+};+#define ETRD_NDELTA 313+int Element_ETRD_nearestSparkablePart(int targetId) {+ if (!elementCount[PT_ETRD])+ return -1;+ if (etrd_count_valid && etrd_life0_count <= 0)+ return -1;+ if (parts[targetId].tmp2 && parts[targetId].tmp > parts[targetId].tmp2) // Invalid range if max is set+ return -1;+ const int maxDistance = (int)(hypotf((float)XRES, (float)YRES));+ int foundDistance = parts[targetId].tmp2 ? imin(parts[targetId].tmp2, maxDistance) : maxDistance; // tmp2 sets max distance+ int foundI = -1;+ int targetX = (int)(p_x(&parts[targetId])), targetY = (int)(p_y(&parts[targetId]));+ if (etrd_count_valid) {+ // countLife0 doesn't need recalculating, so just focus on finding the nearest particle+ // If the simulation contains lots of particles, check near the target position first since going through all particles will be slow.+ // Threshold = number of positions checked, *2 because it's likely to access memory all over the place (less cache friendly) and there's extra logic needed+ // TODO: probably not optimal if excessive stacking is used+ if (parts_active > ETRD_NDELTA*2) {+ for (int k = 0; k < ETRD_NDELTA; k++) {+ int checkX = targetX + ETRD_deltaPos[k].x, checkY = targetY + ETRD_deltaPos[k].y;+ int checkDistance = ETRD_deltaPos[k].length;+ if (parts[targetId].tmp >= checkDistance) { // tmp sets min distance+ continue;+ }+ if (foundDistance < checkDistance) {+ // deltaPos is sorted in order of ascending length, so foundDistance < checkDistance means all later items are further away.+ break;+ }+ if (InBounds(checkX, checkY) && checkDistance <= foundDistance) {+ int r = PMAPAT(checkX, checkY);+ if (r && TYP(r) == PT_ETRD && !parts[ID(r)].life && ID(r) != targetId && checkDistance < foundDistance) {+ foundDistance = checkDistance;+ foundI = ID(r);+ }+ }+ }+ }+ // If neighbor search didn't find a suitable particle, search all particles+ if (foundI < 0) {+ for (int i = 0; i < parts_active; i++) {+ if (parts[i].type == PT_ETRD && !parts[i].life) {+ int checkX = (int)(p_x(&parts[i]))-targetX, checkY = (int)(p_y(&parts[i]))-targetY;+ int checkDistance = (int)(hypotf((float)checkX, (float)checkY));+ if (checkDistance < foundDistance && checkDistance > parts[targetId].tmp && i != targetId) { // tmp sets min distance+ foundDistance = checkDistance;+ foundI = i;+ }+ }+ }+ }+ } else {+ // Recalculate countLife0, and search for the closest suitable particle+ int countLife0 = 0;+ for (int i = 0; i < parts_active; i++) {+ if (parts[i].type == PT_ETRD && !parts[i].life) {+ countLife0++;+ int checkX = (int)(p_x(&parts[i]))-targetX, checkY = (int)(p_y(&parts[i]))-targetY;+ int checkDistance = (int)(hypotf((float)checkX, (float)checkY));+ if (checkDistance < foundDistance && checkDistance > parts[targetId].tmp && i != targetId) { // tmp sets min distance+ foundDistance = checkDistance;+ foundI = i;+ }+ }+ }+ etrd_life0_count = countLife0;+ etrd_count_valid = true;+ }+ return foundI;+}++/* ---------------------------------------------------------------- BTRY */+int el_BTRY_update(UPDATE_FUNC_ARGS) {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if ((rx || ry) && abs(rx)+abs(ry)<4) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ int pavg = parts_avg(i,ID(r),PT_INSL);+ if (pavg!=PT_INSL && pavg!=PT_RSSS) {+ if ((elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[ID(r)].life==0) {+ parts[ID(r)].life = 4;+ parts[ID(r)].ctype = rt;+ part_change_type(ID(r),x+rx,y+ry,PT_SPRK);+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- SWCH */+static bool SWCH_isRedBRAY(int xc, int yc) {+ return TYP(PMAPAT(xc, yc)) == PT_BRAY && parts[ID(PMAPAT(xc, yc))].tmp == 2;+}+int el_SWCH_update(UPDATE_FUNC_ARGS) {+ if (parts[i].life>0 && parts[i].life!=10)+ parts[i].life--;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int pavg = parts_avg(i,ID(r),PT_INSL);+ if (pavg!=PT_INSL && pavg!=PT_RSSS) {+ int rt = TYP(r);+ if (rt==PT_SWCH) {+ if (parts[i].life>=10&&parts[ID(r)].life<10&&parts[ID(r)].life>0)+ parts[i].life = 9;+ else if (parts[i].life==0&&parts[ID(r)].life>=10) {+ //Set to other particle's life instead of 10, otherwise spark loops form when SWCH is sparked while turning on+ parts[i].life = parts[ID(r)].life;+ }+ } else if (rt==PT_SPRK && parts[i].life==10 && parts[ID(r)].life>0 && parts[ID(r)].ctype!=PT_PSCN && parts[ID(r)].ctype!=PT_NSCN) {+ part_change_type(i,x,y,PT_SPRK);+ parts[i].ctype = PT_SWCH;+ parts[i].life = 4;+ }+ }+ }+ }+ }+ //turn SWCH on/off from two red BRAYS. There must be one either above or below, and one either left or right to work, and it can't come from the side, it must be a diagonal beam+ if (!TYP(PMAPAT(x-1, y-1)) && !TYP(PMAPAT(x+1, y-1)) && (SWCH_isRedBRAY(x, y-1) || SWCH_isRedBRAY(x, y+1)) && (SWCH_isRedBRAY(x+1, y) || SWCH_isRedBRAY(x-1, y))) {+ if (parts[i].life == 10)+ parts[i].life = 9;+ else if (parts[i].life <= 5)+ parts[i].life = 14;+ }+ return 0;+}++/* ---------------------------------------------------------------- HSWC */+int el_HSWC_update(UPDATE_FUNC_ARGS) {+ if (parts[i].life!=10) {+ if (parts[i].life>0)+ parts[i].life--;+ } else {+ bool deserializeTemp = parts[i].tmp == 1;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ r = PHOTAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r) == PT_HSWC) {+ if (parts[ID(r)].life<10&&parts[ID(r)].life>0)+ parts[i].life = 9;+ else if (parts[ID(r)].life==0)+ parts[ID(r)].life = 10;+ }+ if (deserializeTemp && TYP(r) == PT_FILT) {+ if (rx >= -1 && rx <= 1 && ry >= -1 && ry <= 1) {+ int newTemp = parts[ID(r)].ctype - 0x10000000;+ if (newTemp >= MIN_TEMP && newTemp <= MAX_TEMP)+ p_set_temp(&parts[i], (float)(parts[ID(r)].ctype - 0x10000000));+ }+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- PCLN */+int el_PCLN_update(UPDATE_FUNC_ARGS) {+ if (parts[i].life>0 && parts[i].life!=10)+ parts[i].life--;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_SPRK) {+ if (parts[ID(r)].life>0 && parts[ID(r)].life<4) {+ if (parts[ID(r)].ctype==PT_PSCN)+ parts[i].life = 10;+ else if (parts[ID(r)].ctype==PT_NSCN)+ parts[i].life = 9;+ }+ } else if (TYP(r)==PT_PCLN) {+ if (parts[i].life==10&&parts[ID(r)].life<10&&parts[ID(r)].life>0)+ parts[i].life = 9;+ else if (parts[i].life==0&&parts[ID(r)].life==10)+ parts[i].life = 10;+ }+ }+ }+ }+ if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !elements[parts[i].ctype].Enabled) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ int r = PHOTAT(x+rx, y+ry);+ if (!r)+ r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (rt!=PT_CLNE && rt!=PT_PCLN &&+ rt!=PT_BCLN && rt!=PT_SPRK &&+ rt!=PT_NSCN && rt!=PT_PSCN &&+ rt!=PT_STKM && rt!=PT_STKM2 &&+ rt!=PT_PBCN && rt<PT_NUM) {+ parts[i].ctype = rt;+ if (rt==PT_LIFE || rt==PT_LAVA)+ parts[i].tmp = parts[ID(r)].ctype;+ }+ }+ }+ }+ if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && elements[parts[i].ctype].Enabled && parts[i].life==10) {+ if (parts[i].ctype==PT_PHOT) {//create photons a different way+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = create_part(-1, x + rx, y + ry, PT_PHOT, -1);+ if (r != -1) {+ p_set_vx(&parts[r], (float)(rx * 3));+ p_set_vy(&parts[r], (float)(ry * 3));+ if (r>i) {+ // Make sure movement doesn't happen until next frame, to avoid gaps in the beams of photons produced+ parts[r].flags |= FLAG_SKIPMOVE;+ }+ }+ }+ }+ }+ } else if (parts[i].ctype==PT_LIFE) { //create life a different way+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ create_part(-1, x+rx, y+ry, PT_LIFE, parts[i].tmp);+ }+ }+ } else if (parts[i].ctype != PT_LIGH || rng_chance(1, 30)) {+ int np = create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), TYP(parts[i].ctype), -1);+ if (np>=0) {+ if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA)+ parts[np].ctype = parts[i].tmp;+ }+ }+ }+ return 0;+}+bool Element_PCLN_ctypeDraw(CTYPEDRAW_FUNC_ARGS) {+ if (t == PT_PSCN || t == PT_NSCN || t == PT_SPRK) {+ return false;+ }+ return ctypeDrawVInTmp(CTYPEDRAW_FUNC_SUBCALL_ARGS);+}++/* ---------------------------------------------------------------- PBCN */+#define ADVECTION 0.1f+int el_PBCN_update(UPDATE_FUNC_ARGS) {+ if (!parts[i].tmp2 && pv[y/ACELL][x/ACELL]>4.0f)+ parts[i].tmp2 = rng_between(80, 119);+ if (parts[i].tmp2) {+ p_set_vx(&parts[i], p_vx(&parts[i]) + (ADVECTION*vx[y/ACELL][x/ACELL]));+ p_set_vy(&parts[i], p_vy(&parts[i]) + (ADVECTION*vy[y/ACELL][x/ACELL]));+ parts[i].tmp2--;+ if(!parts[i].tmp2){+ kill_part(i);+ return 1;+ }+ }+ if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !elements[parts[i].ctype].Enabled) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ int r = PHOTAT(x+rx, y+ry);+ if (!r)+ r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (rt!=PT_CLNE && rt!=PT_PCLN &&+ rt!=PT_BCLN && rt!=PT_SPRK &&+ rt!=PT_NSCN && rt!=PT_PSCN &&+ rt!=PT_STKM && rt!=PT_STKM2 &&+ rt!=PT_PBCN && rt<PT_NUM) {+ parts[i].ctype = rt;+ if (rt==PT_LIFE || rt==PT_LAVA)+ parts[i].tmp = parts[ID(r)].ctype;+ }+ }+ }+ }+ if (parts[i].life!=10) {+ if (parts[i].life>0)+ parts[i].life--;+ } else {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_PBCN) {+ if (parts[ID(r)].life<10&&parts[ID(r)].life>0)+ parts[i].life = 9;+ else if (parts[ID(r)].life==0)+ parts[ID(r)].life = 10;+ }+ }+ }+ }+ if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && elements[parts[i].ctype].Enabled) {+ if (parts[i].ctype==PT_PHOT) {//create photons a different way+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = create_part(-1, x + rx, y + ry, PT_PHOT, -1);+ if (r != -1) {+ p_set_vx(&parts[r], (float)(rx * 3));+ p_set_vy(&parts[r], (float)(ry * 3));+ if (r>i) {+ // Make sure movement doesn't happen until next frame, to avoid gaps in the beams of photons produced+ parts[r].flags |= FLAG_SKIPMOVE;+ }+ }+ }+ }+ }+ } else if (parts[i].ctype==PT_LIFE) { //create life a different way+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ create_part(-1, x+rx, y+ry, PT_LIFE, parts[i].tmp);+ }+ }+ } else if (parts[i].ctype!=PT_LIGH || rng_chance(1, 30)) {+ int np = create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), TYP(parts[i].ctype), -1);+ if (np>-1) {+ if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA)+ parts[np].ctype = parts[i].tmp;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- LCRY */+int el_LCRY_update(UPDATE_FUNC_ARGS) {+ int check, setto;+ switch (parts[i].tmp) {+ case 1:+ if(parts[i].life<=0)+ parts[i].tmp = 0;+ else {+ parts[i].life-=2;+ if(parts[i].life < 0)+ parts[i].life = 0;+ parts[i].tmp2 = parts[i].life;+ }+ /* fallthrough */+ case 0:+ check=3;+ setto=1;+ break;+ case 2:+ if(parts[i].life>=10)+ parts[i].tmp = 3;+ else {+ parts[i].life+=2;+ if(parts[i].life > 10)+ parts[i].life = 10;+ parts[i].tmp2 = parts[i].life;+ }+ /* fallthrough */+ case 3:+ check=0;+ setto=2;+ break;+ default:+ parts[i].tmp = 0;+ parts[i].life = 0;+ return 0;+ }+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_LCRY && parts[ID(r)].tmp == check) {+ parts[ID(r)].tmp = setto;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- DLAY */+int el_DLAY_update(UPDATE_FUNC_ARGS) {+ int oldl = parts[i].life;+ if (parts[i].life>0)+ parts[i].life--;+ if (p_temp(&parts[i])<= 1.0f+273.15f)+ p_set_temp(&parts[i], 1.0f+273.15f);+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int pavg = parts_avg(ID(r), i, PT_INSL);+ if (pavg==PT_INSL || pavg==PT_RSSS)+ continue;+ if (TYP(r)==PT_SPRK && parts[i].life==0 && parts[ID(r)].life>0 && parts[ID(r)].life<4 && parts[ID(r)].ctype==PT_PSCN) {+ parts[i].life = (int)(p_temp(&parts[i])-273.15f+0.5f);+ } else if (TYP(r)==PT_DLAY) {+ if (!parts[i].life) {+ if (parts[ID(r)].life) {+ parts[i].life = parts[ID(r)].life;+ if((ID(r))>i) //If the other particle hasn't been life updated+ parts[i].life--;+ }+ } else if (!parts[ID(r)].life) {+ parts[ID(r)].life = parts[i].life;+ if((ID(r))>i) //If the other particle hasn't been life updated+ parts[ID(r)].life++;+ }+ } else if(TYP(r)==PT_NSCN && oldl==1) {+ create_part(-1, x+rx, y+ry, PT_SPRK, -1);+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- STOR */+/* the stored element is in tmp's bits 0 to 7, the filter in ctype's (their other bits keep the stored particle's+ * ctype, the original's tmp4: see tmp4_get) */+int el_STOR_update(UPDATE_FUNC_ARGS) {+ if (!IsElementOrNone(parts[i].tmp & 0xFF))+ parts[i].tmp &= ~0xFF;+ if(parts[i].life && !(parts[i].tmp & 0xFF))+ parts[i].life--;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ r= PHOTAT(x+rx, y+ry);+ if (!r)+ continue;+ if (!(parts[i].tmp & 0xFF) && !parts[i].life && TYP(r)!=PT_STOR && !(elements[TYP(r)].Properties&TYPE_SOLID) && (!(parts[i].ctype & 0xFF) || TYP(r)==(parts[i].ctype & 0xFF))) {+ if (TYP(r) == PT_SOAP)+ Element_SOAP_detach(ID(r));+ parts[i].tmp = (int16_t)((parts[i].tmp & ~0xFF) | parts[ID(r)].type);+ p_set_temp(&parts[i], p_temp(&parts[ID(r)]));+ parts[i].tmp2 = parts[ID(r)].life;+ parts[i].tmp3 = parts[ID(r)].tmp;+ tmp4_set(i, parts[ID(r)].ctype);+ kill_part(ID(r));+ }+ if((parts[i].tmp & 0xFF) && TYP(r)==PT_SPRK && parts[ID(r)].ctype==PT_PSCN && parts[ID(r)].life>0 && parts[ID(r)].life<4) {+ for(int ry1 = 1; ry1 >= -1; ry1--) {+ for(int rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1-rx1+1) { // Oscillate the X starting at 0, 1, -1, 3, -5, etc (Though stop at -1)+ int np = create_part(-1,x+rx1,y+ry1,TYP(parts[i].tmp), -1);+ if (np!=-1) {+ p_set_temp(&parts[np], p_temp(&parts[i]));+ parts[np].life = parts[i].tmp2;+ parts[np].tmp = parts[i].tmp3;+ parts[np].ctype = tmp4_get(i);+ parts[i].tmp &= ~0xFF;+ parts[i].life = 10;+ break;+ }+ }+ }+ }+ }+ }+ }+ return 0;+}+bool el_STOR_ctypeDraw(CTYPEDRAW_FUNC_ARGS) {+ if (elements[t].Properties & TYPE_SOLID) {+ return false;+ }+ int keep = parts[i].ctype & ~0xFF;+ if (!basicCtypeDraw(CTYPEDRAW_FUNC_SUBCALL_ARGS))+ return false;+ parts[i].ctype |= keep;+ return true;+}++/* ---------------------------------------------------------------- PVOD */+int el_PVOD_update(UPDATE_FUNC_ARGS) {+ if (parts[i].life>0 && parts[i].life!=10)+ parts[i].life--;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_SPRK) {+ if (parts[ID(r)].life>0 && parts[ID(r)].life<4) {+ if (parts[ID(r)].ctype==PT_PSCN)+ parts[i].life = 10;+ else if (parts[ID(r)].ctype==PT_NSCN)+ parts[i].life = 9;+ }+ } else if (TYP(r)==PT_PVOD) {+ if (parts[i].life==10&&parts[ID(r)].life<10&&parts[ID(r)].life>0)+ parts[i].life = 9;+ else if (parts[i].life==0&&parts[ID(r)].life==10)+ parts[i].life = 10;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- PUMP */+int el_PUMP_update(UPDATE_FUNC_ARGS) {+ if (parts[i].life != 10) {+ if (parts[i].life>0)+ parts[i].life--;+ } else {+ if (p_temp(&parts[i]) >= MAX_PRESSURE+273.15f)+ p_set_temp(&parts[i], MAX_PRESSURE+273.15f);+ if (p_temp(&parts[i]) <= MIN_PRESSURE+273.15f)+ p_set_temp(&parts[i], MIN_PRESSURE+273.15f);+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (parts[i].tmp != 1) {+ if (!(rx && ry))+ pv[(y/ACELL)+ry][(x/ACELL)+rx] += 0.1f*((p_temp(&parts[i])-273.15)-pv[(y/ACELL)+ry][(x/ACELL)+rx]);+ } else {+ int r = PMAPAT(x+rx, y+ry);+ if (TYP(r) == PT_FILT) {+ int newPressure = parts[ID(r)].ctype - 0x10000000;+ if (newPressure >= 0 && newPressure <= MAX_PRESSURE - MIN_PRESSURE) {+ pv[(y + ry) / ACELL][(x + rx) / ACELL] = (float)(newPressure) + MIN_PRESSURE;+ }+ }+ }+ }+ }+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r) == PT_PUMP) {+ if (parts[ID(r)].life < 10 && parts[ID(r)].life > 0)+ parts[i].life = 9;+ else if (parts[ID(r)].life == 0)+ parts[ID(r)].life = 10;+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- GPMP */+int el_GPMP_update(UPDATE_FUNC_ARGS) {+ if (parts[i].life!=10) {+ if (parts[i].life>0)+ parts[i].life--;+ } else {+ if (p_temp(&parts[i])>=256.0f+273.15f)+ p_set_temp(&parts[i], 256.0f+273.15f);+ if (p_temp(&parts[i])<= -256.0f+273.15f)+ p_set_temp(&parts[i], -256.0f+273.15f);+ gravmass[(y )/ACELL][(x)/ACELL] = 0.2f * (p_temp(&parts[i]) - 273.15);+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_GPMP) {+ if (parts[ID(r)].life<10&&parts[ID(r)].life>0)+ parts[i].life = 9;+ else if (parts[ID(r)].life==0)+ parts[ID(r)].life = 10;+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- WIFI */+int el_WIFI_update(UPDATE_FUNC_ARGS) {+ parts[i].tmp = (int)((p_temp(&parts[i])-73.15f)/100+1);+ if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1;+ else if (parts[i].tmp<0) parts[i].tmp = 0;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ // wireless[][0] - whether channel is active on this frame+ // wireless[][1] - whether channel should be active on next frame+ if (wireless[parts[i].tmp][0]) {+ if ((TYP(r)==PT_NSCN||TYP(r)==PT_PSCN||TYP(r)==PT_INWR)&&parts[ID(r)].life==0 && wireless[parts[i].tmp][0]) {+ parts[ID(r)].ctype = TYP(r);+ part_change_type(ID(r),x+rx,y+ry,PT_SPRK);+ parts[ID(r)].life = 4;+ }+ }+ if (TYP(r)==PT_SPRK && parts[ID(r)].ctype!=PT_NSCN && parts[ID(r)].life>=3) {+ wireless[parts[i].tmp][1] = 1;+ ISWIRE = 2;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- WIRE */+int el_WIRE_update(UPDATE_FUNC_ARGS) {+ int count=0;+ /*+ 0: wire+ 1: spark head+ 2: spark tail+ tmp is previous state, ctype is current state+ */+ //parts[i].tmp=parts[i].ctype;+ parts[i].ctype=0;+ if (parts[i].tmp==1) {+ parts[i].ctype=2;+ } else if (parts[i].tmp==2) {+ parts[i].ctype=0;+ }+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_SPRK && parts[ID(r)].life==3 && parts[ID(r)].ctype==PT_PSCN) {+ parts[i].ctype=1;+ return 0;+ } else if (TYP(r)==PT_NSCN && parts[i].tmp==1)+ create_part(-1, x+rx, y+ry, PT_SPRK, -1);+ else if (TYP(r)==PT_WIRE && parts[ID(r)].tmp==1 && !parts[i].tmp)+ count++;+ }+ }+ }+ if (count==1 || count==2)+ parts[i].ctype=1;+ return 0;+}++/* ---------------------------------------------------------------- ARAY */+int el_ARAY_update(UPDATE_FUNC_ARGS) {+ int short_bray_life = parts[i].life > 0 ? parts[i].life : 30;+ int long_bray_life = parts[i].life > 0 ? parts[i].life : 1020;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r) == PT_SPRK && parts[ID(r)].life == 3) {+ int destroy = (parts[ID(r)].ctype==PT_PSCN) ? 1 : 0;+ int nostop = (parts[ID(r)].ctype==PT_INST) ? 1 : 0;+ int colored = 0, rt;+ for (int docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1; docontinue; nyy+=nyi, nxx+=nxi) {+ if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0))+ break;+ r = PMAPAT(x+nxi+nxx, y+nyi+nyy);+ rt = TYP(r);+ r = ID(r);+ if (!rt) {+ int nr = create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY, -1);+ if (nr != -1) {+ // if it came from PSCN+ if (destroy) {+ parts[nr].tmp = 2;+ parts[nr].life = 2;+ } else {+ parts[nr].ctype = colored;+ parts[nr].life = short_bray_life;+ }+ p_set_temp(&parts[nr], p_temp(&parts[i]));+ }+ } else if (!destroy) {+ if (rt == PT_BRAY) {+ // cases for hitting different BRAY modes+ switch(parts[r].tmp) {+ // normal white+ case 0:+ if (nyy != 0 || nxx !=0) {+ parts[r].life = long_bray_life; // makes it last a while+ parts[r].tmp = 1;+ if (!parts[r].ctype) // and colors it if it isn't already+ parts[r].ctype = colored;+ }+ // red bray or any other random tmp mode, stop+ /* fallthrough */+ case 2:+ default:+ docontinue = 0;+ break;+ // long life, reset it+ case 1:+ parts[r].life = long_bray_life;+ //docontinue = 1;+ break;+ }+ }+ // get color if passed through FILT+ else if (rt == PT_FILT) {+ if (parts[r].tmp != 6) {+ colored = Element_FILT_interactWavelengths(&parts[r], colored);+ if (!colored)+ break;+ }+ /* (decoration isn't kept: never black) */+ parts[r].life = 4;+ } else if (rt == PT_STOR) {+ if (parts[r].tmp & 0xFF) {+ //Cause STOR to release+ for (int ry1 = 1; ry1 >= -1; ry1--) {+ for (int rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1 - rx1 + 1) {+ int np = create_part(-1, x + nxi + nxx + rx1, y + nyi + nyy + ry1, TYP(parts[r].tmp), -1);+ if (np != -1) {+ p_set_temp(&parts[np], p_temp(&parts[r]));+ parts[np].life = parts[r].tmp2;+ parts[np].tmp = parts[r].tmp3;+ parts[np].ctype = tmp4_get(r);+ parts[r].tmp &= ~0xFF;+ parts[r].life = 10;+ break;+ }+ }+ }+ } else {+ parts[r].life = 10;+ }+ // this if prevents BRAY from stopping on certain materials+ } else if (rt != PT_INWR && (rt != PT_SPRK || parts[r].ctype != PT_INWR) && rt != PT_ARAY && rt != PT_WIFI && !(rt == PT_SWCH && parts[r].life >= 10)) {+ if (nyy!=0 || nxx!=0)+ create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_SPRK, -1);+ if (!(nostop && parts[r].type==PT_SPRK && parts[r].ctype >= 0 && parts[r].ctype < PT_NUM && (elements[parts[r].ctype].Properties&PROP_CONDUCTS)))+ docontinue = 0;+ else+ docontinue = 1;+ }+ } else if (destroy) {+ if (rt == PT_BRAY) {+ parts[r].tmp = 2;+ parts[r].life = 1;+ docontinue = 1;+ //this if prevents red BRAY from stopping on certain materials+ } else if (rt==PT_STOR || rt==PT_INWR || (rt==PT_SPRK && parts[r].ctype==PT_INWR) || rt==PT_ARAY || rt==PT_WIFI || rt==PT_FILT || (rt==PT_SWCH && parts[r].life>=10)) {+ if (rt == PT_STOR) {+ parts[r].tmp &= ~0xFF;+ parts[r].life = 0;+ } else if (rt == PT_FILT) {+ /* (decoration isn't kept: never black) */+ parts[r].life = 2;+ }+ docontinue = 1;+ } else {+ docontinue = 0;+ }+ }+ }+ }+ //parts[i].life = 4;+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- CRAY */+int el_CRAY_update(UPDATE_FUNC_ARGS) {+ int nxx, nyy, docontinue, nxi, nyi;+ // set ctype to things that touch it if it doesn't have one already+ if (parts[i].ctype<=0 || !elements[TYP(parts[i].ctype)].Enabled) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ int r = PHOTAT(x+rx, y+ry);+ if (!r)+ r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)!=PT_CRAY && TYP(r)!=PT_PSCN && TYP(r)!=PT_INST && TYP(r)!=PT_METL && TYP(r)!=PT_SPRK && TYP(r)<PT_NUM) {+ parts[i].ctype = TYP(r);+ p_set_temp(&parts[i], p_temp(&parts[ID(r)]));+ }+ }+ }+ } else {+ for (int rx =-1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_SPRK && parts[ID(r)].life==3) { //spark found, start creating+ bool destroy = parts[ID(r)].ctype==PT_PSCN;+ bool nostop = parts[ID(r)].ctype==PT_INST;+ bool createSpark = (parts[ID(r)].ctype==PT_INWR);+ int partsRemaining = 255;+ if (parts[i].tmp) //how far it shoots+ partsRemaining = parts[i].tmp;+ int spacesRemaining = parts[i].tmp2;+ for (docontinue = 1, nxi = rx*-1, nyi = ry*-1, nxx = spacesRemaining*nxi, nyy = spacesRemaining*nyi; docontinue; nyy+=nyi, nxx+=nxi) {+ if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0)) {+ break;+ }+ r = PMAPAT(x+nxi+nxx, y+nyi+nyy);+ if (!IsWallBlocking(x+nxi+nxx, y+nyi+nyy, TYP(parts[i].ctype)) && (!PMAPAT(x+nxi+nxx, y+nyi+nyy) || createSpark)) { // create, also set color if it has passed through FILT+ int nr = create_part(-1, x+nxi+nxx, y+nyi+nyy, TYP(parts[i].ctype), ID(parts[i].ctype));+ if (nr!=-1) {+ p_set_temp(&parts[nr], p_temp(&parts[i]));+ if (parts[i].life>0)+ parts[nr].life = parts[i].life;+ if(!--partsRemaining)+ docontinue = 0;+ }+ } else if (TYP(r)==PT_FILT) { // get color if passed through FILT+ /* (the decoration colour it would give what it makes isn't kept) */+ parts[ID(r)].life = 4;+ } else if (TYP(r) == PT_CRAY || nostop) {+ docontinue = 1;+ } else if(destroy && r && (TYP(r) != PT_DMND)) {+ kill_part(ID(r));+ if(!--partsRemaining)+ docontinue = 0;+ } else+ docontinue = 0;+ if(!partsRemaining)+ docontinue = 0;+ }+ }+ }+ }+ }+ }+ return 0;+}+bool el_CRAY_ctypeDraw(CTYPEDRAW_FUNC_ARGS) {+ if (!ctypeDrawVInCtype(CTYPEDRAW_FUNC_SUBCALL_ARGS)) {+ return false;+ }+ if (t == PT_LIGH) {+ parts[i].ctype |= PMAPID(30);+ }+ p_set_temp(&parts[i], elements[t].DefaultProperties.temp);+ return true;+}++/* ---------------------------------------------------------------- DRAY */+int el_DRAY_update(UPDATE_FUNC_ARGS) {+ int ctype = TYP(parts[i].ctype), ctypeExtra = ID(parts[i].ctype), copyLength = parts[i].tmp, copySpaces = parts[i].tmp2;+ if (copySpaces < 0)+ copySpaces = parts[i].tmp2 = 0;+ if (copyLength < 0)+ copyLength = parts[i].tmp = 0;+ else if (copyLength > 0)+ copySpaces++; //strange hack+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (TYP(r) == PT_SPRK && parts[ID(r)].life == 3) { //spark found, start creating+ bool overwrite = parts[ID(r)].ctype == PT_PSCN;+ int partsRemaining = copyLength, xCopyTo = -1, yCopyTo = -1; //positions where the line will start being copied at+ int localCopyLength = copyLength;+ if (parts[ID(r)].ctype == PT_INWR && rx && ry) // INWR doesn't spark from diagonals+ continue;+ //figure out where the copying will start/end+ bool foundParticle = false;+ bool isEnergy = false;+ for (int xStep = rx*-1, yStep = ry*-1, xCurrent = x+xStep, yCurrent = y+yStep; ; xCurrent+=xStep, yCurrent+=yStep) {+ // Out of bounds, stop looking and don't copy anything+ if (!InBounds(xCurrent, yCurrent))+ break;+ int rr;+ // haven't found a particle yet, keep looking for one+ // the first particle it sees decides whether it will copy energy particles or not+ if (!foundParticle) {+ rr = PMAPAT(xCurrent, yCurrent);+ if (!rr) {+ rr = PHOTAT(xCurrent, yCurrent);+ if (rr)+ foundParticle = isEnergy = true;+ } else+ foundParticle = true;+ }+ // now that it knows what kind of particle it is copying, do some extra stuff here so we can determine when to stop+ if ((ctype && elements[ctype].Properties&TYPE_ENERGY) || isEnergy)+ rr = PHOTAT(xCurrent, yCurrent);+ else+ rr = PMAPAT(xCurrent, yCurrent);+ // Checks for when to stop:+ // 1: if .tmp isn't set, and the element in this spot is the ctype, then stop+ // 2: if .tmp is set, stop when the length limit reaches 0+ if ((!localCopyLength && TYP(rr) == ctype && (ctype != PT_LIFE || parts[ID(rr)].ctype == ctypeExtra))+ || !--partsRemaining) {+ localCopyLength -= partsRemaining;+ xCopyTo = xCurrent + xStep*copySpaces;+ yCopyTo = yCurrent + yStep*copySpaces;+ break;+ }+ }+ // now, actually copy the particles+ partsRemaining = localCopyLength + 1;+ int type, p;+ for (int xStep = rx*-1, yStep = ry*-1, xCurrent = x+xStep, yCurrent = y+yStep; InBounds(xCopyTo, yCopyTo) && --partsRemaining; xCurrent+=xStep, yCurrent+=yStep, xCopyTo+=xStep, yCopyTo+=yStep) {+ // get particle to copy+ if (isEnergy)+ type = TYP(PHOTAT(xCurrent, yCurrent));+ else+ type = TYP(PMAPAT(xCurrent, yCurrent));+ // if sparked by PSCN, overwrite whatever is in the target location, instead of just ignoring it+ if (overwrite) {+ if (isEnergy) {+ if (PHOTAT(xCopyTo, yCopyTo))+ kill_part(ID(PHOTAT(xCopyTo, yCopyTo)));+ } else {+ if (PMAPAT(xCopyTo, yCopyTo))+ kill_part(ID(PMAPAT(xCopyTo, yCopyTo)));+ }+ }+ if (type == PT_SPRK) // spark hack+ p = create_part(-1, xCopyTo, yCopyTo, PT_METL, -1);+ else if (type == PT_STKM || type == PT_STKM2)+ continue; // do not try to copy these non-copyable particles+ else if (type)+ p = create_part(-1, xCopyTo, yCopyTo, type, -1);+ else+ continue;+ // if new particle was created successfully+ if (p >= 0) {+ if (type == PT_SPRK) // spark hack+ part_change_type(p, xCopyTo, yCopyTo, PT_SPRK);+ int src = isEnergy ? ID(PHOTAT(xCurrent, yCurrent)) : ID(PMAPAT(xCurrent, yCurrent));+ if (isEnergy || type != PT_FIGH) {+ parts[p] = parts[src];+ if (type == PT_PIPE || type == PT_PPIP)+ tmp4_set(p, tmp4_get(src)); /* (the part of tmp4 kept by particle id) */+ } else {+ // FIGH needs special rules+ const Particle *other = &parts[src];+ // need to keep .tmp consistent: it points to fighter metadata+ int old_tmp = parts[p].tmp;+ parts[p] = *other;+ parts[p].tmp = (int16_t)old_tmp;+ // Update the new fighter's metadata+ // Do not attempt to copy kinematics of legs - overwritten next frame anyway+ if (other->tmp >= 0 && other->tmp < MAX_FIGHTERS) {+ const playerst *source_pst = &fighters[other->tmp];+ playerst *this_pst = &fighters[old_tmp];+ this_pst->rocketBoots = source_pst->rocketBoots;+ this_pst->fan = source_pst->fan;+ this_pst->elem = source_pst->elem;+ }+ }+ p_set_x(&parts[p], (float)(xCopyTo));+ p_set_y(&parts[p], (float)(yCopyTo));+ }+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- TESC */+void el_TESC_create(ELEMENT_CREATE_FUNC_ARGS) {+ if (v >= 0) {+ parts[i].tmp = v;+ if (parts[i].tmp > 300)+ parts[i].tmp = 300;+ }+}++/* ---------------------------------------------------------------- EMP */+/* Probability.cpp: P(X >= 1) for X ~ binomial(n, p), and binomial numbers up to a small maximum */+static float binomial_gte1(int n, float p) { return 1.0f - powf(1.0f - p, (float)n); }+typedef struct { float stepSize; unsigned maxK; float cdf[10]; } DeltaTempGenerator;+static void DeltaTempGenerator_init(DeltaTempGenerator *g, unsigned n, float p, float tempStep) {+ g->stepSize = tempStep;+ /* hardcoded limit of 10, to avoid massive lag if someone adds a few zeroes to MAX_TEMP */+ g->maxK = (MAX_TEMP / tempStep < 10) ? ((unsigned)(MAX_TEMP / tempStep) + 1) : 10;+ float pTerm = powf(1.0f - p, (float)n); /* the p^k * (1-p)^(n-k) term */+ unsigned coeffN = 1, coeffD = 1; /* n!/(k!(n-k)!) as coeffN / coeffD */+ float sum = 0;+ for (unsigned k = 0; k < g->maxK; k++) {+ sum += pTerm * ((float)coeffN / coeffD);+ g->cdf[k] = sum;+ pTerm *= p / (1.0f - p);+ coeffN *= n - k;+ coeffD *= k + 1;+ }+}+static void DeltaTempGenerator_apply(const DeltaTempGenerator *g, Particle *p) {+ float randFloat = rng_uniform01();+ unsigned k = 0;+ while (k < g->maxK && !(randFloat < g->cdf[k])) k++;+ p_set_temp(p, restrict_flt(p_temp(p) + k * g->stepSize, MIN_TEMP, MAX_TEMP));+}+void Element_EMP_Trigger(int triggerCount) {+ /* Known differences from original one-particle-at-a-time version:+ * - SPRK that disappears during a frame (such as SPRK with life==0 on that frame) will not cause destruction around it.+ * - SPRK neighbour effects are calculated assuming the SPRK exists and causes destruction around it for the entire frame (so was not turned into BREL/NTCT partway through). This means mass EMP will be more destructive.+ * - The chance of a METL particle near sparked semiconductor turning into BRMT within 1 frame is different if triggerCount>2. See comment for prob_breakMETLMore.+ * - Probability of centre isElec particle breaking is slightly different (1/48 instead of 1-(1-1/80)*(1-1/120) = just under 1/48).+ */+ float prob_changeCenter = binomial_gte1(triggerCount, 1.0f/48);+ DeltaTempGenerator temp_center, temp_metal, temp_SWCH;+ DeltaTempGenerator_init(&temp_center, (unsigned)triggerCount, 1.0f/100, 3000.0f);+ float prob_breakMETL = binomial_gte1(triggerCount, 1.0f/300);+ float prob_breakBMTL = binomial_gte1(triggerCount, 1.0f/160);+ DeltaTempGenerator_init(&temp_metal, (unsigned)triggerCount, 1.0f/280, 3000.0f);+ /* Probability of breaking from BMTL to BRMT, given that the particle has just broken from METL to BMTL. There is no mathematical reasoning for the numbers used, other than:+ * - larger triggerCount should make this more likely, so it should depend on triggerCount instead of being a constant probability+ * - triggerCount==1 should make this a chance of 0 (matching previous behaviour)+ * - triggerCount==2 should make this a chance of 1/160 (matching previous behaviour)+ */+ // TODO: work out in a more mathematical way what this should be?+ float prob_breakMETLMore = binomial_gte1(triggerCount/2, 1.0f/160);+ float prob_randWIFI = binomial_gte1(triggerCount, 1.0f/8);+ float prob_breakWIFI = binomial_gte1(triggerCount, 1.0f/16);+ float prob_breakSWCH = binomial_gte1(triggerCount, 1.0f/100);+ DeltaTempGenerator_init(&temp_SWCH, (unsigned)triggerCount, 1.0f/100, 2000.0f);+ float prob_breakARAY = binomial_gte1(triggerCount, 1.0f/60);+ float prob_randDLAY = binomial_gte1(triggerCount, 1.0f/70);+ for (int r = 0; r < parts_active; r++) {+ int t = parts[r].type;+ int rx = (int)(p_x(&parts[r]));+ int ry = (int)(p_y(&parts[r]));+ if (t==PT_SPRK || (t==PT_SWCH && parts[r].life!=0 && parts[r].life!=10) || (t==PT_WIRE && parts[r].ctype>0)) {+ bool is_elec = false;+ if (parts[r].ctype==PT_PSCN || parts[r].ctype==PT_NSCN || parts[r].ctype==PT_PTCT ||+ parts[r].ctype==PT_NTCT || parts[r].ctype==PT_INST || parts[r].ctype==PT_SWCH || t==PT_WIRE || t==PT_SWCH) {+ is_elec = true;+ DeltaTempGenerator_apply(&temp_center, &parts[r]);+ //@ EMP + PSCN/NSCN/PTCT/NTCT/INST/SWCH/WIRE -> EMP + BREC/NTCT+ if (rng_uniform01() < prob_changeCenter) {+ if (rng_chance(2, 5))+ part_change_type(r, rx, ry, PT_BREC);+ else+ part_change_type(r, rx, ry, PT_NTCT);+ }+ }+ for (int nx =-2; nx <= 2; nx++)+ for (int ny =-2; ny <= 2; ny++)+ if (rx+nx>=0 && ry+ny>=0 && rx+nx<XRES && ry+ny<YRES && (rx || ry)) {+ int n = PMAPAT(rx+nx, ry+ny);+ if (!n)+ continue;+ int ntype = TYP(n);+ n = ID(n);+ //Some elements should only be affected by wire/swch, or by a spark on inst/semiconductor+ //So not affected by spark on metl, watr etc+ if (is_elec) {+ switch (ntype) {+ case PT_METL:+ DeltaTempGenerator_apply(&temp_metal, &parts[n]);+ if (rng_uniform01() < prob_breakMETL) {+ //@ EMP + METL -> EMP + BMTL/BRMT+ part_change_type(n, rx+nx, ry+ny, PT_BMTL);+ if (rng_uniform01() < prob_breakMETLMore) {+ part_change_type(n, rx+nx, ry+ny, PT_BRMT);+ p_set_temp(&parts[n], restrict_flt(p_temp(&parts[n])+1000.0f, MIN_TEMP, MAX_TEMP));+ }+ }+ break;+ case PT_BMTL:+ //@ EMP + BMTL -> EMP + BRMT+ DeltaTempGenerator_apply(&temp_metal, &parts[n]);+ if (rng_uniform01() < prob_breakBMTL) {+ part_change_type(n, rx+nx, ry+ny, PT_BRMT);+ p_set_temp(&parts[n], restrict_flt(p_temp(&parts[n])+1000.0f, MIN_TEMP, MAX_TEMP));+ }+ break;+ case PT_WIFI:+ if (rng_uniform01() < prob_randWIFI) {+ // Randomize channel+ p_set_temp(&parts[n], (float)(rng_between(0, (int)(MAX_TEMP)-1)));+ }+ //@ EMP + WIFI -> EMP + BREC+ if (rng_uniform01() < prob_breakWIFI) {+ create_part(n, rx+nx, ry+ny, PT_BREC, -1);+ p_set_temp(&parts[n], restrict_flt(p_temp(&parts[n])+1000.0f, MIN_TEMP, MAX_TEMP));+ }+ continue;+ default:+ break;+ }+ }+ switch (ntype) {+ case PT_SWCH:+ //@ EMP + SWCH -> EMP + BREC+ if (rng_uniform01() < prob_breakSWCH)+ part_change_type(n, rx+nx, ry+ny, PT_BREC);+ DeltaTempGenerator_apply(&temp_SWCH, &parts[n]);+ break;+ case PT_ARAY:+ //@ EMP + ARAY -> EMP + BREC+ if (rng_uniform01() < prob_breakARAY) {+ create_part(n, rx+nx, ry+ny, PT_BREC, -1);+ p_set_temp(&parts[n], restrict_flt(p_temp(&parts[n])+1000.0f, MIN_TEMP, MAX_TEMP));+ }+ break;+ case PT_DLAY:+ if (rng_uniform01() < prob_randDLAY) {+ // Randomize delay+ p_set_temp(&parts[n], rng_between(0, 255) + 273.15f);+ }+ break;+ default:+ break;+ }+ }+ }+ }+}+diff --git a/games/numpowder/src/el_fire.c b/games/numpowder/src/el_fire.cnew file mode 100644index 00000000..3a5a528f--- /dev/null+++ b/games/numpowder/src/el_fire.c@@ -0,0 +1,1229 @@+/* NumPowder: The Powder Toy's fire and explosives (their files in elements/), ported: FIRE (and LAVA, PLSM), CFLM,+ * COAL (and BCOL), IGNT, FUSE, FSEP, BANG, BOMB, C5, DEST, FIRW, FWRK, GBMB, LIGH, THDR, EMBR, LITH. */+#include "simpriv.h"++/* ---------------------------------------------------------------- FIRE */+static int FIRE_updateLegacy(UPDATE_FUNC_ARGS);+int Element_FIRE_update(UPDATE_FUNC_ARGS) {+ int t = parts[i].type;+ switch (t) {+ case PT_PLSM:+ if (parts[i].life <=1) {+ if (parts[i].ctype == PT_NBLE) {+ //@ PLSM(NBLE) -> NBLE+ part_change_type(i,x,y,PT_NBLE);+ parts[i].life = 0;+ } else if ((parts[i].tmp&0x3) == 3) {+ //@ PLSM + O2 + H2 -> WTRV(FIRE)+ part_change_type(i,x,y,PT_WTRV);+ parts[i].life = 0;+ parts[i].ctype = PT_FIRE;+ }+ }+ break;+ case PT_FIRE:+ if (parts[i].life <=1) {+ if ((parts[i].tmp&0x3) == 3) {+ //@ FIRE + O2 + H2 -> WTRV(FIRE)+ part_change_type(i,x,y,PT_WTRV);+ parts[i].life = 0;+ parts[i].ctype = PT_FIRE;+ } else if (p_temp(&parts[i])<625) {+ //@ FIRE -> SMKE+ part_change_type(i,x,y,PT_SMKE);+ parts[i].life = rng_between(250, 269);+ }+ }+ break;+ case PT_LAVA: {+ float pres = pv[y / ACELL][x / ACELL];+ if (parts[i].ctype == PT_ROCK) {+ if (pres <= -9) {+ //@ LAVA(ROCK) -> LAVA(STNE)+ parts[i].ctype = PT_STNE;+ break;+ }+ if (pres >= 25 && rng_chance(1, 12500)) {+ if (pres <= 50) {+ //@ LAVA(ROCK) -> LAVA(BRMT/CNCT)+ if (rng_chance(1, 2))+ parts[i].ctype = PT_BRMT;+ else+ parts[i].ctype = PT_CNCT;+ } else if (pres <= 75) {+ //@ LAVA(ROCK) -> LAVA(GOLD/QRTZ)+ if (pres >= 73 || rng_chance(1, 8))+ parts[i].ctype = PT_GOLD;+ else+ parts[i].ctype = PT_QRTZ;+ } else if (pres <= 100 && p_temp(&parts[i]) >= 5000) {+ //@ LAVA(ROCK) -> LAVA(TTAN/IRON)+ if (rng_chance(1, 5)) // 1 in 5 chance IRON to TTAN+ parts[i].ctype = PT_TTAN;+ else+ parts[i].ctype = PT_IRON;+ } else if (p_temp(&parts[i]) >= 5000 && rng_chance(1, 5)) {+ //@ LAVA(ROCK) -> LAVA(URAN/PLUT/TUNG)+ if (rng_chance(1, 5))+ parts[i].ctype = PT_URAN;+ else if (rng_chance(1, 5))+ parts[i].ctype = PT_PLUT;+ else+ parts[i].ctype = PT_TUNG;+ }+ }+ } else if (parts[i].ctype == PT_GOLD && pres < -200.0f && p_temp(&parts[i]) > elements[PT_PTNM].HighTemperature && rng_chance(1, 20000)) {+ //@ LAVA(GOLD) -> LAVA(PTNM)+ parts[i].ctype = PT_PTNM;+ pv[y/ACELL][x/ACELL] += 2.0f;+ } else if ((parts[i].ctype == PT_STNE || !parts[i].ctype) && pres >= 30.0f && (p_temp(&parts[i]) > elements[PT_ROCK].HighTemperature || pres < elements[PT_ROCK].HighPressure)) { // Form ROCK with pressure, if it will stay molten or not immediately break+ //@ LAVA -> LAVA(ROCK)+ parts[i].tmp2 = rng_between(0, 10); // Provide tmp2 for color noise+ parts[i].ctype = PT_ROCK;+ }+ break;+ }+ default:+ break;+ }+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ //THRM burning+ if (rt==PT_THRM && (t==PT_FIRE || t==PT_PLSM || t==PT_LAVA)) {+ //@ FIRE/PLSM/LAVA + THRM -> FIRE/PLSM/LAVA + LAVA(BMTL/THRM)+ if (rng_chance(1, 500)) {+ part_change_type(ID(r),x+rx,y+ry,PT_LAVA);+ parts[ID(r)].ctype = PT_BMTL;+ p_set_temp(&parts[ID(r)], 3500.0f);+ pv[(y+ry)/ACELL][(x+rx)/ACELL] += 50.0f;+ } else {+ part_change_type(ID(r),x+rx,y+ry,PT_LAVA);+ parts[ID(r)].life = 400;+ parts[ID(r)].ctype = PT_THRM;+ p_set_temp(&parts[ID(r)], 3500.0f);+ parts[ID(r)].tmp = 20;+ }+ continue;+ }+ if ((rt==PT_COAL) || (rt==PT_BCOL)) {+ if ((t==PT_FIRE || t==PT_PLSM)) {+ if (parts[ID(r)].life>100 && rng_chance(1, 500)) {+ parts[ID(r)].life = 99;+ }+ } else if (t==PT_LAVA) {+ //@ LAVA(IRON) + COAL/BCOL -> LAVA(METL)+ if (parts[i].ctype == PT_IRON && rng_chance(1, 500)) {+ parts[i].ctype = PT_METL;+ kill_part(ID(r));+ continue;+ }+ //@ LAVA + COAL/BCOL -> LAVA(SLCN)+ if ((parts[i].ctype == PT_STNE || parts[i].ctype == PT_NONE) && rng_chance(1, 60)) {+ parts[i].ctype = PT_SLCN;+ kill_part(ID(r));+ continue;+ }+ }+ }+ if (t == PT_LAVA) {+ //@ LAVA(QRTZ) + LAVA(CLST) -> 2xLAVA(CRMC)+ if (parts[i].ctype == PT_QRTZ && rt == PT_LAVA && parts[ID(r)].ctype == PT_CLST) {+ float pres = fmaxf(pv[y/ACELL][x/ACELL]*10.0f, 0.0f);+ if (p_temp(&parts[i]) >= pres+elements[PT_CRMC].HighTemperature+50.0f) {+ parts[i].ctype = PT_CRMC;+ parts[ID(r)].ctype = PT_CRMC;+ }+ } else if (rt == PT_O2 && parts[i].ctype == PT_SLCN) {+ //@ LAVA(SLCN) + O2 -> LAVA(SAND/CLST/PQRT/STNE)+ switch (rng_between(0, 2)) {+ case 0:+ parts[i].ctype = PT_SAND;+ break;+ case 1:+ parts[i].ctype = PT_CLST;+ // avoid creating CRMC.+ if (p_temp(&parts[i]) >= elements[PT_PQRT].HighTemperature * 3) {+ parts[i].ctype = PT_PQRT;+ }+ break;+ case 2:+ parts[i].ctype = PT_STNE;+ break;+ }+ parts[i].tmp = 0;+ kill_part(ID(r));+ continue;+ } else if (rt == PT_LAVA && (parts[ID(r)].ctype == PT_METL || parts[ID(r)].ctype == PT_BMTL) && parts[i].ctype == PT_SLCN) {+ //@ LAVA(SLCN) + LAVA(METL/BMTL) -> LAVA(NSCN) + LAVA(PSCN)+ parts[i].tmp = 0;+ parts[i].ctype = PT_NSCN;+ parts[ID(r)].ctype = PT_PSCN;+ } else if (parts[i].ctype == PT_SLCN && rt == PT_LAVA && parts[ID(r)].ctype == PT_SALT) {+ //@ LAVA(SLCN) + LAVA(SALT) -> LAVA(LITH)+ if (p_temp(&parts[i]) > elements[PT_LITH].HighTemperature && rng_chance(1, 1000)) {+ parts[i].ctype = PT_LITH;+ parts[i].tmp = 0;+ parts[i].tmp2 = 0;+ parts[i].life = 0;+ kill_part(ID(r));+ continue;+ }+ } else if (rt == PT_HEAC && parts[i].ctype == PT_HEAC) {+ if (p_temp(&parts[ID(r)]) > elements[PT_HEAC].HighTemperature) {+ part_change_type(ID(r), x+rx, y+ry, PT_LAVA);+ parts[ID(r)].ctype = PT_HEAC;+ }+ } else if (parts[i].ctype == PT_ROCK && rt == PT_LAVA && parts[ID(r)].ctype == PT_GOLD && parts[ID(r)].tmp == 0 &&+ pv[y / ACELL][x / ACELL] >= 50 && rng_chance(1, 10000)) { // Produce GOLD veins/clusters+ //@ LAVA(ROCK) + LAVA(GOLD) -> 2xLAVA(GOLD)+ parts[i].ctype = PT_GOLD;+ if (rx > 1 || rx < -1) // Trend veins vertical+ parts[i].tmp = 1;+ } else if (parts[i].ctype == PT_SALT && rt == PT_GLAS && parts[ID(r)].life < 234 * 120) {+ parts[ID(r)].life++;+ }+ }+ if ((surround_space || elements[rt].Explosive) &&+ elements[rt].Flammable && rng_chance((int)(elements[rt].Flammable + (pv[(y+ry)/ACELL][(x+rx)/ACELL] * 10.0f)), 1000) &&+ //exceptions, t is the thing causing the spark and rt is what's burning+ (t != PT_SPRK || (rt != PT_RBDM && rt != PT_LRBD && rt != PT_INSL)) &&+ (t != PT_PHOT || rt != PT_INSL) &&+ (rt != PT_SPNG || parts[ID(r)].life == 0)) {+ part_change_type(ID(r), x+rx, y+ry, PT_FIRE);+ p_set_temp(&parts[ID(r)], restrict_flt(elements[PT_FIRE].DefaultProperties.temp + (elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP));+ parts[ID(r)].life = rng_between(180, 259);+ parts[ID(r)].tmp = parts[ID(r)].ctype = 0;+ if (elements[rt].Explosive)+ pv[y/ACELL][x/ACELL] += 0.25f * CFDS;+ }+ }+ }+ }+ if (legacy_enable && t!=PT_SPRK) // SPRK has no legacy reactions+ FIRE_updateLegacy(UPDATE_FUNC_SUBCALL_ARGS);+ return 0;+}+static int FIRE_updateLegacy(UPDATE_FUNC_ARGS) {+ int t = parts[i].type;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (bmap[(y+ry)/WCELL][(x+rx)/WCELL] && bmap[(y+ry)/WCELL][(x+rx)/WCELL]!=WL_STREAM)+ continue;+ int rt = TYP(r);+ int lpv = (int)pv[(y+ry)/ACELL][(x+rx)/ACELL];+ if (lpv < 1) lpv = 1;+ if (elements[rt].Meltable &&+ ((rt!=PT_RBDM && rt!=PT_LRBD) || t!=PT_SPRK)+ && ((t!=PT_FIRE&&t!=PT_PLSM) || (rt!=PT_METL && rt!=PT_IRON && rt!=PT_ETRD && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SALT && rt!=PT_INWR))+ && rng_chance(elements[rt].Meltable*lpv, 1000)) {+ if (t!=PT_LAVA || parts[i].life>0) {+ if (rt==PT_BRMT)+ parts[ID(r)].ctype = PT_BMTL;+ else if (rt==PT_SAND)+ parts[ID(r)].ctype = PT_GLAS;+ else+ parts[ID(r)].ctype = rt;+ part_change_type(ID(r),x+rx,y+ry,PT_LAVA);+ parts[ID(r)].life = rng_between(240, 359);+ } else {+ parts[i].life = 0;+ parts[i].ctype = PT_NONE;//rt;+ part_change_type(i,x,y,(parts[i].ctype)?parts[i].ctype:PT_STNE);+ return 1;+ }+ }+ if (rt==PT_ICEI || rt==PT_SNOW) {+ part_change_type(ID(r), x+rx, y+ry, PT_WATR);+ if (t==PT_FIRE) {+ kill_part(i);+ return 1;+ }+ if (t==PT_LAVA) {+ parts[i].life = 0;+ part_change_type(i,x,y,PT_STNE);+ }+ }+ if (rt==PT_WATR || rt==PT_DSTW || rt==PT_SLTW) {+ kill_part(ID(r));+ if (t==PT_FIRE) {+ kill_part(i);+ return 1;+ }+ if (t==PT_LAVA) {+ parts[i].life = 0;+ parts[i].ctype = PT_NONE;+ part_change_type(i,x,y,(parts[i].ctype)?parts[i].ctype:PT_STNE);+ }+ }+ }+ }+ }+ return 0;+}+void el_FIRE_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].life = rng_between(120, 169);+}++/* ---------------------------------------------------------------- LAVA */+void el_LAVA_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].life = rng_between(240, 359);+}++/* ---------------------------------------------------------------- PLSM */+void el_PLSM_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].life = rng_between(50, 199);+}++/* ---------------------------------------------------------------- CFLM */+void el_CFLM_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].life = rng_between(50, 199);+}++/* ---------------------------------------------------------------- COAL */+int Element_COAL_update(UPDATE_FUNC_ARGS) {+ if (parts[i].life<=0) {+ create_part(i, x, y, PT_FIRE, -1);+ return 1;+ } else if (parts[i].life < 100) {+ parts[i].life--;+ create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), PT_FIRE, -1);+ }+ if (parts[i].type == PT_COAL) {+ if ((pv[y/ACELL][x/ACELL] > 4.3f)&&parts[i].tmp>40)+ parts[i].tmp=39;+ else if (parts[i].tmp<40&&parts[i].tmp>0)+ parts[i].tmp--;+ else if (parts[i].tmp<=0) {+ //@ COAL -> BCOL+ part_change_type(i, x, y, PT_BCOL);+ return 1;+ }+ }+ if(p_temp(&parts[i]) > parts[i].tmp2)+ parts[i].tmp2 = (int)(p_temp(&parts[i]));+ return 0;+}++/* ---------------------------------------------------------------- IGNT */+int el_IGNT_update(UPDATE_FUNC_ARGS) {+ if(parts[i].tmp==0) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (rt==PT_FIRE || rt==PT_PLSM || rt==PT_SPRK || rt==PT_LIGH || (rt==PT_IGNT && parts[ID(r)].life==1)) {+ parts[i].tmp = 1;+ }+ }+ }+ }+ } else if(parts[i].life > 0) {+ if (rng_chance(2, 3)) {+ //@ IGNT -> IGNT + EMBR+ int nb = create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), PT_EMBR, -1);+ if (nb!=-1) {+ parts[nb].tmp = 0;+ parts[nb].life = 30;+ p_set_vx(&parts[nb], (float)(rng_between(-10, 10)));+ p_set_vy(&parts[nb], (float)(rng_between(-10, 10)));+ p_set_temp(&parts[nb], restrict_flt(p_temp(&parts[i])-273.15f+400.0f, MIN_TEMP, MAX_TEMP));+ }+ } else {+ //@ IGNT -> IGNT + FIRE+ create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), PT_FIRE, -1);+ }+ parts[i].life--;+ }+ return 0;+}++/* ---------------------------------------------------------------- FUSE */+int el_FUSE_update(UPDATE_FUNC_ARGS) {+ //@ FUSE -> FUSE + PLSM+ if (parts[i].life<=0) {+ int r = create_part(i, x, y, PT_PLSM, -1);+ if (r>-1)+ parts[r].life = 50;+ return 1;+ } else if (parts[i].life < 40) {+ parts[i].life--;+ if (rng_chance(1, 100)) {+ int r = create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), PT_PLSM, -1);+ if (r>-1)+ parts[r].life = 50;+ }+ }+ if ((pv[y/ACELL][x/ACELL] > 2.7f) && parts[i].tmp>40)+ parts[i].tmp=39;+ else if (parts[i].tmp<=0) {+ //@ FUSE -> FSEP+ create_part(i, x, y, PT_FSEP, -1);+ return 1;+ } else if (parts[i].tmp<40)+ parts[i].tmp--;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_SPRK || (p_temp(&parts[i])>=(273.15+700.0f) && rng_chance(1, 20))) {+ if (parts[i].life > 40)+ parts[i].life = 39;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- FSEP */+int el_FSEP_update(UPDATE_FUNC_ARGS) {+ //@ FSEP -> FSEP + PLSM+ if (parts[i].life<=0) {+ int r = create_part(i, x, y, PT_PLSM, -1);+ if (r!=-1)+ parts[r].life = 50;+ return 1;+ } else if (parts[i].life < 40) {+ parts[i].life--;+ if (rng_chance(1, 10)) {+ int r = create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), PT_PLSM, -1);+ if (r>-1)+ parts[r].life = 50;+ }+ } else {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if ((TYP(r)==PT_SPRK || (p_temp(&parts[i])>=(273.15+400.0f))) && parts[i].life>40 && rng_chance(1, 15)) {+ parts[i].life = 39;+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- BANG */+int el_BANG_update(UPDATE_FUNC_ARGS) {+ if(parts[i].tmp==0) {+ if(p_temp(&parts[i])>=673.0f)+ parts[i].tmp = 1;+ else {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_FIRE || TYP(r)==PT_PLSM || TYP(r)==PT_SPRK || TYP(r)==PT_LIGH) {+ parts[i].tmp = 1;+ }+ }+ }+ }+ }+ } else if(parts[i].tmp==1) {+ if (PMAPAT(x, y) && ID(PMAPAT(x, y)) == i) {+ flood_prop_int(x, y, FIELD_TMP, 2);+ }+ parts[i].tmp = 2;+ } else if(parts[i].tmp==2) {+ parts[i].tmp = 3;+ } else {+ float otemp = p_temp(&parts[i])-273.15f;+ //Explode!!+ pv[y/ACELL][x/ACELL] += 0.5f;+ parts[i].tmp = 0;+ if (rng_chance(1, 3)) {+ if (rng_chance(1, 2)) {+ //@ BANG -> FIRE+ create_part(i, x, y, PT_FIRE, -1);+ } else {+ //@ BANG -> SMKE+ create_part(i, x, y, PT_SMKE, -1);+ parts[i].life = rng_between(500, 549);+ }+ p_set_temp(&parts[i], restrict_flt((MAX_TEMP/4)+otemp, MIN_TEMP, MAX_TEMP));+ } else {+ if (rng_chance(1, 15)) {+ //@ BANG -> EMBR+ create_part(i, x, y, PT_EMBR, -1);+ parts[i].tmp = 0;+ parts[i].life = 50;+ p_set_temp(&parts[i], restrict_flt((MAX_TEMP/3)+otemp, MIN_TEMP, MAX_TEMP));+ p_set_vx(&parts[i], (float)(rng_between(-10, 10)));+ p_set_vy(&parts[i], (float)(rng_between(-10, 10)));+ } else {+ kill_part(i);+ }+ }+ return 1;+ }+ return 0;+}++/* ---------------------------------------------------------------- BOMB */+int el_BOMB_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (rt!=PT_BOMB && rt!=PT_EMBR && rt!=PT_DMND && rt!=PT_CLNE && rt!=PT_PCLN && rt!=PT_BCLN && rt!=PT_VIBR) {+ const int rad = 8;+ kill_part(i);+ for (int nxj =-rad; nxj<=rad; nxj++) {+ for (int nxi =-rad; nxi<=rad; nxi++) {+ if ((nxi*nxi + nxj*nxj) <= rad*rad) {+ int ynxj = y+nxj, xnxi = x+nxi;+ if ((ynxj < 0) || (ynxj >= YRES) || (xnxi < 0) || (xnxi >= XRES))+ continue;+ int nt = TYP(PMAPAT(xnxi, ynxj));+ if (nt!=PT_DMND && nt!=PT_CLNE && nt!=PT_PCLN && nt!=PT_BCLN && nt!=PT_VIBR) {+ if (nt)+ kill_part(ID(PMAPAT(xnxi, ynxj)));+ pv[ynxj/ACELL][xnxi/ACELL] += 0.1f;+ //@ BOMB -> EMBR+ int nb = create_part(-3, xnxi, ynxj, PT_EMBR, -1);+ if (nb!=-1) {+ parts[nb].tmp = 2;+ parts[nb].life = 2;+ p_set_temp(&parts[nb], MAX_TEMP);+ }+ }+ }+ }+ }+ for (int nxj =-(rad+1); nxj<=(rad+1); nxj++) {+ for (int nxi =-(rad+1); nxi<=(rad+1); nxi++) {+ if ((nxi*nxi + nxj*nxj) <= (rad+1)*(rad+1)) {+ int ynxj = y+nxj, xnxi = x+nxi;+ if ((ynxj < 0) || (ynxj >= YRES) || (xnxi < 0) || (xnxi >= XRES))+ continue;+ if (TYP(PMAPAT(xnxi, ynxj)))+ continue;+ //@ BOMB -> EMBR+ int nb = create_part(-3, xnxi, ynxj, PT_EMBR, -1);+ if (nb!=-1) {+ parts[nb].tmp = 0;+ parts[nb].life = 50;+ p_set_temp(&parts[nb], MAX_TEMP);+ p_set_vx(&parts[nb], (float)(rng_between(-20, 20)));+ p_set_vy(&parts[nb], (float)(rng_between(-20, 20)));+ }+ }+ }+ }+ return 1;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- C5 */+int el_C5_update(UPDATE_FUNC_ARGS) {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if ((TYP(r)!=PT_C5 && p_temp(&parts[ID(r)])<100 && !IsHeatInsulator(&parts[ID(r)])) || TYP(r)==PT_CFLM) {+ if (rng_chance(1, 6)) {+ //@ C5 -> CFLM+ part_change_type(i,x,y,PT_CFLM);+ p_set_temp(&parts[i], 0);+ p_set_temp(&parts[ID(r)], 0);+ parts[i].life = rng_between(50, 199);+ pv[y/ACELL][x/ACELL] += 1.5;+ }+ }+ }+ }+ }+ if (parts[i].ctype && !parts[i].life) {+ /* the photon's velocity (the original's tmp, 16 bits each) is in tmp and tmp3, its place in tmp2 */+ float pvx = parts[i].tmp / 255.0f;+ float pvy = parts[i].tmp3 / 255.0f;+ float dx = (int8_t)(parts[i].tmp2 & 0xFF) / 255.0f;+ float dy = (parts[i].tmp2 >> 8) / 255.0f;+ int r = create_part(-3, x, y, PT_PHOT, -1);+ if (r != -1) {+ parts[r].ctype = parts[i].ctype;+ p_set_x(&parts[r], p_x(&parts[r]) + (dx));+ p_set_y(&parts[r], p_y(&parts[r]) + (dy));+ p_set_vx(&parts[r], pvx);+ p_set_vy(&parts[r], pvy);+ p_set_temp(&parts[r], p_temp(&parts[i]));+ }+ parts[i].ctype = 0;+ parts[i].tmp = 0;+ parts[i].tmp2 = 0;+ parts[i].tmp3 = 0;+ }+ return 0;+}++/* ---------------------------------------------------------------- DEST */+int el_DEST_update(UPDATE_FUNC_ARGS) {+ int rx = rng_between(-2, 2);+ int ry = rng_between(-2, 2);+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ return 0;+ int rt = TYP(r);+ if (rt == PT_DEST || rt == PT_DMND || rt == PT_BCLN || rt == PT_CLNE || rt == PT_PCLN || rt == PT_PBCN)+ return 0;+ if (parts[i].life<=0 || parts[i].life>37) {+ parts[i].life = rng_between(30, 49);+ pv[y/ACELL][x/ACELL]+=60.0f;+ }+ if (rt == PT_PLUT || rt == PT_DEUT) {+ pv[y/ACELL][x/ACELL]+=20.0f;+ if (rng_chance(1, 2)) {+ //@ DEST + PLUT/DEUT -> DEST + NEUT+ create_part(ID(r), x+rx, y+ry, PT_NEUT, -1);+ p_set_temp(&parts[ID(r)], MAX_TEMP);+ pv[y/ACELL][x/ACELL] += 10.0f;+ parts[i].life-=4;+ }+ } else if (rt == PT_INSL) {+ //@ DEST + INSL -> DEST + PLSM+ create_part(ID(r), x+rx, y+ry, PT_PLSM, -1);+ } else if (rng_chance(1, 3)) {+ kill_part(ID(r));+ parts[i].life -= 4*((elements[rt].Properties&TYPE_SOLID)?3:1);+ if (parts[i].life<=0)+ parts[i].life=1;+ } else if (!IsHeatInsulator(&parts[ID(r)]))+ p_set_temp(&parts[ID(r)], MAX_TEMP);+ p_set_temp(&parts[i], MAX_TEMP);+ pv[y/ACELL][x/ACELL] = restrict_flt(pv[y/ACELL][x/ACELL] + 80.0f, MIN_PRESSURE, MAX_PRESSURE);+ return 0;+}++/* ---------------------------------------------------------------- FIRW */+/* the renderer's firwTable (Gradient, 200 colours): the embers' colour in their ctype */+static uint32_t FIRW_colour(int index) {+ static const struct { uint32_t c; float point; } stops[] = {+ {0xFF00FF, 0.00f}, {0x0000FF, 0.20f}, {0x00FFFF, 0.40f}, {0x00FF00, 0.60f}, {0xFFFF00, 0.80f}, {0xFF0000, 1.00f}};+ if (index < 0) index = 0;+ if (index > 199) index = 199;+ float point = index / 200.0f;+ int stop = -1;+ while (stop < 5 && stops[stop + 1].point <= point) ++stop;+ if (stop < 0 || stop >= 5) return 0;+ float f = (point - stops[stop].point) / (stops[stop + 1].point - stops[stop].point);+ unsigned a = (uint8_t)(f * 0xFF);+ uint32_t l = stops[stop].c, r = stops[stop + 1].c, out = 0;+ if (a == 0xFF) return r;+ for (int sh = 0; sh <= 16; sh += 8)+ out |= (uint32_t)(((a * ((r >> sh) & 0xFF) + (0xFF - a) * ((l >> sh) & 0xFF)) & 0xFFFF) / 0xFF) << sh;+ return out;+}+int el_FIRW_update(UPDATE_FUNC_ARGS) {+ if (parts[i].tmp<=0) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (rt==PT_FIRE||rt==PT_PLSM||rt==PT_THDR) {+ float gx, gy, multiplier;+ GetGravityField(x, y, elements[PT_FIRW].Gravity, 1.0f, &gx, &gy);+ if (gx*gx+gy*gy < 0.001f) {+ float angle = rng_between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi)+ gx += sinf(angle)*elements[PT_FIRW].Gravity*0.5f;+ gy += cosf(angle)*elements[PT_FIRW].Gravity*0.5f;+ }+ parts[i].tmp = 1;+ parts[i].life = rng_between(20, 29);+ multiplier = (parts[i].life+20)*0.2f/sqrtf(gx*gx+gy*gy);+ p_set_vx(&parts[i], p_vx(&parts[i]) - (gx*multiplier));+ p_set_vy(&parts[i], p_vy(&parts[i]) - (gy*multiplier));+ return 0;+ }+ }+ }+ }+ } else if (parts[i].tmp==1) {+ if (parts[i].life<=0) {+ parts[i].tmp=2;+ } else {+ parts[i].flags &= (uint8_t)~FLAG_STAGNANT;+ }+ } else { //if (parts[i].tmp>=2)+ unsigned col = FIRW_colour(rng_between(0, 199));+ for (int n=0; n<40; n++) {+ //@ FIRW -> EMBR+ int np = create_part(-3, x, y, PT_EMBR, -1);+ if (np>-1) {+ float magnitude = rng_between(40, 99) * 0.05f;+ float angle = rng_between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi)+ p_set_vx(&parts[np], p_vx(&parts[i])*0.5f + cosf(angle)*magnitude);+ p_set_vy(&parts[np], p_vy(&parts[i])*0.5f + sinf(angle)*magnitude);+ parts[np].ctype = col;+ parts[np].tmp = 1;+ parts[np].life = rng_between(70, 109);+ p_set_temp(&parts[np], (float)(rng_between(5750, 6249)));+ }+ }+ pv[y/ACELL][x/ACELL] += 8.0f;+ kill_part(i);+ return 1;+ }+ return 0;+}++/* ---------------------------------------------------------------- FWRK */+int el_FWRK_update(UPDATE_FUNC_ARGS) {+ if (parts[i].life == 0 && ((surround_space && p_temp(&parts[i])>400 && rng_chance((int)(9+p_temp(&parts[i])/40), 100000)) || parts[i].ctype == PT_DUST)) {+ float gx, gy, multiplier, gmax;+ int randTmp;+ GetGravityField(x, y, elements[PT_FWRK].Gravity, 1.0f, &gx, &gy);+ if (gx*gx+gy*gy < 0.001f) {+ float angle = rng_between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi)+ gx += sinf(angle)*elements[PT_FWRK].Gravity*0.5f;+ gy += cosf(angle)*elements[PT_FWRK].Gravity*0.5f;+ }+ gmax = fmaxf(fabsf(gx), fabsf(gy));+ if (eval_move(PT_FWRK, (int)(x-(gx/gmax)+0.5f), (int)(y-(gy/gmax)+0.5f), NULL)) {+ multiplier = 15.0f/sqrtf(gx*gx+gy*gy);+ //Some variation in speed parallel to gravity direction+ randTmp = rng_between(-100, 100);+ gx += gx*randTmp*0.002f;+ gy += gy*randTmp*0.002f;+ //and a bit more variation in speed perpendicular to gravity direction+ randTmp = rng_between(-100, 100);+ gx += -gy*randTmp*0.005f;+ gy += gx*randTmp*0.005f;+ parts[i].life = rng_between(18, 27);+ parts[i].ctype=0;+ p_set_vx(&parts[i], p_vx(&parts[i]) - (gx*multiplier));+ p_set_vy(&parts[i], p_vy(&parts[i]) - (gy*multiplier));+ return 0;+ }+ }+ if (parts[i].life<3&&parts[i].life>0) {+ int r = rng_between(11, 255);+ int g = rng_between(11, 255);+ int b = rng_between(11, 255);+ int n;+ float angle, magnitude;+ unsigned col = (r<<16) | (g<<8) | b;+ for (n=0; n<40; n++) {+ //@ FWRK -> EMBR+ int np = create_part(-3, x, y, PT_EMBR, -1);+ if (np>-1) {+ magnitude = rng_between(40, 99) * 0.05f;+ angle = rng_between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi)+ p_set_vx(&parts[np], p_vx(&parts[i])*0.5f + cosf(angle)*magnitude);+ p_set_vy(&parts[np], p_vy(&parts[i])*0.5f + sinf(angle)*magnitude);+ parts[np].ctype = col;+ parts[np].tmp = 1;+ parts[np].life = rng_between(70, 109);+ p_set_temp(&parts[np], (float)(rng_between(5750, 6249)));+ }+ }+ pv[y/ACELL][x/ACELL] += 8.0f;+ kill_part(i);+ return 1;+ }+ if (parts[i].life>=45)+ parts[i].life=0;+ return 0;+}++/* ---------------------------------------------------------------- GBMB */+int el_GBMB_update(UPDATE_FUNC_ARGS) {+ if (parts[i].life<=0) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ int r = PMAPAT(x+rx, y+ry);+ if(!r)+ continue;+ if(TYP(r)!=PT_BOMB && TYP(r)!=PT_GBMB &&+ TYP(r)!=PT_CLNE && TYP(r)!=PT_PCLN &&+ TYP(r)!=PT_DMND) {+ parts[i].life=60;+ break;+ }+ }+ }+ }+ if (parts[i].life > 20) {+ gravmass[(y )/ACELL][(x)/ACELL] = 20;+ } else if (parts[i].life >= 1) {+ gravmass[(y )/ACELL][(x)/ACELL] = -80;+ }+ return 0;+}++/* ---------------------------------------------------------------- LIGH */+#define LIGHTING_POWER 0.65f+static void LIGH_create_line_par(int x1, int y1, int x2, int y2, int c, float temp, int life, int tmp, int tmp2, int i);+int el_LIGH_update(UPDATE_FUNC_ARGS) {+ /*+ * tmp2:+ * 0 - bending+ * 1 - bending (particle order deferred)+ * 2 - branching+ * 3 - branching (particle order deferred)+ * 4 - first pixel+ * 5+ normal segment. Starts at 8, counts down and is removed at 5+ *+ * life - power of lightning, influences reaction strength and segment length+ *+ * tmp - angle of lighting, measured in degrees counterclockwise from the positive x direction+ */+ int powderful = (int)(p_temp(&parts[i])*(1+parts[i].life/40)*LIGHTING_POWER); /* (an int: its divisions are whole, as the original's) */+ //Element_FIRE::update(UPDATE_FUNC_SUBCALL_ARGS);+ if (aheat_enable) {+ hv[y/ACELL][x/ACELL] += powderful/50;+ if (hv[y/ACELL][x/ACELL] > MAX_TEMP)+ hv[y/ACELL][x/ACELL] = MAX_TEMP;+ // If the LIGH was so powerful that it overflowed hv, set to max temp+ else if (hv[y/ACELL][x/ACELL] < 0)+ hv[y/ACELL][x/ACELL] = MAX_TEMP;+ }+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if ((surround_space || elements[rt].Explosive) &&+ (rt!=PT_SPNG || parts[ID(r)].life==0) &&+ elements[rt].Flammable && rng_chance(elements[rt].Flammable + (int)(pv[(y+ry)/ACELL][(x+rx)/ACELL] * 10.0f), 1000)) {+ //@ LIGH + flammable -> LIGH + FIRE+ part_change_type(ID(r),x+rx,y+ry,PT_FIRE);+ p_set_temp(&parts[ID(r)], restrict_flt(elements[PT_FIRE].DefaultProperties.temp + (elements[rt].Flammable/2), MIN_TEMP, MAX_TEMP));+ parts[ID(r)].life = rng_between(180, 259);+ parts[ID(r)].tmp = parts[ID(r)].ctype = 0;+ if (elements[rt].Explosive)+ pv[y/ACELL][x/ACELL] += 0.25f * CFDS;+ }+ switch (rt) {+ case PT_LIGH:+ case PT_TESC:+ continue;+ case PT_CLNE:+ case PT_THDR:+ case PT_DMND:+ case PT_FIRE:+ p_set_temp(&parts[ID(r)], restrict_flt(p_temp(&parts[ID(r)])+powderful/10, MIN_TEMP, MAX_TEMP));+ continue;+ case PT_DEUT:+ case PT_PLUT:+ p_set_temp(&parts[ID(r)], restrict_flt(p_temp(&parts[ID(r)])+powderful, MIN_TEMP, MAX_TEMP));+ pv[y/ACELL][x/ACELL] = restrict_flt(pv[y/ACELL][x/ACELL] + powderful/35, MIN_PRESSURE, MAX_PRESSURE);+ if (rng_chance(1, 3)) {+ //@ LIGH + DEUT/PLUT -> LIGH + NEUT+ part_change_type(ID(r),x+rx,y+ry,PT_NEUT);+ parts[ID(r)].life = rng_between(480, 959);+ p_set_vx(&parts[ID(r)], (float)(rng_between(-5, 5)));+ p_set_vy(&parts[ID(r)], (float)(rng_between(-5, 5)));+ }+ break;+ case PT_COAL:+ case PT_BCOL:+ if (parts[ID(r)].life>100)+ parts[ID(r)].life = 99;+ break;+ case PT_STKM:+ if (player.elem!=PT_LIGH)+ parts[ID(r)].life-=powderful/100;+ break;+ case PT_STKM2:+ if (player2.elem!=PT_LIGH)+ parts[ID(r)].life-=powderful/100;+ break;+ case PT_HEAC:+ p_set_temp(&parts[ID(r)], restrict_flt(p_temp(&parts[ID(r)])+powderful/10, MIN_TEMP, MAX_TEMP));+ if (p_temp(&parts[ID(r)]) > elements[PT_HEAC].HighTemperature) {+ //@ LIGH + HEAC -> LIGH + LAVA(HEAC)+ part_change_type(ID(r), x+rx, y+ry, PT_LAVA);+ parts[ID(r)].ctype = PT_HEAC;+ }+ break;+ default:+ break;+ }+ if ((elements[TYP(r)].Properties&PROP_CONDUCTS) && parts[ID(r)].life==0)+ create_part(ID(r),x+rx,y+ry,PT_SPRK, -1);+ pv[y/ACELL][x/ACELL] = restrict_flt(pv[y/ACELL][x/ACELL] + powderful/400, MIN_PRESSURE, MAX_PRESSURE);+ if (!IsHeatInsulator(&parts[ID(r)])) p_set_temp(&parts[ID(r)], restrict_flt(p_temp(&parts[ID(r)])+powderful/1.3, MIN_TEMP, MAX_TEMP));+ }+ }+ }+ // Deferred branch or bend; or in removal countdown stage+ if (parts[i].tmp2 == 1 || parts[i].tmp2 == 3 || (parts[i].tmp2 >= 6 && parts[i].tmp2 <= 8)) {+ // Probably set via console, make sure it doesn't stick around forever+ if (parts[i].tmp2 >= 9)+ parts[i].tmp2 = 7;+ else+ parts[i].tmp2--;+ return 0;+ }+ if (parts[i].tmp2 == 5 || parts[i].life <= 1) {+ kill_part(i);+ return 1;+ }+ float angle = (float)((parts[i].tmp + rng_between(-30, 30)) % 360);+ float multipler = (int)(parts[i].life * 1.5) + rng_between(0, parts[i].life);+ int rx = (int)(cosf(angle * NP_PI / 180) * multipler);+ int ry = (int)(-sinf(angle * NP_PI / 180) * multipler);+ LIGH_create_line_par(x, y, x+rx, y+ry, PT_LIGH, p_temp(&parts[i]), parts[i].life, (int)(angle), parts[i].tmp2, i);+ if (parts[i].tmp2 == 2) { // && pNear == -1)+ float angle2 = (float)(((int)angle + rng_between(-100, 100)) % 360);+ rx = (int)(cosf(angle2 * NP_PI / 180) * multipler);+ ry = (int)(-sinf(angle2 * NP_PI / 180) * multipler);+ LIGH_create_line_par(x, y, x+rx, y+ry, PT_LIGH, p_temp(&parts[i]), parts[i].life, (int)(angle2), parts[i].tmp2, i);+ }+ parts[i].tmp2 = 7;+ return 0;+}+static bool LIGH_create_LIGH(int x, int y, int c, float temp, int life, int tmp, int tmp2, bool last, int i) {+ int p = create_part(-1, x, y,c, -1);+ if (p != -1) {+ p_set_temp(&parts[p], (float)(temp));+ parts[p].tmp = tmp;+ if (last) {+ int nextSegmentLife = (int)(life/1.5 - rng_between(0, 1));+ parts[p].life = nextSegmentLife;+ if (nextSegmentLife > 1) {+ // Decide whether to branch or to bend+ bool doBranch = rng_chance(7, 10);+ parts[p].tmp2 = (doBranch ? 2 : 0) + (p > i && tmp2 != 4 ? 1 : 0);+ }+ // Not enough energy to continue+ else {+ parts[p].tmp2 = 7 + (p > i ? 1 : 0);+ }+ } else {+ parts[p].life = life;+ parts[p].tmp2 = 7 + (p > i ? 1 : 0);+ }+ } else if (x >= 0 && x < XRES && y >= 0 && y < YRES) {+ int r = PMAPAT(x, y);+ if (((TYP(r)==PT_VOID || (TYP(r)==PT_PVOD && parts[ID(r)].life >= 10)) && (!parts[ID(r)].ctype || (parts[ID(r)].ctype==c)!=(parts[ID(r)].tmp&1))) || TYP(r)==PT_BHOL || TYP(r)==PT_NBHL) // VOID, PVOD, VACU, and BHOL eat LIGH here+ return true;+ } else return true;+ return false;+}+static void LIGH_create_line_par(int x1, int y1, int x2, int y2, int c, float temp, int life, int tmp, int tmp2, int i) {+ bool reverseXY = abs(y2-y1) > abs(x2-x1), back = false;+ int x, y, dx, dy, Ystep;+ float e = 0.0f, de;+ if (reverseXY) {+ y = x1;+ x1 = y1;+ y1 = y;+ y = x2;+ x2 = y2;+ y2 = y;+ }+ if (x1 > x2)+ back = 1;+ dx = x2 - x1;+ dy = abs(y2 - y1);+ if (dx)+ de = dy/(float)dx;+ else+ de = 0.0f;+ y = y1;+ Ystep = (y1<y2) ? 1 : -1;+ if (!back) {+ for (x = x1; x <= x2; x++) {+ bool ret;+ if (reverseXY)+ ret = LIGH_create_LIGH(y, x, c, temp, life, tmp, tmp2,x==x2, i);+ else+ ret = LIGH_create_LIGH(x, y, c, temp, life, tmp, tmp2,x==x2, i);+ if (ret)+ return;+ e += de;+ if (e >= 0.5f) {+ y += Ystep;+ e -= 1.0f;+ }+ }+ } else {+ for (x = x1; x >= x2; x--) {+ bool ret;+ if (reverseXY)+ ret = LIGH_create_LIGH(y, x, c, temp, life, tmp, tmp2,x==x2, i);+ else+ ret = LIGH_create_LIGH(x, y, c, temp, life, tmp, tmp2,x==x2, i);+ if (ret)+ return;+ e += de;+ if (e <= -0.5f) {+ y += Ystep;+ e += 1.0f;+ }+ }+ }+}+void el_LIGH_create(ELEMENT_CREATE_FUNC_ARGS) {+ float gx, gy, gsize;+ if (v >= 0) {+ if (v > 55)+ v = 55;+ parts[i].life = v;+ } else+ parts[i].life = 30;+ p_set_temp(&parts[i], parts[i].life * 150.0f); // temperature of the lightning shows the power of the lightning+ GetGravityField(x, y, 1.0f, 1.0f, &gx, &gy);+ gsize = gx * gx + gy * gy;+ if (gsize < 0.0016f) {+ float angle = rng_between(0, 6283) * 0.001f; //(in radians, between 0 and 2*pi)+ gsize = sqrtf(gsize);+ // randomness in weak gravity fields (more randomness with weaker fields)+ gx += cosf(angle) * (0.04f - gsize);+ gy += sinf(angle) * (0.04f - gsize);+ }+ parts[i].tmp = ((int)(atan2f(-gy, gx) * 180.0f / NP_PI) + rng_between(-20, 20) + 360) % 360;+ parts[i].tmp2 = 4;+}++/* ---------------------------------------------------------------- THDR */+int el_THDR_update(UPDATE_FUNC_ARGS) {+ bool kill=false;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if ((elements[TYP(r)].Properties&PROP_CONDUCTS) && parts[ID(r)].life==0 && !(rt==PT_WATR||rt==PT_SLTW) && parts[ID(r)].ctype!=PT_SPRK) {+ parts[ID(r)].ctype = parts[ID(r)].type;+ part_change_type(ID(r),x+rx,y+ry,PT_SPRK);+ parts[ID(r)].life = 4;+ kill=true;+ } else if (rt!=PT_CLNE&&rt!=PT_THDR&&rt!=PT_SPRK&&rt!=PT_DMND&&rt!=PT_FIRE) {+ pv[y/ACELL][x/ACELL] = restrict_flt(pv[y/ACELL][x/ACELL] + 100.0f, MIN_PRESSURE, MAX_PRESSURE);+ if (legacy_enable && rng_chance(1, 200)) {+ //@ THDR -> FIRE+ parts[i].life = rng_between(120, 169);+ part_change_type(i,x,y,PT_FIRE);+ } else+ kill=true;+ }+ }+ }+ }+ if (kill) {+ kill_part(i);+ return 1;+ }+ return 0;+}++/* ---------------------------------------------------------------- EMBR */+int el_EMBR_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if ((elements[TYP(r)].Properties & (TYPE_SOLID | TYPE_PART | TYPE_LIQUID)) && !(elements[TYP(r)].Properties & PROP_SPARKSETTLE)) {+ kill_part(i);+ return 1;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- LITH */+/*+tmp2: carbonation factor+life: burn timer above 1000, spark cooldown timer otherwise+tmp: hydrogenation factor+ctype: absorbed energy+For game reasons, baseline LITH has the reactions of both its pure form and+its hydroxide, and also has basic li-ion battery-like behavior.+It absorbs CO2 like its hydroxide form, but can only be converted into GLAS+after having absorbed CO2.+*/+int el_LITH_update(UPDATE_FUNC_ARGS) {+ Particle *self = &parts[i];+#define hydrogenationFactor (self->tmp)+#define burnTimer (self->life)+#define carbonationFactor (self->tmp2)+#define storedEnergy (self->ctype)+ if (storedEnergy < 0) {+ storedEnergy = 0;+ }+ bool charged = false;+ bool discharged = false;+ for (int rx = -2; rx <= 2; ++rx) {+ for (int ry = -2; ry <= 2; ++ry) {+ if (rx || ry) {+ int neighborData = PMAPAT(x + rx, y + ry);+ if (!neighborData) {+ if (burnTimer > 1012 && rng_chance(1, 10)) {+ //@ LITH -> LITH + FIRE+ create_part(-1, x + rx, y + ry, PT_FIRE, -1);+ }+ continue;+ }+ Particle *neighbor = &parts[ID(neighborData)];+ int pavg = parts_avg(i, ID(neighborData), PT_INSL);+ switch (TYP(neighborData)) {+ case PT_SLTW:+ case PT_WTRV:+ case PT_WATR:+ case PT_DSTW:+ case PT_CBNW:+ if (burnTimer > 1016) {+ //@ LITH + SLTW/WATR/DSTW/CBNW -> LITH + WTRV+ part_change_type(ID(neighborData), x + rx, y + ry, PT_WTRV);+ p_set_temp(neighbor, 440.f);+ continue;+ }+ if (hydrogenationFactor + carbonationFactor >= 10) {+ continue;+ }+ //@ LITH + SLTW/WTRV/WATR/DSTW/CBNW -> LITH + H2+ if (p_temp(self) > 440.f) {+ burnTimer = 1024 + (storedEnergy > 24 ? 96 : storedEnergy * 4);+ part_change_type(ID(neighborData), x + rx, y + ry, PT_H2);+ hydrogenationFactor = 10;+ } else {+ p_set_temp(self, restrict_flt(p_temp(self) + 20.365f + storedEnergy * storedEnergy * 1.5f, MIN_TEMP, MAX_TEMP));+ part_change_type(ID(neighborData), x + rx, y + ry, PT_H2);+ hydrogenationFactor += 1;+ }+ break;+ case PT_CO2:+ if (hydrogenationFactor + carbonationFactor >= 10) {+ continue;+ }+ kill_part(ID(neighborData));+ carbonationFactor += 1;+ break;+ case PT_SPRK:+ if (pavg == PT_INSL || pavg == PT_RSSS) {+ break;+ }+ if (hydrogenationFactor + carbonationFactor >= 5) {+ continue; // too impure to do battery things.+ }+ if (neighbor->ctype == PT_PSCN && neighbor->life == 3 && !charged && !burnTimer) {+ charged = true;+ }+ break;+ case PT_NSCN:+ if (pavg == PT_INSL || pavg == PT_RSSS) {+ break;+ }+ if (neighbor->life == 0 && storedEnergy > 0 && !burnTimer) {+ part_change_type(ID(neighborData), x + rx, y + ry, PT_SPRK);+ neighbor->life = 4;+ neighbor->ctype = PT_NSCN;+ discharged = true;+ }+ break;+ case PT_FIRE:+ if (p_temp(self) > 440.f && rng_chance(1, 40) && hydrogenationFactor < 6) {+ burnTimer = 1013;+ hydrogenationFactor += 1;+ }+ break;+ case PT_O2:+ if (burnTimer > 1000 && rng_chance(1, 10)) {+ //@ LITH + O2 -> 2xPLSM+ part_change_type(i, x, y, PT_PLSM);+ part_change_type(ID(neighborData), x + rx, y + ry, PT_PLSM);+ pv[y / ACELL][x / ACELL] += 4.0;+ return 0;+ }+ break;+ }+ }+ }+ }+ if (charged) {+ storedEnergy += 1;+ burnTimer = 8;+ }+ if (discharged) {+ storedEnergy -= 1;+ burnTimer = 8;+ }+ for (int trade = 0; trade < 9; ++trade) {+ int rx = rng_between(-3, 3);+ int ry = rng_between(-3, 3);+ if (rx || ry) {+ int neighborData = PMAPAT(x + rx, y + ry);+ if (TYP(neighborData) != PT_LITH) {+ continue;+ }+ Particle *neighbor = &parts[ID(neighborData)];+#define neighborStoredEnergy (neighbor->ctype)+ // Transfer overcharge explosion status to nearby LITH+ if (burnTimer < 1000 && storedEnergy > 90 && neighbor->life > 1000)+ burnTimer = 1024;+ if (storedEnergy > neighborStoredEnergy) {+ int transfer = storedEnergy - neighborStoredEnergy;+ transfer -= transfer / 2;+ neighborStoredEnergy += transfer;+ storedEnergy -= transfer;+ break;+ }+#undef neighborStoredEnergy+ }+ }+ // Overcharged - begin explosion+ if (burnTimer < 1000 && storedEnergy >= 100)+ burnTimer = 1024;+ if (burnTimer == 1000) {+ burnTimer = 0;+ part_change_type(i, x, y, PT_LAVA);+ if (carbonationFactor < 3) {+ p_set_temp(self, restrict_flt(500.f + storedEnergy * 10, MIN_TEMP, MAX_TEMP));+ //@ LITH -> LAVA(LITH)+ self->ctype = PT_LITH;+ } else {+ p_set_temp(self, restrict_flt(2000.f + storedEnergy * 10, MIN_TEMP, MAX_TEMP));+ //@ LITH -> LAVA(GLAS)+ self->ctype = PT_GLAS;+ }+ }+ return 0;+#undef hydrogenationFactor+#undef burnTimer+#undef carbonationFactor+#undef storedEnergy+}+diff --git a/games/numpowder/src/el_force.c b/games/numpowder/src/el_force.cnew file mode 100644index 00000000..edee4078--- /dev/null+++ b/games/numpowder/src/el_force.c@@ -0,0 +1,450 @@+/* NumPowder: The Powder Toy's force elements (their files in elements/), ported: ACEL, DCEL, RPEL, FRAY, PSTN, DMG. */+#include "simpriv.h"++/* ---------------------------------------------------------------- ACEL */+int el_ACEL_update(UPDATE_FUNC_ARGS) {+ float multiplier;+ if (parts[i].life!=0) {+ int change = parts[i].life > 1000 ? 1000 : (parts[i].life < 0 ? 0 : parts[i].life);+ multiplier = 1.0f+(change/100.0f);+ } else {+ multiplier = 1.1f;+ }+ parts[i].tmp = 0;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (!rx != !ry) {+ int r = PMAPAT(x+rx, y+ry);+ if(!r)+ r = PHOTAT(x+rx, y+ry);+ if (!r)+ continue;+ if(elements[TYP(r)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)) {+ float pvx = p_vx(&parts[ID(r)]);+ float pvy = p_vy(&parts[ID(r)]);+ pvx *= multiplier;+ pvy *= multiplier;+ // Restrict velocity and try to preserve direction+ float mv = fmaxf(fabsf(pvx), fabsf(pvy));+ if (mv > MAX_VELOCITY) {+ pvx *= MAX_VELOCITY/mv;+ pvy *= MAX_VELOCITY/mv;+ }+ p_set_vx(&parts[ID(r)], pvx);+ p_set_vy(&parts[ID(r)], pvy);+ parts[i].tmp = 1;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- DCEL */+int el_DCEL_update(UPDATE_FUNC_ARGS) {+ float multiplier = 1.0f/1.1f;+ if (parts[i].life!=0) {+ multiplier = 1.0f - ((parts[i].life > 100 ? 100 : (parts[i].life < 0 ? 0 : parts[i].life)) / 100.0f);+ }+ parts[i].tmp = 0;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if ((rx || ry) && !(rx && ry)) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ r = PHOTAT(x+rx, y+ry);+ if (!r)+ continue;+ if (elements[TYP(r)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)) {+ p_set_vx(&parts[ID(r)], p_vx(&parts[ID(r)]) * (multiplier));+ p_set_vy(&parts[ID(r)], p_vy(&parts[ID(r)]) * (multiplier));+ parts[i].tmp = 1;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- RPEL */+int el_RPEL_update(UPDATE_FUNC_ARGS) {+ int r, rx, ry, ri;+ for(ri = 0; ri <= 10; ri++) {+ rx = rng_between(-10, 10);+ ry = rng_between(-10, 10);+ if (x+rx >= 0 && x+rx < XRES && y+ry >= 0 && y+ry < YRES && (rx || ry)) {+ r = PMAPAT(x+rx, y+ry);+ if (!r)+ r = PHOTAT(x+rx, y+ry);+ if (r && !(elements[TYP(r)].Properties & TYPE_SOLID)) {+ if (!parts[i].ctype || parts[i].ctype == parts[ID(r)].type) {+ p_set_vx(&parts[ID(r)], restrict_flt(p_vx(&parts[ID(r)]) + isign(rx)*((p_temp(&parts[i])-273.15)/10.0f), -MAX_VELOCITY, MAX_VELOCITY));+ p_set_vy(&parts[ID(r)], restrict_flt(p_vy(&parts[ID(r)]) + isign(ry)*((p_temp(&parts[i])-273.15)/10.0f), -MAX_VELOCITY, MAX_VELOCITY));+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- FRAY */+int el_FRAY_update(UPDATE_FUNC_ARGS) {+ int curlen;+ if (parts[i].tmp > 0)+ curlen = parts[i].tmp;+ else+ curlen = 10;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_SPRK) {+ for (int nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1, len = 0; ; nyy+=nyi, nxx+=nxi, len++) {+ if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0) || len>curlen) {+ break;+ }+ r = PMAPAT(x+nxi+nxx, y+nyi+nyy);+ if (!r)+ r = PHOTAT(x+nxi+nxx, y+nyi+nyy);+ if (r && !(elements[TYP(r)].Properties & TYPE_SOLID)){+ float coef = (p_temp(&parts[i])-273.15f)/10.0f;+ p_set_vx(&parts[ID(r)], restrict_flt(p_vx(&parts[ID(r)]) + nxi*coef, -MAX_VELOCITY, MAX_VELOCITY));+ p_set_vy(&parts[ID(r)], restrict_flt(p_vy(&parts[ID(r)]) + nyi*coef, -MAX_VELOCITY, MAX_VELOCITY));+ }+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- PSTN */+typedef struct { int pushed, spaces; } StackData;+static StackData StackData_make(int pushed, int spaces) { return (StackData){pushed, spaces}; }+enum { PISTON_INACTIVE = 0x00, PISTON_RETRACT = 0x01, PISTON_EXTEND = 0x02, MAX_FRAME = 0x0F, DEFAULT_LIMIT = 0x1F,+ DEFAULT_ARM_LIMIT = 0xFF };+// tmp3 as a bitfield+enum {+ FLAG_EXT_OBSTACLE = 0x01, // xxx1 : Don't extend if blocked by obstacles+ FLAG_EXT_ARMLIMIT = 0x02, // xx1x : Don't extend if blocked by arm limit+ FLAG_RET_OBSTACLE = 0x04, // x1xx : Don't retract if frme hinders movement+ FLAG_RET_TOOSHORT = 0x08, // 1xxx : Don't retract if arm is shorter than retraction length+};+static StackData PSTN_CanMoveStack(int stackX, int stackY, int directionX, int directionY, int maxSize, int amount, bool retract, int block);+static int PSTN_MoveStack(int stackX, int stackY, int directionX, int directionY, int maxSize, int amount, bool retract, int block, bool sticky, int callDepth, bool cancelOnObstacle);+int el_PSTN_update(UPDATE_FUNC_ARGS) {+ if (parts[i].life)+ return 0;+ int maxSize = parts[i].tmp ? parts[i].tmp : DEFAULT_LIMIT;+ int armLimit = parts[i].tmp2 ? parts[i].tmp2 : DEFAULT_ARM_LIMIT;+ int state = PISTON_INACTIVE;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if ((rx || ry) && (!rx || !ry)) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r) == PT_SPRK && parts[ID(r)].life == 3) {+ if (parts[ID(r)].ctype == PT_PSCN)+ state = PISTON_EXTEND;+ else+ state = PISTON_RETRACT;+ }+ }+ }+ }+ if (state == PISTON_EXTEND || state == PISTON_RETRACT) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if ((rx || ry) && (!rx || !ry)) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r) == PT_PSTN && !parts[ID(r)].life) {+ bool movedPiston = false;+ bool foundEnd = false;+ int pistonEndX, pistonEndY;+ int pistonCount = -1;// number of PSTN particles minus 1+ int armCount = 0;+ int directionX = rx;+ int directionY = ry;+ int nxi = directionX, nyi = directionY;+ for (int nxx = 0, nyy = 0; ; nyy += nyi, nxx += nxi) {+ if (!(x+nxx<XRES && y+nyy<YRES && x+nxx >= 0 && y+nyy >= 0)) {+ break;+ }+ r = PMAPAT(x+nxx, y+nyy);+ if (TYP(r) == PT_PSTN) {+ if (parts[ID(r)].life)+ armCount++;+ else if (armCount) {+ pistonEndX = x+nxx;+ pistonEndY = y+nyy;+ foundEnd = true;+ break;+ } else {+ pistonCount += (int)(floorf((p_temp(&parts[ID(r)]) - 268.15f) / 10));// How many tens of degrees above 0 C, rounded to nearest ten degrees. Can be negative.+ }+ } else if (nxx == 0 && nyy == 0) {+ // compatibility with BAD THINGS: starting PSTN layered underneath other particles+ // (in v90, it started scanning from the neighbouring particle, so could not break out of loop at offset=(0,0))+ pistonCount += (int)(floorf((p_temp(&parts[i]) - 268.15f) / 10));+ continue;+ } else {+ pistonEndX = x+nxx;+ pistonEndY = y+nyy;+ foundEnd = true;+ break;+ }+ }+ if (foundEnd) {+ if (state == PISTON_EXTEND) {+ if (armCount + pistonCount > armLimit) {+ // If extending piston would exceed the armLimit, skip extension entirely+ if (parts[i].tmp3 & FLAG_EXT_ARMLIMIT)+ continue;+ pistonCount = armLimit - armCount;+ }+ if (pistonCount > 0) {+ bool cancelOnObstacle = parts[i].tmp3 & FLAG_EXT_OBSTACLE;+ int newSpace = PSTN_MoveStack(pistonEndX, pistonEndY, directionX, directionY, maxSize, pistonCount, false, parts[i].ctype, true, 0, cancelOnObstacle);+ if (newSpace) {+ // Create new piston section+ for (int j = 0; j < newSpace; j++) {+ int nr = create_part(-3, pistonEndX + (nxi * j), pistonEndY + (nyi * j), PT_PSTN, -1);+ if (nr > -1) {+ parts[nr].life = 1;+ }+ }+ movedPiston = true;+ }+ }+ } else if (state == PISTON_RETRACT) {+ if (pistonCount > armCount) {+ // Arm too short to retract the full amount+ if (parts[i].tmp3 & FLAG_RET_TOOSHORT)+ continue;+ pistonCount = armCount;+ }+ if (armCount && pistonCount > 0) {+ bool cancelOnObstacle = parts[i].tmp3 & FLAG_RET_OBSTACLE; // Only retract if no obstacles hinder frme movement+ PSTN_MoveStack(pistonEndX, pistonEndY, directionX, directionY,+ maxSize, pistonCount, true, parts[i].ctype, true, 0, cancelOnObstacle);+ movedPiston = true;+ }+ }+ }+ if (movedPiston)+ return 0;+ }+ }+ }+ }+ }+ return 0;+}+static StackData PSTN_CanMoveStack(int stackX, int stackY, int directionX, int directionY, int maxSize, int amount, bool retract, int block) {+ int posX, posY, spaces = 0, currentPos = 0;+ if (amount <= 0)+ return StackData_make(0, 0);+ for (posX = stackX, posY = stackY; currentPos < maxSize + amount && currentPos < XRES - 1; posX += directionX, posY += directionY) {+ if (!(posX < XRES && posY < YRES && posX >= 0 && posY >= 0))+ break;+ int r = PMAPAT(posX, posY);+ if (IsWallBlocking(posX, posY, 0) || (block && TYP(r) == block))+ return StackData_make(currentPos - spaces, spaces);+ if (!r) {+ spaces++;+ Element_PSTN_tempParts[currentPos++] = -1; /* (100 at most here: currentPos < XRES - 1) */+ if (spaces >= amount)+ break;+ } else {+ if (currentPos - spaces < maxSize && (!retract || (TYP(r) == PT_FRME && posX == stackX && posY == stackY)))+ Element_PSTN_tempParts[currentPos++] = ID(r);+ else+ return StackData_make(currentPos - spaces, spaces);+ }+ }+ return StackData_make(currentPos - spaces, spaces);+}+static int PSTN_MoveStack(int stackX, int stackY, int directionX, int directionY, int maxSize, int amount, bool retract, int block, bool sticky, int callDepth, bool cancelOnObstacle) {+ int posX, posY, r;+ r = PMAPAT(stackX, stackY);+ if (!callDepth && TYP(r) == PT_FRME) {+ int newY = !!directionX, newX = !!directionY;+ int realDirectionX = retract ? -directionX : directionX;+ int realDirectionY = retract ? -directionY : directionY;+ int maxRight = MAX_FRAME, maxLeft = MAX_FRAME;+ //check if we can push all the FRME+ for (int c = retract; c < MAX_FRAME; c++) {+ posY = stackY + (c * newY);+ posX = stackX + (c * newX);+ if (posX < XRES && posY < YRES && posX >= 0 && posY >= 0 && TYP(PMAPAT(posX, posY)) == PT_FRME) {+ int spaces = PSTN_CanMoveStack(posX, posY, realDirectionX, realDirectionY, maxSize, amount, retract, block).spaces;+ if (spaces < amount) {+ // Obstacle encountered, tmp3 flags are set such that shortened movement is not allowed, abort before moving anything+ if (cancelOnObstacle)+ return 0;+ amount = spaces;+ }+ } else {+ maxRight = c;+ break;+ }+ }+ for (int c = 1; c < MAX_FRAME; c++) {+ posY = stackY - (c*newY);+ posX = stackX - (c*newX);+ if (posX < XRES && posY < YRES && posX >= 0 && posY >= 0 && TYP(PMAPAT(posX, posY)) == PT_FRME) {+ int spaces = PSTN_CanMoveStack(posX, posY, realDirectionX, realDirectionY, maxSize, amount, retract, block).spaces;+ if (spaces < amount) {+ // Obstacle encountered, tmp3 flags are set such that shortened movement is not allowed, abort before moving anything+ if (cancelOnObstacle)+ return 0;+ amount = spaces;+ }+ } else {+ maxLeft = c;+ break;+ }+ }+ //If the piston is pushing frame, iterate out from the centre to the edge and push everything resting on frame+ for (int c = 1; c < maxRight; c++) {+ posY = stackY + (c*newY);+ posX = stackX + (c*newX);+ PSTN_MoveStack(posX, posY, directionX, directionY, maxSize, amount, retract, block, !parts[ID(PMAPAT(posX, posY))].tmp, 1, cancelOnObstacle);+ }+ for (int c = 1; c < maxLeft; c++) {+ posY = stackY - (c*newY);+ posX = stackX - (c*newX);+ PSTN_MoveStack(posX, posY, directionX, directionY, maxSize, amount, retract, block, !parts[ID(PMAPAT(posX, posY))].tmp, 1, cancelOnObstacle);+ }+ //Remove arm section if retracting with FRME+ if (retract)+ for (int j = 1; j <= amount; j++)+ kill_part(ID(PMAPAT(stackX+(directionX * -j), stackY+(directionY * -j))));+ return PSTN_MoveStack(stackX, stackY, directionX, directionY, maxSize, amount, retract, block, !parts[ID(PMAPAT(stackX, stackY))].tmp, 1, cancelOnObstacle);+ }+ if (retract) {+ bool foundParts = false;+ //Remove arm section if retracting without FRME+ if (!callDepth)+ for (int j = 1; j <= amount; j++)+ kill_part(ID(PMAPAT(stackX + (directionX * -j), stackY + (directionY * -j))));+ int currentPos = 0;+ for (posX = stackX, posY = stackY; currentPos < maxSize && currentPos < XRES-1; posX += directionX, posY += directionY) {+ if (!(posX < XRES && posY < YRES && posX >= 0 && posY >= 0)) {+ break;+ }+ r = PMAPAT(posX, posY);+ if (!r || TYP(r) == block || (!sticky && TYP(r) != PT_FRME)) {+ break;+ } else {+ foundParts = true;+ Element_PSTN_tempParts[currentPos++] = ID(r);+ }+ }+ if (foundParts) {+ //Move particles+ for (int j = 0; j < currentPos; j++) {+ int jP = Element_PSTN_tempParts[j];+ int srcX = (int)(p_x(&parts[jP]) + 0.5f), srcY = (int)(p_y(&parts[jP]) + 0.5f);+ int destX = srcX-directionX*amount, destY = srcY-directionY*amount;+ PMAPSET(srcX, srcY, 0);+ p_set_x(&parts[jP], (float)(destX));+ p_set_y(&parts[jP], (float)(destY));+ PMAPSET(destX, destY, PMAP(jP, parts[jP].type));+ }+ return amount;+ }+ } else {+ StackData stackData = PSTN_CanMoveStack(stackX, stackY, directionX, directionY, maxSize, amount, retract, block);+ int currentPos = stackData.pushed + stackData.spaces;+ if (currentPos) {+ //Move particles+ int possibleMovement = 0;+ for (int j = currentPos-1; j >= 0; j--) {+ int jP = Element_PSTN_tempParts[j];+ if (jP < 0) {+ possibleMovement++;+ continue;+ }+ if (!possibleMovement)+ continue;+ int srcX = (int)(p_x(&parts[jP]) + 0.5f), srcY = (int)(p_y(&parts[jP]) + 0.5f);+ int destX = srcX+directionX*possibleMovement, destY = srcY+directionY*possibleMovement;+ PMAPSET(srcX, srcY, 0);+ p_set_x(&parts[jP], (float)(destX));+ p_set_y(&parts[jP], (float)(destY));+ PMAPSET(destX, destY, PMAP(jP, parts[jP].type));+ }+ return possibleMovement;+ }+ }+ return 0;+}+bool el_PSTN_ctypeDraw(CTYPEDRAW_FUNC_ARGS) {+ if (t == PT_FRME) {+ return false;+ }+ return basicCtypeDraw(CTYPEDRAW_FUNC_SUBCALL_ARGS);+}++/* ---------------------------------------------------------------- DMG */+int el_DMG_update(UPDATE_FUNC_ARGS) {+ int rad = 25;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)!=PT_DMG && TYP(r)!=PT_EMBR && TYP(r)!=PT_DMND && TYP(r)!=PT_CLNE && TYP(r)!=PT_PCLN && TYP(r)!=PT_BCLN) {+ kill_part(i);+ for (int nxj =-rad; nxj<=rad; nxj++) {+ for (int nxi =-rad; nxi<=rad; nxi++) {+ if (x+nxi>=0 && y+nxj>=0 && x+nxi<XRES && y+nxj<YRES && (nxi || nxj)) {+ int dist = (int)(sqrtf(powf(nxi, 2.0f)+powf(nxj, 2.0f)));//;(powf((float)nxi,2))/(powf((float)rad,2))+(powf((float)nxj,2))/(powf((float)rad,2));+ if (!dist || (dist <= rad)) {+ int rr = PMAPAT(x+nxi, y+nxj);+ if (rr) {+ float angle = atan2f((float)nxj, nxi);+ float fx = cosf(angle) * 7.0f;+ float fy = sinf(angle) * 7.0f;+ p_set_vx(&parts[ID(rr)], p_vx(&parts[ID(rr)]) + (fx));+ p_set_vy(&parts[ID(rr)], p_vy(&parts[ID(rr)]) + (fy));+ vx[(y+nxj)/ACELL][(x+nxi)/ACELL] += fx;+ vy[(y+nxj)/ACELL][(x+nxi)/ACELL] += fy;+ pv[(y+nxj)/ACELL][(x+nxi)/ACELL] += 1.0f;+ int t = TYP(rr);+ if (t && elements[t].HighPressureTransition>-1 && elements[t].HighPressureTransition<PT_NUM)+ part_change_type(ID(rr), x+nxi, y+nxj, elements[t].HighPressureTransition);+ else if (t == PT_BMTL) //@ DMG + BMTL -> BRMT+ part_change_type(ID(rr), x+nxi, y+nxj, PT_BRMT);+ else if (t == PT_GLAS) //@ DMG + GLAS -> BGLA+ part_change_type(ID(rr), x+nxi, y+nxj, PT_BGLA);+ else if (t == PT_COAL) //@ DMG + COAL -> BCOL+ part_change_type(ID(rr), x+nxi, y+nxj, PT_BCOL);+ else if (t == PT_QRTZ) //@ DMG + QRTZ -> PQRT+ part_change_type(ID(rr), x+nxi, y+nxj, PT_PQRT);+ else if (t == PT_TUNG) { //@ DMG + TUNG -> BRMT(TUNG)+ part_change_type(ID(rr), x+nxi, y+nxj, PT_BRMT);+ parts[ID(rr)].ctype = PT_TUNG;+ } else if (t == PT_WOOD) //@ DMG + WOOD -> SAWD+ part_change_type(ID(rr), x+nxi, y+nxj, PT_SAWD);+ }+ }+ }+ }+ }+ return 1;+ }+ }+ }+ }+ return 0;+}+diff --git a/games/numpowder/src/el_gases.c b/games/numpowder/src/el_gases.cnew file mode 100644index 00000000..fa522909--- /dev/null+++ b/games/numpowder/src/el_gases.c@@ -0,0 +1,365 @@+/* NumPowder: The Powder Toy's gases: WTRV, O2, CO2, H2, NBLE, BOYL, CAUS, FOG (their elements/ files), ported: each one's update and the rest but graphics. */+#include "simpriv.h"++/* ---------------------------------------------------------------- WTRV */+int el_WTRV_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if ((TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) && !legacy_enable && p_temp(&parts[i])>(273.15f+12.0f) && rng_chance(1, 100)) {+ //@ WTRV + RBDM/LRBD -> FIRE + RBDM/LRBD+ part_change_type(i,x,y,PT_FIRE);+ parts[i].life = 4;+ parts[i].ctype = PT_WATR;+ }+ }+ }+ }+ if(p_temp(&parts[i])>1273&&parts[i].ctype==PT_FIRE)+ p_set_temp(&parts[i], p_temp(&parts[i]) - (p_temp(&parts[i])/1000));+ return 0;+}++/* ---------------------------------------------------------------- O2 */+int el_O2_update(UPDATE_FUNC_ARGS) {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_FIRE) {+ p_set_temp(&parts[ID(r)], p_temp(&parts[ID(r)]) + (rng_between(0, 99)));+ if (parts[ID(r)].tmp & 0x01)+ p_set_temp(&parts[ID(r)], 3473);+ parts[ID(r)].tmp |= 2;+ //@ O2 + FIRE -> 2xFIRE+ create_part(i,x,y,PT_FIRE, -1);+ p_set_temp(&parts[i], p_temp(&parts[i]) + (rng_between(0, 99)));+ parts[i].tmp |= 2;+ } else if (TYP(r)==PT_PLSM && !(parts[ID(r)].tmp&4)) {+ //@ O2 + PLSM -> FIRE + PLSM+ create_part(i,x,y,PT_FIRE, -1);+ p_set_temp(&parts[i], p_temp(&parts[i]) + (rng_between(0, 99)));+ parts[i].tmp |= 2;+ }+ }+ }+ }+ if (p_temp(&parts[i]) > 9973.15 && pv[y/ACELL][x/ACELL] > 250.0f) {+ float gx = gravx[y/ACELL][x/ACELL];+ float gy = gravy[y/ACELL][x/ACELL];+ //@ O2 -> BRMT + NEUT + PHOT + GRVT + sometimes PLSM+ if (gx*gx + gy*gy > 400) {+ if (rng_chance(1, 5)) {+ int j;+ create_part(i,x,y,PT_BRMT, -1);+ j = create_part(-3,x,y,PT_NEUT, -1);+ if (j != -1)+ p_set_temp(&parts[j], MAX_TEMP);+ j = create_part(-3,x,y,PT_PHOT, -1);+ if (j != -1) {+ p_set_temp(&parts[j], MAX_TEMP);+ parts[j].tmp = 0x1;+ }+ int rx = x + rng_between(-1, 1), ry = y + rng_between(-1, 1), r = TYP(PMAPAT(rx, ry));+ if (can_move(PT_PLSM, r) || r == PT_O2) {+ j = create_part(-3,rx,ry,PT_PLSM, -1);+ if (j > -1) {+ p_set_temp(&parts[j], MAX_TEMP);+ parts[j].tmp |= 4;+ }+ }+ j = create_part(-3,x,y,PT_GRVT, -1);+ if (j != -1)+ p_set_temp(&parts[j], MAX_TEMP);+ p_set_temp(&parts[i], MAX_TEMP);+ pv[y/ACELL][x/ACELL] = MAX_PRESSURE;+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- CO2 */+int el_CO2_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r) {+ if (parts[i].ctype==5 && rng_chance(1, 2000)) {+ //@ CO2 -> WATR+ if (create_part(-1, x+rx, y+ry, PT_WATR, -1)>=0)+ parts[i].ctype = 0;+ }+ continue;+ }+ if (TYP(r)==PT_FIRE) {+ kill_part(ID(r));+ if (rng_chance(1, 30)) {+ kill_part(i);+ return 1;+ }+ } else if ((TYP(r)==PT_WATR || TYP(r)==PT_DSTW) && rng_chance(1, 50)) {+ part_change_type(ID(r), x+rx, y+ry, PT_CBNW);+ if (parts[i].ctype==5) { //conserve number of water particles - ctype=5 means this CO2 hasn't released the water particle from BUBW yet+ //@ CO2 + WATR/DSTW -> WATR + CBNW+ create_part(i, x, y, PT_WATR, -1);+ return 0;+ } else {+ //@ CO2 + WATR/DSTW -> CBNW+ kill_part(i);+ return 1;+ }+ }+ }+ }+ }+ if (p_temp(&parts[i]) > 9773.15 && pv[y/ACELL][x/ACELL] > 200.0f) {+ if (rng_chance(1, 5)) {+ int j;+ //@ CO2 -> O2 + NEUT+ create_part(i,x,y,PT_O2, -1);+ j = create_part(-3,x,y,PT_NEUT, -1);+ if (j != -1)+ p_set_temp(&parts[j], MAX_TEMP);+ if (rng_chance(1, 50)) {+ //@ CO2 -> O2 + NEUT + ELEC+ j = create_part(-3,x,y,PT_ELEC, -1);+ if (j != -1)+ p_set_temp(&parts[j], MAX_TEMP);+ }+ p_set_temp(&parts[i], MAX_TEMP);+ pv[y/ACELL][x/ACELL] += 100;+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- H2 */+int el_H2_update(UPDATE_FUNC_ARGS) {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (pv[y/ACELL][x/ACELL] > 8.0f && rt == PT_DESL) {+ //@ H2 + DESL -> OIL + WATR+ part_change_type(ID(r),x+rx,y+ry,PT_WATR);+ part_change_type(i,x,y,PT_OIL);+ return 1;+ }+ if (pv[y/ACELL][x/ACELL] > 45.0f) {+ if (p_temp(&parts[ID(r)]) > 2273.15)+ continue;+ } else {+ if (rt==PT_FIRE) {+ if(parts[ID(r)].tmp&0x02)+ p_set_temp(&parts[ID(r)], 3473.0f);+ else+ p_set_temp(&parts[ID(r)], 2473.15f);+ parts[ID(r)].tmp |= 1;+ //@ H2 + FIRE -> 2xFIRE+ create_part(i,x,y,PT_FIRE, -1);+ p_set_temp(&parts[i], p_temp(&parts[i]) + (rng_between(0, 99)));+ parts[i].tmp |= 1;+ return 1;+ } else if ((rt==PT_PLSM && !(parts[ID(r)].tmp&4)) || (rt==PT_LAVA && parts[ID(r)].ctype != PT_BMTL)) {+ //@ H2 + PLSM/LAVA -> FIRE + PLSM/LAVA+ create_part(i,x,y,PT_FIRE, -1);+ p_set_temp(&parts[i], p_temp(&parts[i]) + (rng_between(0, 99)));+ parts[i].tmp |= 1;+ return 1;+ }+ }+ }+ }+ }+ if (p_temp(&parts[i]) > 2273.15 && pv[y/ACELL][x/ACELL] > 50.0f) {+ if (rng_chance(1, 5)) {+ int j;+ float temp = p_temp(&parts[i]);+ create_part(i,x,y,PT_NBLE, -1);+ parts[i].tmp = 0x1;+ //@ H2 -> NBLE + NEUT + PHOT+ j = create_part(-3,x,y,PT_NEUT, -1);+ if (j>-1)+ p_set_temp(&parts[j], temp);+ if (rng_chance(1, 10)) {+ //@ H2 -> NBLE + NEUT + PHOT + ELEC+ j = create_part(-3,x,y,PT_ELEC, -1);+ if (j>-1)+ p_set_temp(&parts[j], temp);+ }+ j = create_part(-3,x,y,PT_PHOT, -1);+ if (j>-1) {+ parts[j].ctype = 0x7C0000;+ p_set_temp(&parts[j], temp);+ parts[j].tmp = 0x1;+ }+ int rx = x + rng_between(-1, 1), ry = y + rng_between(-1, 1), rt = TYP(PMAPAT(rx, ry));+ if (can_move(PT_PLSM, rt) || rt == PT_H2) {+ //@ H2 -> NBLE + NEUT + PHOT + ELEC + PLSM+ j = create_part(-3,rx,ry,PT_PLSM, -1);+ if (j>-1) {+ p_set_temp(&parts[j], temp);+ parts[j].tmp |= 4;+ }+ }+ p_set_temp(&parts[i], temp + rng_between(750, 1249));+ pv[y/ACELL][x/ACELL] += 30;+ return 1;+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- NBLE */+int el_NBLE_update(UPDATE_FUNC_ARGS) {+ if (p_temp(&parts[i]) > 5273.15 && pv[y/ACELL][x/ACELL] > 100.0f) {+ parts[i].tmp |= 0x1;+ //@ NBLE -> CO2 + NEUT + PHOT + sometimes ELEC + PLSM+ if (rng_chance(1, 5)) {+ int j;+ float temp = p_temp(&parts[i]);+ create_part(i,x,y,PT_CO2, -1);+ j = create_part(-3,x,y,PT_NEUT, -1);+ if (j != -1)+ p_set_temp(&parts[j], temp);+ if (rng_chance(1, 25)) {+ j = create_part(-3,x,y,PT_ELEC, -1);+ if (j != -1)+ p_set_temp(&parts[j], temp);+ }+ j = create_part(-3,x,y,PT_PHOT, -1);+ if (j != -1) {+ parts[j].ctype = 0xF800000;+ p_set_temp(&parts[j], temp);+ parts[j].tmp = 0x1;+ }+ int rx = x + rng_between(-1, 1), ry = y + rng_between(-1, 1), rt = TYP(PMAPAT(rx, ry));+ if (can_move(PT_PLSM, rt) || rt == PT_NBLE) {+ j = create_part(-3,rx,ry,PT_PLSM, -1);+ if (j != -1) {+ p_set_temp(&parts[j], temp);+ parts[j].tmp |= 4;+ }+ }+ p_set_temp(&parts[i], temp + 1750 + rng_between(0, 499));+ pv[y/ACELL][x/ACELL] += 50;+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- BOYL */+int el_BOYL_update(UPDATE_FUNC_ARGS) {+ float limit = p_temp(&parts[i]) / 100;+ if (pv[y / ACELL][x / ACELL] < limit)+ pv[y / ACELL][x / ACELL] += 0.001f*(limit - pv[y / ACELL][x / ACELL]);+ if (pv[y / ACELL + 1][x / ACELL] < limit)+ pv[y / ACELL + 1][x / ACELL] += 0.001f*(limit - pv[y / ACELL + 1][x / ACELL]);+ if (pv[y / ACELL - 1][x / ACELL] < limit)+ pv[y / ACELL - 1][x / ACELL] += 0.001f*(limit - pv[y / ACELL - 1][x / ACELL]);+ pv[y / ACELL][x / ACELL + 1] += 0.001f*(limit - pv[y / ACELL][x / ACELL + 1]);+ pv[y / ACELL + 1][x / ACELL + 1] += 0.001f*(limit - pv[y / ACELL + 1][x / ACELL + 1]);+ pv[y / ACELL][x / ACELL - 1] += 0.001f*(limit - pv[y / ACELL][x / ACELL - 1]);+ pv[y / ACELL - 1][x / ACELL - 1] += 0.001f*(limit - pv[y / ACELL - 1][x / ACELL - 1]);+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_WATR) {+ //@ BOYL + WATR -> BOYL + FOG+ if (rng_chance(1, 30))+ part_change_type(ID(r),x+rx,y+ry,PT_FOG);+ } else if (TYP(r)==PT_O2) {+ //@ BOYL + O2 -> WATR+ if (rng_chance(1, 9)) {+ kill_part(ID(r));+ part_change_type(i,x,y,PT_WATR);+ pv[y/ACELL][x/ACELL] += 4.0;+ return 1;+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- CAUS */+int el_CAUS_update(UPDATE_FUNC_ARGS) {+ bool converted = false;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r) == PT_GAS) {+ if (pv[(y+ry)/ACELL][(x+rx)/ACELL] > 3) {+ //@ CAUS + GAS -> 2xRFRG+ part_change_type(ID(r), x+rx, y+ry, PT_RFRG);+ part_change_type(i, x, y, PT_RFRG);+ converted = true;+ }+ } else if (TYP(r) != PT_ACID && TYP(r) != PT_CAUS && TYP(r) != PT_RFRG && TYP(r) != PT_RFGL) {+ if ((TYP(r) != PT_CLNE && TYP(r) != PT_PCLN && ((TYP(r) != PT_FOG && TYP(r) != PT_RIME) || parts[ID(r)].tmp <= 5) && rng_chance(elements[TYP(r)].Hardness, 1000)) && parts[i].life > 50) {+ // GLAS protects stuff from acid+ if (parts_avg(i, ID(r),PT_GLAS) != PT_GLAS) {+ float newtemp = ((60.0f - (float)elements[TYP(r)].Hardness)) * 7.0f;+ if (newtemp < 0)+ newtemp = 0;+ p_set_temp(&parts[i], p_temp(&parts[i]) + (newtemp));+ parts[i].life--;+ kill_part(ID(r));+ }+ } else if (parts[i].life <= 50) {+ kill_part(i);+ return 1;+ }+ }+ }+ }+ }+ return converted;+}++/* ---------------------------------------------------------------- FOG */+int el_FOG_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if ((elements[TYP(r)].Properties&TYPE_SOLID) && rng_chance(1, 10) && parts[i].life==0 && !(TYP(r)==PT_CLNE || TYP(r)==PT_PCLN || TYP(r)==PT_BCLN || TYP(r)==PT_PBCN)) {+ //@ FOG -> RIME+ part_change_type(i,x,y,PT_RIME);+ }+ if (TYP(r)==PT_SPRK) {+ parts[i].life += rng_between(0, 19);+ }+ // GAS increases acidity+ if (TYP(r) == PT_GAS && parts[i].tmp < 10) {+ kill_part(ID(r));+ if (parts[i].ctype == PT_DSTW)+ parts[i].ctype = 0;+ else+ parts[i].tmp++;+ }+ }+ }+ }+ return 0;+}+diff --git a/games/numpowder/src/el_liquids.c b/games/numpowder/src/el_liquids.cnew file mode 100644index 00000000..939fa68c--- /dev/null+++ b/games/numpowder/src/el_liquids.c@@ -0,0 +1,1009 @@+/* NumPowder: The Powder Toy's liquids (their files in elements/), ported: WATR, DSTW, SLTW, CBNW, ACID, GLOW, MERC,+ * GEL, SOAP, FRZW, BIZR (and BIZRG, BIZRS), RFRG (and RFGL), RSST, BASE, VIRS (and VRSS, VRSG). */+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("O3") /* (a hot path: a few KB of flash for speed) */+#endif+#include "simpriv.h"++/* ---------------------------------------------------------------- WATR */+int el_WATR_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_SALT && rng_chance(1, 50)) {+ //@ WATR + SALT -> SLTW + SALT+ part_change_type(i,x,y,PT_SLTW);+ // on average, convert 3 WATR to SLTW before SALT turns into SLTW+ if (rng_chance(1, 3))+ part_change_type(ID(r),x+rx,y+ry,PT_SLTW);+ } else if ((TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) && (legacy_enable||p_temp(&parts[i])>(273.15f+12.0f)) && rng_chance(1, 100)) {+ //@ WATR + RBDM/LRBD -> FIRE + RBDM/LRBD+ part_change_type(i,x,y,PT_FIRE);+ parts[i].life = 4;+ parts[i].ctype = PT_WATR;+ } else if (TYP(r)==PT_FIRE && parts[ID(r)].ctype!=PT_WATR) {+ kill_part(ID(r));+ if (rng_chance(1, 30)) {+ kill_part(i);+ return 1;+ }+ } else if (TYP(r)==PT_SLTW && rng_chance(1, 2000)) {+ //@ WATR + SLTW -> 2xSLTW+ part_change_type(i,x,y,PT_SLTW);+ } else if (TYP(r)==PT_ROCK && fabsf(p_vx(&parts[i]))+fabsf(p_vy(&parts[i])) >= 0.5 && rng_chance(1, 1000)) { // ROCK erosion+ //@ WATR + ROCK -> WATR + SAND/STNE+ if (rng_chance(1,3))+ part_change_type(ID(r),x+rx,y+ry,PT_SAND);+ else+ part_change_type(ID(r),x+rx,y+ry,PT_STNE);+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- DSTW */+int el_DSTW_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ switch (TYP(r)) {+ case PT_SALT:+ if (rng_chance(1, 50)) {+ //@ DSTW + SALT -> 2xSLTW+ part_change_type(i,x,y,PT_SLTW);+ // on average, convert 3 DSTW to SLTW before SALT turns into SLTW+ if (rng_chance(1, 3))+ part_change_type(ID(r),x+rx,y+ry,PT_SLTW);+ }+ break;+ case PT_SLTW:+ if (rng_chance(1, 2000)) {+ //@ DSTW + SLTW -> 2xSLTW+ part_change_type(i,x,y,PT_SLTW);+ break;+ }+ /* fallthrough */+ case PT_WATR:+ if (rng_chance(1, 100)) {+ //@ DSTW + WATR -> 2xWATR+ part_change_type(i,x,y,PT_WATR);+ }+ break;+ case PT_RBDM:+ case PT_LRBD:+ if ((legacy_enable||p_temp(&parts[i])>12.0f) && rng_chance(1, 100)) {+ //@ DSTW + RBDM/LRBD -> FIRE + RBDM/LRBD+ part_change_type(i,x,y,PT_FIRE);+ parts[i].life = 4;+ }+ break;+ case PT_FIRE:+ kill_part(ID(r));+ if (rng_chance(1, 30)) {+ kill_part(i);+ return 1;+ }+ break;+ case PT_SMKE:+ if (p_temp(&parts[ID(r)]) > (40 + 273.15f) && p_temp(&parts[ID(r)]) < (60 + 273.15f) &&+ p_temp(&parts[i]) > (40 + 273.15f) && p_temp(&parts[i]) < (60 + 273.15f)) {+ if (rng_chance(1, 100)) {+ //@ DSTW + SMKE -> BASE+ part_change_type(i,x,y,PT_BASE);+ parts[i].life = 1;+ kill_part(ID(r));+ }+ }+ break;+ default:+ continue;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- SLTW */+int el_SLTW_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ switch (TYP(r)) {+ case PT_SALT:+ //@ SLTW + SALT -> 2xSLTW+ if (rng_chance(1, 2000))+ part_change_type(ID(r),x+rx,y+ry,PT_SLTW);+ break;+ case PT_PLNT:+ if (rng_chance(1, 40))+ kill_part(ID(r));+ break;+ case PT_RBDM:+ case PT_LRBD:+ //@ SLTW + RBDM/LRBD -> FIRE + RBDM/LRBD+ if ((legacy_enable||p_temp(&parts[i])>(273.15f+12.0f)) && rng_chance(1, 100)) {+ part_change_type(i,x,y,PT_FIRE);+ parts[i].life = 4;+ parts[i].ctype = PT_WATR;+ }+ break;+ case PT_FIRE:+ if (parts[ID(r)].ctype!=PT_WATR) {+ kill_part(ID(r));+ if (rng_chance(1, 30)) {+ kill_part(i);+ return 1;+ }+ }+ break;+ case PT_NONE:+ break;+ default:+ continue;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- CBNW */+int el_CBNW_update(UPDATE_FUNC_ARGS) {+ if (pv[y/ACELL][x/ACELL]<=3) {+ if (pv[y/ACELL][x/ACELL] <= -0.5 || rng_chance(1, 4000)) {+ //@ CBNW -> CO2+ part_change_type(i,x,y,PT_CO2);+ parts[i].ctype = 5;+ pv[y/ACELL][x/ACELL] += 0.5f;+ }+ }+ if (parts[i].tmp2!=20) {+ parts[i].tmp2 -= (parts[i].tmp2>20)?1:-1;+ } else if (rng_chance(1, 200)) {+ parts[i].tmp2 = rng_between(0, 39);+ }+ if(parts[i].tmp>0) {+ //Explode+ if(parts[i].tmp==1 && rng_chance(3, 4)) {+ //@ CBNW -> CO2+ part_change_type(i,x,y,PT_CO2);+ parts[i].ctype = 5;+ pv[y/ACELL][x/ACELL] += 0.2f;+ }+ parts[i].tmp--;+ }+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if ((elements[TYP(r)].Properties&TYPE_PART) && parts[i].tmp == 0 && rng_chance(1, 83)) {+ //Start explode+ parts[i].tmp = rng_between(0, 24);+ } else if((elements[TYP(r)].Properties&TYPE_SOLID) && TYP(r)!=PT_DMND && TYP(r)!=PT_GLAS && parts[i].tmp == 0 && rng_chance((int)(2 - pv[y/ACELL][x/ACELL]), 6667)) {+ //@ CBNW -> CO2+ part_change_type(i,x,y,PT_CO2);+ parts[i].ctype = 5;+ pv[y/ACELL][x/ACELL] += 0.2f;+ }+ if (TYP(r)==PT_CBNW) {+ if(!parts[i].tmp) {+ if (parts[ID(r)].tmp) {+ parts[i].tmp = parts[ID(r)].tmp;+ if((ID(r))>i) //If the other particle hasn't been life updated+ parts[i].tmp--;+ }+ } else if(!parts[ID(r)].tmp) {+ parts[ID(r)].tmp = parts[i].tmp;+ if((ID(r))>i) //If the other particle hasn't been life updated+ parts[ID(r)].tmp++;+ }+ } else if (TYP(r)==PT_RBDM||TYP(r)==PT_LRBD) {+ if ((legacy_enable||p_temp(&parts[i])>(273.15f+12.0f)) && rng_chance(1, 166)) {+ //@ CBNW + RBDM/LRBD -> CBNW + FIRE+ part_change_type(i,x,y,PT_FIRE);+ parts[i].life = 4;+ parts[i].ctype = PT_WATR;+ }+ } else if (TYP(r)==PT_FIRE && parts[ID(r)].ctype!=PT_WATR){+ kill_part(ID(r));+ if (rng_chance(1, 50)) {+ kill_part(i);+ return 1;+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- ACID */+int el_ACID_update(UPDATE_FUNC_ARGS) {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (rt != PT_ACID && rt != PT_CAUS) {+ if (rt == PT_PLEX || rt == PT_NITR || rt == PT_GUNP || rt == PT_RBDM || rt == PT_LRBD) {+ //@ ACID + PLEX/NITR/GUNP/RBDM/LRBD -> 2xFIRE+ part_change_type(i,x,y,PT_FIRE);+ part_change_type(ID(r),x+rx,y+ry,PT_FIRE);+ parts[i].life = 4;+ parts[ID(r)].life = 4;+ } else if (rt == PT_WTRV) {+ if (rng_chance(1, 250)) {+ //@ ACID + WTRV -> CAUS+ part_change_type(i, x, y, PT_CAUS);+ parts[i].life = rng_between(25, 74);+ kill_part(ID(r));+ }+ } else if (rt != PT_CLNE && rt != PT_PCLN && ((rt != PT_FOG && rt != PT_RIME) || parts[ID(r)].tmp <= 5) && parts[i].life > 50 && rng_chance(elements[rt].Hardness, 1000)) {+ if (parts_avg(i, ID(r),PT_GLAS)!= PT_GLAS) { //GLAS protects stuff from acid+ float newtemp = ((60.0f-(float)elements[rt].Hardness))*7.0f;+ if(newtemp < 0){+ newtemp = 0;+ }+ p_set_temp(&parts[i], p_temp(&parts[i]) + (newtemp));+ parts[i].life--;+ switch (rt) {+ case PT_LITH:+ //@ ACID + LITH -> ACID + H2+ part_change_type(ID(r), x + rx, y + ry, PT_H2);+ break;+ default:+ kill_part(ID(r));+ break;+ }+ }+ } else if (parts[i].life<=50) {+ kill_part(i);+ return 1;+ }+ }+ }+ }+ }+ for (int trade = 0; trade<2; trade++) {+ int rx = rng_between(-2, 2);+ int ry = rng_between(-2, 2);+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r) == PT_ACID && (parts[i].life > parts[ID(r)].life) && parts[i].life>0) { //diffusion+ int temp = parts[i].life - parts[ID(r)].life;+ if (temp == 1) {+ parts[ID(r)].life++;+ parts[i].life--;+ } else if (temp>0) {+ parts[ID(r)].life += temp/2;+ parts[i].life -= temp/2;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- GLOW */+int el_GLOW_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_WATR && rng_chance(1, 400)) {+ //@ GLOW + WATR -> DEUT+ kill_part(i);+ part_change_type(ID(r),x+rx,y+ry,PT_DEUT);+ parts[ID(r)].life = 10;+ return 1;+ } else if (TYP(r) == PT_GEL) {+ //@ GLOW + GEL -> RSST+ kill_part(i);+ part_change_type(ID(r),x+rx,y+ry,PT_RSST);+ parts[ID(r)].tmp = 0;+ return 1;+ }+ }+ }+ }+ int ctype = (int)(pv[y/ACELL][x/ACELL]*16);+ if (ctype < 0)+ ctype = 0;+ parts[i].ctype = ctype;+ parts[i].tmp = abs((int)((vx[y/ACELL][x/ACELL]+vy[y/ACELL][x/ACELL])*16.0f)) + abs((int)((p_vx(&parts[i])+p_vy(&parts[i]))*64.0f));+ return 0;+}++/* ---------------------------------------------------------------- MERC */+int el_MERC_update(UPDATE_FUNC_ARGS) {+ // Max number of particles that can be condensed into one+ const int absorbScale = 10000;+ p_set_temp(&parts[i], restrict_flt(p_temp(&parts[i]), MIN_TEMP, MAX_TEMP));+ int maxtmp = (int)(absorbScale/(p_temp(&parts[i]) + 1))-1;+ int it1 = (int)(p_temp(&parts[i])) + 1;+ if (it1 < 1)+ it1 = 1;+ if (rng_chance(absorbScale % it1, it1))+ maxtmp ++;+ if (parts[i].tmp < 0) {+ parts[i].tmp = 0;+ }+ if (parts[i].tmp > absorbScale) {+ parts[i].tmp = absorbScale;+ }+ if (parts[i].tmp < maxtmp) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r || (parts[i].tmp >=maxtmp))+ continue;+ if (TYP(r)==PT_MERC&& rng_chance(1, 3)) {+ if ((parts[i].tmp + parts[ID(r)].tmp + 1) <= maxtmp) {+ parts[i].tmp += parts[ID(r)].tmp + 1;+ kill_part(ID(r));+ }+ }+ }+ }+ }+ } else {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (parts[i].tmp<=maxtmp)+ continue;+ if ((!r)&&parts[i].tmp>=1) { //if nothing then create MERC+ int np = create_part(-1,x+rx,y+ry,PT_MERC, -1);+ if (np<0) continue;+ parts[i].tmp--;+ p_set_temp(&parts[np], p_temp(&parts[i]));+ parts[np].tmp = 0;+ }+ }+ }+ }+ }+ for (int trade = 0; trade<4; trade ++) {+ int rx = rng_between(-2, 2);+ int ry = rng_between(-2, 2);+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_MERC&&(parts[i].tmp>parts[ID(r)].tmp)&&parts[i].tmp>0) { //diffusion+ int temp = parts[i].tmp - parts[ID(r)].tmp;+ if (temp ==1) {+ parts[ID(r)].tmp ++;+ parts[i].tmp --;+ } else if (temp>0) {+ parts[ID(r)].tmp += temp/2;+ parts[i].tmp -= temp/2;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- GEL */+int el_GEL_update(UPDATE_FUNC_ARGS) {+ if (parts[i].tmp > 100)+ parts[i].tmp = 100;+ if (parts[i].tmp < 0)+ parts[i].tmp = 0;+ int absorbChanceDenom = parts[i].tmp * 10 + 500;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ bool gel = false;+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ //Desaturation+ switch (rt) {+ case PT_WATR:+ case PT_DSTW:+ case PT_FRZW:+ if (parts[i].tmp<100 && rng_chance(500, absorbChanceDenom)) {+ parts[i].tmp++;+ kill_part(ID(r));+ }+ break;+ case PT_PSTE:+ if (parts[i].tmp<100 && rng_chance(20, absorbChanceDenom)) {+ parts[i].tmp++;+ //@ GEL + PSTE -> GEL + CLST+ create_part(ID(r), x+rx, y+ry, PT_CLST, -1);+ }+ break;+ case PT_SLTW:+ if (parts[i].tmp<100 && rng_chance(50, absorbChanceDenom)) {+ parts[i].tmp++;+ //@ GEL + SLTW -> GEL + SALT+ if (rng_chance(3, 4))+ kill_part(ID(r));+ else+ part_change_type(ID(r), x+rx, y+ry, PT_SALT);+ }+ break;+ case PT_CBNW:+ if (parts[i].tmp < 100 && rng_chance(100, absorbChanceDenom)) {+ parts[i].tmp++;+ //@ GEL + CBNW -> GEL + CO2+ part_change_type(ID(r), x+rx, y+ry, PT_CO2);+ }+ break;+ case PT_SPNG:+ // Concentration diffusion+ if (parts[ID(r)].life>0 && parts[i].tmp<100 && ((parts[ID(r)].life+1)>parts[i].tmp)) {+ // SPNG -> GEL+ parts[ID(r)].life--;+ parts[i].tmp++;+ } else if (parts[i].tmp>0 && (parts[ID(r)].life+1)<parts[i].tmp) {+ // SPNG <- GEL (saturation limit of SPNG is ignored here)+ parts[ID(r)].life++;+ parts[i].tmp--;+ }+ break;+ case PT_GEL:+ if ((parts[ID(r)].tmp+1)<parts[i].tmp) {+ parts[ID(r)].tmp++;+ parts[i].tmp--;+ }+ gel = true;+ break;+ case PT_BASE:+ // Base absorbs water from gel+ if (parts[i].tmp > 0 && parts[ID(r)].life > 1) {+ // BASE <- GEL+ parts[ID(r)].life--;+ parts[i].tmp--;+ }+ break;+ default:+ break;+ }+ float dx, dy;+ dx = p_x(&parts[i]) - p_x(&parts[ID(r)]);+ dy = p_y(&parts[i]) - p_y(&parts[ID(r)]);+ //Stickiness+ if ((dx*dx + dy*dy)>1.5 && (gel || !elements[rt].Falldown || (fabsf((float)rx)<2 && fabsf((float)ry)<2))) {+ float per, nd;+ nd = dx*dx + dy*dy - 0.5;+ per = 5*(1 - parts[i].tmp/100)*(nd/(dx*dx + dy*dy + nd) - 0.5);+ if (elements[rt].Properties&TYPE_LIQUID)+ per *= 0.1f;+ dx *= per; dy *= per;+ p_set_vx(&parts[i], p_vx(&parts[i]) + (dx));+ p_set_vy(&parts[i], p_vy(&parts[i]) + (dy));+ if ((elements[rt].Properties&TYPE_PART) || rt==PT_GOO) {+ p_set_vx(&parts[ID(r)], p_vx(&parts[ID(r)]) - (dx));+ p_set_vy(&parts[ID(r)], p_vy(&parts[ID(r)]) - (dy));+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- SOAP */+/* the shortest way between two particles when the edges loop (Element_SOAP_neighourLoop) */+void SOAP_neighbourLoop(float *dx, float *dy) {+ if (edgeMode == EDGE_LOOP) {+ if (*dx >= (XRES / 2 - BORDER)) *dx -= XRES - 2 * BORDER;+ if (*dy >= (YRES / 2 - BORDER)) *dy -= YRES - 2 * BORDER;+ if (*dx < -(XRES / 2 - BORDER)) *dx += XRES - 2 * BORDER;+ if (*dy < -(YRES / 2 - BORDER)) *dy += YRES - 2 * BORDER;+ }+}+static bool SOAP_validIndex(int i) {+ return i >= 0 && i < NPART;+}+void Element_SOAP_detach(int i) {+ if ((parts[i].ctype&2) == 2 && SOAP_validIndex(parts[i].tmp) && parts[parts[i].tmp].type == PT_SOAP) {+ if ((parts[parts[i].tmp].ctype&4) == 4)+ parts[parts[i].tmp].ctype ^= 4;+ }+ if ((parts[i].ctype&4) == 4 && SOAP_validIndex(parts[i].tmp2) && parts[parts[i].tmp2].type == PT_SOAP) {+ if ((parts[parts[i].tmp2].ctype&2) == 2)+ parts[parts[i].tmp2].ctype ^= 2;+ }+ parts[i].ctype = 0;+}+static void SOAP_attach(int i1, int i2) {+ if (!(parts[i2].ctype&4)) {+ parts[i1].ctype |= 2;+ parts[i1].tmp = i2;+ parts[i2].ctype |= 4;+ parts[i2].tmp2 = i1;+ } else if (!(parts[i2].ctype&2)) {+ parts[i1].ctype |= 4;+ parts[i1].tmp2= i2;+ parts[i2].ctype |= 2;+ parts[i2].tmp = i1;+ }+}+#define FREEZING 248.15f+int el_SOAP_update(UPDATE_FUNC_ARGS) {+ //0x01 - bubble on/off+ //0x02 - first mate yes/no+ //0x04 - "back" mate yes/no+ if (parts[i].ctype&1) {+ // reset invalid SOAP links+ if (!SOAP_validIndex(parts[i].tmp) || !SOAP_validIndex(parts[i].tmp2)) {+ parts[i].tmp = parts[i].tmp2 = parts[i].ctype = 0;+ return 0;+ }+ if (p_temp(&parts[i])>FREEZING) {+ if (parts[i].life<=0) {+ //if only connected on one side+ if ((parts[i].ctype&6) != 6 && (parts[i].ctype&6)) {+ int target = i;+ //break entire bubble in a loop+ while((parts[target].ctype&6) != 6 && (parts[target].ctype&6) && parts[target].type == PT_SOAP) {+ if (parts[target].ctype&2) {+ target = parts[target].tmp;+ if (!SOAP_validIndex(target)) {+ break;+ }+ Element_SOAP_detach(target);+ }+ if (parts[target].ctype&4) {+ target = parts[target].tmp2;+ if (!SOAP_validIndex(target)) {+ break;+ }+ Element_SOAP_detach(target);+ }+ }+ }+ if ((parts[i].ctype&6) != 6)+ parts[i].ctype = 0;+ if (SOAP_validIndex(parts[i].tmp) && (parts[i].ctype&6) == 6 && (parts[parts[i].tmp].ctype&6) == 6 && parts[parts[i].tmp].tmp == i)+ Element_SOAP_detach(i);+ }+ p_set_vy(&parts[i], (p_vy(&parts[i])-0.1f)*0.5f);+ p_set_vx(&parts[i], p_vx(&parts[i]) * (0.5f));+ }+ if(!(parts[i].ctype&2)) {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if ((parts[ID(r)].type == PT_SOAP) && (parts[ID(r)].ctype&1) && !(parts[ID(r)].ctype&4))+ SOAP_attach(i, ID(r));+ }+ }+ }+ } else {+ if (parts[i].life<=0) {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r && !bmap[(y+ry)/WCELL][(x+rx)/WCELL])+ continue;+ if (p_temp(&parts[i])>FREEZING) {+ if (bmap[(y+ry)/WCELL][(x+rx)/WCELL]+ || (r && !(elements[TYP(r)].Properties&TYPE_GAS)+ && TYP(r) != PT_SOAP && TYP(r) != PT_GLAS)) {+ Element_SOAP_detach(i);+ continue;+ }+ }+ if (TYP(r) == PT_SOAP) {+ if (parts[ID(r)].ctype == 1) {+ int buf = parts[i].tmp;+ parts[i].tmp = ID(r);+ if (SOAP_validIndex(buf) && parts[buf].type == PT_SOAP)+ parts[buf].tmp2 = ID(r);+ parts[ID(r)].tmp2 = i;+ parts[ID(r)].tmp = buf;+ parts[ID(r)].ctype = 7;+ } else if (parts[ID(r)].ctype == 7 && parts[i].tmp != ID(r) && parts[i].tmp2 != ID(r)) {+ if (SOAP_validIndex(parts[i].tmp) && parts[parts[i].tmp].type == PT_SOAP)+ parts[parts[i].tmp].tmp2 = parts[ID(r)].tmp2;+ if (SOAP_validIndex(parts[ID(r)].tmp2) && parts[parts[ID(r)].tmp2].type == PT_SOAP)+ parts[parts[ID(r)].tmp2].tmp = parts[i].tmp;+ parts[ID(r)].tmp2 = i;+ parts[i].tmp = ID(r);+ }+ }+ }+ }+ }+ }+ }+ if(parts[i].ctype&2 && SOAP_validIndex(parts[i].tmp)) {+ float d, dx, dy;+ dx = p_x(&parts[i]) - p_x(&parts[parts[i].tmp]);+ dy = p_y(&parts[i]) - p_y(&parts[parts[i].tmp]);+ SOAP_neighbourLoop(&dx, &dy);+ d = 9/(powf(dx, 2)+powf(dy, 2)+9)-0.5;+ p_set_vx(&parts[parts[i].tmp], p_vx(&parts[parts[i].tmp]) - (dx*d));+ p_set_vy(&parts[parts[i].tmp], p_vy(&parts[parts[i].tmp]) - (dy*d));+ p_set_vx(&parts[i], p_vx(&parts[i]) + (dx*d));+ p_set_vy(&parts[i], p_vy(&parts[i]) + (dy*d));+ if ((parts[parts[i].tmp].ctype&2) && (parts[parts[i].tmp].ctype&1)+ && SOAP_validIndex(parts[parts[i].tmp].tmp)+ && (parts[parts[parts[i].tmp].tmp].ctype&2) && (parts[parts[parts[i].tmp].tmp].ctype&1)) {+ int ii = parts[parts[parts[i].tmp].tmp].tmp;+ if (SOAP_validIndex(ii)) {+ dx = p_x(&parts[ii]) - p_x(&parts[parts[i].tmp]);+ dy = p_y(&parts[ii]) - p_y(&parts[parts[i].tmp]);+ SOAP_neighbourLoop(&dx, &dy);+ d = 81/(powf(dx, 2)+powf(dy, 2)+81)-0.5;+ p_set_vx(&parts[parts[i].tmp], p_vx(&parts[parts[i].tmp]) - (dx*d*0.5f));+ p_set_vy(&parts[parts[i].tmp], p_vy(&parts[parts[i].tmp]) - (dy*d*0.5f));+ p_set_vx(&parts[ii], p_vx(&parts[ii]) + (dx*d*0.5f));+ p_set_vy(&parts[ii], p_vy(&parts[ii]) + (dy*d*0.5f));+ }+ }+ }+ } else {+ if (pv[y/ACELL][x/ACELL]>0.5f || pv[y/ACELL][x/ACELL]<(-0.5f)) {+ parts[i].ctype = 1;+ parts[i].life = 10;+ }+ //SOAP+OIL foam effect+ for (int rx =-2; rx<3; rx++)+ for (int ry =-2; ry<3; ry++)+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r) == PT_OIL) {+ float ax, ay, gx, gy;+ GetGravityField(x, y, elements[PT_SOAP].Gravity, 1.0f, &gx, &gy);+ ax = ((p_vx(&parts[i])-gx)*0.5f + p_vx(&parts[ID(r)]))/2;+ ay = ((p_vy(&parts[i])-gy)*0.5f + p_vy(&parts[ID(r)]))/2;+ p_set_vx(&parts[ID(r)], ax);+ p_set_vx(&parts[i], ax);+ p_set_vy(&parts[ID(r)], ay);+ p_set_vy(&parts[i], ay);+ }+ }+ }+ /* (then the original fades the decoration of what touches it: decoration isn't kept) */+ return 0;+}+void el_SOAP_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) {+ if (from == PT_SOAP && to != PT_SOAP) {+ Element_SOAP_detach(i);+ }+}++/* ---------------------------------------------------------------- FRZW */+int el_FRZW_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_WATR && rng_chance(1, 14)) {+ //@ FRZW + WATR -> 2xFRZW+ part_change_type(ID(r),x+rx,y+ry,PT_FRZW);+ }+ }+ }+ }+ if ((parts[i].life==0 && rng_chance(1, 192)) || rng_chance(100-parts[i].life, 50000)) {+ //@ FRZW -> ICEI(FRZW)+ part_change_type(i,x,y,PT_ICEI);+ parts[i].ctype=PT_FRZW;+ p_set_temp(&parts[i], restrict_flt(p_temp(&parts[i])-200.0f, MIN_TEMP, MAX_TEMP));+ }+ return 0;+}++/* ---------------------------------------------------------------- BIZR */+/* BIZR, BIZRG and BIZRS blend their decoration colour into what touches them: decoration isn't kept */+int Element_BIZR_update(UPDATE_FUNC_ARGS) {+ return 0;+}++/* ---------------------------------------------------------------- RFRG */+int Element_RFRG_update(UPDATE_FUNC_ARGS) {+ /* the last pressure, a float in the original's 32-bit tmp: here its bits in tmp (low half) and tmp2 */+ float new_pressure = pv[y/ACELL][x/ACELL];+ union { uint32_t u; float f; } old;+ old.u = (uint16_t)parts[i].tmp | (uint32_t)(uint16_t)parts[i].tmp2 << 16;+ float *old_pressure = &old.f;+ if (isnan(*old_pressure)) {+ *old_pressure = new_pressure;+ parts[i].tmp = (int16_t)(old.u & 0xFFFF);+ parts[i].tmp2 = (int16_t)(old.u >> 16);+ return 0;+ }+ // * 0 bar seems to be pressure value -256 in TPT, see Air.cpp. Also, 1 bar seems to be pressure value 0.+ // With those two values we can set up our pressure scale which states that ... the highest pressure+ // we can achieve in TPT is 2 bar. That's not particularly realistic, but good enough for TPT.+ p_set_temp_d(&parts[i], restrict_flt(p_temp(&parts[i]) * ((new_pressure + 257.f) / (*old_pressure + 257.f)), 0, MAX_TEMP)); /* (small changes: dithered) */+ *old_pressure = new_pressure;+ parts[i].tmp = (int16_t)(old.u & 0xFFFF);+ parts[i].tmp2 = (int16_t)(old.u >> 16);+ return 0;+}++/* ---------------------------------------------------------------- RSST */+int el_RSST_update(UPDATE_FUNC_ARGS) {+ for(int rx = -1; rx < 2; rx++) {+ for(int ry = -1; ry < 2; ry++) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ //@ RSST + GUNP -> FIRW+ if(TYP(r) == PT_GUNP) {+ create_part(i, x, y, PT_FIRW, -1);+ kill_part(ID(r));+ return 1;+ }+ //@ RSST + BCOL -> FSEP+ if(TYP(r) == PT_BCOL) {+ create_part(i, x, y, PT_FSEP, -1);+ parts[i].life = 50;+ kill_part(ID(r));+ return 1;+ }+ // Set RSST ctype from nearby clone+ if((TYP(r) == PT_CLNE) || (TYP(r) == PT_PCLN)) {+ if(parts[ID(r)].ctype != PT_RSST)+ parts[i].ctype = parts[ID(r)].ctype;+ }+ // Set RSST tmp from nearby breakable clone+ if((TYP(r) == PT_BCLN) || (TYP(r) == PT_PBCN)) {+ if(parts[ID(r)].ctype != PT_RSST)+ parts[i].tmp = parts[ID(r)].ctype;+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- BASE */+int el_BASE_update(UPDATE_FUNC_ARGS) {+ //Reset spark effect+ parts[i].tmp = 0;+ if (parts[i].life < 1)+ parts[i].life = 1;+ if (parts[i].life > 100)+ parts[i].life = 100;+ float pres = pv[y/ACELL][x/ACELL];+ //Base evaporates into BOYL or increases concentration+ if (parts[i].life < 100 && pres < 10.0f && p_temp(&parts[i]) > (120.0f + 273.15f)) {+ //Slow down boiling+ if (rng_chance(1, 20)) {+ //This way we preserve the total amount of concentrated BASE in the solution+ if (rng_chance(1, parts[i].life+1)) {+ //@ BASE -> BOYL+ createPartTempVel(i, x, y, PT_BOYL);+ return 1;+ } else {+ parts[i].life++;+ //Enthalpy of vaporization+ p_set_temp_d(&parts[i], p_temp(&parts[i]) - (20.0f / ((float)parts[i].life))); /* (small changes: dithered) */+ }+ }+ }+ //Base's freezing point lowers with its concentration+ if (p_temp(&parts[i]) < (273.15f - ((float)parts[i].life)/4.0f)) {+ //@ BASE -> ICE(BASE)+ //We don't save base's concentration, so ICEI(BASE) will unfreeze into life = 0+ createPartTempVel(i, x, y, PT_ICEI);+ parts[i].ctype = PT_BASE;+ parts[i].life = 0;+ return 1;+ }+ //Reactions+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ //Don't react with some elements+ if (rt != PT_BASE && rt != PT_SALT && rt != PT_SLTW && rt != PT_BOYL && rt != PT_MERC &&+ rt != PT_BMTL && rt != PT_BRMT && rt != PT_SOAP && rt != PT_CLNE && rt != PT_PCLN &&+ !(rt == PT_ICEI && parts[ID(r)].ctype == PT_BASE) && !(rt == PT_SNOW && parts[ID(r)].ctype == PT_BASE) &&+ !(rt == PT_SPRK && parts[ID(r)].ctype == PT_BMTL) && !(rt == PT_SPRK && parts[ID(r)].ctype == PT_BRMT)) {+ //Base is diluted by water+ if (parts[i].life > 1 && (rt == PT_WATR || rt == PT_DSTW || rt == PT_CBNW)) {+ if (rng_chance(1, 20)) {+ int saturh = parts[i].life/2;+ //@ BASE + WATR/DSTW/CBNW -> 2xBASE+ createPartTempVel(ID(r), x+rx, y+ry, PT_BASE);+ parts[ID(r)].life = saturh;+ p_set_temp_d(&parts[ID(r)], p_temp(&parts[ID(r)]) + (((float)saturh)/10.0f));+ parts[i].life -= saturh;+ }+ } //Base neutralizes acid+ else if (rt == PT_ACID) {+ if (parts[ID(r)].life > 50 && parts[i].life > 0) {+ parts[ID(r)].life--;+ parts[i].life--;+ }+ //@ BASE + ACID -> 2xSLTW+ if (parts[ID(r)].life <= 50)+ createPartTempVel(ID(r), x+rx, y+ry, PT_SLTW);+ if (parts[i].life <= 0) {+ createPartTempVel(i, x, y, PT_SLTW);+ return 1;+ }+ } //Base neutralizes CAUS+ else if (rt == PT_CAUS) {+ if (parts[ID(r)].life > 50 && parts[i].life > 0) {+ parts[ID(r)].life--;+ parts[i].life--;+ }+ //@ BASE + CAUS -> SLTW+ if (parts[ID(r)].life <= 50)+ kill_part(ID(r));+ if (parts[i].life <= 0) {+ createPartTempVel(i, x, y, PT_SLTW);+ return 1;+ }+ } //@ BASE + OIL -> SOAP+ else if (parts[i].life >= 70 && rt == PT_OIL) {+ createPartTempVel(i, x, y, PT_SOAP);+ kill_part(ID(r));+ return 1;+ } //@ BASE + GOO -> BASE + GEL+ else if (parts[i].life > 1 && rt == PT_GOO) {+ createPartTempVel(ID(r), x+rx, y+ry, PT_GEL);+ parts[i].life--;+ } //@ BASE + BCOL -> BASE + GUNP+ else if (parts[i].life > 1 && rt == PT_BCOL) {+ createPartTempVel(ID(r), x+rx, y+ry, PT_GUNP);+ parts[i].life--;+ } //@ BASE + LAVA(ROCK) -> MERC+ else if (rt == PT_LAVA && parts[ID(r)].ctype == PT_ROCK && pres >= 10.0f && rng_chance(1, 1000)) {+ createPartTempVel(i, x, y, PT_MERC);+ kill_part(ID(r));+ return 1;+ } //Base rusts conductive solids+ else if (parts[i].life >= 10 &&+ (elements[rt].Properties & (TYPE_SOLID|PROP_CONDUCTS)) == (TYPE_SOLID|PROP_CONDUCTS) && rng_chance(1, 10)) {+ //@ BASE + conductive solid -> BASE + BMTL+ createPartTempVel(ID(r), x+rx, y+ry, PT_BMTL);+ parts[ID(r)].tmp = rng_between(20, 29);+ parts[i].life--;+ //Draw a spark effect+ parts[i].tmp = 1;+ } //Base destroys a substance slower if acid destroys it faster+ else if (elements[rt].Hardness > 0 && elements[rt].Hardness < 50 &&+ parts[i].life >= (2*elements[rt].Hardness) && rng_chance(50-elements[rt].Hardness, 1000)) {+ kill_part(ID(r));+ parts[i].life -= 2;+ //Draw a spark+ parts[i].tmp = 1;+ }+ }+ }+ }+ }+ //Diffusion+ for (int trade = 0; trade<2; trade++) {+ int rx = rng_between(-1, 1);+ int ry = rng_between(-1, 1);+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r) == PT_BASE && (parts[i].life > parts[ID(r)].life) && parts[i].life>1) {+ int temp = parts[i].life - parts[ID(r)].life;+ if (temp == 1) {+ parts[ID(r)].life++;+ parts[i].life--;+ } else if (temp>0) {+ parts[ID(r)].life += temp/2;+ parts[i].life -= temp/2;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- VIRS */+/* tmp3: frames until it's cured, when above 0 (being cured); tmp4, frames until it dies, is minus tmp3 when that+ * isn't above 0 (the original's tmp4 matters only while tmp3 is 0) */+int Element_VIRS_update(UPDATE_FUNC_ARGS) {+ int rndstore = rng_gen();+ if (parts[i].tmp3 > 0) {+ parts[i].tmp3 -= (rndstore & 0x1) ? 0:1;+ //has been cured, so change back into the original element+ if (!parts[i].tmp3) {+ part_change_type(i,x,y,parts[i].tmp2);+ parts[i].tmp2 = 0;+ parts[i].tmp3 = 0;+ tmp4_clear(i); /* (the element it's back to: a PIPE's, STOR's, PLNT's... tmp4 is 0, as the original's) */+ }+ return 0;+ //cured virus is never in below code+ }+ int tmp4 = -parts[i].tmp3;+ //decrease tmp4 so it slowly dies+ if (tmp4) {+ if (!(rndstore & 0x7) && --tmp4 <= 0) {+ kill_part(i);+ return 1;+ }+ parts[i].tmp3 = (int16_t)-tmp4;+ rndstore >>= 3;+ }+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ //spread "being cured" state+ if (parts[ID(r)].tmp3 > 0 && (TYP(r) == PT_VIRS || TYP(r) == PT_VRSS || TYP(r) == PT_VRSG)) {+ parts[i].tmp3 = parts[ID(r)].tmp3 + ((rndstore & 0x3) ? 2:1);+ return 0;+ }+ //soap cures virus+ else if (TYP(r) == PT_SOAP) {+ parts[i].tmp3 = 10; /* (the original's tmp3 += 10, from 0) */+ if (!(rndstore & 0x3))+ kill_part(ID(r));+ return 0;+ } else if (TYP(r) == PT_PLSM) {+ if (surround_space && rng_chance(10 + (int)(pv[(y+ry)/ACELL][(x+rx)/ACELL]), 100)) {+ //@ VIRS/VRSS/VRSG + PLSM -> 2xPLSM+ create_part(i, x, y, PT_PLSM, -1);+ return 1;+ }+ }+ //transforms things into virus here+ else if (TYP(r) != PT_VIRS && TYP(r) != PT_VRSS && TYP(r) != PT_VRSG && TYP(r) != PT_DMND && TYP(r) != PT_BASE) {+ if (!(rndstore & 0x7)) {+ parts[ID(r)].tmp2 = TYP(r);+ /* tmp3 = 0, tmp4 = this one's + 1 (or 0) */+ parts[ID(r)].tmp3 = (int16_t)-(tmp4 ? imin(tmp4 + 1, 32767) : 0);+ if (p_temp(&parts[ID(r)]) < 305.0f)+ part_change_type(ID(r), x+rx, y+ry, PT_VRSS);+ else if (p_temp(&parts[ID(r)]) > 673.0f)+ part_change_type(ID(r), x+rx, y+ry, PT_VRSG);+ else+ part_change_type(ID(r), x+rx, y+ry, PT_VIRS);+ }+ rndstore >>= 3;+ }+ //protons make VIRS last forever+ else if (TYP(PHOTAT(x+rx, y+ry)) == PT_PROT) {+ tmp4 = 0;+ parts[i].tmp3 = 0;+ }+ }+ //reset rndstore only once, halfway through+ else if (!rx && !ry)+ rndstore = rng_gen();+ }+ }+ return 0;+}diff --git a/games/numpowder/src/el_misc.c b/games/numpowder/src/el_misc.cnew file mode 100644index 00000000..b4f67ac1--- /dev/null+++ b/games/numpowder/src/el_misc.c@@ -0,0 +1,102 @@+/* NumPowder: The Powder Toy's element functions shared by several elements (Element.cpp): drawing an element+ * on one to set its ctype, and the update for when the heat simulation is off (legacyUpdate). */+#include "simpriv.h"++bool basicCtypeDraw(CTYPEDRAW_FUNC_ARGS) {+ if (parts[i].type == t || elements[t].Properties & PROP_NOCTYPEDRAW) return false;+ parts[i].ctype = t;+ return true;+}++/* CLNE, BCLN, DTEC...: LIFE's rule goes in tmp */+bool ctypeDrawVInTmp(CTYPEDRAW_FUNC_ARGS) {+ if (!basicCtypeDraw(CTYPEDRAW_FUNC_SUBCALL_ARGS)) return false;+ if (t == PT_LIFE) parts[i].tmp = (int16_t)v; /* (the built-in rules' numbers: custom rules aren't offered) */+ return true;+}++bool ctypeDrawVInCtype(CTYPEDRAW_FUNC_ARGS) {+ if (!basicCtypeDraw(CTYPEDRAW_FUNC_SUBCALL_ARGS)) return false;+ if (t == PT_LIFE) parts[i].ctype |= PMAPID(v);+ return true;+}++/* when the heat simulation is off: water boils near fire, ice melts... (Element::legacyUpdate) */+int Element_legacyUpdate(UPDATE_FUNC_ARGS) {+ int r, rx, ry;+ int t = parts[i].type;+ if (t == PT_WTRV) {+ for (rx = -2; rx < 3; rx++)+ for (ry = -2; ry < 3; ry++)+ if (x + rx >= 0 && y + ry > 0 && x + rx < XRES && y + ry < YRES && (rx || ry)) {+ r = PMAPAT(x + rx, y + ry);+ if (!r) continue;+ if ((TYP(r) == PT_WATR || TYP(r) == PT_DSTW || TYP(r) == PT_SLTW) && rng_chance(1, 1000)) {+ part_change_type(i, x, y, PT_WATR);+ part_change_type(ID(r), x + rx, y + ry, PT_WATR);+ }+ if ((TYP(r) == PT_ICEI || TYP(r) == PT_SNOW) && rng_chance(1, 1000)) {+ part_change_type(i, x, y, PT_WATR);+ if (rng_chance(1, 1000)) part_change_type(ID(r), x + rx, y + ry, PT_WATR);+ }+ }+ } else if (t == PT_WATR) {+ for (rx = -2; rx < 3; rx++)+ for (ry = -2; ry < 3; ry++)+ if (x + rx >= 0 && y + ry > 0 && x + rx < XRES && y + ry < YRES && (rx || ry)) {+ r = PMAPAT(x + rx, y + ry);+ if (!r) continue;+ if ((TYP(r) == PT_FIRE || TYP(r) == PT_LAVA) && rng_chance(1, 10)) part_change_type(i, x, y, PT_WTRV);+ }+ } else if (t == PT_SLTW) {+ for (rx = -2; rx < 3; rx++)+ for (ry = -2; ry < 3; ry++)+ if (x + rx >= 0 && y + ry > 0 && x + rx < XRES && y + ry < YRES && (rx || ry)) {+ r = PMAPAT(x + rx, y + ry);+ if (!r) continue;+ if ((TYP(r) == PT_FIRE || TYP(r) == PT_LAVA) && rng_chance(1, 10)) {+ if (rng_chance(1, 4)) part_change_type(i, x, y, PT_SALT);+ else part_change_type(i, x, y, PT_WTRV);+ }+ }+ } else if (t == PT_DSTW) {+ for (rx = -2; rx < 3; rx++)+ for (ry = -2; ry < 3; ry++)+ if (x + rx >= 0 && y + ry > 0 && x + rx < XRES && y + ry < YRES && (rx || ry)) {+ r = PMAPAT(x + rx, y + ry);+ if (!r) continue;+ if ((TYP(r) == PT_FIRE || TYP(r) == PT_LAVA) && rng_chance(1, 10)) part_change_type(i, x, y, PT_WTRV);+ }+ } else if (t == PT_ICEI) {+ for (rx = -2; rx < 3; rx++)+ for (ry = -2; ry < 3; ry++)+ if (x + rx >= 0 && y + ry > 0 && x + rx < XRES && y + ry < YRES && (rx || ry)) {+ r = PMAPAT(x + rx, y + ry);+ if (!r) continue;+ if ((TYP(r) == PT_WATR || TYP(r) == PT_DSTW) && rng_chance(1, 1000)) {+ part_change_type(i, x, y, PT_ICEI);+ part_change_type(ID(r), x + rx, y + ry, PT_ICEI);+ }+ }+ } else if (t == PT_SNOW) {+ for (rx = -2; rx < 3; rx++)+ for (ry = -2; ry < 3; ry++)+ if (x + rx >= 0 && y + ry > 0 && x + rx < XRES && y + ry < YRES && (rx || ry)) {+ r = PMAPAT(x + rx, y + ry);+ if (!r) continue;+ if ((TYP(r) == PT_WATR || TYP(r) == PT_DSTW) && rng_chance(1, 1000)) {+ part_change_type(i, x, y, PT_ICEI);+ part_change_type(ID(r), x + rx, y + ry, PT_ICEI);+ }+ if ((TYP(r) == PT_WATR || TYP(r) == PT_DSTW) && rng_chance(3, 200)) part_change_type(i, x, y, PT_WATR);+ }+ }+ if (t == PT_WTRV && pv[y / ACELL][x / ACELL] > 4.0f) part_change_type(i, x, y, PT_DSTW);+ if (t == PT_OIL && pv[y / ACELL][x / ACELL] < -6.0f) part_change_type(i, x, y, PT_GAS);+ if (t == PT_GAS && pv[y / ACELL][x / ACELL] > 6.0f) part_change_type(i, x, y, PT_OIL);+ if (t == PT_DESL && pv[y / ACELL][x / ACELL] > 12.0f) {+ part_change_type(i, x, y, PT_FIRE);+ parts[i].life = (int16_t)rng_between(120, 169);+ }+ return 0;+}diff --git a/games/numpowder/src/el_nuclear.c b/games/numpowder/src/el_nuclear.cnew file mode 100644index 00000000..fdd3751b--- /dev/null+++ b/games/numpowder/src/el_nuclear.c@@ -0,0 +1,991 @@+/* NumPowder: The Powder Toy's radioactive and energy elements (their files in elements/), ported: NEUT, PHOT, PLUT,+ * URAN, ISOZ, ISZS, AMTR, DEUT, WARP, SING, ELEC, PROT, GRVT, EXOT, POLO. */+#include "simpriv.h"++/* ---------------------------------------------------------------- NEUT */+static int NEUT_DeutExplosion(int n, int x, int y, float temp, int t);+int el_NEUT_update(UPDATE_FUNC_ARGS) {+ unsigned int pressureFactor = 3 + (int)pv[y/ACELL][x/ACELL];+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ int r = PMAPAT(x+rx, y+ry);+ switch (TYP(r)) {+ case PT_WATR:+ //@ NEUT + WATR -> NEUT + DSTW+ if (rng_chance(3, 20))+ part_change_type(ID(r),x+rx,y+ry,PT_DSTW);+ /* fallthrough */+ case PT_ICEI:+ case PT_SNOW:+ p_set_vx(&parts[i], p_vx(&parts[i]) * (0.995f));+ p_set_vy(&parts[i], p_vy(&parts[i]) * (0.995f));+ break;+ case PT_PLUT:+ if (rng_chance(pressureFactor, 1000)) {+ if (rng_chance(1, 3)) {+ //@ NEUT + PLUT -> NEUT + URAN/LAVA(PLUT)+ create_part(ID(r), x+rx, y+ry, rng_chance(2, 3) ? PT_LAVA : PT_URAN, -1);+ p_set_temp(&parts[ID(r)], MAX_TEMP);+ if (parts[ID(r)].type==PT_LAVA) {+ parts[ID(r)].tmp = 100;+ parts[ID(r)].ctype = PT_PLUT;+ }+ } else {+ //@ NEUT + PLUT -> 2xNEUT+ create_part(ID(r), x+rx, y+ry, PT_NEUT, -1);+ p_set_vx(&parts[ID(r)], 0.25f*p_vx(&parts[ID(r)]) + p_vx(&parts[i]));+ p_set_vy(&parts[ID(r)], 0.25f*p_vy(&parts[ID(r)]) + p_vy(&parts[i]));+ }+ pv[y/ACELL][x/ACELL] += 10.0f * CFDS; //Used to be 2, some people said nukes weren't powerful enough+ Element_FIRE_update(UPDATE_FUNC_SUBCALL_ARGS);+ }+ break;+ case PT_DEUT:+ if (rng_chance(pressureFactor + 1 + (parts[ID(r)].life/100), 1000)) {+ //@ NEUT + DEUT -> 2xNEUT+ NEUT_DeutExplosion(parts[ID(r)].life, x+rx, y+ry, restrict_flt(p_temp(&parts[ID(r)]) + parts[ID(r)].life*500.0f, MIN_TEMP, MAX_TEMP), PT_NEUT);+ kill_part(ID(r));+ }+ break;+ case PT_GUNP:+ //@ NEUT + GUNP -> NEUT + DUST+ if (rng_chance(3, 200))+ part_change_type(ID(r),x+rx,y+ry,PT_DUST);+ break;+ case PT_DYST:+ //@ NEUT + DYST -> NEUT + YEST+ if (rng_chance(3, 200))+ part_change_type(ID(r),x+rx,y+ry,PT_YEST);+ break;+ case PT_YEST:+ //@ NEUT + YEST -> NEUT + DYST+ part_change_type(ID(r),x+rx,y+ry,PT_DYST);+ break;+ case PT_PLEX:+ //@ NEUT + PLEX -> NEUT + GOO+ if (rng_chance(3, 200))+ part_change_type(ID(r),x+rx,y+ry,PT_GOO);+ break;+ case PT_NITR:+ //@ NEUT + NITR -> NEUT + DESL+ if (rng_chance(3, 200))+ part_change_type(ID(r),x+rx,y+ry,PT_DESL);+ break;+ case PT_PLNT:+ //@ NEUT + PLNT -> NEUT + WOOD+ if (rng_chance(1, 20))+ create_part(ID(r), x+rx, y+ry, PT_WOOD, -1);+ break;+ case PT_DESL:+ case PT_OIL:+ //@ NEUT + DESL/OIL -> NEUT + GAS+ if (rng_chance(3, 200))+ part_change_type(ID(r),x+rx,y+ry,PT_GAS);+ break;+ case PT_COAL:+ //@ NEUT + COAL -> NEUT + WOOD+ if (rng_chance(1, 20))+ create_part(ID(r), x+rx, y+ry, PT_WOOD, -1);+ break;+ case PT_BCOL:+ //@ NEUT + BCOL -> NEUT + SAWD+ if (rng_chance(1, 20))+ create_part(ID(r), x+rx, y+ry, PT_SAWD, -1);+ break;+ case PT_DUST:+ //@ NEUT + DUST -> NEUT + FWRK+ if (rng_chance(1, 20))+ part_change_type(ID(r), x+rx, y+ry, PT_FWRK);+ break;+ case PT_FWRK:+ if (rng_chance(1, 20))+ parts[ID(r)].ctype = PT_DUST;+ break;+ case PT_ACID:+ //@ NEUT + ACID -> NEUT + ISOZ+ if (rng_chance(1, 20))+ create_part(ID(r), x+rx, y+ry, PT_ISOZ, -1);+ break;+ case PT_TTAN:+ if (rng_chance(1, 20)) {+ kill_part(i);+ return 1;+ }+ break;+ case PT_EXOT:+ if (rng_chance(1, 20))+ parts[ID(r)].life = 1500;+ break;+ case PT_RFRG:+ //@ NEUT + RFRG -> NEUT + GAS/CAUS+ if (rng_chance(1, 2))+ create_part(ID(r), x+rx, y+ry, PT_GAS, -1);+ else+ create_part(ID(r), x+rx, y+ry, PT_CAUS, -1);+ break;+ case PT_RSSS:+ if(!rx && !ry) {+ int ct_under, tmp_under;+ ct_under = parts[ID(r)].ctype;+ tmp_under = parts[ID(r)].tmp;+ //If there's a correct ctype set, liquefy into it+ if(ct_under > 0 && ct_under < PT_NUM) {+ //@ NEUT + RSSS(ctype) -> ctype+ create_part(ID(r), x, y, ct_under, -1);+ //If there's a correct tmp set, use it for ctype+ if((tmp_under > 0) && (tmp_under < PT_NUM) && (elements[ct_under].CarriesTypeIn & (1U << FIELD_CTYPE)))+ parts[ID(r)].ctype = tmp_under;+ } else //@ NEUT + RSSS -> RSST+ part_change_type(ID(r), x, y, PT_RSST); //Default to RSST if no ctype+ kill_part(i);+ return 1;+ }+ break;+ case PT_BASE:+ //@ NEUT + BASE -> NEUT + LRBD+ if (p_temp(&parts[ID(r)]) > (50 + 273.15) && rng_chance(1, 35))+ create_part(ID(r), x+rx, y+ry, PT_LRBD, -1);+ break;+ case PT_SEED:+ if(!rx && !ry) {+ // Flip a random gene with 1/2 chance+ switch (rng_between(0, 9)) {+ case 0:+ parts[ID(r)].ctype ^= 1 << rng_between(PLNT_COLOUR, PLNT_LIFE-1);+ break;+ case 1:+ parts[ID(r)].tmp ^= 1 << rng_between(0, PLNT_TOTAL_TMP-1);+ break;+ case 2:+ parts[ID(r)].tmp2 ^= 1 << rng_between(0, PLNT_TOTAL_TMP-1);+ break;+ case 3:+ parts[ID(r)].tmp3 ^= 1 << rng_between(0, PLNT_TOTAL_TMP-1);+ break;+ case 4:+ tmp4_set(ID(r), tmp4_get(ID(r)) ^ (1 << rng_between(0, PLNT_TOTAL_TMP-1)));+ break;+ default:+ break;+ }+ }+ break;+ default:+ break;+ }+ }+ }+ return 0;+}+void el_NEUT_create(ELEMENT_CREATE_FUNC_ARGS) {+ float r = rng_between(128, 255) / 127.0f;+ float a = rng_between(0, 359) * NP_PI / 180.0f;+ parts[i].life = rng_between(480, 959);+ p_set_vx(&parts[i], r * cosf(a));+ p_set_vy(&parts[i], r * sinf(a));+}+static int NEUT_DeutExplosion(int n, int x, int y, float temp, int t) { //testing a new deut create part+ int i;+ n = (n/50);+ if (n < 1)+ n = 1;+ else if (n > 340)+ n = 340;+ for (int c = 0; c < n; c++) {+ i = create_part(-3, x, y, t, -1);+ if (i >= 0)+ p_set_temp(&parts[i], temp);+ else if (parts_full())+ break;+ }+ pv[y/ACELL][x/ACELL] += (6.0f * CFDS)*n;+ return 0;+}++/* ---------------------------------------------------------------- PHOT */+int el_PHOT_update(UPDATE_FUNC_ARGS) {+ if (!(parts[i].ctype&0x3FFFFFFF)) {+ kill_part(i);+ return 1;+ }+ if (p_temp(&parts[i]) > 506)+ if (rng_chance(1, 10))+ Element_FIRE_update(UPDATE_FUNC_SUBCALL_ARGS);+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_ISOZ || TYP(r)==PT_ISZS) {+ if (rng_chance(1, 400)) {+ p_set_vx(&parts[i], p_vx(&parts[i]) * (0.90f));+ p_set_vy(&parts[i], p_vy(&parts[i]) * (0.90f));+ //@ PHOT + ISOZ/ISZS -> 2xPHOT+ create_part(ID(r), x+rx, y+ry, PT_PHOT, -1);+ float rrr = rng_between(0, 359) * NP_PI / 180.0f;+ int rr;+ if (TYP(r) == PT_ISOZ)+ rr = (int)(rng_between(128, 255) / 127.0f);+ else+ rr = (int)(rng_between(128, 355) / 127.0f);+ p_set_vx(&parts[ID(r)], rr*cosf(rrr));+ p_set_vy(&parts[ID(r)], rr*sinf(rrr));+ pv[y/ACELL][x/ACELL] -= 15.0f * CFDS;+ }+ } else if((TYP(r) == PT_QRTZ || TYP(r) == PT_PQRT) && !ry && !rx) { //if on QRTZ+ float a = rng_between(0, 359) * NP_PI / 180.0f;+ p_set_vx(&parts[i], 3.0f*cosf(a));+ p_set_vy(&parts[i], 3.0f*sinf(a));+ if(parts[i].ctype == 0x3FFFFFFF)+ parts[i].ctype = 0x1F << rng_between(0, 25);+ if (parts[i].life)+ parts[i].life++; //Delay death+ } else if(TYP(r) == PT_BGLA && !ry && !rx) { //if on BGLA+ float a = rng_between(-50, 50) * 0.001f;+ float rx = cosf(a), ry = sinf(a), nvx, nvy;+ nvx = rx * p_vx(&parts[i]) + ry * p_vy(&parts[i]);+ nvy = rx * p_vy(&parts[i]) - ry * p_vx(&parts[i]);+ p_set_vx(&parts[i], nvx);+ p_set_vy(&parts[i], nvy);+ } else if(TYP(r) == PT_RSST && !ry && !rx) { //if on RSST, make it solid+ int ct_under, tmp_under;+ ct_under = parts[ID(r)].ctype;+ tmp_under = parts[ID(r)].tmp;+ //If there's a correct ctype set, solidify RSST into it+ if(ct_under > 0 && ct_under < PT_NUM) {+ //@ PHOT + RSST(ctype) -> ctype+ create_part(ID(r), x, y, ct_under, -1);+ //If there's a correct tmp set, use it for ctype+ if((tmp_under > 0) && (tmp_under < PT_NUM) && (elements[ct_under].CarriesTypeIn & (1U << FIELD_CTYPE)))+ parts[ID(r)].ctype = tmp_under;+ } else //@ PHOT + RSST -> RSSS+ part_change_type(ID(r), x, y, PT_RSSS); //Default to RSSS if no ctype+ kill_part(i);+ return 1;+ } else if (TYP(r) == PT_FILT && parts[ID(r)].tmp==9) {+ p_set_vx(&parts[i], p_vx(&parts[i]) + (((float)rng_between(-500, 500))/1000.0f));+ p_set_vy(&parts[i], p_vy(&parts[i]) + (((float)rng_between(-500, 500))/1000.0f));+ }+ }+ }+ return 0;+}+void el_PHOT_create(ELEMENT_CREATE_FUNC_ARGS) {+ float a = rng_between(0, 7) * 0.78540f;+ p_set_vx(&parts[i], 3.0f * cosf(a));+ p_set_vy(&parts[i], 3.0f * sinf(a));+ if (TYP(PMAPAT(x, y)) == PT_FILT)+ parts[i].ctype = Element_FILT_interactWavelengths(&parts[ID(PMAPAT(x, y))], parts[i].ctype);+}++/* ---------------------------------------------------------------- PLUT */+int el_PLUT_update(UPDATE_FUNC_ARGS) {+ if (rng_chance(1, 100) && rng_chance((int)(5.0f*pv[y/ACELL][x/ACELL]), 1000)) {+ //@ PLUT -> NEUT+ create_part(i, x, y, PT_NEUT, -1);+ }+ return 0;+}++/* ---------------------------------------------------------------- URAN */+int el_URAN_update(UPDATE_FUNC_ARGS) {+ if (!legacy_enable && pv[y/ACELL][x/ACELL]>0.0f) {+ if (p_temp(&parts[i]) == MIN_TEMP) {+ p_set_temp_d(&parts[i], p_temp(&parts[i]) + (.01f));+ } else {+ p_set_temp_d(&parts[i], restrict_flt((p_temp(&parts[i])*(1 + (pv[y / ACELL][x / ACELL] / 2000))) + MIN_TEMP, MIN_TEMP, MAX_TEMP));+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- ISOZ */+int el_ISOZ_update(UPDATE_FUNC_ARGS) {+ float rr, rrr;+ if (rng_chance(1, 200) && rng_chance((int)(-4.0f * pv[y/ACELL][x/ACELL]), 1000)) {+ //@ ISOZ -> PHOT+ create_part(i, x, y, PT_PHOT, -1);+ rr = rng_between(128, 355) / 127.0f;+ rrr = rng_between(0, 359) * NP_PI / 180.0f;+ p_set_vx(&parts[i], rr*cosf(rrr));+ p_set_vy(&parts[i], rr*sinf(rrr));+ }+ return 0;+}++/* ---------------------------------------------------------------- ISZS */+int el_ISZS_update(UPDATE_FUNC_ARGS) {+ float rr, rrr;+ if (rng_chance(1, 200) && rng_chance((int)(-4.0f * pv[y/ACELL][x/ACELL]), 1000)) {+ //@ ISZS -> PHOT+ create_part(i, x, y, PT_PHOT, -1);+ rr = rng_between(128, 355) / 127.0f;+ rrr = rng_between(0, 359) * NP_PI / 180.0f;+ p_set_vx(&parts[i], rr*cosf(rrr));+ p_set_vy(&parts[i], rr*sinf(rrr));+ }+ return 0;+}++/* ---------------------------------------------------------------- AMTR */+int el_AMTR_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (rt!=PT_AMTR && rt!=PT_DMND && rt!=PT_CLNE && rt!=PT_PCLN && rt!=PT_VOID && rt!=PT_BHOL && rt!=PT_NBHL && rt!=PT_PRTI && rt!=PT_PRTO) {+ parts[i].life++;+ if (parts[i].life==4) {+ kill_part(i);+ return 1;+ }+ //@ AMTR + anything -> AMTR + PHOT+ if (rng_chance(1, 10))+ create_part(ID(r), x+rx, y+ry, PT_PHOT, -1);+ else+ kill_part(ID(r));+ pv[y/ACELL][x/ACELL] -= 2.0f;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- DEUT */+int el_DEUT_update(UPDATE_FUNC_ARGS) {+ float gravtot = fabsf(gravx[y/ACELL][x/ACELL]) + fabsf(gravy[y/ACELL][x/ACELL]);+ // Prevent division by 0+ float temp = fmaxf(1.0f, (p_temp(&parts[i]) + 1));+ int maxlife = (int)(((10000/(temp + 1))-1));+ if (rng_chance(10000 % (int)(temp + 1), (int)(temp + 1)))+ maxlife++;+ // Compress when Newtonian gravity is applied+ // multiplier=1 when gravtot=0, multiplier -> 5 as gravtot -> inf+ maxlife = maxlife*(int)(5.0f - 8.0f/(gravtot+2.0f));+ if (parts[i].life < maxlife) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r || (parts[i].life >=maxlife))+ continue;+ if (TYP(r)==PT_DEUT&& rng_chance(1, 3)) {+ // If neighbour life+1 fits in the free capacity for this particle, absorb neighbour+ // Condition is written in this way so that large neighbour life values don't cause integer overflow+ if (parts[ID(r)].life <= maxlife - parts[i].life - 1) {+ parts[i].life += parts[ID(r)].life + 1;+ kill_part(ID(r));+ }+ }+ }+ }+ }+ } else {+ /* tryExpand */+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ //Leave if there is nothing to do+ if (parts[i].life <= maxlife) {+ goto expanded;+ }+ int r = PMAPAT(x+rx, y+ry);+ if ((!r)&&parts[i].life>=1) { //if nothing then create deut+ int np = create_part(-1,x+rx,y+ry,PT_DEUT, -1);+ if (np<0) continue;+ parts[i].life--;+ p_set_temp(&parts[np], p_temp(&parts[i]));+ parts[np].life = 0;+ }+ }+ }+ }+ expanded:;+ }+ for (int trade = 0; trade<4; trade ++) {+ int rx = rng_between(-2, 2);+ int ry = rng_between(-2, 2);+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_DEUT&&(parts[i].life>parts[ID(r)].life)&&parts[i].life>0) { //diffusion+ int temp = parts[i].life - parts[ID(r)].life;+ if (temp ==1) {+ parts[ID(r)].life ++;+ parts[i].life --;+ } else if (temp>0) {+ parts[ID(r)].life += temp/2;+ parts[i].life -= temp/2;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- WARP */+int el_WARP_update(UPDATE_FUNC_ARGS) {+ if (parts[i].tmp2 > 2000) {+ p_set_temp(&parts[i], 10000); /* (the original's 10000 K: MAX_TEMP here, simdefs.h) */+ pv[y/ACELL][x/ACELL] = restrict_flt(pv[y/ACELL][x/ACELL] + (parts[i].tmp2 / 5000) * CFDS, MIN_PRESSURE, MAX_PRESSURE);+ //@ WARP -> WARP + ELEC+ if (rng_chance(1, 50))+ create_part(-3, x, y, PT_ELEC, -1);+ }+ for (int trade = 0; trade < 5; trade ++) {+ int rx = rng_between(-1, 1);+ int ry = rng_between(-1, 1);+ if (rx || ry) {+ int r = PMAPAT(x + rx, y + ry);+ if (!r)+ continue;+ if (TYP(r) != PT_WARP && TYP(r) != PT_STKM && TYP(r) != PT_STKM2 && TYP(r) != PT_DMND && TYP(r) != PT_CLNE && TYP(r) != PT_BCLN && TYP(r) != PT_PCLN) {+ p_set_x(&parts[i], p_x(&parts[ID(r)]));+ p_set_y(&parts[i], p_y(&parts[ID(r)]));+ p_set_x(&parts[ID(r)], (float)(x));+ p_set_y(&parts[ID(r)], (float)(y));+ p_set_vx(&parts[ID(r)], rng_between(-2, 1) + 0.5f);+ p_set_vy(&parts[ID(r)], (float)(rng_between(-2, 1)));+ parts[i].life = (int16_t)(parts[i].life <= 32767 - 4 ? parts[i].life + 4 : 32767); /* (16 bits: kept at the top) */+ PMAPSET(x, y, r);+ PMAPSET(x + rx, y + ry, PMAP(i, parts[i].type));+ trade = 5;+ }+ }+ }+ return 0;+}+void el_WARP_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].life = rng_between(70, 164);+}++/* ---------------------------------------------------------------- SING */+int el_SING_update(UPDATE_FUNC_ARGS) {+ int singularity = -parts[i].life;+ if (pv[y/ACELL][x/ACELL]<singularity)+ pv[y/ACELL][x/ACELL] += 0.1f*(singularity-pv[y/ACELL][x/ACELL]);+ if (pv[y/ACELL+1][x/ACELL]<singularity)+ pv[y/ACELL+1][x/ACELL] += 0.1f*(singularity-pv[y/ACELL+1][x/ACELL]);+ if (pv[y/ACELL-1][x/ACELL]<singularity)+ pv[y/ACELL-1][x/ACELL] += 0.1f*(singularity-pv[y/ACELL-1][x/ACELL]);+ pv[y/ACELL][x/ACELL+1] = restrict_flt(pv[y/ACELL][x/ACELL+1] + 0.1f*(singularity-pv[y/ACELL][x/ACELL+1]), MIN_PRESSURE, MAX_PRESSURE);+ pv[y/ACELL+1][x/ACELL+1] = restrict_flt(pv[y/ACELL+1][x/ACELL+1] + 0.1f*(singularity-pv[y/ACELL+1][x/ACELL+1]), MIN_PRESSURE, MAX_PRESSURE);+ pv[y/ACELL][x/ACELL-1] = restrict_flt(pv[y/ACELL][x/ACELL-1] + 0.1f*(singularity-pv[y/ACELL][x/ACELL-1]), MIN_PRESSURE, MAX_PRESSURE);+ pv[y/ACELL-1][x/ACELL-1] = restrict_flt(pv[y/ACELL-1][x/ACELL-1] + 0.1f*(singularity-pv[y/ACELL-1][x/ACELL-1]), MIN_PRESSURE, MAX_PRESSURE);+ if (parts[i].life<1) {+ //Pop!+ for (int rx = -1; rx <= 1; rx++) {+ int crx = (x/ACELL)+rx;+ for (int ry = -1; ry <= 1; ry++) {+ int cry = (y/ACELL)+ry;+ if (cry >= 0 && crx >= 0 && crx < XACELLS && cry < YACELLS) {+ pv[cry][crx] = restrict_flt(pv[cry][crx] + (float)parts[i].tmp, MIN_PRESSURE, MAX_PRESSURE);+ }+ }+ }+ int spawncount = abs(parts[i].tmp);+ spawncount = spawncount>255 ? 3019 : (int)((float)((spawncount/8)*(spawncount/8))*NP_PI); /* (the same as in doubles for these) */+ for (int j = 0;j < spawncount; j++) {+ int nb = -1;+ switch (rng_gen() % 3) {+ case 0:+ //@ SING -> PHOT+ nb = create_part(-3, x, y, PT_PHOT, -1);+ break;+ case 1:+ //@ SING -> NEUT+ nb = create_part(-3, x, y, PT_NEUT, -1);+ break;+ case 2:+ //@ SING -> ELEC+ nb = create_part(-3, x, y, PT_ELEC, -1);+ break;+ }+ if (nb!=-1) {+ parts[nb].life = rng_between(0, 299);+ p_set_temp(&parts[nb], MAX_TEMP / 2);+ float angle = rng_uniform01() * 2.0f * NP_PI;+ float v = rng_uniform01() * 5.0f;+ p_set_vx(&parts[nb], v * cosf(angle));+ p_set_vy(&parts[nb], v * sinf(angle));+ } else if (parts_full())+ break;//if we've run out of particles, stop trying to create them - saves a lot of lag on "sing bomb" saves+ }+ kill_part(i);+ return 1;+ }+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)!=PT_DMND&& rng_chance(1, 3)) {+ if (TYP(r)==PT_SING && parts[ID(r)].life >10) {+ if (parts[i].life+parts[ID(r)].life > 255)+ continue;+ parts[i].life += parts[ID(r)].life;+ } else {+ if (parts[i].life+3 > 255) {+ if (parts[ID(r)].type!=PT_SING && rng_chance(1, 1000)) {+ int np;+ np = create_part(ID(r),x+rx,y+ry,PT_SING, -1);+ parts[np].life = rng_between(60, 109);+ }+ continue;+ }+ parts[i].life += 3;+ parts[i].tmp++;+ }+ p_set_temp(&parts[i], restrict_flt(p_temp(&parts[ID(r)])+p_temp(&parts[i]), MIN_TEMP, MAX_TEMP));+ kill_part(ID(r));+ }+ }+ }+ }+ return 0;+}+void el_SING_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].life = rng_between(60, 109);+}++/* ---------------------------------------------------------------- ELEC */+int el_ELEC_update(UPDATE_FUNC_ARGS) {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ r = PHOTAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ switch (rt) {+ case PT_GLAS:+ for (int rrx =-1; rrx<=1; rrx++) {+ for (int rry =-1; rry<=1; rry++) {+ if (x+rx+rrx>=0 && y+ry+rry>=0 && x+rx+rrx<XRES && y+ry+rry<YRES) {+ //@ ELEC + GLAS -> EMBR + GLAS+ int nb = create_part(-1, x+rx+rrx, y+ry+rry, PT_EMBR, -1);+ if (nb!=-1) {+ parts[nb].tmp = 0;+ parts[nb].life = 50;+ p_set_temp(&parts[nb], p_temp(&parts[i])*0.8f);+ p_set_vx(&parts[nb], (float)(rng_between(-10, 10)));+ p_set_vy(&parts[nb], (float)(rng_between(-10, 10)));+ }+ }+ }+ }+ kill_part(i);+ return 1;+ case PT_LCRY:+ parts[ID(r)].tmp2 = rng_between(5, 9);+ break;+ case PT_WATR:+ case PT_DSTW:+ case PT_SLTW:+ case PT_CBNW:+ //@ ELEC + WATR/DSTW/SLTW/CBNW -> O2/H2+ if (rng_chance(1, 3))+ create_part(ID(r), x+rx, y+ry, PT_O2, -1);+ else+ create_part(ID(r), x+rx, y+ry, PT_H2, -1);+ kill_part(i);+ return 1;+ case PT_PROT: // this is the correct reaction, not NEUT, but leaving NEUT in anyway+ if (parts[ID(r)].tmp2 & 0x1)+ break;+ /* fallthrough */+ case PT_NEUT:+ //@ ELEC + PROT/NEUT -> H2+ part_change_type(ID(r), x+rx, y+ry, PT_H2);+ parts[ID(r)].life = 0;+ parts[ID(r)].ctype = 0;+ kill_part(i);+ break;+ case PT_DEUT:+ if(parts[ID(r)].life < 6000)+ parts[ID(r)].life += 1;+ p_set_temp(&parts[ID(r)], 0);+ kill_part(i);+ return 1;+ case PT_EXOT:+ parts[ID(r)].tmp2 += 5;+ parts[ID(r)].life = 1000;+ break;+ case PT_RSST: //Destroy RSST+ if(!rx && !ry) {+ kill_part(ID(r));+ kill_part(i);+ return 1;+ }+ break;+ case PT_NONE: //seems to speed up ELEC even if it isn't used+ break;+ default:+ if ((elements[rt].Properties & PROP_CONDUCTS) && (rt!=PT_NBLE||p_temp(&parts[i])<2273.15)) {+ create_part(-1, x+rx, y+ry, PT_SPRK, -1);+ kill_part(i);+ return 1;+ }+ break;+ }+ }+ }+ return 0;+}+void el_ELEC_create(ELEMENT_CREATE_FUNC_ARGS) {+ float a = rng_between(0, 359) * NP_PI / 180.0f;+ parts[i].life = 680;+ p_set_vx(&parts[i], 2.0f * cosf(a));+ p_set_vy(&parts[i], 2.0f * sinf(a));+}++/* ---------------------------------------------------------------- PROT */+static int PROT_DeutImplosion(int n, int x, int y, float temp, int t);+/* the energy of its collisions (the original's tmp, up to 500000): tmp (low half) and tmp3 */+static int PROT_tmp(int i) { return (int)((uint16_t)parts[i].tmp | (uint32_t)(uint16_t)parts[i].tmp3 << 16); }+static void PROT_set_tmp(int i, int v) {+ parts[i].tmp = (int16_t)(v & 0xFFFF);+ parts[i].tmp3 = (int16_t)((uint32_t)v >> 16);+}+int el_PROT_update(UPDATE_FUNC_ARGS) {+ pv[y/ACELL][x/ACELL] -= .003f;+ int under = PMAPAT(x, y);+ int utype = TYP(under);+ int uID = ID(under);+ switch (utype) {+ case PT_SPRK: {+ //remove active sparks+ int sparked = parts[uID].ctype;+ if (!part_change_type(uID, x, y, sparked)) {+ parts[uID].life = 44 + parts[uID].life;+ parts[uID].ctype = 0;+ } else+ utype = 0;+ break;+ }+ case PT_DEUT:+ if (rng_chance(-((int)pv[y / ACELL][x / ACELL] - 4) + (parts[uID].life / 100), 200)) {+ PROT_DeutImplosion(parts[uID].life, x, y, restrict_flt(p_temp(&parts[uID]) + parts[uID].life * 500, MIN_TEMP, MAX_TEMP), PT_PROT);+ kill_part(uID);+ }+ break;+ case PT_LCRY:+ //Powered LCRY reaction: PROT->PHOT+ if (parts[uID].life > 5 && rng_chance(1, 10)) {+ //@ PROT + LCRY -> PHOT + LCRY+ part_change_type(i, x, y, PT_PHOT);+ parts[i].life *= 2;+ parts[i].ctype = 0x3FFFFFFF;+ }+ break;+ case PT_EXOT:+ parts[uID].ctype = PT_PROT;+ break;+ case PT_WIFI: {+ float change;+ if (p_temp(&parts[i]) < 173.15f) change = -1000.0f;+ else if (p_temp(&parts[i]) < 273.15f) change = -100.0f;+ else if (p_temp(&parts[i]) > 473.15f) change = 1000.0f;+ else if (p_temp(&parts[i]) > 373.15f) change = 100.0f;+ else change = 0.0f;+ p_set_temp(&parts[uID], restrict_flt(p_temp(&parts[uID]) + change, MIN_TEMP, MAX_TEMP));+ break;+ }+ case PT_RSSS: { //Destroy RSSS+ kill_part(uID);+ kill_part(i);+ return 1;+ }+ break;+ case PT_SEED: // Mutate seeds+ if (rng_chance(1, 2)) {+ int tmps[4] = {parts[uID].tmp, parts[uID].tmp2, parts[uID].tmp3, tmp4_get(uID)};+ int j = rng_between(0, 3);+ int k = rng_between(0, 3);+ int old_tmpj = tmps[j];+ int old_tmpk = tmps[k];+ // Swap genes for j-th and k-th phases+ tmps[j] = old_tmpk;+ tmps[k] = old_tmpj;+ parts[uID].tmp = (int16_t)tmps[0], parts[uID].tmp2 = (int16_t)tmps[1], parts[uID].tmp3 = (int16_t)tmps[2];+ tmp4_set(uID, tmps[3]);+ }+ break;+ case PT_NONE:+ //slowly kill if it's not inside an element+ if (parts[i].life) {+ if (!--parts[i].life) {+ kill_part(i);+ return 1;+ }+ }+ break;+ default:+ //set off explosives (only when hot because it wasn't as fun when it made an entire save explode)+ if (p_temp(&parts[i]) > 273.15f + 500.0f && (elements[utype].Flammable || elements[utype].Explosive || utype == PT_BANG)) {+ create_part(uID, x, y, PT_FIRE, -1);+ p_set_temp(&parts[uID], p_temp(&parts[uID]) + (restrict_flt((float)(elements[utype].Flammable * 5), MIN_TEMP, MAX_TEMP)));+ pv[y / ACELL][x / ACELL] += 1.00f;+ }+ //prevent inactive sparkable elements from being sparked+ else if ((elements[utype].Properties&PROP_CONDUCTS) && parts[uID].life <= 4) {+ parts[uID].life = 40 + parts[uID].life;+ }+ break;+ }+ //make temp of other things closer to it's own temperature. This will change temp of things that don't conduct, and won't change the PROT's temperature+ if (utype && utype != PT_WIFI)+ p_set_temp(&parts[uID], restrict_flt(p_temp(&parts[uID])-(p_temp(&parts[uID])-p_temp(&parts[i]))/4.0f, MIN_TEMP, MAX_TEMP));+ //if this proton has collided with another last frame, change it into a heavier element+ if (PROT_tmp(i)) {+ int newID, element, ptmp = PROT_tmp(i);+ if (ptmp > 500000) {+ if (utype == PT_TUNG)+ element = PT_AMTR; //@ PROT + TUNG -> AMTR+ else //@ PROT -> SING+ element = PT_SING; //particle accelerators are known to create earth-destroying black holes+ } else if (ptmp > 700)+ element = PT_PLUT; //@ PROT -> PLUT+ else if (ptmp > 420)+ element = PT_URAN; //@ PROT -> URAN+ else if (ptmp > 310)+ element = PT_POLO; //@ PROT -> POLO+ else if (ptmp > 250)+ element = PT_PLSM; //@ PROT -> PLSM+ else if (ptmp > 100)+ element = PT_O2; //@ PROT -> O2+ else if (ptmp > 50)+ element = PT_CO2; //@ PROT -> CO2+ else+ element = PT_NBLE; //@ PROT -> NBLE+ newID = create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), element, -1);+ if (newID >= 0)+ p_set_temp(&parts[newID], restrict_flt(100.0f*ptmp, MIN_TEMP, MAX_TEMP));+ kill_part(i);+ return 1;+ }+ //collide with other protons to make heavier materials+ int ahead = PHOTAT(x, y);+ if (ID(ahead) != i && TYP(ahead) == PT_PROT) {+ float velocity1 = powf(p_vx(&parts[i]), 2.0f)+powf(p_vy(&parts[i]), 2.0f);+ float velocity2 = powf(p_vx(&parts[ID(ahead)]), 2.0f)+powf(p_vy(&parts[ID(ahead)]), 2.0f);+ float direction1 = atan2f(-p_vy(&parts[i]), p_vx(&parts[i]));+ float direction2 = atan2f(-p_vy(&parts[ID(ahead)]), p_vx(&parts[ID(ahead)]));+ float difference = direction1 - direction2; if (difference < 0) difference += 6.28319f;+ if (difference > 3.12659f && difference < 3.15659f && velocity1 + velocity2 > 10.0f) {+ PROT_set_tmp(ID(ahead), PROT_tmp(ID(ahead)) + (int)(velocity1 + velocity2));+ kill_part(i);+ return 1;+ }+ }+ return 0;+}+static int PROT_DeutImplosion(int n, int x, int y, float temp, int t) {+ int i;+ n = (n/50);+ if (n < 1)+ n = 1;+ else if (n > 340)+ n = 340;+ for (int c = 0; c < n; c++) {+ i = create_part(-3, x, y, t, -1);+ if (i >= 0)+ p_set_temp(&parts[i], temp);+ else if (parts_full())+ break;+ }+ pv[y/ACELL][x/ACELL] -= (6.0f * CFDS)*n;+ return 0;+}+void el_PROT_create(ELEMENT_CREATE_FUNC_ARGS) {+ float a = rng_between(0, 35) * 0.17453f;+ parts[i].life = 680;+ p_set_vx(&parts[i], 2.0f * cosf(a));+ p_set_vy(&parts[i], 2.0f * sinf(a));+}++/* ---------------------------------------------------------------- GRVT */+int el_GRVT_update(UPDATE_FUNC_ARGS) {+ //at higher tmps they just go completely insane+ if (parts[i].tmp >= 100)+ parts[i].tmp = 100;+ if (parts[i].tmp <= -100)+ parts[i].tmp = -100;+ int under = PMAPAT(x, y);+ int utype = TYP(under);+ //Randomly kill GRVT inside RSSS+ if((utype == PT_RSSS) && rng_chance(1, 5)) {+ kill_part(i);+ return 1;+ }+ gravmass[(y )/ACELL][(x)/ACELL] = 0.2f * parts[i].tmp;+ return 0;+}+void el_GRVT_create(ELEMENT_CREATE_FUNC_ARGS) {+ float a = rng_between(0, 359) * NP_PI / 180.0f;+ parts[i].life = 250 + rng_between(0, 199);+ p_set_vx(&parts[i], 2.0f * cosf(a));+ p_set_vy(&parts[i], 2.0f * sinf(a));+}++/* ---------------------------------------------------------------- EXOT */+int el_EXOT_update(UPDATE_FUNC_ARGS) {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (rt == PT_WARP) {+ if (parts[ID(r)].tmp2>2000 && rng_chance(1, 100)) {+ parts[i].tmp2 += 100;+ }+ } else if (rt == PT_EXOT) {+ if (parts[ID(r)].ctype == PT_PROT)+ parts[i].ctype = PT_PROT;+ if (parts[ID(r)].life == 1500 && rng_chance(1, 1000))+ parts[i].life = 1500;+ } else if (rt == PT_LAVA) {+ //turn molten TTAN or molten GOLD to molten VIBR+ if (parts[ID(r)].ctype == PT_TTAN || parts[ID(r)].ctype == PT_GOLD) {+ if (rng_chance(1, 10)) {+ //@ EXOT + LAVA(TTAN/GOLD) -> LAVA(VIBR)+ parts[ID(r)].ctype = PT_VIBR;+ kill_part(i);+ return 1;+ }+ }+ //molten VIBR will kill the leftover EXOT though, so the VIBR isn't killed later+ else if (parts[ID(r)].ctype == PT_VIBR) {+ if (rng_chance(1, 1000)) {+ kill_part(i);+ return 1;+ }+ }+ }+ if (parts[i].tmp > 245 && parts[i].life > 1337)+ if (rt!=PT_EXOT && rt!=PT_BREC && rt!=PT_DMND && rt!=PT_CLNE && rt!=PT_PRTI && rt!=PT_PRTO && rt!=PT_PCLN && rt!=PT_VOID && rt!=PT_NBHL && rt!=PT_WARP) {+ if (create_part(i, x, y, rt, -1) != -1) {+ return 1;+ }+ }+ }+ }+ }+ parts[i].tmp--;+ parts[i].tmp2--;+ //reset tmp every 250 frames, gives EXOT it's slow flashing effect+ if (parts[i].tmp < 1 || parts[i].tmp > 250)+ parts[i].tmp = 250;+ if (parts[i].tmp2 < 1)+ parts[i].tmp2 = 1;+ else if (parts[i].tmp2 > 6000) {+ parts[i].tmp2 = 10000;+ if (parts[i].life < 1001) {+ //@ EXOT -> WARP+ part_change_type(i, x, y, PT_WARP);+ return 1;+ }+ } else if(parts[i].life < 1001)+ pv[y/ACELL][x/ACELL] += (parts[i].tmp2*CFDS)/160000;+ if (pv[y/ACELL][x/ACELL]>200 && p_temp(&parts[i])>9000 && parts[i].tmp2>200) {+ parts[i].tmp2 = 6000;+ //@ EXOT -> WARP+ part_change_type(i, x, y, PT_WARP);+ return 1;+ }+ if (parts[i].tmp2 > 100) {+ for (int trade = 0; trade < 9; trade++) {+ int rx = rng_between(-2, 2);+ int ry = rng_between(-2, 2);+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_EXOT && (parts[i].tmp2 > parts[ID(r)].tmp2) && parts[ID(r)].tmp2 >= 0) { //diffusion+ int tym = parts[i].tmp2 - parts[ID(r)].tmp2;+ if (tym == 1) {+ parts[ID(r)].tmp2++;+ parts[i].tmp2--;+ break;+ }+ if (tym > 0) {+ parts[ID(r)].tmp2 += tym/2;+ parts[i].tmp2 -= tym/2;+ break;+ }+ }+ }+ }+ }+ if (parts[i].ctype == PT_PROT) {+ if (p_temp(&parts[i]) < 50.0f) {+ //@ EXOT(PROT) -> CFLM+ if (create_part(i, x, y, PT_CFLM, -1) != -1) { // I don't see how this could fail but whatever+ return 1;+ }+ } else+ p_set_temp(&parts[i], p_temp(&parts[i]) - (1.0f));+ } else if (p_temp(&parts[i]) < 273.15f) {+ p_set_vx(&parts[i], 0);+ p_set_vy(&parts[i], 0);+ pv[y/ACELL][x/ACELL] -= 0.01f;+ parts[i].tmp--;+ }+ return 0;+}++/* ---------------------------------------------------------------- POLO */+#define COOLDOWN 15+#define LIMIT 5+int el_POLO_update(UPDATE_FUNC_ARGS) {+ int r = PHOTAT(x, y);+ if (parts[i].tmp < LIMIT && !parts[i].life) {+ if (rng_chance(1, 10000) && !parts[i].tmp) {+ //@ POLO -> POLO + NEUT+ int s = create_part(-3, x, y, PT_NEUT, -1);+ if (s >= 0) {+ parts[i].life = COOLDOWN;+ parts[i].tmp++;+ p_set_temp(&parts[i], ((p_temp(&parts[i]) + p_temp(&parts[s])) + 600.0f) / 2.0f);+ p_set_temp(&parts[s], p_temp(&parts[i]));+ }+ }+ if (r && rng_chance(1, 100)) {+ //@ POLO -> POLO + NEUT+ int s = create_part(-3, x, y, PT_NEUT, -1);+ if (s >= 0) {+ p_set_temp(&parts[i], ((p_temp(&parts[i]) + p_temp(&parts[ID(r)]) + p_temp(&parts[ID(r)])) + 600.0f) / 3.0f);+ parts[i].life = COOLDOWN;+ parts[i].tmp++;+ p_set_temp(&parts[ID(r)], p_temp(&parts[i]));+ p_set_temp(&parts[s], p_temp(&parts[i]));+ p_set_vx(&parts[s], p_vx(&parts[ID(r)]));+ p_set_vy(&parts[s], p_vy(&parts[ID(r)]));+ }+ }+ }+ if (parts[i].tmp2 >= 10) {+ //@ POLO -> PLUT+ part_change_type(i,x,y,PT_PLUT);+ p_set_temp(&parts[i], (p_temp(&parts[i])+600.0f)/2.0f);+ return 1;+ }+ if (TYP(r) == PT_PROT) {+ parts[i].tmp2++;+ kill_part(ID(r));+ }+ if (p_temp(&parts[i]) < 388.15f) {+ p_set_temp_d(&parts[i], p_temp(&parts[i]) + (0.2f));+ }+ return 0;+}+diff --git a/games/numpowder/src/el_pipe.c b/games/numpowder/src/el_pipe.cnew file mode 100644index 00000000..1b7d2fe7--- /dev/null+++ b/games/numpowder/src/el_pipe.c@@ -0,0 +1,345 @@+/* NumPowder: The Powder Toy's PIPE and PPIP (elements/PIPE.cpp, PPIP.cpp), ported.+ *+ * A pipe pixel holds a particle: its element in ctype's bits 0 to 7, its life in tmp2, its tmp in tmp3 and its ctype+ * (the original's tmp4) in ctype's bits 8 to 31 (see tmp4_get). The original's 32 bits of flags in tmp are moved to+ * fit 16 bits of tmp and 8 of flags (simpriv.h: PIPE_SINGLE...); the particle-decoration flag goes (no+ * decoration). */+#include "simpriv.h"++static const struct { int8_t X, Y; } Element_PIPE_offsets[8] = {+ {-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1},+};++static unsigned int PIPE_prevColor(unsigned int flags) {+ unsigned int color = flags & PFLAG_COLORS;+ if (color == PFLAG_COLOR_RED) return PFLAG_COLOR_GREEN;+ else if (color == PFLAG_COLOR_GREEN) return PFLAG_COLOR_BLUE;+ else if (color == PFLAG_COLOR_BLUE) return PFLAG_COLOR_RED;+ return PFLAG_COLOR_RED;+}+static unsigned int PIPE_nextColor(unsigned int flags) {+ unsigned int color = flags & PFLAG_COLORS;+ if (color == PFLAG_COLOR_RED) return PFLAG_COLOR_BLUE;+ else if (color == PFLAG_COLOR_BLUE) color = PFLAG_COLOR_GREEN;+ else if (color == PFLAG_COLOR_GREEN) return PFLAG_COLOR_RED;+ return PFLAG_COLOR_GREEN;+}++static inline int pid(const Particle *p) { return (int)(p - parts); }+/* clears the particle a pipe holds: its element (the original's ctype = 0) and the rest of its ctype */+static void pipe_clear(Particle *pipe) {+ pipe->ctype = 0;+ pipe_ovf_clear(pid(pipe));+}++/* props_pipe_to_part: a pipe's (or STOR's) particle, to part */+static void props_pipe_to_part(const Particle *pipe, Particle *part, bool STOR) {+ /* STOR also moves particles to PRTI this way; it keeps its particle as PIPE does, but the element in tmp */+ int stored_ctype = tmp4_get(pid(pipe));+ if (STOR) part->type = (uint8_t)TYP(pipe->tmp);+ else part->type = (uint8_t)TYP(pipe->ctype);+ part->temp = pipe->temp;+ part->life = pipe->tmp2;+ part->tmp = pipe->tmp3;+ part->ctype = stored_ctype;+ if (!(elements[part->type].Properties & TYPE_ENERGY)) {+ part->vx = 0;+ part->vy = 0;+ }+ part->tmp2 = 0;+ part->flags = 0;+}++void Element_PIPE_transfer_pipe_to_part(Particle *pipe, Particle *part, bool STOR) {+ props_pipe_to_part(pipe, part, STOR);+ if (STOR) pipe->tmp &= ~0xFF; /* (the original's tmp = 0: its tmp4 stays) */+ else pipe_clear(pipe);+ /* (a particle in the pipe's decoration isn't kept) */+}++void Element_PIPE_transfer_part_to_pipe(Particle *part, Particle *pipe) {+ int i = pid(pipe);+ pipe->ctype = part->type;+ if ((pipe->tmp & PFLAG_CAN_CONDUCT) == 0) {+ pipe->temp = part->temp;+ } else {+ float c_pipe = elements[pipe->type].HeatCapacity, c_part = elements[part->type].HeatCapacity;+ p_set_temp(pipe, (c_part * p_temp(part) + c_pipe * p_temp(pipe)) / (c_part + c_pipe));+ }+ pipe->tmp2 = part->life;+ pipe->tmp3 = part->tmp;+ tmp4_set(i, part->ctype);+}++static void transfer_pipe_to_pipe(Particle *src, Particle *dest, bool STOR) {+ int t4 = tmp4_get(pid(src));+ if (STOR) { /* STOR to PIPE */+ dest->ctype = src->tmp & 0xFF;+ src->tmp &= ~0xFF;+ } else {+ dest->ctype = src->ctype & 0xFF;+ pipe_clear(src);+ }+ if ((dest->tmp & PFLAG_CAN_CONDUCT) == 0) {+ dest->temp = src->temp;+ } else {+ int src_ctype = src->ctype & 0xFF; /* (0 for a pipe now; a STOR's filter, as in the original) */+ float c_src = (0 < src_ctype && src_ctype < PT_NUM) ? elements[src_ctype].HeatCapacity : 1.0f;+ float c_dest = elements[dest->type].HeatCapacity;+ p_set_temp(dest, (c_src * p_temp(src) + c_dest * p_temp(dest)) / (c_src + c_dest));+ }+ dest->tmp2 = src->tmp2;+ dest->tmp3 = src->tmp3;+ tmp4_set(pid(dest), t4);+}++/* pushes a pipe's particle along (up to 2 a frame) */+static void pushParticle(int i, int count, int original) {+ unsigned int notctype = PIPE_nextColor((unsigned)parts[i].tmp);+ if (!TYP(parts[i].ctype) || count >= 2) /* nothing there, or the max speed of 2 a frame */+ return;+ int x = (parts[i].x + 32) / 64, y = (parts[i].y + 32) / 64;+ if (!(parts[i].tmp & PIPE_FWD_SINGLE)) {+ /* normal random push: 5 tries in a random number, 3 used */+ int rndstore = (int)rng_gen();+ for (int q = 0; q < 3; q++) { /* try to push 3 times */+ int rnd = rndstore & 7;+ rndstore = rndstore >> 3;+ int rx = Element_PIPE_offsets[rnd].X, ry = Element_PIPE_offsets[rnd].Y;+ int r = PMAPAT(x + rx, y + ry);+ if (!r) {+ continue;+ } else if ((TYP(r) == PT_PIPE || TYP(r) == PT_PPIP) && (parts[ID(r)].tmp & PFLAG_COLORS) != (int)notctype && !TYP(parts[ID(r)].ctype)) {+ transfer_pipe_to_pipe(parts + i, parts + ID(r), false);+ if (ID(r) > original) parts[ID(r)].flags |= PFLAG_NORMALSPEED; /* skip its push, normalizes speed */+ count++;+ pushParticle(ID(r), count, original);+ } else if (TYP(r) == PT_PRTI) { /* into PRTI for a pipe speed increase */+ int portaltmp = parts[ID(r)].tmp;+ if (portaltmp >= CHANNELS) portaltmp = CHANNELS - 1;+ else if (portaltmp < 0) portaltmp = 0;+ if (portal_free(portaltmp, count)) {+ Particle p;+ memset(&p, 0, sizeof p);+ Element_PIPE_transfer_pipe_to_part(parts + i, &p, false);+ portal_put(portaltmp, count, &p);+ count++;+ }+ }+ }+ } else { /* predefined 1 pixel thick pipe movement */+ int coords = 7 - ((parts[i].tmp >> PIPE_FWD_SHIFT) & 7);+ int r = PMAPAT(x + Element_PIPE_offsets[coords].X, y + Element_PIPE_offsets[coords].Y);+ if ((TYP(r) == PT_PIPE || TYP(r) == PT_PPIP) && (parts[ID(r)].tmp & PFLAG_COLORS) != (int)notctype && !TYP(parts[ID(r)].ctype)) {+ transfer_pipe_to_pipe(parts + i, parts + ID(r), false);+ if (ID(r) > original) parts[ID(r)].flags |= PFLAG_NORMALSPEED;+ count++;+ pushParticle(ID(r), count, original);+ } else if (TYP(r) == PT_PRTI) {+ int portaltmp = parts[ID(r)].tmp;+ if (portaltmp >= CHANNELS) portaltmp = CHANNELS - 1;+ else if (portaltmp < 0) portaltmp = 0;+ if (portal_free(portaltmp, count)) {+ Particle p;+ memset(&p, 0, sizeof p);+ Element_PIPE_transfer_pipe_to_part(parts + i, &p, false);+ portal_put(portaltmp, count, &p);+ count++;+ }+ } else if (!r) { /* out of the pipe at its end, much faster */+ int rx = Element_PIPE_offsets[coords].X, ry = Element_PIPE_offsets[coords].Y;+ int np = create_part(-1, x + rx, y + ry, TYP(parts[i].ctype), -1);+ if (np != -1) Element_PIPE_transfer_pipe_to_part(parts + i, parts + np, false);+ }+ }+}++int Element_PIPE_update(UPDATE_FUNC_ARGS) {+ if (TYP(parts[i].ctype) && !elements[TYP(parts[i].ctype)].Enabled) pipe_clear(&parts[i]);+ if (parts[i].flags & PPIP_TMPFLAG_TRIGGERS) {+ int pause_changed = 0;+ if (parts[i].flags & PPIP_TMPFLAG_TRIGGER_ON) { /* TRIGGER_ON overrides TRIGGER_OFF */+ if (parts[i].tmp & PPIP_TMPFLAG_PAUSED) pause_changed = 1;+ parts[i].tmp &= ~PPIP_TMPFLAG_PAUSED;+ } else if (parts[i].flags & PPIP_TMPFLAG_TRIGGER_OFF) {+ if (!(parts[i].tmp & PPIP_TMPFLAG_PAUSED)) pause_changed = 1;+ parts[i].tmp |= PPIP_TMPFLAG_PAUSED;+ }+ if (pause_changed) {+ for (int rx = -2; rx <= 2; rx++)+ for (int ry = -2; ry <= 2; ry++)+ if (rx || ry) {+ int r = PMAPAT(x + rx, y + ry);+ if (TYP(r) == PT_BRCK) {+ if (parts[i].tmp & PPIP_TMPFLAG_PAUSED) parts[ID(r)].tmp = 0;+ else parts[ID(r)].tmp = 1; /* make surrounding BRCK glow */+ }+ }+ }+ if (parts[i].flags & PPIP_TMPFLAG_TRIGGER_REVERSE) {+ parts[i].tmp ^= PPIP_TMPFLAG_REVERSED;+ /* switch colours so it goes in reverse */+ if ((parts[i].tmp & PFLAG_COLORS) != PFLAG_COLOR_GREEN) parts[i].tmp ^= PFLAG_COLOR_GREEN;+ if (parts[i].tmp & PIPE_SINGLE) { /* switch the one pixel pipe's directions */+ int coords = (parts[i].tmp >> 6) & 0xF; /* the reverse group (the original's tmp >> 13) */+ int coords2 = (parts[i].tmp >> 2) & 0xF; /* the forward group (tmp >> 9) */+ parts[i].tmp &= ~(PIPE_FWD_GROUP | PIPE_REV_GROUP);+ parts[i].tmp |= (int16_t)(coords << 2);+ parts[i].tmp |= (int16_t)(coords2 << 6);+ }+ }+ parts[i].flags &= (uint8_t)~PPIP_TMPFLAG_TRIGGERS;+ }+ if ((parts[i].tmp & PFLAG_COLORS) && !(parts[i].tmp & PPIP_TMPFLAG_PAUSED)) {+ if (parts[i].life == 3) {+ int lastneighbor = -1, neighborcount = 0, count = 0;+ bool heatPipe = false;+ /* make automatic pipe pattern */+ for (int rx = -1; rx <= 1; rx++)+ for (int ry = -1; ry <= 1; ry++)+ if (rx || ry) {+ count++;+ int r = PMAPAT(x + rx, y + ry);+ if (!r) continue;+ if (TYP(r) == PT_HEAC) {+ heatPipe = true;+ continue;+ }+ if (TYP(r) != PT_PIPE && TYP(r) != PT_PPIP) continue;+ unsigned int next = PIPE_nextColor((unsigned)parts[i].tmp), prev = PIPE_prevColor((unsigned)parts[i].tmp);+ if (parts[ID(r)].tmp & PFLAG_INITIALIZING) {+ parts[ID(r)].tmp |= (int16_t)next;+ parts[ID(r)].tmp &= ~PFLAG_INITIALIZING;+ parts[ID(r)].life = 6;+ if (parts[i].tmp & PIPE_SINGLE) { /* a single pixel pipe */+ parts[ID(r)].tmp |= PIPE_FWD_SINGLE; /* it transfers to a single pixel pipe */+ parts[ID(r)].tmp |= (int16_t)((count - 1) << PIPE_FWD_SHIFT); /* where it came from */+ parts[i].tmp |= (int16_t)((8 - count) << PIPE_REV_SHIFT);+ parts[i].tmp |= PIPE_REV_SINGLE;+ }+ neighborcount++;+ lastneighbor = ID(r);+ } else if ((parts[ID(r)].tmp & PFLAG_COLORS) != (int)prev) {+ neighborcount++;+ lastneighbor = ID(r);+ }+ }+ if (neighborcount == 1) parts[lastneighbor].tmp |= PIPE_SINGLE;+ if (heatPipe) Element_PPIP_flood_trigger(x, y, PT_HEAC);+ } else {+ if (parts[i].flags & PFLAG_NORMALSPEED) { /* skip the push, so more particles don't speed it up */+ parts[i].flags &= (uint8_t)~PFLAG_NORMALSPEED;+ } else {+ pushParticle(i, 0, i);+ }+ if (nt) { /* something besides PIPE around */+ int rndstore = (int)rng_gen();+ int rnd = rndstore & 7;+ int rx = Element_PIPE_offsets[rnd].X, ry = Element_PIPE_offsets[rnd].Y;+ int r = PMAPAT(x + rx, y + ry);+ if (!r) r = PHOTAT(x + rx, y + ry);+ if (surround_space && !r && TYP(parts[i].ctype)) { /* creating at the end */+ int np = create_part(-1, x + rx, y + ry, TYP(parts[i].ctype), -1);+ if (np != -1) Element_PIPE_transfer_pipe_to_part(parts + i, parts + np, false);+ }+ /* eating a particle at the entrance */+ else if (!TYP(parts[i].ctype) && (elements[TYP(r)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) {+ if (TYP(r) == PT_SOAP) Element_SOAP_detach(ID(r));+ Element_PIPE_transfer_part_to_pipe(parts + ID(r), parts + i);+ kill_part(ID(r));+ } else if (!TYP(parts[i].ctype) && TYP(r) == PT_STOR && IsElement(parts[ID(r)].tmp & 0xFF) &&+ (elements[parts[ID(r)].tmp & 0xFF].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) {+ /* STOR stores properties in the same places as PIPE does */+ transfer_pipe_to_pipe(parts + ID(r), parts + i, true);+ }+ }+ }+ } else if (!(parts[i].tmp & (PFLAG_COLORS | PFLAG_INITIALIZING)) && parts[i].life <= 10) {+ /* make a border of BRCK */+ for (int rx = -2; rx <= 2; rx++)+ for (int ry = -2; ry <= 2; ry++)+ if (rx || ry) {+ int r = PMAPAT(x + rx, y + ry);+ if (!r) {+ int index = create_part(-1, x + rx, y + ry, PT_BRCK, -1);+ if (parts[i].type == PT_PPIP && index != -1) parts[index].tmp = 1;+ }+ }+ if (parts[i].life <= 1) parts[i].tmp |= PFLAG_INITIALIZING;+ }+ /* wait for empty space before starting to generate the automatic pipe pattern */+ else if (parts[i].tmp & PFLAG_INITIALIZING) {+ if (!parts[i].life) {+ for (int rx = -1; rx <= 1; rx++)+ for (int ry = -1; ry <= 1; ry++)+ if (rx || ry) {+ int b = bmap[(y + ry) / WCELL][(x + rx) / WCELL];+ if (!PMAPAT(x + rx, y + ry) && b != WL_ALLOWAIR && b != WL_WALL && b != WL_WALLELEC &&+ (b != WL_EWALL || emap[(y + ry) / WCELL][(x + rx) / WCELL]))+ parts[i].life = 50;+ }+ } else if (parts[i].life == 5) { /* the start of a single pixel pipe? */+ int issingle = 1;+ for (int rx = -1; rx <= 1; rx++)+ for (int ry = -1; ry <= 1; ry++)+ if (rx || ry) {+ int r = PMAPAT(x + rx, y + ry);+ if ((TYP(r) == PT_PIPE || TYP(r) == PT_PPIP) && parts[i].life) issingle = 0;+ }+ if (issingle) parts[i].tmp |= PIPE_SINGLE;+ } else if (parts[i].life == 2) {+ parts[i].tmp |= PFLAG_COLOR_RED;+ parts[i].tmp &= ~PFLAG_INITIALIZING;+ parts[i].life = 6;+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- PPIP */+/* the triggers of a powered pipe and the pipes connected to it, for the next frame (the original's tmp << 3, here+ * flags << PPIP_LATE_SHIFT); HEAC next to a pipe makes it conduct heat */+static bool ppip_has(int id, int prop, bool tmpProp) {+ return tmpProp ? (parts[id].tmp & prop) != 0 : (parts[id].flags & prop) != 0;+}+void Element_PPIP_flood_trigger(int x, int y, int sparkedBy) {+ int x1, x2, t = TYP(PMAPAT(x, y));+ if (t != PT_PIPE && t != PT_PPIP) return;+ /* separate flags for on and off, so PSCN beats NSCN on the same frame whatever the particle order */+ int prop = 0;+ bool tmpProp = false;+ if (sparkedBy == PT_PSCN) prop = PPIP_TMPFLAG_TRIGGER_ON << PPIP_LATE_SHIFT;+ else if (sparkedBy == PT_NSCN) prop = PPIP_TMPFLAG_TRIGGER_OFF << PPIP_LATE_SHIFT;+ else if (sparkedBy == PT_INST) prop = PPIP_TMPFLAG_TRIGGER_REVERSE << PPIP_LATE_SHIFT;+ else if (sparkedBy == PT_HEAC) prop = PFLAG_CAN_CONDUCT, tmpProp = true; /* special case for HEAC near pipe */+ if (prop == 0 || (t != PT_PPIP && sparkedBy != PT_HEAC) || ppip_has(ID(PMAPAT(x, y)), prop, tmpProp)) return;+ flood_stack_init(0);+ flood_stack_push(x, y);+ do {+ flood_stack_pop(&x, &y);+ x1 = x2 = x;+ while (x1 >= BORDER) { /* go left as far as possible */+ if (TYP(PMAPAT(x1 - 1, y)) != t) break;+ x1--;+ }+ while (x2 < XRES - BORDER) {+ if (TYP(PMAPAT(x2 + 1, y)) != t) break;+ x2++;+ }+ for (x = x1; x <= x2; x++) { /* fill span */+ int id = ID(PMAPAT(x, y));+ if (!ppip_has(id, prop, tmpProp) && sparkedBy != PT_HEAC) Element_PPIP_ppip_changed = 1;+ if (tmpProp) parts[id].tmp |= (int16_t)prop;+ else parts[id].flags |= (uint8_t)prop;+ }+ /* adjacent pixels, diagonals too (x limits already within the edge) */+ if (y >= BORDER + 1)+ for (x = x1 - 1; x <= x2 + 1; x++)+ if (TYP(PMAPAT(x, y - 1)) == t && !ppip_has(ID(PMAPAT(x, y - 1)), prop, tmpProp))+ if (!flood_stack_push(x, y - 1)) return;+ if (y < YRES - BORDER - 1)+ for (x = x1 - 1; x <= x2 + 1; x++)+ if (TYP(PMAPAT(x, y + 1)) == t && !ppip_has(ID(PMAPAT(x, y + 1)), prop, tmpProp))+ if (!flood_stack_push(x, y + 1)) return;+ } while (flood_stack_size() > 0);+}diff --git a/games/numpowder/src/el_powders.c b/games/numpowder/src/el_powders.cnew file mode 100644index 00000000..4a2e1c22--- /dev/null+++ b/games/numpowder/src/el_powders.c@@ -0,0 +1,441 @@+/* NumPowder: The Powder Toy's powders (their files in elements/), ported: SNOW, FRZZ, RIME, YEST, BRMT, BREC, CLST,+ * SLCN, GRAV, ANAR, SEED. */+#include "simpriv.h"++/* ---------------------------------------------------------------- SNOW */+int el_SNOW_update(UPDATE_FUNC_ARGS) {+ if (parts[i].ctype==PT_FRZW) { //get colder if it is from FRZW+ p_set_temp(&parts[i], restrict_flt(p_temp(&parts[i])-1.0f, MIN_TEMP, MAX_TEMP));+ }+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ //@ SNOW + SALT/SLTW -> 2xSLTW+ if ((TYP(r)==PT_SALT || TYP(r)==PT_SLTW) && rng_chance(1, 333)) {+ part_change_type(i,x,y,PT_SLTW);+ part_change_type(ID(r),x+rx,y+ry,PT_SLTW);+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- FRZZ */+int el_FRZZ_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_WATR && rng_chance(1, 20)) {+ //@ FRZZ + WATR -> FRZW+ part_change_type(ID(r),x+rx,y+ry,PT_FRZW);+ parts[ID(r)].life = 100;+ kill_part(i);+ return 1;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- RIME */+int el_RIME_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_SPRK) {+ //@ RIME -> FOG+ part_change_type(i,x,y,PT_FOG);+ parts[i].life = rng_between(60, 119);+ }+ // GAS increases acidity+ else if (TYP(r) == PT_GAS && parts[i].tmp < 10) {+ kill_part(ID(r));+ if (parts[i].ctype == PT_DSTW)+ parts[i].ctype = 0;+ else+ parts[i].tmp++;+ } else if (TYP(r)==PT_FOG&&parts[ID(r)].life>0) {+ //@ RIME + FOG -> 2xFOG+ part_change_type(i,x,y,PT_FOG);+ parts[i].life = parts[ID(r)].life;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- YEST */+int el_YEST_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_DYST && rng_chance(1, 6) && !legacy_enable) {+ //@ YEST -> DYST+ part_change_type(i,x,y,PT_DYST);+ }+ }+ }+ }+ if (p_temp(&parts[i]) > 303 && p_temp(&parts[i]) < 317) {+ create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), PT_YEST, -1);+ }+ return 0;+}++/* ---------------------------------------------------------------- BRMT */+int el_BRMT_update(UPDATE_FUNC_ARGS) {+ if (p_temp(&parts[i]) > 523.15f) { //250.0f+273.15f+ float tempFactor = (int)(1000 - ((523.15f-p_temp(&parts[i]))*2));+ if(tempFactor < 2)+ tempFactor = 2;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_BREC && rng_chance(1, tempFactor)) {+ if (rng_chance(1, 2)) {+ //@ BRMT + BREC -> BRMT + THRM+ create_part(ID(r), x+rx, y+ry, PT_THRM, -1);+ } else //@ BRMT + BREC -> THRM + BREC+ create_part(i, x, y, PT_THRM, -1);+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- BREC */+int el_BREC_update(UPDATE_FUNC_ARGS) {+ if (parts[i].life) {+ if (pv[y/ACELL][x/ACELL]>10.0f) {+ if (p_temp(&parts[i])>9000 && pv[y/ACELL][x/ACELL]>30.0f && rng_chance(1, 200)) {+ //@ BREC -> EXOT+ part_change_type(i, x, y, PT_EXOT);+ parts[i].life = 1000;+ }+ p_set_temp(&parts[i], p_temp(&parts[i]) + ((pv[y/ACELL][x/ACELL])/8));+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- CLST */+int el_CLST_update(UPDATE_FUNC_ARGS) {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_WATR) {+ if (rng_chance(1, 1500)) {+ //@ CLST + WATR -> PSTS+ create_part(i, x, y, PT_PSTS, -1);+ kill_part(ID(r));+ }+ } else if (TYP(r)==PT_NITR) {+ //@ CLST + NITR -> 2xBANG+ create_part(i, x, y, PT_BANG, -1);+ create_part(ID(r), x+rx, y+ry, PT_BANG, -1);+ } else if (TYP(r)==PT_CLST) {+ float cxy;+ if(p_temp(&parts[i]) <195)+ cxy = 0.05f;+ else if(p_temp(&parts[i]) <295)+ cxy = 0.015f;+ else if(p_temp(&parts[i]) <350)+ cxy = 0.01f;+ else+ cxy = 0.005f;+ p_set_vx(&parts[i], p_vx(&parts[i]) + (cxy*rx));+ p_set_vy(&parts[i], p_vy(&parts[i]) + (cxy*ry));//These two can be set not to calculate over 350 later. They do virtually nothing over 0.005.+ }+ }+ }+ }+ return 0;+}+void el_CLST_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].tmp = rng_between(0, 6);+}++/* ---------------------------------------------------------------- SLCN */+/* the sparkles' state (the original's 32-bit tmp): bits 0 to 15 in tmp, 16 to 31 in tmp2 */+static uint32_t SLCN_get(int i) { return (uint16_t)parts[i].tmp | (uint32_t)(uint16_t)parts[i].tmp2 << 16; }+static void SLCN_set(int i, uint32_t v) {+ parts[i].tmp = (int16_t)(v & 0xFFFF);+ parts[i].tmp2 = (int16_t)(v >> 16);+}+static void SLCN_initSparkles(int i) {+ // bits 31-20: phase increment (randomised to a value between 1 and 9)+ // bits 19-16: next colour index+ // bits 15-12: current colour index+ // bits 11-00: phase+ SLCN_set(i, (uint32_t)rng_between(0x100000, 0x9FFFFF));+}+int el_SLCN_update(UPDATE_FUNC_ARGS) {+ if (!SLCN_get(i)) {+ SLCN_initSparkles(i);+ }+ uint32_t tmp = SLCN_get(i);+ int phase = (tmp & 0xFFF) + ((tmp >> 20) & 0xFFF);+ if (phase & 0x1000) {+ // discard current, current <- next, next <- random, wrap phase+ SLCN_set(i, (tmp & 0xFFF00000) | (phase & 0xFFF) | ((uint32_t)rng_between(0, 15) << 16) | ((tmp >> 4) & 0xF000));+ } else {+ // update phase+ SLCN_set(i, (tmp & 0xFFFFF000) | (uint32_t)phase);+ }+ if (parts[i].life == 0 && p_temp(&parts[i]) < 373.15f) {+ for (int j = 0; j < 4; j++) {+ static const int check_coords_x[] = { -4, 4, 0, 0 };+ static const int check_coords_y[] = { 0, 0, -4, 4 };+ int n = PMAPAT(x + check_coords_x[j], y + check_coords_y[j]);+ if (n && TYP(n) == PT_SPRK) {+ Particle *neighbour = &parts[ID(n)];+ if (neighbour->life != 0 && neighbour->life < 4) {+ part_change_type(i, x, y, PT_SPRK);+ parts[i].life = 4;+ parts[i].ctype = PT_SLCN;+ }+ }+ }+ }+ return 0;+}+void el_SLCN_create(ELEMENT_CREATE_FUNC_ARGS) {+ SLCN_initSparkles(i);+}++/* ---------------------------------------------------------------- GRAV */+int el_GRAV_update(UPDATE_FUNC_ARGS) {+ if (p_vx(&parts[i])*p_vx(&parts[i]) + p_vy(&parts[i])*p_vy(&parts[i]) >= 0.1f && rng_chance(1, 512)) {+ if (!parts[i].life)+ parts[i].life = 48;+ }+ return 0;+}++/* ---------------------------------------------------------------- ANAR */+int el_ANAR_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_CFLM && rng_chance(1, 4)) {+ //@ ANAR + CFLM -> 2xCFLM+ part_change_type(i,x,y,PT_CFLM);+ parts[i].life = rng_between(50, 199);+ p_set_temp(&parts[i], 0);+ p_set_temp(&parts[ID(r)], 0);+ pv[y/ACELL][x/ACELL] -= 0.5;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- SEED */+// Fields used (see also PLNT.cpp):+// ctype, tmp-tmp4 have the same meaning as in PLNT,+// but the first bit of ctype is used to determine whether a seed bred with another seed or not.+// life is used as a timer.+int el_SEED_update(UPDATE_FUNC_ARGS) {+ float temp = p_temp(&parts[i]);+ // Turn into liquid wax under high temperature and pressure+ if (temp > 320.0f && pv[y/ACELL][x/ACELL] > 50.0f && rng_chance(1, 150)) {+ //@ SEED -> MWAX+ create_part(i, x, y, PT_MWAX, -1);+ parts[i].ctype = 0;+ parts[i].life = 0;+ parts[i].tmp = 0;+ parts[i].tmp2 = 0;+ parts[i].tmp3 = 0;+ tmp4_set(i, 0);+ return 0;+ }+ // Don't do anything at bad temperatures+ if (temp > 343.15f || temp < 278.15f) {+ parts[i].ctype &= ~(0xFF << PLNT_LIFE); // Set water to zero+ parts[i].life = 0;+ return 0;+ }+ int water = (parts[i].ctype >> PLNT_LIFE) & 0xFF;+ // Check if we can grow+ if (water > 3) {+ int down = Element_PLNT_detectDown(x, y); // Down gravity direction+ // Set a default direction if can't decide using gravity+ if (down < 0 || down > 7)+ down = 4;+ int up = (down+4)%8;+ // Check if there's SAND/SPNG under the seed particle and empty space above+ int downPart = PMAPAT(x+dir3x3[down].X, y+dir3x3[down].Y);+ if ((TYP(downPart) == PT_SAND || TYP(downPart) == PT_SPNG) && !TYP(PMAPAT(x+dir3x3[up].X, y+dir3x3[up].Y))) {+ if (parts[i].life > 200) {+ // Start growth+ //@ SEED -> PLNT+ part_change_type(i, x, y, PT_PLNT);+ parts[i].ctype &= ~((7 << PLNT_DIR) | (3 << PLNT_PHASE)); // Clear direction and phase+ parts[i].ctype |= ((up & 7) << PLNT_DIR) | 1; // Set initial growth direction and growth bit+ parts[i].life = 15*water; // Make the first branch longer+ return 1;+ } else+ parts[i].life++;+ } else+ parts[i].life = 0; // Reset growth counter if we lost contact with ground+ }+ for (int rx = -1; rx <= 1; rx++)+ for (int ry = -1; ry <= 1; ry++)+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ switch (TYP(r)) {+ case PT_WATR: // Drink water+ if (water < 31) {+ kill_part(ID(r));+ water++;+ parts[i].life = 0;+ }+ break;+ case PT_DEUT: // Heavy water allows extra growth+ if (water < 255) {+ kill_part(ID(r));+ water++;+ parts[i].life = 0;+ }+ break;+ case PT_CBNW:+ case PT_DSTW: // Distilled or carbonated water is allowed only in very limited amount+ if (water < 3) {+ kill_part(ID(r));+ water++;+ parts[i].life = 0;+ }+ break;+ case PT_SLTW: // Salty water is harmful+ if (water > 0) {+ kill_part(ID(r));+ water--;+ parts[i].life = 0;+ }+ break;+ case PT_SPNG: // Allow absorbing some water from SPNG+ if (water < 15 && parts[ID(r)].life > 0) {+ parts[ID(r)].life--;+ water++;+ parts[i].life = 0;+ }+ break;+ case PT_SEED: // Breed with another seed+ if (water > 0 && !(parts[i].ctype & 1) && !(parts[ID(r)].ctype & 1) && rng_chance(1, 10)) {+ int ac = parts[i].ctype;+ int bc = parts[ID(r)].ctype;+ int old_tmpsi[4] = {parts[i].tmp, parts[i].tmp2, parts[i].tmp3, tmp4_get(i)};+ int old_tmpsr[4] = {parts[ID(r)].tmp, parts[ID(r)].tmp2, parts[ID(r)].tmp3, tmp4_get(ID(r))};+ int new_tmpsi[4] = {old_tmpsi[0], old_tmpsi[1], old_tmpsi[2], old_tmpsi[3]};+ int new_tmpsr[4] = {old_tmpsr[0], old_tmpsr[1], old_tmpsr[2], old_tmpsr[3]};+ // We set breeding bits, so these seeds will no longer breed with others+ parts[i].ctype = 1 | (parts[i].ctype & ~PLNT_CTYPE);+ parts[ID(r)].ctype = 1 | (parts[ID(r)].ctype & ~PLNT_CTYPE);+ // Inherit colour+ for(int ind = 0; ind < 3; ind++) {+ int bits[2][2];+ for(int kid = 0; kid < 2; kid++) {+ // Decide which allele is chosen from the first parent+ if (rng_chance(1, 2))+ bits[kid][0] = (ac & (1 << (2*ind + PLNT_COLOUR))) != 0;+ else+ bits[kid][0] = (ac & (1 << (1 + 2*ind + PLNT_COLOUR))) != 0;+ // ... from the second parent+ if (rng_chance(1, 2))+ bits[kid][1] = (bc & (1 << (2*ind + PLNT_COLOUR))) != 0;+ else+ bits[kid][1] = (bc & (1 << (1 + 2*ind + PLNT_COLOUR))) != 0;+ }+ // Set the corresponding genes+ parts[i].ctype |= bits[0][0] << (2*ind + PLNT_COLOUR);+ parts[i].ctype |= bits[0][1] << (1 + 2*ind + PLNT_COLOUR);+ parts[ID(r)].ctype |= bits[1][0] << (2*ind + PLNT_COLOUR);+ parts[ID(r)].ctype |= bits[1][1] << (1 + 2*ind + PLNT_COLOUR);+ }+ // Inherit the branching part of tmp - tmp4+ for(int ind = 0; ind < 5; ind++) {+ // Loop over tmp - tmp4+ for(int field = 0; field < 4; field++) {+ new_tmpsi[field] |= rng_chance(1, 2) ?+ (old_tmpsi[field] & (1 << ind)) : (old_tmpsr[field] & (1 << ind));+ new_tmpsr[field] |= rng_chance(1, 2) ?+ (old_tmpsi[field] & (1 << ind)) : (old_tmpsr[field] & (1 << ind));+ }+ }+ // Inherit the phases part of tmp - tmp4+ for(int ind = 5; ind < PLNT_TOTAL_TMP; ind += 2) {+ // Loop over tmp - tmp4+ for(int field = 0; field < 4; field++) {+ new_tmpsi[field] |= rng_chance(1, 2) ?+ (old_tmpsi[field] & (3 << ind)) : (old_tmpsr[field] & (3 << ind));+ new_tmpsr[field] |= rng_chance(1, 2) ?+ (old_tmpsi[field] & (3 << ind)) : (old_tmpsr[field] & (3 << ind));+ }+ }+ parts[i].tmp = (int16_t)new_tmpsi[0], parts[i].tmp2 = (int16_t)new_tmpsi[1], parts[i].tmp3 = (int16_t)new_tmpsi[2];+ tmp4_set(i, new_tmpsi[3]);+ parts[ID(r)].tmp = (int16_t)new_tmpsr[0], parts[ID(r)].tmp2 = (int16_t)new_tmpsr[1], parts[ID(r)].tmp3 = (int16_t)new_tmpsr[2];+ tmp4_set(ID(r), new_tmpsr[3]);+ }+ break;+ default:+ continue;+ }+ }+ // Update water counter+ parts[i].ctype &= ~(0xFF << PLNT_LIFE);+ parts[i].ctype |= (water & 0xFF) << PLNT_LIFE;+ return 0;+}+void el_SEED_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].ctype = 0x760; /* 0b111011'000'00'0 */+ int down = Element_PLNT_detectDown(x, y); // Down gravity direction+ // Use random down direction if can't decide using gravity+ if (down < 0 || down > 7)+ down = rng_between(0, 7);+ int up = (down+4)%8; // Up gravity direction+ parts[i].ctype |= (up & 7) << PLNT_DIR;+ parts[i].tmp = 0;+ parts[i].tmp2 = 0;+ parts[i].tmp3 = 0;+ int tmp4 = 0;+ for(int ind = 0; ind < PLNT_TOTAL_TMP; ind++) {+ if(rng_chance(1, 2))+ parts[i].tmp |= (1<<ind);+ if(rng_chance(1, 2))+ parts[i].tmp2 |= (1<<ind);+ if(rng_chance(1, 2))+ parts[i].tmp3 |= (1<<ind);+ if(rng_chance(1, 2))+ tmp4 |= (1<<ind);+ }+ tmp4_set(i, tmp4);+}+diff --git a/games/numpowder/src/el_sensors.c b/games/numpowder/src/el_sensors.cnew file mode 100644index 00000000..1aedd019--- /dev/null+++ b/games/numpowder/src/el_sensors.c@@ -0,0 +1,514 @@+/* NumPowder: The Powder Toy's sensors (their files in elements/), ported: DTEC, TSNS, PSNS, LSNS, VSNS, LDTC, INVIS. */+#include "simpriv.h"++/* ---------------------------------------------------------------- DTEC */+int el_DTEC_update(UPDATE_FUNC_ARGS) {+ int rd = parts[i].tmp2;+ if (rd > 25) parts[i].tmp2 = rd = 25;+ if (parts[i].life) {+ parts[i].life = 0;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ int pavg = parts_avg(i,ID(r),PT_INSL);+ if (pavg != PT_INSL && pavg != PT_RSSS) {+ if ((elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[ID(r)].life==0) {+ parts[ID(r)].life = 4;+ parts[ID(r)].ctype = rt;+ part_change_type(ID(r),x+rx,y+ry,PT_SPRK);+ }+ }+ }+ }+ }+ }+ bool setFilt = false;+ int photonWl = 0;+ for (int rx =-rd; rx<rd+1; rx++) {+ for (int ry =-rd; ry<rd+1; ry++) {+ if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) {+ int r = PMAPAT(x+rx, y+ry);+ if(!r)+ r = PHOTAT(x+rx, y+ry);+ if(!r)+ continue;+ if (TYP(r) == parts[i].ctype && (parts[i].ctype != PT_LIFE || parts[i].tmp == parts[ID(r)].ctype || !parts[i].tmp))+ parts[i].life = 1;+ if (TYP(r) == PT_PHOT || (TYP(r) == PT_BRAY && parts[ID(r)].tmp!=2) || TYP(r) == PT_BIZR || TYP(r) == PT_BIZRG || TYP(r) == PT_BIZRS) {+ setFilt = true;+ photonWl = parts[ID(r)].ctype;+ }+ }+ }+ }+ if (setFilt) {+ int nx, ny;+ for (int rx =-1; rx<2; rx++) {+ for (int ry =-1; ry<2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ nx = x+rx;+ ny = y+ry;+ while (TYP(r)==PT_FILT) {+ parts[ID(r)].ctype = photonWl;+ nx += rx;+ ny += ry;+ if (nx<0 || ny<0 || nx>=XRES || ny>=YRES)+ break;+ r = PMAPAT(nx, ny);+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- TSNS */+int el_TSNS_update(UPDATE_FUNC_ARGS) {+ int rd = parts[i].tmp2;+ if (rd > 25)+ parts[i].tmp2 = rd = 25;+ if (parts[i].life) {+ parts[i].life = 0;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ r = PHOTAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ int pavg = parts_avg(i, ID(r), PT_INSL);+ if (pavg != PT_INSL && pavg != PT_RSSS) {+ if ((elements[rt].Properties&PROP_CONDUCTS) && !(rt == PT_WATR || rt == PT_SLTW || rt == PT_NTCT || rt == PT_PTCT || rt == PT_INWR) && parts[ID(r)].life == 0) {+ parts[ID(r)].life = 4;+ parts[ID(r)].ctype = rt;+ part_change_type(ID(r), x+rx, y+ry, PT_SPRK);+ }+ }+ }+ }+ }+ }+ bool setFilt = false;+ int photonWl = 0;+ for (int rx = -rd; rx <= rd; rx++)+ for (int ry = -rd; ry <= rd; ry++)+ if (x + rx >= 0 && y + ry >= 0 && x + rx < XRES && y + ry < YRES && (rx || ry)) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ r = PHOTAT(x+rx, y+ry);+ if (!r)+ continue;+ if (parts[i].tmp == 0 && TYP(r) != PT_TSNS && TYP(r) != PT_METL && p_temp(&parts[ID(r)]) > p_temp(&parts[i]))+ parts[i].life = 1;+ if (parts[i].tmp == 2 && TYP(r) != PT_TSNS && TYP(r) != PT_METL && p_temp(&parts[ID(r)]) < p_temp(&parts[i]))+ parts[i].life = 1;+ if (parts[i].tmp == 1 && TYP(r) != PT_TSNS && TYP(r) != PT_FILT) {+ setFilt = true;+ photonWl = (int)(p_temp(&parts[ID(r)]));+ }+ }+ if (setFilt) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int nx = x + rx;+ int ny = y + ry;+ while (TYP(r) == PT_FILT) {+ parts[ID(r)].ctype = 0x10000000 + photonWl;+ nx += rx;+ ny += ry;+ if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES)+ break;+ r = PMAPAT(nx, ny);+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- PSNS */+int el_PSNS_update(UPDATE_FUNC_ARGS) {+ if ((parts[i].tmp == 0 && pv[y/ACELL][x/ACELL] > p_temp(&parts[i])-273.15f) || (parts[i].tmp == 2 && pv[y/ACELL][x/ACELL] < p_temp(&parts[i])-273.15f)) {+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int pavg = parts_avg(i,ID(r),PT_INSL);+ if (pavg != PT_INSL && pavg != PT_RSSS) {+ int rt = TYP(r);+ if ((elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[ID(r)].life==0) {+ parts[ID(r)].life = 4;+ parts[ID(r)].ctype = rt;+ part_change_type(ID(r),x+rx,y+ry,PT_SPRK);+ }+ }+ }+ }+ }+ }+ if (parts[i].tmp == 1) {+ bool setFilt = true;+ float photonWl = pv[y / ACELL][x / ACELL];+ if (setFilt) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x + rx, y + ry);+ if (!r)+ continue;+ int nx = x + rx;+ int ny = y + ry;+ while (TYP(r) == PT_FILT) {+ parts[ID(r)].ctype = 0x10000000 + (int)(roundf(photonWl) - MIN_PRESSURE);+ nx += rx;+ ny += ry;+ if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES)+ break;+ r = PMAPAT(nx, ny);+ }+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- LSNS */+int el_LSNS_update(UPDATE_FUNC_ARGS) {+ int rd = parts[i].tmp2;+ if (rd > 25) parts[i].tmp2 = rd = 25;+ if (parts[i].life) {+ parts[i].life = 0;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x + rx, y + ry);+ if (!r)+ r = PHOTAT(x + rx, y + ry);+ if (!r)+ continue;+ int rt = TYP(r);+ int pavg = parts_avg(i, ID(r), PT_INSL);+ if (pavg != PT_INSL && pavg != PT_RSSS) {+ if ((elements[rt].Properties&PROP_CONDUCTS) && !(rt == PT_WATR || rt == PT_SLTW || rt == PT_NTCT || rt == PT_PTCT || rt == PT_INWR) && parts[ID(r)].life == 0) {+ parts[ID(r)].life = 4;+ parts[ID(r)].ctype = rt;+ part_change_type(ID(r), x + rx, y + ry, PT_SPRK);+ }+ }+ }+ }+ }+ }+ bool doSerialization = false;+ bool doDeserialization = false;+ int life = 0;+ for (int rx = -rd; rx < rd + 1; rx++) {+ for (int ry = -rd; ry < rd + 1; ry++) {+ if (x + rx >= 0 && y + ry >= 0 && x + rx < XRES && y + ry < YRES && (rx || ry)) {+ int r = PMAPAT(x + rx, y + ry);+ if (!r)+ r = PHOTAT(x + rx, y + ry);+ if (!r)+ continue;+ switch (parts[i].tmp) {+ case 1:+ // .life serialization into FILT+ if (TYP(r) != PT_LSNS && TYP(r) != PT_FILT && parts[ID(r)].life >= 0) {+ doSerialization = true;+ life = parts[ID(r)].life;+ }+ break;+ case 3:+ // .life deserialization+ if (TYP(r) == PT_FILT) {+ doDeserialization = true;+ life = parts[ID(r)].ctype;+ }+ break;+ case 2:+ // Invert mode+ if (TYP(r) != PT_METL && parts[ID(r)].life <= p_temp(&parts[i]) - 273.15)+ parts[i].life = 1;+ break;+ default:+ // Normal mode+ if (TYP(r) != PT_METL && parts[ID(r)].life > p_temp(&parts[i]) - 273.15)+ parts[i].life = 1;+ break;+ }+ }+ }+ }+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x + rx, y + ry);+ if (!r)+ r = PHOTAT(x + rx, y + ry);+ if (!r)+ continue;+ int nx = x + rx;+ int ny = y + ry;+ // .life serialization.+ if (doSerialization) {+ while (TYP(r) == PT_FILT) {+ parts[ID(r)].ctype = 0x10000000 + life;+ nx += rx;+ ny += ry;+ if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES)+ break;+ r = PMAPAT(nx, ny);+ }+ }+ // .life deserialization.+ else if (doDeserialization) {+ if (TYP(r) != PT_FILT)+ parts[ID(r)].life = life - 0x10000000;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- VSNS */+int el_VSNS_update(UPDATE_FUNC_ARGS) {+ int rd = parts[i].tmp2;+ if (rd > 25) parts[i].tmp2 = rd = 25;+ if (parts[i].life) {+ parts[i].life = 0;+ for (int rx = -2; rx <= 2; rx++) {+ for (int ry = -2; ry <= 2; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x + rx, y + ry);+ if (!r)+ continue;+ int rt = TYP(r);+ int pavg = parts_avg(i, ID(r), PT_INSL);+ if (pavg != PT_INSL && pavg != PT_RSSS) {+ if ((elements[rt].Properties &PROP_CONDUCTS) && !(rt == PT_WATR || rt == PT_SLTW || rt == PT_NTCT || rt == PT_PTCT || rt == PT_INWR) && parts[ID(r)].life == 0) {+ parts[ID(r)].life = 4;+ parts[ID(r)].ctype = rt;+ part_change_type(ID(r), x + rx, y + ry, PT_SPRK);+ }+ }+ }+ }+ }+ }+ bool doSerialization = false;+ bool doDeserialization = false;+ float Vs = 0;+ for (int rx = -rd; rx < rd + 1; rx++)+ for (int ry = -rd; ry < rd + 1; ry++)+ if (x + rx >= 0 && y + ry >= 0 && x + rx < XRES && y + ry < YRES && (rx || ry)) {+ int r = PMAPAT(x + rx, y + ry);+ if (!r)+ r = PHOTAT(x + rx, y + ry);+ if (!r)+ continue;+ float Vx = p_vx(&parts[ID(r)]);+ float Vy = p_vy(&parts[ID(r)]);+ float Vm = sqrtf(Vx*Vx + Vy*Vy);+ switch (parts[i].tmp) {+ case 1:+ // serialization+ if (TYP(r) != PT_VSNS && TYP(r) != PT_FILT && !(elements[TYP(r)].Properties & TYPE_SOLID)) {+ doSerialization = true;+ Vs = Vm;+ }+ break;+ case 3:+ // deserialization+ if (TYP(r) == PT_FILT) {+ int vel = parts[ID(r)].ctype - 0x10000000;+ if (vel >= 0 && vel < MAX_VELOCITY) {+ doDeserialization = true;+ Vs = (float)(vel);+ }+ }+ break;+ case 2:+ // Invert mode+ if (!(elements[TYP(r)].Properties & TYPE_SOLID) && Vm <= p_temp(&parts[i]) - 273.15)+ parts[i].life = 1;+ break;+ default:+ // Normal mode+ if (!(elements[TYP(r)].Properties & TYPE_SOLID) && Vm > p_temp(&parts[i]) - 273.15)+ parts[i].life = 1;+ break;+ }+ }+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x + rx, y + ry);+ if (!r)+ r = PHOTAT(x + rx, y + ry);+ if (!r)+ continue;+ int nx = x + rx;+ int ny = y + ry;+ //Serialization.+ if (doSerialization) {+ while (TYP(r) == PT_FILT) {+ parts[ID(r)].ctype = 0x10000000 + (int)(Vs + 0.5f);+ nx += rx;+ ny += ry;+ if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES)+ break;+ r = PMAPAT(nx, ny);+ }+ }+ //Deserialization.+ if (doDeserialization) {+ if (TYP(r) != PT_FILT && !(elements[TYP(r)].Properties & TYPE_SOLID)) {+ float Vx = p_vx(&parts[ID(r)]);+ float Vy = p_vy(&parts[ID(r)]);+ float Vm = sqrtf(Vx*Vx + Vy*Vy);+ if (Vm > 0) {+ p_set_vx(&parts[ID(r)], p_vx(&parts[ID(r)]) * (Vs / Vm));+ p_set_vy(&parts[ID(r)], p_vy(&parts[ID(r)]) * (Vs / Vm));+ }+ break;+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- LDTC */+enum { FLAG_INVERT_FILTER = 0x1, FLAG_IGNORE_ENERGY = 0x2, FLAG_NO_COPY_COLOR = 0x4, FLAG_KEEP_SEARCHING = 0x8 };+//NOTES:+// ctype is used to store the target element, if any. (NONE is treated as a wildcard)+// life is used for the amount of pixels to skip before starting the scan. Starts just in front of the LDTC if 0.+// tmp is the number of particles that will be scanned before scanning stops. Unbounded if 0.+// tmp2 is used for settings (binary flags). The flags are as follows:+// 0x01: Inverts the CTYPE filter so that the element in ctype is the only thing that doesn't trigger LDTC, instead of the opposite.+// 0x02: Ignore energy particles+// 0x04: Ignore FILT (do not use color copying mode)+// 0x08: Keep searching even after finding a particle+/* Returns true for particles that activate the special FILT color copying mode */+static bool LDTC_phot_data_type(int rt) {+ return rt == PT_FILT || rt == PT_PHOT || rt == PT_BRAY || rt == PT_BIZR || rt == PT_BIZRG || rt == PT_BIZRS;+}+/* Returns true for particles that start a ray search ("dtec" mode)+ */+static bool LDTC_accepted_conductor(int r) {+ int rt = TYP(r);+ return (elements[rt].Properties & PROP_CONDUCTS) &&+ !(rt == PT_WATR || rt == PT_SLTW || rt == PT_NTCT ||+ rt == PT_PTCT || rt == PT_INWR) &&+ parts[ID(r)].life == 0;+}+int el_LDTC_update(UPDATE_FUNC_ARGS) {+ int ctype = TYP(parts[i].ctype), ctypeExtra = ID(parts[i].ctype), detectLength = parts[i].tmp, detectSpaces = parts[i].tmp2;+ bool copyColor = !(parts[i].tmp2 & FLAG_NO_COPY_COLOR);+ bool ignoreEnergy = parts[i].tmp2 & FLAG_IGNORE_ENERGY;+ bool invertFilter = parts[i].tmp2 & FLAG_INVERT_FILTER;+ bool keepSearching = parts[i].tmp2 & FLAG_KEEP_SEARCHING;+ if (detectSpaces < 0)+ detectSpaces = parts[i].tmp2 = 0;+ if (detectLength < 0)+ detectLength = parts[i].tmp = 0;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ bool boolMode = LDTC_accepted_conductor(r);+ bool filtMode = copyColor && TYP(r) == PT_FILT;+ if (!boolMode && !filtMode)+ continue;+ int maxRange = parts[i].life + parts[i].tmp;+ int xStep = rx * -1, yStep = ry * -1;+ int xCurrent = x + (xStep * (parts[i].life + 1)), yCurrent = y + (yStep * (parts[i].life + 1));+ for (; !parts[i].tmp ||+ (xStep * (xCurrent - x) <= maxRange &&+ yStep * (yCurrent - y) <= maxRange);+ xCurrent += xStep, yCurrent += yStep) {+ if (!(xCurrent>=0 && yCurrent>=0 && xCurrent<XRES && yCurrent<YRES))+ break; // We're out of bounds! Oops!+ int rr = PMAPAT(xCurrent, yCurrent);+ if (!rr && !ignoreEnergy)+ rr = PHOTAT(xCurrent, yCurrent);+ if (!rr)+ continue;+ // If ctype isn't set (no type restriction), or ctype matches what we found+ // Can use .tmp2 flag to invert this+ bool matchesCtype = ctype == TYP(rr) && (ctype != PT_LIFE || parts[ID(rr)].ctype == ctypeExtra);+ bool matchesFilter = !ctype || (invertFilter ^ (int)matchesCtype);+ if (!matchesFilter) {+ if (keepSearching)+ continue;+ else+ break;+ }+ // room for more conditions here.+ if (boolMode) {+ parts[ID(r)].life = 4;+ parts[ID(r)].ctype = TYP(r);+ part_change_type(ID(r), x + rx, y + ry, PT_SPRK);+ break;+ }+ if (filtMode) {+ if (!LDTC_phot_data_type(TYP(rr)))+ continue;+ int nx = x + rx, ny = y + ry;+ int photonWl = TYP(rr) == PT_FILT ?+ Element_FILT_getWavelengths(&parts[ID(rr)]) :+ parts[ID(rr)].ctype;+ while (TYP(r) == PT_FILT) {+ parts[ID(r)].ctype = photonWl;+ nx += rx;+ ny += ry;+ if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES)+ break;+ r = PMAPAT(nx, ny);+ }+ break;+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- INVIS */+int el_INVIS_update(UPDATE_FUNC_ARGS) {+ float pressureResistance = 0.0f;+ if (parts[i].tmp > 0)+ pressureResistance = (float) parts[i].tmp;+ else+ pressureResistance = 4.0f;+ if (pv[y/ACELL][x/ACELL] < -pressureResistance || pv[y/ACELL][x/ACELL] > pressureResistance)+ parts[i].tmp2 = 1;+ else+ parts[i].tmp2 = 0;+ return 0;+}+diff --git a/games/numpowder/src/el_solids.c b/games/numpowder/src/el_solids.cnew file mode 100644index 00000000..ec22704c--- /dev/null+++ b/games/numpowder/src/el_solids.c@@ -0,0 +1,1456 @@+/* NumPowder: The Powder Toy's solids (their files in elements/), ported: GOO, ICEI, WOOD, PLNT, BMTL, GLAS, GOLD,+ * IRON, TTAN, TUNG, PTNM, CRMC, HEAC, ROCK, VINE, SPNG, QRTZ (and PQRT), VIBR (and BVBR), RSSS, SHLD1 to SHLD4,+ * SPAWN, SPAWN2, FILT. */+#include "simpriv.h"++/* ---------------------------------------------------------------- GOO */+#define ADVECTION 0.1f+int el_GOO_update(UPDATE_FUNC_ARGS) {+ if (!parts[i].life && pv[y/ACELL][x/ACELL]>1.0f)+ parts[i].life = rng_between(300, 379);+ if (parts[i].life) {+ p_set_vx(&parts[i], p_vx(&parts[i]) + (ADVECTION*vx[y/ACELL][x/ACELL]));+ p_set_vy(&parts[i], p_vy(&parts[i]) + (ADVECTION*vy[y/ACELL][x/ACELL]));+ }+ return 0;+}++/* ---------------------------------------------------------------- ICEI */+int el_ICEI_update(UPDATE_FUNC_ARGS) {+ if (parts[i].ctype==PT_FRZW) { //get colder if it is from FRZW+ p_set_temp(&parts[i], restrict_flt(p_temp(&parts[i])-1.0f, MIN_TEMP, MAX_TEMP));+ }+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_SALT || TYP(r)==PT_SLTW) {+ if (p_temp(&parts[i]) > elements[PT_SLTW].LowTemperature && rng_chance(1, 200)) {+ //@ ICEI + SALT/SLTW -> 2xSLTW+ part_change_type(i,x,y,PT_SLTW);+ part_change_type(ID(r),x+rx,y+ry,PT_SLTW);+ return 0;+ }+ } else if ((TYP(r)==PT_FRZZ) && rng_chance(1, 200)) {+ //@ ICEI + FRZZ -> ICEI + ICEI(FRZW)+ part_change_type(ID(r),x+rx,y+ry,PT_ICEI);+ parts[ID(r)].ctype = PT_FRZW;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- WOOD */+int el_WOOD_update(UPDATE_FUNC_ARGS) {+ if (p_temp(&parts[i]) > 450 && p_temp(&parts[i]) > parts[i].tmp)+ parts[i].tmp = (int)p_temp(&parts[i]);+ if (p_temp(&parts[i]) > 773.0f && pv[y/ACELL][x/ACELL] <= -10.0f) {+ float temp = p_temp(&parts[i]);+ //@ WOOD -> BCOL+ create_part(i, x, y, PT_BCOL, -1);+ p_set_temp(&parts[i], temp);+ }+ return 0;+}++/* ---------------------------------------------------------------- PLNT */+// Fields used for tree growth (see also PLNT.h):+// ctype: tree or usual PLNT (1 bit), phase (2 bits), direction (3 bits), colour (6 bits), water (8 bits)+// life: used as a counter in growth+// tmp-tmp4: branching bitmask (5 bits), new phases (5x2 bits)+int el_PLNT_update(UPDATE_FUNC_ARGS) {+ // Select tree growth code or usual PLNT code+ if (parts[i].ctype & 1) {+ float temp = p_temp(&parts[i]);+ // Hot and cold temperature kills tree growth+ if (temp > 373.15f || temp < 223.15f) {+ parts[i].ctype = 0;+ parts[i].tmp = 0;+ parts[i].tmp2 = 0;+ parts[i].tmp3 = 0;+ tmp4_set(i, 0);+ return 0;+ }+ // No growth happens at bad temperatures+ if (temp > 343.15f || temp < 278.15f)+ return 0;+ // Slow things down+ if (rng_chance(9, 10))+ return 0;+ // Current phase, direction and life+ int phase = (parts[i].ctype>>PLNT_PHASE) & 0x3;+ int dir = (parts[i].ctype>>PLNT_DIR) & 0x7;+ int life = (parts[i].ctype>>PLNT_LIFE) & 0xFF;+ int prog = 0;+ // Select a program for the current phase+ switch (phase) {+ case 0: prog = parts[i].tmp; break;+ case 1: prog = parts[i].tmp2; break;+ case 2: prog = parts[i].tmp3; break;+ case 3: prog = tmp4_get(i); break;+ }+ int si = -1; // Used for create_part calls+ bool stopped = false; // Did the cell stop growing?+ int down = Element_PLNT_detectDown(x, y); // Down gravity direction (8 means no direction)+ // Do we continue growing?+ if (life > 0) {+ // Do we grow forward or branch?+ if (!parts[i].life) {+ // Branching+ int bmask = prog&0x1F;+ int phases = prog>>5;+ // Can we branch or it's a dead end?+ if (bmask) {+ // Loop through all possible branching directions+ for (int phi = 0; phi < 5; phi++) {+ if ((bmask>>phi)&0x1) {+ int ndir = (dir + phi + 6) % 8; // phi = 0 is -90 deg, phi = 1 is -45 deg etc+ int nphase = phases&0x3;+ int nlife = (2*life)/3;+ // Discourage branches which go down+ if (down < 8) {+ // Down+ if(ndir == down)+ nlife = life/3;+ // Down-left and down-right+ if(ndir == ((down+1)%8) || ndir == ((down+7)%8))+ nlife = life/3;+ // Sideways+ if(life > 4 && (ndir == ((down+2)%8) || ndir == ((down+6)%8)))+ nlife = life/2;+ }+ si = create_part(-1, x+dir3x3[ndir].X, y+dir3x3[ndir].Y, PT_PLNT, -1);+ if (si >= 0) {+ parts[si].ctype = ((nlife & 0xFF) << PLNT_LIFE) | (parts[i].ctype & (0x3f << PLNT_COLOUR))+ | ((ndir & 7) << PLNT_DIR) | ((nphase & 3) << PLNT_PHASE) | 0x1;+ // Reduce the length of diagonal branches by 1/sqrtf(2) ~= 0.7+ parts[si].life = (ndir%2 == 1) ? 7*nlife : 10*nlife;+ parts[si].tmp = parts[i].tmp;+ parts[si].tmp2 = parts[i].tmp2;+ parts[si].tmp3 = parts[i].tmp3;+ tmp4_set(si, tmp4_get(i));+ }+ }+ phases = phases>>2;+ }+ } else+ stopped = true;+ } else {+ // Grow forward+ si = create_part(-1, x+dir3x3[dir].X, y+dir3x3[dir].Y, PT_PLNT, -1);+ if (si >= 0) {+ parts[si].ctype = ((life & 0xFF) << PLNT_LIFE) | (parts[i].ctype & (0x3f << PLNT_COLOUR))+ | ((dir & 7) << PLNT_DIR) | ((phase & 3) << PLNT_PHASE) | 0x1;+ parts[si].life = parts[i].life;+ parts[si].tmp = parts[i].tmp;+ parts[si].tmp2 = parts[i].tmp2;+ parts[si].tmp3 = parts[i].tmp3;+ tmp4_set(si, tmp4_get(i));+ }+ }+ if (!stopped) {+ // Create a stem+ if (phase || life < 12) {+ //@ PLNT -> WOOD+ create_part(i, x, y, PT_WOOD, -1);+ parts[i].ctype = 0;+ parts[i].life = 0;+ parts[i].tmp = 0;+ parts[i].tmp2 = 0;+ parts[i].tmp3 = 0;+ tmp4_set(i, 0);+ } else {+ // Thick stem+ //@ PLNT -> GOO+ create_part(i, x, y, PT_GOO, -1);+ parts[i].ctype = 0;+ parts[i].life = 0;+ parts[i].tmp = 0;+ parts[i].tmp2 = 0;+ parts[i].tmp3 = 0;+ tmp4_set(i, 0);+ int left_dir = (dir+6)%8;+ int right_dir = (dir+2)%8;+ // Correction for diagonal directions+ if (dir%2) {+ left_dir = (dir+5)%8;+ right_dir = (dir+3)%8;+ }+ create_part(-1, x+dir3x3[left_dir].X, y+dir3x3[left_dir].Y, PT_WOOD, -1);+ create_part(-1, x+dir3x3[right_dir].X, y+dir3x3[right_dir].Y, PT_WOOD, -1);+ }+ }+ } else+ stopped = true;+ // Stop growing+ if (stopped) {+ // Shoot out a seed+ if (rng_chance(1, 10)) {+ //@ PLNT -> PLNT + SEED+ si = create_part(-1, x+2*dir3x3[dir].X, y+2*dir3x3[dir].Y, PT_SEED, -1);+ if (si >= 0) {+ p_set_vx(&parts[si], (float)(dir3x3[dir].X));+ p_set_vy(&parts[si], (float)(dir3x3[dir].Y));+ // Inherit genome+ parts[si].ctype = parts[i].ctype & (0x3f << PLNT_COLOUR); // Preserve only the colour+ parts[si].tmp = parts[i].tmp;+ parts[si].tmp2 = parts[i].tmp2;+ parts[si].tmp3 = parts[i].tmp3;+ tmp4_set(si, tmp4_get(i));+ }+ }+ // Turn into usual plant (but preserve color)+ // We set direction to 7 to tell graphics() that PLNT needs coloring+ parts[i].ctype = (parts[i].ctype & (0x3f << PLNT_COLOUR)) | (7 << PLNT_DIR);+ parts[i].life = 0;+ parts[i].tmp = 0;+ parts[i].tmp2 = 0;+ parts[i].tmp3 = 0;+ tmp4_set(i, 0);+ }+ return 1;+ } else+ { // Usual PLNT code+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ switch (TYP(r)) {+ case PT_WATR:+ if (rng_chance(1, 50)) {+ //@ PLNT + WATR -> 2xPLNT+ int np = create_part(ID(r),x+rx,y+ry,PT_PLNT, -1);+ if (np<0) continue;+ parts[np].life = 0;+ parts[np].ctype = parts[i].ctype & PLNT_CTYPE;//Keep the color identical+ }+ break;+ case PT_LAVA:+ if (rng_chance(1, 50)) {+ //@ PLNT + LAVA -> FIRE + LAVA+ part_change_type(i,x,y,PT_FIRE);+ parts[i].life = 4;+ }+ break;+ case PT_SMKE:+ case PT_CO2:+ if (rng_chance(1, 50)) {+ kill_part(ID(r));+ parts[i].life = rng_between(60, 119);+ }+ break;+ case PT_WOOD: {+ int rndstore = rng_gen();+ if (surround_space && !(rndstore%4) && parts[i].tmp==1) {+ rndstore >>= 3;+ int nnx = (rndstore%3) -1;+ rndstore >>= 2;+ int nny = (rndstore%3) -1;+ if (nnx || nny) {+ if (PMAPAT(x+rx+nnx, y+ry+nny))+ continue;+ int np = create_part(-1,x+rx+nnx,y+ry+nny,PT_VINE, -1);+ if (np<0) continue;+ p_set_temp(&parts[np], p_temp(&parts[i]));+ }+ }+ }+ break;+ default:+ continue;+ }+ }+ }+ }+ if (parts[i].life==2) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ //@ PLNT + SMKE/CO2 -> PLNT + O2+ if (!r)+ create_part(-1,x+rx,y+ry,PT_O2, -1);+ }+ }+ }+ parts[i].life = 0;+ }+ if (p_temp(&parts[i]) > 350 && p_temp(&parts[i]) > parts[i].tmp2)+ parts[i].tmp2 = (int)p_temp(&parts[i]);+ }+ return 0;+}+// Inverse of dir3x3 table+static const int invDir[3][3] = {+ { 1, 2, 3 },+ { 0, 8, 4 },+ { 7, 6, 5 },+};+int Element_PLNT_detectDown(int x, int y) {+ float pGravX = 0;+ float pGravY = 0;+ GetGravityField(x, y, 1.0f, 1.0f, &pGravX, &pGravY);+ float gravLen = hypotf(pGravX, pGravY);+ // Normalize gravity+ if (gravLen > 0) {+ pGravX /= gravLen;+ pGravY /= gravLen;+ }+ int gravx = 1;+ int gravy = 1;+ if (pGravX > 0.5f)+ gravx = 2;+ if (pGravX < -0.5f)+ gravx = 0;+ if (pGravY > 0.5f)+ gravy = 2;+ if (pGravY < -0.5f)+ gravy = 0;+ return invDir[gravx][gravy];+}++/* ---------------------------------------------------------------- BMTL */+int el_BMTL_update(UPDATE_FUNC_ARGS) {+ if (parts[i].tmp>1) {+ parts[i].tmp--;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if ((TYP(r)==PT_METL || TYP(r)==PT_IRON) && rng_chance(1, 100)) {+ //@ BMTL + METL/IRON -> 2xBMTL+ part_change_type(ID(r),x+rx,y+ry,PT_BMTL);+ parts[ID(r)].tmp = (parts[i].tmp<=7) ? parts[i].tmp=1 : parts[i].tmp - rng_between(0, 4);+ }+ }+ }+ }+ } else if (parts[i].tmp==1 && rng_chance(1, 1000)) {+ //@ BMTL -> BRMT+ parts[i].tmp = 0;+ part_change_type(i,x,y,PT_BRMT);+ }+ return 0;+}++/* ---------------------------------------------------------------- GLAS */+int el_GLAS_update(UPDATE_FUNC_ARGS) {+ int press = (int)(pv[y/ACELL][x/ACELL] * 64);+ int diff = press - parts[i].tmp3;+ // Determine whether the GLAS is chemically strengthened via .life setting. (250 = Max., 16 = Min.)+ int strength = (parts[i].life / 120) + 16;+ if (strength < 16)+ strength = 16;+ if (diff > strength || diff < -1 * strength) {+ //@ GLAS -> BGLA+ part_change_type(i, x, y, PT_BGLA);+ }+ parts[i].tmp3 = press;+ // Liquid nitrogen condenses on chemically strengthened glass+ if ((strength > 200) && (p_temp(&parts[i]) < 77.0f) && (hv[y/ACELL][x/ACELL] < 77.0f)+ && (pv[y/ACELL][x/ACELL] > 5.0f) && rng_chance(1, 100)) {+ // Sample 4 adjacent cells+ int adj = rng_between(0, 3);+ int rx = (1 - 2*(adj%2))*(1 - adj/2);+ int ry = (1 - 2*(adj%2))*(adj/2);+ int r = PMAPAT(x+rx, y+ry);+ // If found an empty spot around glass+ if (!r) {+ //@ GLAS -> GLAS + LNTG+ int np = create_part(-1, x+rx, y+ry, PT_LNTG, -1);+ if (np>-1) {+ pv[y/ACELL][x/ACELL] -= 1.0f;+ p_set_temp(&parts[i], p_temp(&parts[i]) + (200.0f));+ }+ }+ }+ return 0;+}+void el_GLAS_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].tmp3 = (int)(pv[y/ACELL][x/ACELL] * 64);+}++/* ---------------------------------------------------------------- GOLD */+int el_GOLD_update(UPDATE_FUNC_ARGS) {+ static int checkCoordsX[] = { -4, 4, 0, 0 };+ static int checkCoordsY[] = { 0, 0, -4, 4 };+ //Find nearby rusted iron (BMTL with tmp 1+)+ for(int j = 0; j < 8; j++) {+ int rndstore = rng_gen();+ int rx = (rndstore % 9)-4;+ rndstore >>= 4;+ int ry = (rndstore % 9)-4;+ if ((!rx != !ry)) {+ int r = PMAPAT(x+rx, y+ry);+ if(!r) continue;+ if(TYP(r)==PT_BMTL && parts[ID(r)].tmp) {+ //@ GOLD + BMTL -> GOLD + IRON+ parts[ID(r)].tmp = 0;+ part_change_type(ID(r), x+rx, y+ry, PT_IRON);+ }+ }+ }+ //Find sparks+ if(!parts[i].life) {+ for(int j = 0; j < 4; j++) {+ int rx = checkCoordsX[j];+ int ry = checkCoordsY[j];+ int r = PMAPAT(x+rx, y+ry);+ if(!r) continue;+ if(TYP(r)==PT_SPRK && parts[ID(r)].life && parts[ID(r)].life<4) {+ part_change_type(i, x, y, PT_SPRK);+ parts[i].life = 4;+ parts[i].ctype = PT_GOLD;+ }+ }+ }+ if (TYP(PHOTAT(x, y)) == PT_NEUT) {+ if (rng_chance(1, 7)) {+ kill_part(ID(PHOTAT(x, y)));+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- IRON */+int el_IRON_update(UPDATE_FUNC_ARGS) {+ if (parts[i].life)+ return 0;+ bool tryBreak = false;+ for (bool once = true; once; once = false) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ switch (TYP(r)) {+ case PT_SALT:+ //@ IRON + SALT -> BMTL + SALT+ if (rng_chance(1, 47))+ { tryBreak = true; goto done; }+ break;+ case PT_SLTW:+ //@ IRON + SLTW -> BMTL + SLTW+ if (rng_chance(1, 67))+ { tryBreak = true; goto done; }+ break;+ case PT_WATR:+ //@ IRON + WATR -> BMTL + WATR+ if (rng_chance(1, 1200))+ { tryBreak = true; goto done; }+ break;+ case PT_O2:+ //@ IRON + O2 -> BMTL + O2+ if (rng_chance(1, 250))+ { tryBreak = true; goto done; }+ break;+ case PT_LO2:+ //@ IRON + LO2 -> BMTL + LO2+ tryBreak = true;+ goto done;+ default:+ break;+ }+ }+ }+ }+ }+done:+ if (tryBreak) {+ part_change_type(i,x,y,PT_BMTL);+ parts[i].tmp = rng_between(20, 29);+ }+ return 0;+}++/* ---------------------------------------------------------------- TTAN */+int el_TTAN_update(UPDATE_FUNC_ARGS) {+ int ttan = 0;+ if (nt <= 2)+ ttan = 2;+ else if (parts[i].tmp)+ ttan = 2;+ else if (nt <= 6) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (!rx != !ry) {+ if (TYP(PMAPAT(x+rx, y+ry)) == PT_TTAN)+ ttan++;+ }+ }+ }+ }+ if (ttan >= 2) {+ bmap_blockair[y/ACELL][x/ACELL] = 1;+ bmap_blockairh[y/ACELL][x/ACELL] = 0x8;+ }+ return 0;+}++/* ---------------------------------------------------------------- TUNG */+int el_TUNG_update(UPDATE_FUNC_ARGS) {+ bool splode = false;+ const float MELTING_POINT = elements[PT_TUNG].HighTemperature;+ if(p_temp(&parts[i]) > 2400.0) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if(TYP(r) == PT_O2) {+ splode = true;+ }+ }+ }+ }+ }+ if((p_temp(&parts[i]) > MELTING_POINT && rng_chance(1, 20)) || splode) {+ if (rng_chance(1, 50)) {+ pv[y/ACELL][x/ACELL] += 50.0f;+ } else if (rng_chance(1, 100)) {+ //@ TUNG -> FIRE+ part_change_type(i, x, y, PT_FIRE);+ parts[i].life = rng_between(0, 499);+ return 1;+ } else {+ //@ TUNG -> LAVA(TUNG)+ part_change_type(i, x, y, PT_LAVA);+ parts[i].ctype = PT_TUNG;+ return 1;+ }+ if(splode) {+ p_set_temp(&parts[i], restrict_flt(MELTING_POINT + rng_between(200, 799), MIN_TEMP, MAX_TEMP));+ }+ p_set_vx(&parts[i], p_vx(&parts[i]) + (rng_between(-50, 50)));+ p_set_vy(&parts[i], p_vy(&parts[i]) + (rng_between(-50, 50)));+ return 1;+ }+ int press = (int)(pv[y/ACELL][x/ACELL] * 64);+ int diff = press - parts[i].tmp3;+ if (diff > 32 || diff < -32) {+ //@ TUNG -> BRMT(TUNG)+ part_change_type(i,x,y,PT_BRMT);+ parts[i].ctype = PT_TUNG;+ return 1;+ }+ parts[i].tmp3 = press;+ return 0;+}+void el_TUNG_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].tmp3 = (int)(pv[y/ACELL][x/ACELL] * 64);+}++/* ---------------------------------------------------------------- PTNM */+static void PTNM_wtrv_reactions(int wtrv1_id, UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x + rx, y + ry);+ if (!r || ID(r) == wtrv1_id)+ continue;+ int rt = TYP(r);+ //@ PTNM + WTRV + BCOL -> PTNM + OIL+ if (rt == PT_BCOL && p_temp(&parts[ID(r)]) > 200.0f + 273.15f && p_temp(&parts[wtrv1_id]) > 200.0f + 273.15f && pv[(y + ry) / ACELL][(x + rx) / ACELL] > 7.f) {+ part_change_type(ID(r), x + rx, y + ry, PT_OIL);+ kill_part(wtrv1_id);+ return;+ }+ }+ }+ }+}+static void PTNM_hygn_reactions(int hygn1_id, UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x + rx, y + ry);+ if (!r || ID(r) == hygn1_id)+ continue;+ int rt = TYP(r);+ //@ PTNM + H2 + DESL -> PTNM + OIL + WATR+ if (rt == PT_DESL) {+ part_change_type(ID(r), x + rx, y + ry, PT_WATR);+ part_change_type(hygn1_id, (int)(p_x(&parts[hygn1_id]) + 0.5f), (int)(p_y(&parts[hygn1_id]) + 0.5f), PT_OIL);+ return;+ }+ //@ PTNM + H2 + O2 -> PTNM + 2xDSTW+ if (rt == PT_O2 && !parts[i].life) {+ part_change_type(ID(r), x + rx, y + ry, PT_DSTW);+ part_change_type(hygn1_id, (int)(p_x(&parts[hygn1_id]) + 0.5f), (int)(p_y(&parts[hygn1_id]) + 0.5f), PT_DSTW);+ p_set_temp(&parts[ID(r)], p_temp(&parts[ID(r)]) + (5.0f));+ p_set_temp(&parts[hygn1_id], p_temp(&parts[hygn1_id]) + (5.0f));+ parts[i].ctype = PT_PTNM;+ parts[i].life = 4;+ part_change_type(i, x, y, PT_SPRK);+ return;+ }+ // Cold fusion: 2 hydrogen > 500 C has a chance to fuse+ if (rt == PT_H2 && rng_chance(1, 1000) && p_temp(&parts[ID(r)]) > 500.0f + 273.15f && p_temp(&parts[hygn1_id]) > 500.0f + 273.15f) {+ //@ PTNM + 2xH2 -> PTNM + NBLE + NEUT + PHOT + maybe ELEC+ part_change_type(ID(r), x + rx, y + ry, PT_NBLE);+ part_change_type(hygn1_id, (int)(p_x(&parts[hygn1_id]) + 0.5f), (int)(p_y(&parts[hygn1_id]) + 0.5f), PT_NEUT);+ p_set_temp(&parts[ID(r)], p_temp(&parts[ID(r)]) + (1000.0f));+ p_set_temp(&parts[hygn1_id], p_temp(&parts[hygn1_id]) + (1000.0f));+ pv[(y + ry) / ACELL][(x + rx) / ACELL] += 10.0f;+ int j = create_part(-3, x + rx, y + ry, PT_PHOT, -1);+ if (j > -1) {+ parts[j].ctype = 0x7C0000;+ p_set_temp(&parts[j], p_temp(&parts[ID(r)]));+ parts[j].tmp = 0x1;+ }+ if (rng_chance(1, 10)) {+ int j = create_part(-3, x + rx, y + ry, PT_ELEC, -1);+ if (j > -1)+ p_set_temp(&parts[j], p_temp(&parts[ID(r)]));+ }+ return;+ }+ }+ }+ }+}+int el_PTNM_update(UPDATE_FUNC_ARGS) {+ int hygn1_id = -1; // Id of a hydrogen particle for hydrogen multi-particle reactions+ int wtrv1_id = -1; // same but wtrv+ // Fast conduction (like GOLD)+ if (!parts[i].life) {+ for (int j = 0; j < 4; j++) {+ static const int checkCoordsX[] = { -4, 4, 0, 0 };+ static const int checkCoordsY[] = { 0, 0, -4, 4 };+ int rx = checkCoordsX[j];+ int ry = checkCoordsY[j];+ int r = PMAPAT(x + rx, y + ry);+ if (r && TYP(r) == PT_SPRK && parts[ID(r)].life && parts[ID(r)].life < 4) {+ part_change_type(i, x, y, PT_SPRK);+ parts[i].life = 4;+ parts[i].ctype = PT_PTNM;+ }+ }+ }+ // Single element reactions+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x + rx, y + ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (rt == PT_H2 && hygn1_id < 0)+ hygn1_id = ID(r);+ if (rt == PT_WTRV && wtrv1_id < 0)+ wtrv1_id = ID(r);+ // These reactions will occur instantly in contact with PTNM+ // --------------------------------------------------------+ // Shield instantly grows (even without SPRK)+ if (!parts[ID(r)].life && (rt == PT_SHLD1 || rt == PT_SHLD2 || rt == PT_SHLD3)) {+ int next = PT_SHLD1;+ switch (rt) {+ case PT_SHLD1: next = PT_SHLD2; break;+ case PT_SHLD2: next = PT_SHLD3; break;+ case PT_SHLD3: next = PT_SHLD4; break;+ }+ part_change_type(ID(r), x + rx, y + ry, next);+ parts[ID(r)].life = 7;+ continue;+ }+ //@ PTNM + ISZS/ISOZ -> PTNM + PLUT + PHOT+ if (rt == PT_ISZS || rt == PT_ISOZ) {+ part_change_type(ID(r), x + rx, y + ry, PT_PLUT);+ create_part(-3, x + rx, y + ry, PT_PHOT, -1);+ continue;+ }+ // These reactions are dependent on temperature+ // Probability goes quadratically from 0% / frame to 100% / frame from 0 C to 1500 C+ // --------------------------------------------------------+ float prob = fminf(1.0f, p_temp(&parts[i]) / (273.15f + 1500.0f));+ prob *= prob;+ if (rng_uniform01() <= prob) {+ switch (rt) {+ case PT_GAS: // GAS + > 2 pressure + >= 200 C -> INSL+ if (p_temp(&parts[ID(r)]) >= 200.0f + 273.15f && pv[(y + ry) / ACELL][(x + rx) / ACELL] > 2.0f) {+ //@ PTNM + GAS -> PTNM + INSL+ part_change_type(ID(r), x + rx, y + ry, PT_INSL);+ p_set_temp(&parts[i], p_temp(&parts[i]) + (60.0f)); // Other part is INSL, adding temp is useless+ }+ break;+ case PT_BREC: // BREL + > 1000 C + > 50 pressure -> EXOT+ if (p_temp(&parts[ID(r)]) > 1000.0f + 273.15f && pv[(y + ry) / ACELL][(x + rx) / ACELL] > 50.0f) {+ //@ PTNM + BREC -> PTNM + EXOT+ part_change_type(ID(r), x + rx, y + ry, PT_EXOT);+ p_set_temp(&parts[ID(r)], p_temp(&parts[ID(r)]) - (30.0f));+ p_set_temp(&parts[i], p_temp(&parts[i]) - (30.0f));+ }+ break;+ case PT_SMKE: //@ PTNM + SMKE -> PTNM + CO2+ part_change_type(ID(r), x + rx, y + ry, PT_CO2);+ break;+ case PT_RSST: //@ PTNM + RSST -> PTNM + BIZR+ create_part(ID(r), x + rx, y + ry, PT_BIZR, -1);+ break;+ }+ }+ }+ }+ }+ // Hydrogen reactions+ if (hygn1_id >= 0) {+ PTNM_hygn_reactions(hygn1_id, UPDATE_FUNC_SUBCALL_ARGS);+ }+ // WTRV reactions+ if (wtrv1_id >= 0) {+ PTNM_wtrv_reactions(wtrv1_id, UPDATE_FUNC_SUBCALL_ARGS);+ }+ return 0;+}+void el_PTNM_create(ELEMENT_CREATE_FUNC_ARGS) {+ if (rng_chance(1, 15))+ parts[i].tmp = 1;+}++/* ---------------------------------------------------------------- CRMC */+int el_CRMC_update(UPDATE_FUNC_ARGS) {+ float origTemp = p_temp(&parts[i]);+ //@ CRMC -> CLST+ if (pv[y/ACELL][x/ACELL] < -30.0f)+ create_part(i, x, y, PT_CLST, -1);+ p_set_temp(&parts[i], origTemp);+ return 0;+}+void el_CRMC_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].tmp2 = rng_between(0, 4);+}++/* ---------------------------------------------------------------- HEAC */+/* is there a heat insulator on the line (CheckLine with HEAC's predicate) */+static bool HEAC_insulated(int x1, int y1, int x2, int y2) {+ bool reverseXY = abs(y2-y1) > abs(x2-x1);+ int x, y, dx, dy, sy, p;+ float e, de;+ if (reverseXY) {+ y = x1, x1 = y1, y1 = y;+ y = x2, x2 = y2, y2 = y;+ }+ if (x1 > x2) {+ y = x1, x1 = x2, x2 = y;+ y = y1, y1 = y2, y2 = y;+ }+ dx = x2 - x1;+ dy = abs(y2 - y1);+ e = 0.0f;+ de = dx ? dy/(float)dx : 0.0f;+ y = y1;+ sy = (y1<y2) ? 1 : -1;+ for (x=x1; x<=x2; x++) {+ p = reverseXY ? PMAPAT(y, x) : PMAPAT(x, y);+ if (p && IsHeatInsulator(&parts[ID(p)])) return true;+ e += de;+ if (e >= 0.5f) {+ y += sy;+ if ((y1<y2) ? (y<=y2) : (y>=y2)) {+ p = reverseXY ? PMAPAT(y, x) : PMAPAT(x, y);+ if (p && IsHeatInsulator(&parts[ID(p)])) return true;+ }+ e -= 1.0f;+ }+ }+ return false;+}+int el_HEAC_update(UPDATE_FUNC_ARGS) {+ const int rad = 4;+ int rry, rrx, r;+ float c_heat = 0.0f;+ float hc_total = 0.0f;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ rry = ry * rad;+ rrx = rx * rad;+ if (x+rrx >= 0 && x+rrx < XRES && y+rry >= 0 && y+rry < YRES && !HEAC_insulated(x, y, x+rrx, y+rry)) {+ r = PMAPAT(x+rrx, y+rry);+ if (r && !IsHeatInsulator(&parts[ID(r)])) {+ float hc = HeatCapacityOf(&parts[ID(r)]);+ c_heat += p_temp(&parts[ID(r)]) * hc;+ hc_total += hc;+ }+ r = PHOTAT(x+rrx, y+rry);+ if (r && !IsHeatInsulator(&parts[ID(r)])) {+ float hc = HeatCapacityOf(&parts[ID(r)]);+ c_heat += p_temp(&parts[ID(r)]) * hc;+ hc_total += hc;+ }+ }+ }+ }+ if (hc_total > 0.0f) {+ float pt = restrict_flt(c_heat / hc_total, MIN_TEMP, MAX_TEMP);+ p_set_temp(&parts[i], pt);+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ rry = ry * rad;+ rrx = rx * rad;+ if (x+rrx >= 0 && x+rrx < XRES && y+rry >= 0 && y+rry < YRES && !HEAC_insulated(x, y, x+rrx, y+rry)) {+ r = PMAPAT(x+rrx, y+rry);+ if (r && !IsHeatInsulator(&parts[ID(r)]))+ p_set_temp(&parts[ID(r)], pt);+ r = PHOTAT(x+rrx, y+rry);+ if (r && !IsHeatInsulator(&parts[ID(r)]))+ p_set_temp(&parts[ID(r)], pt);+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- ROCK */+void el_ROCK_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].tmp2 = rng_between(0, 10);+}++/* ---------------------------------------------------------------- VINE */+int el_VINE_update(UPDATE_FUNC_ARGS) {+ int rndstore = rng_gen();+ int rx = (rndstore % 3) - 1;+ rndstore >>= 2;+ int ry = (rndstore % 3) - 1;+ rndstore >>= 2;+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ //@ VINE -> PLNT+ if (!(rndstore % 15))+ part_change_type(i, x, y, PT_PLNT);+ else if (!r) {+ int np = create_part(-1,x+rx,y+ry,PT_VINE, -1);+ if (np<0) return 0;+ p_set_temp(&parts[np], p_temp(&parts[i]));+ part_change_type(i,x,y,PT_PLNT);+ }+ }+ if (p_temp(&parts[i]) > 350 && p_temp(&parts[i]) > parts[i].tmp2)+ parts[i].tmp2 = (int)p_temp(&parts[i]);+ return 0;+}++/* ---------------------------------------------------------------- SPNG */+int el_SPNG_update(UPDATE_FUNC_ARGS) {+ int limit = 50;+ if (parts[i].life<limit && pv[y/ACELL][x/ACELL]<=3&&pv[y/ACELL][x/ACELL]>=-3&&p_temp(&parts[i])<=374.0f) {+ int absorbChanceDenom = parts[i].life*10000/limit + 500;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ switch (TYP(r)) {+ case PT_WATR:+ case PT_DSTW:+ case PT_FRZW:+ if (parts[i].life<limit && rng_chance(500, absorbChanceDenom)) {+ parts[i].life++;+ kill_part(ID(r));+ }+ break;+ case PT_SLTW:+ if (parts[i].life<limit && rng_chance(50, absorbChanceDenom)) {+ parts[i].life++;+ if (rng_chance(3, 4))+ kill_part(ID(r));+ else //@ SPNG + SLTW -> SPNG + SALT+ part_change_type(ID(r), x+rx, y+ry, PT_SALT);+ }+ break;+ case PT_CBNW:+ if (parts[i].life<limit && rng_chance(100, absorbChanceDenom)) {+ parts[i].life++;+ //@ SPNG + CBNW -> SPNG + CO2+ part_change_type(ID(r), x+rx, y+ry, PT_CO2);+ }+ break;+ case PT_PSTE:+ if (parts[i].life<limit && rng_chance(20, absorbChanceDenom)) {+ parts[i].life++;+ //@ SPNG + PSTE -> SPNG + CLST+ create_part(ID(r), x+rx, y+ry, PT_CLST, -1);+ }+ break;+ default:+ continue;+ }+ }+ }+ }+ } else {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if ((!r)&&parts[i].life>=1) { //if nothing then create water+ //@ SPNG -> SPNG + WATR+ int np = create_part(-1,x+rx,y+ry,PT_WATR, -1);+ if (np>-1) parts[i].life--;+ }+ }+ }+ }+ }+ for (int trade = 0; trade<9; trade ++) {+ int rx = rng_between(-2, 2);+ int ry = rng_between(-2, 2);+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_SPNG&&(parts[i].life>parts[ID(r)].life)&&parts[i].life>0) { //diffusion+ int tmp = parts[i].life - parts[ID(r)].life;+ if (tmp ==1) {+ parts[ID(r)].life ++;+ parts[i].life --;+ trade = 9;+ } else if (tmp>0) {+ parts[ID(r)].life += tmp/2;+ parts[i].life -= tmp/2;+ trade = 9;+ }+ }+ }+ }+ int tmp = 0;+ if (parts[i].life>0) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (TYP(r)==PT_FIRE) {+ tmp++;+ if (parts[ID(r)].life>60)+ parts[ID(r)].life -= parts[ID(r)].life/60;+ else if (parts[ID(r)].life>2)+ parts[ID(r)].life--;+ }+ }+ }+ }+ }+ if (tmp && parts[i].life>3)+ parts[i].life -= parts[i].life/3;+ if (tmp>1)+ tmp = tmp/2;+ if (tmp || p_temp(&parts[i])>=374) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if ((!r)&&parts[i].life>=1) { //if nothing then create steam+ //@ SPNG -> SPNG + WTRV+ int np = create_part(-1,x+rx,y+ry,PT_WTRV, -1);+ if (np>-1) {+ p_set_temp(&parts[np], p_temp(&parts[i]));+ tmp--;+ parts[i].life--;+ p_set_temp(&parts[i], restrict_flt(p_temp(&parts[i]) - 20.0f, MIN_TEMP, MAX_TEMP));+ }+ }+ }+ }+ }+ }+ if (tmp>0) {+ if (parts[i].life>tmp)+ parts[i].life -= tmp;+ else+ parts[i].life = 0;+ }+ return 0;+}++/* ---------------------------------------------------------------- QRTZ */+int Element_QRTZ_update(UPDATE_FUNC_ARGS) {+ int t = parts[i].type;+ if (t == PT_QRTZ) {+ int press = (int)(pv[y/ACELL][x/ACELL] * 64);+ float diffTolerance = p_temp(&parts[i]) * 1.0666f;+ if (press - parts[i].tmp3 > diffTolerance || press - parts[i].tmp3 < -diffTolerance) {+ //@ QRTZ -> PQRT+ part_change_type(i,x,y,PT_PQRT);+ parts[i].life = 5; //timer before it can grow or diffuse again+ }+ parts[i].tmp3 = press;+ }+ if (parts[i].life>5)+ parts[i].life = 5;+ // absorb SLTW+ if (parts[i].tmp != -1) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ else if (TYP(r)==PT_SLTW && rng_chance(1, 500)) {+ kill_part(ID(r));+ parts[i].tmp++;+ }+ }+ }+ }+ }+ // grow and diffuse+ if (parts[i].tmp > 0 && (p_vx(&parts[i])*p_vx(&parts[i]) + p_vy(&parts[i])*p_vy(&parts[i]))<0.2f && parts[i].life<=0) {+ bool stopgrow = false;+ for (int trade = 0; trade < 9; trade++) {+ int rnd = rng_gen() % 0x3FF;+ int rx = (rnd%5)-2;+ int srx = (rnd%3)-1;+ rnd >>= 3;+ int ry = (rnd%5)-2;+ int sry = (rnd%3)-1;+ if (rx || ry) {+ if (!stopgrow) { //try to grow+ if (!PMAPAT(x+srx, y+sry) && parts[i].tmp!=0) {+ //@ PQRT/QRTZ -> 2xQRTZ+ int np = create_part(-1,x+srx,y+sry,PT_QRTZ, -1);+ if (np>-1) {+ p_set_temp(&parts[np], p_temp(&parts[i]));+ parts[np].tmp2 = parts[i].tmp2;+ if (rng_chance(1, 2)) {+ parts[np].tmp2 = iclamp(parts[np].tmp2 + rng_between(-1, 1), 0, 10);+ }+ parts[i].tmp--;+ if (t == PT_PQRT) {+ // If PQRT is stationary and has started growing particles of QRTZ, the PQRT is basically part of a new QRTZ crystal. So turn it back into QRTZ so that it behaves more like part of the crystal.+ part_change_type(i,x,y,PT_QRTZ);+ }+ if (rng_chance(1, 2)) {+ parts[np].tmp=-1;//dead qrtz+ } else if (!parts[i].tmp && rng_chance(1, 15)) {+ parts[i].tmp=-1;+ }+ stopgrow=true;+ }+ }+ }+ //diffusion+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ else if (TYP(r)==PT_QRTZ && (parts[i].tmp>parts[ID(r)].tmp) && parts[ID(r)].tmp>=0) {+ int tmp = parts[i].tmp - parts[ID(r)].tmp;+ if (tmp ==1) {+ parts[ID(r)].tmp++;+ parts[i].tmp--;+ break;+ }+ if (tmp>0) {+ parts[ID(r)].tmp += tmp/2;+ parts[i].tmp -= tmp/2;+ break;+ }+ }+ }+ }+ }+ return 0;+}+void el_QRTZ_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].tmp2 = rng_between(0, 10);+ parts[i].tmp3 = (int)(pv[y/ACELL][x/ACELL] * 64);+}++/* ---------------------------------------------------------------- PQRT */+void el_PQRT_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].tmp2 = rng_between(0, 10);+}++/* ---------------------------------------------------------------- VIBR */+static const int orbit_rx[8] = { -1, 0, 1, 1, 1, 0, -1, -1 };+static const int orbit_ry[8] = { -1, -1, -1, 0, 1, 1, 1, 0 };+int Element_VIBR_update(UPDATE_FUNC_ARGS) {+ int rndstore = 0;+ if (!parts[i].life) { //if not exploding+ //Heat absorption code+ if (p_temp(&parts[i]) > 274.65f) {+ parts[i].tmp++;+ p_set_temp(&parts[i], p_temp(&parts[i]) - (3));+ } else if (p_temp(&parts[i]) < 271.65f) {+ parts[i].tmp--;+ p_set_temp(&parts[i], p_temp(&parts[i]) + (3));+ }+ //Pressure absorption code+ if (pv[y/ACELL][x/ACELL] > 2.5) {+ parts[i].tmp += 7;+ pv[y/ACELL][x/ACELL]--;+ } else if (pv[y/ACELL][x/ACELL] < -2.5) {+ parts[i].tmp -= 2;+ pv[y/ACELL][x/ACELL]++;+ }+ //initiate explosion counter+ if (parts[i].tmp > 1000)+ parts[i].life = 750;+ } else { //if it is exploding+ //Release sparks before explode+ rndstore = rng_gen();+ if (parts[i].life < 300) {+ int rx = orbit_rx[rndstore & 7];+ int ry = orbit_ry[rndstore & 7];+ rndstore = rndstore >> 3;+ int r = PMAPAT(x+rx, y+ry);+ if (TYP(r) && TYP(r) != PT_BREC && (elements[TYP(r)].Properties&PROP_CONDUCTS) && !parts[ID(r)].life) {+ parts[ID(r)].life = 4;+ parts[ID(r)].ctype = TYP(r);+ part_change_type(ID(r),x+rx,y+ry,PT_SPRK);+ }+ }+ //Release all heat+ if (parts[i].life < 500) {+ int rx = rndstore%7-3;+ int ry = (rndstore>>3)%7-3;+ int r = PMAPAT(x+rx, y+ry);+ if (TYP(r) && TYP(r) != PT_VIBR && TYP(r) != PT_BVBR && (!IsHeatInsulator(&parts[ID(r)]))) {+ p_set_temp(&parts[ID(r)], restrict_flt(p_temp(&parts[ID(r)]) + parts[i].tmp * 3, MIN_TEMP, MAX_TEMP));+ parts[i].tmp = 0;+ }+ }+ //Explosion code+ if (parts[i].life == 1) {+ if (!parts[i].tmp2) {+ //@ VIBR/BVBR -> EXOT + ELEC + PHOT + BREC+ rndstore = rng_gen();+ int index = create_part(-3, x + (orbit_rx[rndstore & 7]), y + (orbit_ry[rndstore & 7]), PT_ELEC, -1);+ if (index != -1)+ p_set_temp(&parts[index], 7000);+ index = create_part(-3, x + (orbit_rx[(rndstore >> 3) & 7]), y + (orbit_ry[(rndstore >> 3) & 7]), PT_PHOT, -1);+ if (index != -1)+ p_set_temp(&parts[index], 7000);+ index = create_part(-1, x + (orbit_rx[(rndstore >> 6) & 7]), y + (orbit_ry[(rndstore >> 6) & 7]), PT_BREC, -1);+ if (index != -1)+ p_set_temp(&parts[index], 7000);+ create_part(i, x, y, PT_EXOT, -1);+ parts[i].tmp2 = (rndstore >> 9) % 1000;+ p_set_temp(&parts[i], 9000);+ pv[y/ACELL][x/ACELL] += 50;+ return 1;+ } else {+ parts[i].tmp2 = 0;+ p_set_temp(&parts[i], 273.15f);+ parts[i].tmp = 0;+ }+ }+ }+ //Neighbor check loop+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ if (parts[i].life) {+ //Makes EXOT around it get tmp to start exploding too+ if ((TYP(r)==PT_VIBR || TYP(r)==PT_BVBR)) {+ if (!parts[ID(r)].life)+ parts[ID(r)].tmp += 45;+ else if (parts[i].tmp2 && parts[i].life > 75 && rng_chance(1, 2)) {+ parts[ID(r)].tmp2 = 1;+ parts[i].tmp = 0;+ }+ } else if (TYP(r)==PT_CFLM) {+ parts[i].tmp2 = 1;+ parts[i].tmp = 0;+ }+ } else {+ //Melts into EXOT+ if (TYP(r) == PT_EXOT && rng_chance(1, 25)) {+ //@ VIBR/BVBR + EXOT -> 2xEXOT+ part_change_type(i, x, y, PT_EXOT);+ return 1;+ }+ }+ //@ VIBR + ANAR -> BVBR+ if (parts[i].type != PT_BVBR && TYP(r) == PT_ANAR) {+ part_change_type(i,x,y,PT_BVBR);+ pv[y/ACELL][x/ACELL] -= 1;+ }+ }+ }+ }+ for (int trade = 0; trade < 9; trade++) {+ if (!(trade%2))+ rndstore = rng_gen();+ int rx = rndstore%7-3;+ rndstore >>= 3;+ int ry = rndstore%7-3;+ rndstore >>= 3;+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (TYP(r) != PT_VIBR && TYP(r) != PT_BVBR)+ continue;+ if (parts[i].tmp > parts[ID(r)].tmp) {+ int transfer = parts[i].tmp - parts[ID(r)].tmp;+ parts[ID(r)].tmp += transfer/2;+ parts[i].tmp -= transfer/2;+ break;+ }+ }+ }+ parts[i].tmp = (int16_t)iclamp(parts[i].tmp, 0, 32767); /* (the original: 0 to 1 << 15) */+ return 0;+}++/* ---------------------------------------------------------------- RSSS */+int el_RSSS_update(UPDATE_FUNC_ARGS) {+ for(int rx = -1; rx < 2; rx++) {+ for(int ry = -1; ry < 2; ry++) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ // Set RSSS ctype from nearby clone+ if((TYP(r) == PT_CLNE) || (TYP(r) == PT_PCLN)) {+ if(parts[ID(r)].ctype != PT_RSSS)+ parts[i].ctype = parts[ID(r)].ctype;+ }+ // Set RSSS tmp from nearby breakable clone+ if((TYP(r) == PT_BCLN) || (TYP(r) == PT_PBCN)) {+ if(parts[ID(r)].ctype != PT_RSSS)+ parts[i].tmp = parts[ID(r)].ctype;+ }+ }+ }+ //Block air like TTAN+ bmap_blockair[y/ACELL][x/ACELL] = 1;+ bmap_blockairh[y/ACELL][x/ACELL] = 0x8;+ return 0;+}++/* ---------------------------------------------------------------- SHLD1 */+int el_SHLD1_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ else if (TYP(r)==PT_SPRK&&parts[i].life==0) {+ if (rng_chance(11, 40)) {+ part_change_type(i,x,y,PT_SHLD2);+ parts[i].life = 7;+ }+ for (int nnx = -1; nnx <= 1; nnx++) {+ for (int nny = -1; nny <= 1; nny++) {+ if (!PMAPAT(x+rx+nnx, y+ry+nny)) {+ create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1, -1);+ //parts[ID(PMAPAT(x+nx+nnx, y+ny+nny))].life=7;+ }+ }+ }+ } else if (TYP(r) == PT_SHLD3 && rng_chance(2, 5)) {+ part_change_type(i,x,y,PT_SHLD2);+ parts[i].life = 7;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- SHLD2 */+int el_SHLD2_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r) {+ if (parts[i].life>0)+ create_part(-1,x+rx,y+ry,PT_SHLD1, -1);+ continue;+ } else if (TYP(r)==PT_SPRK&&parts[i].life==0) {+ if (rng_chance(1, 8)) {+ part_change_type(i,x,y,PT_SHLD3);+ parts[i].life = 7;+ }+ for (int nnx = -1; nnx <= 1; nnx++) {+ for (int nny = -1; nny <= 1; nny++) {+ if (!PMAPAT(x+rx+nnx, y+ry+nny)) {+ int np = create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1, -1);+ if (np<0) continue;+ parts[np].life=7;+ }+ }+ }+ } else if (TYP(r) == PT_SHLD4 && rng_chance(2, 5)) {+ part_change_type(i,x,y,PT_SHLD3);+ parts[i].life = 7;+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- SHLD3 */+int el_SHLD3_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r) {+ if (rng_chance(1, 2500)) {+ int np = create_part(-1,x+rx,y+ry,PT_SHLD1, -1);+ if (np<0) continue;+ parts[np].life=7;+ part_change_type(i,x,y,PT_SHLD2);+ }+ continue;+ }+ if (TYP(r)==PT_SHLD1 && parts[i].life>3) {+ part_change_type(ID(r),x+rx,y+ry,PT_SHLD2);+ parts[ID(r)].life=7;+ } else if (TYP(r)==PT_SPRK&&parts[i].life==0) {+ if (rng_chance(3, 500)) {+ part_change_type(i,x,y,PT_SHLD4);+ parts[i].life = 7;+ }+ for (int nnx = -1; nnx <= 1; nnx++) {+ for (int nny = -1; nny <= 1; nny++) {+ if (!PMAPAT(x+rx+nnx, y+ry+nny)) {+ int np = create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1, -1);+ if (np<0) continue;+ parts[np].life=7;+ }+ }+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- SHLD4 */+int el_SHLD4_update(UPDATE_FUNC_ARGS) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r) {+ if (rng_chance(1, 5500)) {+ int np = create_part(-1,x+rx,y+ry,PT_SHLD1, -1);+ if (np<0) continue;+ parts[np].life=7;+ part_change_type(i,x,y,PT_SHLD2);+ }+ continue;+ }+ if (TYP(r)==PT_SHLD2 && parts[i].life>3) {+ part_change_type(ID(r),x+rx,y+ry,PT_SHLD3);+ parts[ID(r)].life = 7;+ } else if (TYP(r)==PT_SPRK&&parts[i].life==0) {+ for (int nnx = -1; nnx <= 1; nnx++) {+ for (int nny = -1; nny <= 1; nny++) {+ if (!PMAPAT(x+rx+nnx, y+ry+nny)) {+ int np = create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1, -1);+ if (np<0) continue;+ parts[np].life=7;+ }+ }+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- SPAWN */+bool el_SPAWN_createAllowed(ELEMENT_CREATE_ALLOWED_FUNC_ARGS) {+ return player.spawnID == -1;+}+void el_SPAWN_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) {+ if (to == PT_SPAWN) {+ if (player.spawnID == -1)+ player.spawnID = i;+ } else {+ if (player.spawnID == i)+ player.spawnID = -1;+ }+}++/* ---------------------------------------------------------------- SPAWN2 */+bool el_SPAWN2_createAllowed(ELEMENT_CREATE_ALLOWED_FUNC_ARGS) {+ return player2.spawnID == -1;+}+void el_SPAWN2_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) {+ if (to == PT_SPAWN2) {+ if (player2.spawnID == -1)+ player2.spawnID = i;+ } else {+ if (player2.spawnID == i)+ player2.spawnID = -1;+ }+}++/* ---------------------------------------------------------------- FILT */+void el_FILT_create(ELEMENT_CREATE_FUNC_ARGS) {+ parts[i].tmp = v;+}+// Returns the wavelengths in a particle after FILT interacts with it (e.g. a photon)+// cpart is the FILT particle, origWl the original wavelengths in the interacting particle+int Element_FILT_interactWavelengths(Particle* cpart, int origWl) {+ const int mask = 0x3FFFFFFF;+ int filtWl = Element_FILT_getWavelengths(cpart);+ switch (cpart->tmp) {+ case 0:+ return filtWl; //Assign Colour+ case 1:+ return origWl & filtWl; //Filter Colour+ case 2:+ return origWl | filtWl; //Add Colour+ case 3:+ return origWl & (~filtWl); //Filter Colour the other way+ case 4: {+ int shift = (int)((p_temp(cpart)-273.0f)*0.025f);+ if (shift<=0) shift = 1;+ return (int)(((unsigned)origWl << (shift & 31)) & mask); // red shift (a count over 31 taken mod 32, as on x86)+ }+ case 5: {+ int shift = (int)((p_temp(cpart)-273.0f)*0.025f);+ if (shift<=0) shift = 1;+ return (origWl >> (shift & 31)) & mask; // blue shift+ }+ case 6:+ return origWl; // No change+ case 7:+ return origWl ^ filtWl; // XOR colours+ case 8:+ return (~origWl) & mask; // Invert colours+ case 9: {+ int t1 = (origWl & 0x0000FF) + rng_between(-2, 2);+ int t2 = ((origWl & 0x00FF00)>>8) + rng_between(-2, 2);+ int t3 = ((origWl & 0xFF0000)>>16) + rng_between(-2, 2);+ return (origWl & 0xFF000000) | (t3<<16) | (t2<<8) | t1;+ }+ case 10: {+ long long int lsb = filtWl & (-(long long)filtWl);+ return (int)((origWl * lsb) & 0x3FFFFFFF); //red shift+ }+ case 11: {+ long long int lsb = filtWl & (-(long long)filtWl);+ return lsb ? (int)((origWl / lsb) & 0x3FFFFFFF) : 0; // blue shift+ }+ default:+ return filtWl;+ }+}+int Element_FILT_getWavelengths(const Particle* cpart) {+ if (cpart->ctype&0x3FFFFFFF) {+ return cpart->ctype;+ } else {+ int temp_bin = (int)((p_temp(cpart)-273.0f)*0.025f);+ if (temp_bin < 0) temp_bin = 0;+ if (temp_bin > 25) temp_bin = 25;+ return (0x1F << temp_bin);+ }+}+diff --git a/games/numpowder/src/el_special.c b/games/numpowder/src/el_special.cnew file mode 100644index 00000000..acb7a50c--- /dev/null+++ b/games/numpowder/src/el_special.c@@ -0,0 +1,534 @@+/* NumPowder: The Powder Toy's special elements (their files in elements/), ported: CLNE, BCLN, CONV, NBHL, NWHL,+ * PRTI, PRTO, LIFE, MORT, TRON. */+#include "simpriv.h"++/* ---------------------------------------------------------------- CLNE */+int el_CLNE_update(UPDATE_FUNC_ARGS) {+ if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !elements[parts[i].ctype].Enabled) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ int r = PHOTAT(x+rx, y+ry);+ if (!r)+ r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (rt!=PT_CLNE && rt!=PT_PCLN &&+ rt!=PT_BCLN && rt!=PT_STKM &&+ rt!=PT_PBCN && rt!=PT_STKM2 &&+ rt<PT_NUM) {+ parts[i].ctype = rt;+ if (rt==PT_LIFE || rt==PT_LAVA)+ parts[i].tmp = parts[ID(r)].ctype;+ }+ }+ }+ } else {+ if (parts[i].ctype==PT_LIFE) create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), PT_LIFE, parts[i].tmp);+ else if (parts[i].ctype!=PT_LIGH || rng_chance(1, 30)) {+ int np = create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), TYP(parts[i].ctype), -1);+ if (np>=0) {+ if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA)+ parts[np].ctype = parts[i].tmp;+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- BCLN */+#define ADVECTION 0.1f+int el_BCLN_update(UPDATE_FUNC_ARGS) {+ if (!parts[i].life && pv[y/ACELL][x/ACELL]>4.0f)+ parts[i].life = rng_between(80, 119);+ if (parts[i].life) {+ p_set_vx(&parts[i], p_vx(&parts[i]) + (ADVECTION*vx[y/ACELL][x/ACELL]));+ p_set_vy(&parts[i], p_vy(&parts[i]) + (ADVECTION*vy[y/ACELL][x/ACELL]));+ }+ if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !elements[parts[i].ctype].Enabled) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ int r = PHOTAT(x+rx, y+ry);+ if (!r)+ r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (rt!=PT_CLNE && rt!=PT_PCLN &&+ rt!=PT_BCLN && rt!=PT_STKM &&+ rt!=PT_PBCN && rt!=PT_STKM2 &&+ rt<PT_NUM) {+ parts[i].ctype = rt;+ if (rt==PT_LIFE || rt==PT_LAVA)+ parts[i].tmp = parts[ID(r)].ctype;+ }+ }+ }+ } else {+ if (parts[i].ctype==PT_LIFE) create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), PT_LIFE, parts[i].tmp);+ else if (parts[i].ctype!=PT_LIGH || rng_chance(1, 30)) {+ int np = create_part(-1, x + rng_between(-1, 1), y + rng_between(-1, 1), TYP(parts[i].ctype), -1);+ if (np>=0) {+ if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && elements[parts[i].tmp].HighTemperatureTransition==PT_LAVA)+ parts[np].ctype = parts[i].tmp;+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- CONV */+int el_CONV_update(UPDATE_FUNC_ARGS) {+ int ctype = TYP(parts[i].ctype);+ if (ctype<=0 || ctype>=PT_NUM || !elements[ctype].Enabled || ctype==PT_CONV) {+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ int r = PHOTAT(x+rx, y+ry);+ if (!r)+ r = PMAPAT(x+rx, y+ry);+ if (!r)+ continue;+ int rt = TYP(r);+ if (rt != PT_CLNE && rt != PT_PCLN &&+ rt != PT_BCLN && rt != PT_STKM &&+ rt != PT_PBCN && rt != PT_STKM2 &&+ rt != PT_CONV && rt < PT_NUM) {+ parts[i].ctype = rt;+ if (rt == PT_LIFE)+ parts[i].ctype |= PMAPID(parts[ID(r)].ctype);+ }+ }+ }+ } else {+ int restrictElement = IsElement(parts[i].tmp) ? parts[i].tmp : 0;+ for (int rx = -1; rx <= 1; rx++) {+ for (int ry = -1; ry <= 1; ry++) {+ if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) {+ int r = PHOTAT(x+rx, y+ry);+ if (!r || (restrictElement && ((TYP(r) == restrictElement) == (parts[i].tmp2 == 1))))+ r = PMAPAT(x+rx, y+ry);+ if (!r || (restrictElement && ((TYP(r) == restrictElement) == (parts[i].tmp2 == 1))))+ continue;+ if (TYP(r) != PT_CONV && TYP(r) != PT_DMND && TYP(r) != ctype) {+ create_part(ID(r), x+rx, y+ry, TYP(parts[i].ctype), ID(parts[i].ctype));+ }+ }+ }+ }+ }+ return 0;+}++/* ---------------------------------------------------------------- NBHL */+int el_NBHL_update(UPDATE_FUNC_ARGS) {+ if (parts[i].tmp) {+ gravmass[(y )/ACELL][(x)/ACELL] += restrict_flt(0.001f * parts[i].tmp, 0.1f, 51.2f);+ } else {+ gravmass[(y )/ACELL][(x)/ACELL] += 0.1f;+ }+ return 0;+}++/* ---------------------------------------------------------------- NWHL */+int el_NWHL_update(UPDATE_FUNC_ARGS) {+ if (parts[i].tmp) {+ gravmass[(y )/ACELL][(x)/ACELL] -= restrict_flt(0.001f * parts[i].tmp, 0.1f, 51.2f);+ } else {+ gravmass[(y )/ACELL][(x)/ACELL] -= 0.1f;+ }+ return 0;+}++/* ---------------------------------------------------------------- PRTI */+/* the orbits drawn around portals (orbitalparts.h): 4 distances in the original's 32-bit life, here in life (two)+ * and tmp2 (two), and 4 places in ctype */+static void orbitalparts_get(int i, int resblock1[], int resblock2[]) {+ uint32_t block1 = (uint16_t)parts[i].life | (uint32_t)(uint16_t)parts[i].tmp2 << 16, block2 = (uint32_t)parts[i].ctype;+ for (int k = 0; k < 4; k++) {+ resblock1[k] = (int)((block1 >> (8 * k)) & 0xFF);+ resblock2[k] = (int)((block2 >> (8 * k)) & 0xFF);+ }+}+static void orbitalparts_set(int i, int resblock1[], int resblock2[]) {+ uint32_t block1 = 0, block2 = 0;+ for (int k = 0; k < 4; k++) {+ block1 |= (uint32_t)(resblock1[k] & 0xFF) << (8 * k);+ block2 |= (uint32_t)(resblock2[k] & 0xFF) << (8 * k);+ }+ parts[i].life = (int16_t)(block1 & 0xFFFF);+ parts[i].tmp2 = (int16_t)(block1 >> 16);+ parts[i].ctype = (int32_t)block2;+}+static bool orbit_life_zero(int i) { return !parts[i].life && !parts[i].tmp2; }+static void orbit_life_set(int i, uint32_t v) {+ parts[i].life = (int16_t)(v & 0xFFFF);+ parts[i].tmp2 = (int16_t)(v >> 16);+}+/*these are the count values of where the particle gets stored, depending on where it came from+ 0 1 2+ 7 . 3+ 6 5 4+ PRTO does (count+4)%8, so that it will come out at the opposite place to where it came in+ PRTO does +/-1 to the count, so it doesn't jam as easily+*/+int el_PRTI_update(UPDATE_FUNC_ARGS) {+ int fe = 0;+ parts[i].tmp = (int)((p_temp(&parts[i])-73.15f)/100+1);+ if (parts[i].tmp >= CHANNELS)+ parts[i].tmp = CHANNELS-1;+ else if (parts[i].tmp < 0)+ parts[i].tmp = 0;+ for (int count = 0; count < 8; count++) {+ int rx = portal_rx[count];+ int ry = portal_ry[count];+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r || TYP(r) == PT_STOR)+ fe = 1;+ if (!r || (!(elements[TYP(r)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)) && TYP(r)!=PT_SPRK && TYP(r)!=PT_STOR)) {+ r = PHOTAT(x+rx, y+ry);+ if (!r)+ continue;+ }+ if (TYP(r)==PT_STKM || TYP(r)==PT_STKM2 || TYP(r)==PT_FIGH)+ continue;// Handling these is a bit more complicated, and is done in STKM_interact()+ if (TYP(r) == PT_SOAP)+ Element_SOAP_detach(ID(r));+ /* the first free place of the 80 of this channel and direction */+ if (portal_free(parts[i].tmp, count)) {+ if (TYP(r) == PT_STOR) {+ int stored = parts[ID(r)].tmp & 0xFF;+ if (IsElement(stored) && (elements[stored].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))) {+ // STOR uses same format as PIPE, so we can use this function to do the transfer+ Particle p;+ memset(&p, 0, sizeof p);+ Element_PIPE_transfer_pipe_to_part(parts+(ID(r)), &p, true);+ portal_put(parts[i].tmp, count, &p);+ }+ } else {+ portal_put(parts[i].tmp, count, &parts[ID(r)]);+ if (TYP(r) == PT_SPRK)+ part_change_type(ID(r),x+rx,y+ry,parts[ID(r)].ctype);+ else+ kill_part(ID(r));+ fe = 1;+ }+ }+ }+ }+ if (fe) {+ int orbd[4] = {0, 0, 0, 0}; //Orbital distances+ int orbl[4] = {0, 0, 0, 0}; //Orbital locations+ if (orbit_life_zero(i)) orbit_life_set(i, rng_gen());+ if (!parts[i].ctype) parts[i].ctype = (int32_t)rng_gen();+ orbitalparts_get(i, orbd, orbl);+ for (int r = 0; r < 4; r++) {+ if (orbd[r]>1) {+ orbd[r] -= 12;+ if (orbd[r]<1) {+ orbd[r] = rng_between(128, 255);+ orbl[r] = rng_between(0, 254);+ } else {+ orbl[r] += 2;+ orbl[r] = orbl[r]%255;+ }+ } else {+ orbd[r] = rng_between(128, 255);+ orbl[r] = rng_between(0, 254);+ }+ }+ orbitalparts_set(i, orbd, orbl);+ } else {+ orbit_life_set(i, 0);+ parts[i].ctype = 0;+ }+ return 0;+}++/* ---------------------------------------------------------------- PRTO */+/*these are the count values of where the particle gets stored, depending on where it came from+ 0 1 2+ 7 . 3+ 6 5 4+ PRTO does (count+4)%8, so that it will come out at the opposite place to where it came in+ PRTO does +/-1 to the count, so it doesn't jam as easily+*/+int el_PRTO_update(UPDATE_FUNC_ARGS) {+ int fe = 0;+ parts[i].tmp = (int)((p_temp(&parts[i])-73.15f)/100+1);+ if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1;+ else if (parts[i].tmp<0) parts[i].tmp = 0;+ for (int count =0; count<8; count++) {+ int rx = portal_rx[count];+ int ry = portal_ry[count];+ if (rx || ry) {+ int r = PMAPAT(x+rx, y+ry);+ if (!r) {+ fe = 1;+ if (!portal_any(parts[i].tmp)) {+ for (int nnx = 0; nnx < 80; nnx++) rng_between(-1, 1); /* (nothing to find, but the same random numbers) */+ continue;+ }+ for (int nnx =0 ; nnx<80; nnx++) {+ int randomness = (count + rng_between(-1, 1) + 4) % 8;//add -1,0,or 1 to count+ int slot = portal_find(parts[i].tmp, randomness, nnx);+ if (slot < 0)+ continue;+ Particle *pp = &portalp[slot].p;+ if (pp->type==PT_SPRK) { // TODO: make it look better, spark creation+ create_part(-1,x+1,y,PT_SPRK, -1);+ create_part(-1,x+1,y+1,PT_SPRK, -1);+ create_part(-1,x+1,y-1,PT_SPRK, -1);+ create_part(-1,x,y-1,PT_SPRK, -1);+ create_part(-1,x,y+1,PT_SPRK, -1);+ create_part(-1,x-1,y+1,PT_SPRK, -1);+ create_part(-1,x-1,y,PT_SPRK, -1);+ create_part(-1,x-1,y-1,PT_SPRK, -1);+ portal_take(slot);+ break;+ } else if (pp->type) {+ if (pp->type==PT_STKM)+ player.spwn = 0;+ if (pp->type==PT_STKM2)+ player2.spwn = 0;+ if (pp->type==PT_FIGH) {+ fighcount--;+ if ((unsigned char)pp->tmp < MAX_FIGHTERS) fighters[(unsigned char)pp->tmp].spwn = 0;+ }+ int np = create_part(-1, x+rx, y+ry, pp->type, -1);+ if (np<0) {+ if (pp->type==PT_STKM)+ player.spwn = 1;+ if (pp->type==PT_STKM2)+ player2.spwn = 1;+ if (pp->type==PT_FIGH) {+ fighcount++;+ if ((unsigned char)pp->tmp < MAX_FIGHTERS) fighters[(unsigned char)pp->tmp].spwn = 1;+ }+ continue;+ }+ if (parts[np].type==PT_FIGH) {+ // Release the fighters[] element allocated by create_part, the one reserved when the fighter went into the portal will be used+ if ((unsigned char)parts[np].tmp < MAX_FIGHTERS) fighters[(unsigned char)parts[np].tmp].spwn = 0;+ if ((unsigned char)pp->tmp < MAX_FIGHTERS) fighters[(unsigned char)pp->tmp].spwn = 1;+ }+ if (pp->vx == 0 && pp->vy == 0) {+ // particles that have passed from PIPE into PRTI have lost their velocity, so use the velocity of the newly created particle if the particle in the portal has no velocity+ int16_t tmp_vx = parts[np].vx, tmp_vy = parts[np].vy;+ parts[np] = *pp;+ parts[np].vx = tmp_vx;+ parts[np].vy = tmp_vy;+ } else+ parts[np] = *pp;+ p_set_x(&parts[np], (float)(x+rx));+ p_set_y(&parts[np], (float)(y+ry));+ portal_take(slot);+ break;+ }+ }+ }+ }+ }+ if (fe) {+ int orbd[4] = {0, 0, 0, 0}; //Orbital distances+ int orbl[4] = {0, 0, 0, 0}; //Orbital locations+ if (orbit_life_zero(i)) orbit_life_set(i, rng_gen());+ if (!parts[i].ctype) parts[i].ctype = (int32_t)rng_gen();+ orbitalparts_get(i, orbd, orbl);+ for (int r = 0; r < 4; r++) {+ if (orbd[r]<254) {+ orbd[r] += 16;+ if (orbd[r]>254) {+ orbd[r] = 0;+ orbl[r] = rng_between(0, 254);+ } else {+ orbl[r] += 1;+ orbl[r] = orbl[r]%255;+ }+ } else {+ orbd[r] = 0;+ orbl[r] = rng_between(0, 254);+ }+ }+ orbitalparts_set(i, orbd, orbl);+ } else {+ orbit_life_set(i, 0);+ parts[i].ctype = 0;+ }+ return 0;+}++/* ---------------------------------------------------------------- LIFE */+void el_LIFE_create(ELEMENT_CREATE_FUNC_ARGS) {+ if (v == -1)+ v = 0;+ // * 0x200000: No need to look for colours, they'll be set later anyway.+ bool skipLookup = v & 0x200000;+ v &= 0x1FFFFF;+ parts[i].ctype = v;+ if (v < NGOL) {+ /* (the first colour, the original's dcolour, isn't kept: it's builtinGol[ctype].colour; the second, the+ * original's 24-bit tmp, is kept in tmp as RGB565) */+ uint32_t c2 = builtinGol[v].colour2;+ parts[i].tmp = (int16_t)(((c2 >> 8) & 0xF800) | ((c2 >> 5) & 0x07E0) | ((c2 >> 3) & 0x001F));+ v = builtinGol[v].ruleset;+ } else if (!skipLookup) {+ /* (custom types' colours aren't kept) */+ }+ parts[i].tmp2 = ((v >> 17) & 0xF) + 1;+}++/* ---------------------------------------------------------------- MORT */+int el_MORT_update(UPDATE_FUNC_ARGS) {+ create_part(-1, x, y-1, PT_SMKE, -1);+ return 0;+}++/* ---------------------------------------------------------------- TRON */+/* TRON element is meant to resemble a tron bike (or worm) moving around and trying to avoid obstacles itself.+ * It has four direction each turn to choose from, 0 (left) 1 (up) 2 (right) 3 (down).+ * Each turn has a small random chance to randomly turn one way (so it doesn't do the exact same thing in a large room)+ * If the place it wants to move isn't a barrier, it will try and 'see' in front of itself to determine its safety.+ * For now the tron can only see its own body length in pixels ahead of itself (and around corners)+ * - - - - - - - - - -+ * - - - - + - - - - -+ * - - - + + + - - - -+ * - - +<--+-->+ - - -+ * - +<----+---->+ - -+ * - - - - H - - - - -+ * Where H is the head with tail length 4, it checks the + area to see if it can hit any of the edges, then it is called safe, or picks the biggest area if none safe.+ * .tmp bit values: 1st head, 2nd no tail growth, 3rd wait flag, 4th Nodie, 5th Dying, 6th & 7th is direction, 8th - 16th hue, 17th Norandom+ * .tmp2 is tail length (gets longer every few hundred frames)+ * .life is the timer that kills the end of the tail (the head uses life for how often it grows longer)+ * .ctype Contains the colour, lost on save, regenerated using hue tmp (bits 7 - 16)+ */+#define TRON_HEAD 0x00000001+#define TRON_NOGROW 0x00000002+#define TRON_WAIT 0x00000004 //it was just created, so WAIT a frame+#define TRON_NODIE 0x00000008+#define TRON_DEATH 0x00000010 //Crashed, now dying+/* the original's TRON_NORANDOM is tmp's bit 16: here ctype's bit 30 (ctype is copied to new heads, as the flag) */+#define TRON_NORANDOM_CT 0x40000000+static const int tron_rx[4] = {-1, 0, 1, 0};+static const int tron_ry[4] = { 0,-1, 0, 1};+static int TRON_trymovetron(int x, int y, int dir, int i, int len);+static bool TRON_canmovetron(int r, int len);+static int TRON_new_tronhead(int x, int y, int i, int direction);+int el_TRON_update(UPDATE_FUNC_ARGS) {+ if (parts[i].tmp&TRON_WAIT) {+ parts[i].tmp &= ~TRON_WAIT;+ return 0;+ }+ if (parts[i].tmp&TRON_HEAD) {+ int firstdircheck = 0, seconddir = 0, seconddircheck = 0, lastdir = 0, lastdircheck = 0;+ int direction = (parts[i].tmp>>5 & 0x3);+ int originaldir = direction;+ //random turn+ int random = rng_between(0, 339);+ if ((random==1 || random==3) && !(parts[i].ctype & TRON_NORANDOM_CT)) {+ //randomly turn left(3) or right(1)+ direction = (direction + random)%4;+ }+ //check in front+ //do sight check+ firstdircheck = TRON_trymovetron(x,y,direction,i,parts[i].tmp2);+ if (firstdircheck < parts[i].tmp2) {+ if (parts[i].ctype & TRON_NORANDOM_CT) {+ seconddir = (direction + 1)%4;+ lastdir = (direction + 3)%4;+ } else if (originaldir != direction) { //if we just tried a random turn, don't pick random again+ seconddir = originaldir;+ lastdir = (direction + 2)%4;+ } else {+ seconddir = (direction + (rng_between(0, 1)*2)+1)% 4;+ lastdir = (seconddir + 2)%4;+ }+ seconddircheck = TRON_trymovetron(x,y,seconddir,i,parts[i].tmp2);+ lastdircheck = TRON_trymovetron(x,y,lastdir,i,parts[i].tmp2);+ }+ //find the best move+ if (seconddircheck > firstdircheck)+ direction = seconddir;+ if (lastdircheck > seconddircheck && lastdircheck > firstdircheck)+ direction = lastdir;+ //now try making new head, even if it fails+ if (TRON_new_tronhead(x + tron_rx[direction],y + tron_ry[direction],i,direction) == -1) {+ //ohgod crash+ parts[i].tmp |= TRON_DEATH;+ //trigger tail death for TRON_NODIE, or is that mode even needed? just set a high tail length(but it still won't start dying when it crashes)+ }+ //set own life and clear .tmp (it dies if it can't move anyway)+ parts[i].life = parts[i].tmp2;+ parts[i].tmp = (int16_t)(parts[i].tmp & (parts[i].tmp&0xF818));+ } else { // fade tail deco, or prevent tail from dying+ if (parts[i].tmp&TRON_NODIE)+ parts[i].life++;+ }+ return 0;+}+void el_TRON_create(ELEMENT_CREATE_FUNC_ARGS) {+ int randhue = rng_between(0, 359);+ int randomdir = rng_between(0, 3);+ // Set as a head and a direction+ parts[i].tmp = (int16_t)(1 | (randomdir << 5) | (randhue << 7));+ // Tail+ parts[i].tmp2 = 4;+ parts[i].life = 5;+}+static int TRON_new_tronhead(int x, int y, int i, int direction) {+ int np = create_part(-1, x , y ,PT_TRON, -1);+ if (np==-1)+ return -1;+ if (parts[i].life >= 100) { // increase tail length+ if (!(parts[i].tmp&TRON_NOGROW))+ parts[i].tmp2++;+ parts[i].life = 5;+ }+ //give new head our properties+ parts[np].tmp = (int16_t)(1 | direction<<5 | (parts[i].tmp&(TRON_NOGROW|TRON_NODIE)) | (parts[i].tmp&0xF800));+ if (np > i)+ parts[np].tmp |= TRON_WAIT;+ parts[np].ctype = parts[i].ctype;+ parts[np].tmp2 = parts[i].tmp2;+ parts[np].life = parts[i].life + 2;+ return 1;+}+static int TRON_trymovetron(int x, int y, int dir, int i, int len) {+ int k,j,r,rx,ry,tx,ty,count;+ count = 0;+ rx = x;+ ry = y;+ for (k = 1; k <= len; k ++) {+ rx += tron_rx[dir];+ ry += tron_ry[dir];+ if (ry >= BORDER && rx >= BORDER && ry < YRES-BORDER && rx < XRES-BORDER && (r = PMAPAT(rx, ry), TRON_canmovetron(r, k-1)) && !bmap[(ry)/WCELL][(rx)/WCELL]) {+ count++;+ for (tx = rx - tron_ry[dir] , ty = ry - tron_rx[dir], j=1; abs(tx-rx) < (len-k) && abs(ty-ry) < (len-k); tx-=tron_ry[dir],ty-=tron_rx[dir],j++) {+ if (ty >= BORDER && tx >= BORDER && ty < YRES-BORDER && tx < XRES-BORDER && (r = PMAPAT(tx, ty), TRON_canmovetron(r, j+k-1)) && !bmap[(ty)/WCELL][(tx)/WCELL]) {+ if (j == (len-k))//there is a safe path, so we can break out+ return len+1;+ count++;+ } else //we hit a block so no need to check farther here+ break;+ }+ for (tx = rx + tron_ry[dir] , ty = ry + tron_rx[dir], j=1; abs(tx-rx) < (len-k) && abs(ty-ry) < (len-k); tx+=tron_ry[dir],ty+=tron_rx[dir],j++) {+ if (ty >= BORDER && tx >= BORDER && ty < YRES-BORDER && tx < XRES-BORDER && (r = PMAPAT(tx, ty), TRON_canmovetron(r, j+k-1)) && !bmap[(ty)/WCELL][(tx)/WCELL]) {+ if (j == (len-k))+ return len+1;+ count++;+ } else+ break;+ }+ } else //a block infront, no need to continue+ break;+ }+ return count;+}+static bool TRON_canmovetron(int r, int len) {+ if (!r || (TYP(r) == PT_SWCH && parts[ID(r)].life >= 10) || (TYP(r) == PT_INVIS && parts[ID(r)].tmp2 == 1))+ return true;+ if ((((elements[TYP(r)].Properties & PROP_LIFE_KILL_DEC) && parts[ID(r)].life > 0)|| ((elements[TYP(r)].Properties & PROP_LIFE_KILL) && (elements[TYP(r)].Properties & PROP_LIFE_DEC))) && parts[ID(r)].life < len)+ return true;+ return false;+}+diff --git a/games/numpowder/src/el_stkm.c b/games/numpowder/src/el_stkm.cnew file mode 100644index 00000000..3860ced1--- /dev/null+++ b/games/numpowder/src/el_stkm.c@@ -0,0 +1,689 @@+/* NumPowder: The Powder Toy's stickmen (elements/STKM.cpp, STKM2.cpp, FIGH.cpp), ported. The original keeps 100+ * fighters; MAX_FIGHTERS here. */+#include "simpriv.h"++/* ---------------------------------------------------------------- STKM */+static void STKM_die(playerst *playerp, int i);+static void FIGH_Free(unsigned char i);+static inline bool InWallBounds(int x, int y) { return x >= 0 && y >= 0 && x < XWCELLS && y < YWCELLS; }+int el_STKM_update(UPDATE_FUNC_ARGS) {+ Element_STKM_run_stickman(&player, UPDATE_FUNC_SUBCALL_ARGS);+ return 0;+}+void el_STKM_create(ELEMENT_CREATE_FUNC_ARGS) {+ int spawnID = create_part(-3, x, y, PT_SPAWN, -1);+ if (spawnID >= 0)+ player.spawnID = spawnID;+}+bool el_STKM_createAllowed(ELEMENT_CREATE_ALLOWED_FUNC_ARGS) {+ return elementCount[PT_STKM] <= 0 && !player.spwn;+}+void el_STKM_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) {+ if (to == PT_STKM) {+ Element_STKM_init_legs(&player, i);+ player.spwn = 1;+ } else+ player.spwn = 0;+}+static void STKM_die(playerst *playerp, int i) {+ if (playerp->fan) {+ int x = (int)(p_x(&parts[i]) + 0.5f) / ACELL;+ int y = (int)(p_y(&parts[i]) + 0.5f) / ACELL;+ pv[y][x] += 64;+ } else {+ int x = (int)(p_x(&parts[i]) + 0.5f);+ int y = (int)(p_y(&parts[i]) + 0.5f);+ for (int r = -2; r <= 1; r++) {+ create_part(-1, x + r, y - 2, playerp->elem, -1);+ create_part(-1, x + r + 1, y + 2, playerp->elem, -1);+ create_part(-1, x - 2, y + r + 1, playerp->elem, -1);+ create_part(-1, x + 2, y + r, playerp->elem, -1);+ }+ }+ kill_part(i); //Kill him+}+int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS) {+ int r, rx, ry;+ int t = parts[i].type;+ float pp, d;+ float dt = 0.9f;///(FPSB*FPSB); //Delta time in square+ float gvx, gvy;+ float gx, gy, dl, dr;+ float rocketBootsHeadEffect = 0.35f;+ float rocketBootsFeetEffect = 0.15f;+ float rocketBootsHeadEffectV = 0.3f;// stronger acceleration vertically, to counteract gravity+ float rocketBootsFeetEffectV = 0.45f;+ if (!playerp->fan && parts[i].ctype && IsElementOrNone(parts[i].ctype))+ Element_STKM_set_element(playerp, parts[i].ctype);+ playerp->frames++;+ //Temperature handling+ if (p_temp(&parts[i])<243)+ parts[i].life -= 1;+ if ((p_temp(&parts[i])<309.6f) && (p_temp(&parts[i])>=243))+ p_set_temp(&parts[i], p_temp(&parts[i]) + (1));+ //Death+ if (parts[i].life<1 || (pv[y/ACELL][x/ACELL]>=4.5f && !playerp->fan) ) { //If his HP is less than 0 or there is very big wind...+ STKM_die(playerp, i);+ return 1;+ }+ //Follow gravity+ gvx = gvy = 0.0f;+ switch (gravityMode) {+ default:+ case GRAV_VERTICAL:+ gvy = 1;+ break;+ case GRAV_OFF:+ gvy = gvx = 0.0f;+ break;+ case GRAV_RADIAL: {+ float gravd;+ gravd = 0.01f - hypotf((p_x(&parts[i]) - XCNTR), (p_y(&parts[i]) - YCNTR));+ gvx = ((float)(p_x(&parts[i]) - XCNTR) / gravd);+ gvy = ((float)(p_y(&parts[i]) - YCNTR) / gravd);+ }+ break;+ case GRAV_CUSTOM:+ gvx = customGravityX;+ gvy = customGravityY;+ break;+ }+ gvx += gravx[((int)(p_y(&parts[i])) )/ACELL][((int)(p_x(&parts[i])))/ACELL];+ gvy += gravy[((int)(p_y(&parts[i])) )/ACELL][((int)(p_x(&parts[i])))/ACELL];+ float mvx = gvx;+ float mvy = gvy;+ bool rbLowGrav = false;+ float tmp = fabsf(mvx) > fabsf(mvy)?fabsf(mvx):fabsf(mvy);+ if (tmp < 0.001f) {+ rbLowGrav = true;+ mvx = -p_vx(&parts[i]);+ mvy = -p_vy(&parts[i]);+ tmp = fabsf(mvx) > fabsf(mvy)?fabsf(mvx):fabsf(mvy);+ }+ if (tmp < 0.001f) {+ mvx = 0;+ mvy = 1.0f;+ tmp = 1.0f;+ } else+ tmp = 1.0f/sqrtf(mvx*mvx+mvy*mvy);+ mvx *= tmp;// scale to a unit vector+ mvy *= tmp;+ if (rbLowGrav) {+ rocketBootsHeadEffectV = rocketBootsHeadEffect;+ rocketBootsFeetEffectV = rocketBootsFeetEffect;+ }+ p_set_vx(&parts[i], p_vx(&parts[i]) - (gvx*dt)); //Head up!+ p_set_vy(&parts[i], p_vy(&parts[i]) - (gvy*dt));+ //Verlet integration+ pp = 2*playerp->legs[0]-playerp->legs[2]+playerp->accs[0]*dt*dt;+ playerp->legs[2] = playerp->legs[0];+ playerp->legs[0] = pp;+ pp = 2*playerp->legs[1]-playerp->legs[3]+playerp->accs[1]*dt*dt;+ playerp->legs[3] = playerp->legs[1];+ playerp->legs[1] = pp;+ pp = 2*playerp->legs[4]-playerp->legs[6]+(playerp->accs[2]+gvx)*dt*dt;+ playerp->legs[6] = playerp->legs[4];+ playerp->legs[4] = pp;+ pp = 2*playerp->legs[5]-playerp->legs[7]+(playerp->accs[3]+gvy)*dt*dt;+ playerp->legs[7] = playerp->legs[5];+ playerp->legs[5] = pp;+ pp = 2*playerp->legs[8]-playerp->legs[10]+playerp->accs[4]*dt*dt;+ playerp->legs[10] = playerp->legs[8];+ playerp->legs[8] = pp;+ pp = 2*playerp->legs[9]-playerp->legs[11]+playerp->accs[5]*dt*dt;+ playerp->legs[11] = playerp->legs[9];+ playerp->legs[9] = pp;+ pp = 2*playerp->legs[12]-playerp->legs[14]+(playerp->accs[6]+gvx)*dt*dt;+ playerp->legs[14] = playerp->legs[12];+ playerp->legs[12] = pp;+ pp = 2*playerp->legs[13]-playerp->legs[15]+(playerp->accs[7]+gvy)*dt*dt;+ playerp->legs[15] = playerp->legs[13];+ playerp->legs[13] = pp;+ //Setting acceleration to 0+ playerp->accs[0] = 0;+ playerp->accs[1] = 0;+ playerp->accs[2] = 0;+ playerp->accs[3] = 0;+ playerp->accs[4] = 0;+ playerp->accs[5] = 0;+ playerp->accs[6] = 0;+ playerp->accs[7] = 0;+ gx = (playerp->legs[4] + playerp->legs[12])/2 - gvy;+ gy = (playerp->legs[5] + playerp->legs[13])/2 + gvx;+ dl = powf(gx - playerp->legs[4], 2) + powf(gy - playerp->legs[5], 2);+ dr = powf(gx - playerp->legs[12], 2) + powf(gy - playerp->legs[13], 2);+ //Go left+ if (((int)(playerp->comm)&0x01) == 0x01) {+ bool moved = false;+ if (dl>dr) {+ if (InBounds((int)(playerp->legs[4]), (int)(playerp->legs[5])) && !eval_move(t, (int)(playerp->legs[4]), (int)(playerp->legs[5]), NULL)) {+ playerp->accs[2] = -3*mvy-3*mvx;+ playerp->accs[3] = 3*mvx-3*mvy;+ playerp->accs[0] = -mvy;+ playerp->accs[1] = mvx;+ moved = true;+ }+ } else {+ if (InBounds((int)(playerp->legs[12]), (int)(playerp->legs[13])) && !eval_move(t, (int)(playerp->legs[12]), (int)(playerp->legs[13]), NULL)) {+ playerp->accs[6] = -3*mvy-3*mvx;+ playerp->accs[7] = 3*mvx-3*mvy;+ playerp->accs[0] = -mvy;+ playerp->accs[1] = mvx;+ moved = true;+ }+ }+ if (!moved && playerp->rocketBoots) {+ p_set_vx(&parts[i], p_vx(&parts[i]) - (rocketBootsHeadEffect*mvy));+ p_set_vy(&parts[i], p_vy(&parts[i]) + (rocketBootsHeadEffect*mvx));+ playerp->accs[2] -= rocketBootsFeetEffect*mvy;+ playerp->accs[6] -= rocketBootsFeetEffect*mvy;+ playerp->accs[3] += rocketBootsFeetEffect*mvx;+ playerp->accs[7] += rocketBootsFeetEffect*mvx;+ for (int leg=0; leg<2; leg++) {+ if (leg==1 && (((int)(playerp->comm)&0x02) == 0x02))+ continue;+ int footX = (int)(playerp->legs[leg*8+4]), footY = (int)(playerp->legs[leg*8+5]);+ int np = create_part(-1, footX, footY, PT_PLSM, -1);+ if (np>=0) {+ p_set_vx(&parts[np], p_vx(&parts[i])+mvy*25);+ p_set_vy(&parts[np], p_vy(&parts[i])-mvx*25);+ parts[np].life += 30;+ }+ }+ }+ }+ //Go right+ if (((int)(playerp->comm)&0x02) == 0x02) {+ bool moved = false;+ if (dl<dr) {+ if (InBounds((int)(playerp->legs[4]), (int)(playerp->legs[5])) && !eval_move(t, (int)(playerp->legs[4]), (int)(playerp->legs[5]), NULL)) {+ playerp->accs[2] = 3*mvy-3*mvx;+ playerp->accs[3] = -3*mvx-3*mvy;+ playerp->accs[0] = mvy;+ playerp->accs[1] = -mvx;+ moved = true;+ }+ } else {+ if (InBounds((int)(playerp->legs[12]), (int)(playerp->legs[13])) && !eval_move(t, (int)(playerp->legs[12]), (int)(playerp->legs[13]), NULL)) {+ playerp->accs[6] = 3*mvy-3*mvx;+ playerp->accs[7] = -3*mvx-3*mvy;+ playerp->accs[0] = mvy;+ playerp->accs[1] = -mvx;+ moved = true;+ }+ }+ if (!moved && playerp->rocketBoots) {+ p_set_vx(&parts[i], p_vx(&parts[i]) + (rocketBootsHeadEffect*mvy));+ p_set_vy(&parts[i], p_vy(&parts[i]) - (rocketBootsHeadEffect*mvx));+ playerp->accs[2] += rocketBootsFeetEffect*mvy;+ playerp->accs[6] += rocketBootsFeetEffect*mvy;+ playerp->accs[3] -= rocketBootsFeetEffect*mvx;+ playerp->accs[7] -= rocketBootsFeetEffect*mvx;+ for (int leg=0; leg<2; leg++) {+ if (leg==0 && (((int)(playerp->comm)&0x01) == 0x01))+ continue;+ int footX = (int)(playerp->legs[leg*8+4]), footY = (int)(playerp->legs[leg*8+5]);+ int np = create_part(-1, footX, footY, PT_PLSM, -1);+ if (np>=0) {+ p_set_vx(&parts[np], p_vx(&parts[i])-mvy*25);+ p_set_vy(&parts[np], p_vy(&parts[i])+mvx*25);+ parts[np].life += 30;+ }+ }+ }+ }+ if (playerp->rocketBoots && ((int)(playerp->comm)&0x03) == 0x03) {+ // Pressing left and right simultaneously with rocket boots on slows the stickman down+ // Particularly useful in zero gravity+ p_set_vx(&parts[i], p_vx(&parts[i]) * (0.5f));+ p_set_vy(&parts[i], p_vy(&parts[i]) * (0.5f));+ playerp->accs[2] = playerp->accs[6] = 0;+ playerp->accs[3] = playerp->accs[7] = 0;+ }+ //Jump+ if (((int)(playerp->comm)&0x04) == 0x04) {+ if (playerp->rocketBoots) {+ p_set_vx(&parts[i], p_vx(&parts[i]) - (rocketBootsHeadEffectV*mvx));+ p_set_vy(&parts[i], p_vy(&parts[i]) - (rocketBootsHeadEffectV*mvy));+ playerp->accs[2] -= rocketBootsFeetEffectV*mvx;+ playerp->accs[6] -= rocketBootsFeetEffectV*mvx;+ playerp->accs[3] -= rocketBootsFeetEffectV*mvy;+ playerp->accs[7] -= rocketBootsFeetEffectV*mvy;+ for (int leg=0; leg<2; leg++) {+ int footX = (int)(playerp->legs[leg*8+4]), footY = (int)(playerp->legs[leg*8+5]);+ int np = create_part(-1, footX, footY+1, PT_PLSM, -1);+ if (np>=0) {+ p_set_vx(&parts[np], p_vx(&parts[i])+mvx*30);+ p_set_vy(&parts[np], p_vy(&parts[i])+mvy*30);+ parts[np].life += 10;+ }+ }+ } else if ((InBounds((int)(playerp->legs[4]), (int)(playerp->legs[5])) && !eval_move(t, (int)(playerp->legs[4]), (int)(playerp->legs[5]), NULL)) ||+ (InBounds((int)(playerp->legs[12]), (int)(playerp->legs[13])) && !eval_move(t, (int)(playerp->legs[12]), (int)(playerp->legs[13]), NULL))) {+ p_set_vx(&parts[i], p_vx(&parts[i]) - (4*mvx));+ p_set_vy(&parts[i], p_vy(&parts[i]) - (4*mvy));+ playerp->accs[2] -= mvx;+ playerp->accs[6] -= mvx;+ playerp->accs[3] -= mvy;+ playerp->accs[7] -= mvy;+ }+ }+ //Charge detector wall if foot inside+ if (InWallBounds((int)(playerp->legs[4]+0.5f)/WCELL, (int)(playerp->legs[5]+0.5f)/WCELL) &&+ bmap[(int)(playerp->legs[5]+0.5f)/WCELL][(int)(playerp->legs[4]+0.5f)/WCELL]==WL_DETECT)+ set_emap((int)playerp->legs[4]/WCELL, (int)playerp->legs[5]/WCELL);+ if (InWallBounds((int)(playerp->legs[12]+0.5f)/WCELL, (int)(playerp->legs[13]+0.5f)/WCELL) &&+ bmap[(int)(playerp->legs[13]+0.5f)/WCELL][(int)(playerp->legs[12]+0.5f)/WCELL]==WL_DETECT)+ set_emap((int)(playerp->legs[12]+0.5f)/WCELL, (int)(playerp->legs[13]+0.5f)/WCELL);+ //Searching for particles near head+ for (rx=-2; rx<3; rx++)+ for (ry=-2; ry<3; ry++)+ if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry)) {+ r = PMAPAT(x+rx, y+ry);+ if (!r)+ r = PHOTAT(x+rx, y+ry);+ if (!r && !bmap[(y+ry)/WCELL][(x+rx)/WCELL])+ continue;+ Element_STKM_set_element(playerp, TYP(r));+ if (TYP(r) == PT_PLNT && parts[i].life<100) { //Plant gives him 5 HP+ if (parts[i].life<=95)+ parts[i].life += 5;+ else+ parts[i].life = 100;+ kill_part(ID(r));+ }+ if (TYP(r) == PT_NEUT) {+ if (parts[i].life<=100) parts[i].life -= (102-parts[i].life)/2;+ else parts[i].life = (int)(parts[i].life * 0.9f);+ kill_part(ID(r));+ }+ if (bmap[(ry+y)/WCELL][(rx+x)/WCELL]==WL_FAN)+ playerp->fan = true;+ else if (bmap[(ry+y)/WCELL][(rx+x)/WCELL]==WL_EHOLE)+ playerp->rocketBoots = false;+ else if (bmap[(ry+y)/WCELL][(rx+x)/WCELL]==WL_GRAV /* && parts[i].type!=PT_FIGH */)+ playerp->rocketBoots = true;+ if (TYP(r)==PT_PRTI)+ Element_STKM_interact(playerp, i, rx, ry);+ if (!parts[i].type)//STKM_interact may kill STKM+ return 1;+ }+ //Head position+ rx = x + 3*((((int)playerp->pcomm)&0x02) == 0x02) - 3*((((int)playerp->pcomm)&0x01) == 0x01);+ ry = y - 3*(playerp->pcomm == 0);+ //Spawn+ if (((int)(playerp->comm)&0x08) == 0x08) {+ ry -= 2 * rng_between(0, 1) + 1;+ /* (the head near the edge: the place can be off the grid, where there's nothing, and nothing is made) */+ r = InBounds(rx, ry) ? PMAPAT(rx, ry) : 0;+ if (elements[TYP(r)].Properties&TYPE_SOLID) {+ create_part(-1, rx, ry, PT_SPRK, -1);+ playerp->frames = 0;+ } else {+ int np = -1;+ if (playerp->fan) {+ for(int j = -4; j < 5; j++)+ for (int k = -4; k < 5; k++) {+ int airx = rx + 3*((((int)playerp->pcomm)&0x02) == 0x02) - 3*((((int)playerp->pcomm)&0x01) == 0x01)+j;+ int airy = ry+k;+ if (airx < 0 || airy < 0 || airx >= XRES || airy >= YRES)+ continue; /* (the original writes outside the air there) */+ pv[airy/ACELL][airx/ACELL] += 0.03f;+ if (airy + ACELL < YRES)+ pv[airy/ACELL+1][airx/ACELL] += 0.03f;+ if (airx + ACELL < XRES) {+ pv[airy/ACELL][airx/ACELL+1] += 0.03f;+ if (airy + ACELL < YRES)+ pv[airy/ACELL+1][airx/ACELL+1] += 0.03f;+ }+ }+ } else if (playerp->elem==PT_LIGH && playerp->frames<30)//limit lightning creation rate+ np = -1;+ else+ np = create_part(-1, rx, ry, playerp->elem, -1);+ if ( (np < NPART) && np>=0) {+ if (playerp->elem == PT_PHOT) {+ int random = abs((rng_between(-1, 1)))*3;+ if (random==0) {+ kill_part(np);+ } else {+ p_set_vy(&parts[np], 0);+ if (((int)playerp->pcomm)&(0x01|0x02))+ p_set_vx(&parts[np], (float)((((((int)playerp->pcomm)&0x02) == 0x02) - (((int)(playerp->pcomm)&0x01) == 0x01))*random));+ else+ p_set_vx(&parts[np], (float)(random));+ }+ } else if (playerp->elem == PT_LIGH) {+ int angle;+ int power = 100;+ if (gvx!=0 || gvy!=0)+ angle = (int)(atan2f(mvx, mvy)*180.0f/NP_PI);+ else+ angle = rng_between(0, 359);+ if (((int)playerp->pcomm)&0x01)+ angle += 180;+ if (angle>360)+ angle-=360;+ if (angle<0)+ angle+=360;+ parts[np].tmp = angle;+ parts[np].life = rng_between(0, 1+power/15) + power/7;+ p_set_temp(&parts[np], parts[np].life*power/2.5);+ parts[np].tmp2 = 1;+ } else if (!playerp->fan) {+ p_set_vx(&parts[np], p_vx(&parts[np]) - (-mvy*(5*((((int)playerp->pcomm)&0x02) == 0x02) - 5*(((int)(playerp->pcomm)&0x01) == 0x01))));+ p_set_vy(&parts[np], p_vy(&parts[np]) - (mvx*(5*((((int)playerp->pcomm)&0x02) == 0x02) - 5*(((int)(playerp->pcomm)&0x01) == 0x01))));+ p_set_vx(&parts[i], p_vx(&parts[i]) - ((elements[(int)playerp->elem].Weight*p_vx(&parts[np]))/1000));+ }+ playerp->frames = 0;+ }+ }+ }+ //Simulation of joints+ d = 25/(powf((playerp->legs[0]-playerp->legs[4]), 2) + powf((playerp->legs[1]-playerp->legs[5]), 2)+25) - 0.5; //Fast distance+ playerp->legs[4] -= (playerp->legs[0]-playerp->legs[4])*d;+ playerp->legs[5] -= (playerp->legs[1]-playerp->legs[5])*d;+ playerp->legs[0] += (playerp->legs[0]-playerp->legs[4])*d;+ playerp->legs[1] += (playerp->legs[1]-playerp->legs[5])*d;+ d = 25/(powf((playerp->legs[8]-playerp->legs[12]), 2) + powf((playerp->legs[9]-playerp->legs[13]), 2)+25) - 0.5;+ playerp->legs[12] -= (playerp->legs[8]-playerp->legs[12])*d;+ playerp->legs[13] -= (playerp->legs[9]-playerp->legs[13])*d;+ playerp->legs[8] += (playerp->legs[8]-playerp->legs[12])*d;+ playerp->legs[9] += (playerp->legs[9]-playerp->legs[13])*d;+ d = 36/(powf((playerp->legs[0]-p_x(&parts[i])), 2) + powf((playerp->legs[1]-p_y(&parts[i])), 2)+36) - 0.5;+ p_set_vx(&parts[i], p_vx(&parts[i]) - ((playerp->legs[0]-p_x(&parts[i]))*d));+ p_set_vy(&parts[i], p_vy(&parts[i]) - ((playerp->legs[1]-p_y(&parts[i]))*d));+ playerp->legs[0] += (playerp->legs[0]-p_x(&parts[i]))*d;+ playerp->legs[1] += (playerp->legs[1]-p_y(&parts[i]))*d;+ d = 36/(powf((playerp->legs[8]-p_x(&parts[i])), 2) + powf((playerp->legs[9]-p_y(&parts[i])), 2)+36) - 0.5;+ p_set_vx(&parts[i], p_vx(&parts[i]) - ((playerp->legs[8]-p_x(&parts[i]))*d));+ p_set_vy(&parts[i], p_vy(&parts[i]) - ((playerp->legs[9]-p_y(&parts[i]))*d));+ playerp->legs[8] += (playerp->legs[8]-p_x(&parts[i]))*d;+ playerp->legs[9] += (playerp->legs[9]-p_y(&parts[i]))*d;+ if (InBounds((int)(playerp->legs[4]), (int)(playerp->legs[5])) && !eval_move(t, (int)(playerp->legs[4]), (int)(playerp->legs[5]), NULL)) {+ playerp->legs[4] = playerp->legs[6];+ playerp->legs[5] = playerp->legs[7];+ }+ if (InBounds((int)(playerp->legs[12]), (int)(playerp->legs[13])) && !eval_move(t, (int)(playerp->legs[12]), (int)(playerp->legs[13]), NULL)) {+ playerp->legs[12] = playerp->legs[14];+ playerp->legs[13] = playerp->legs[15];+ }+ //This makes stick man "pop" from obstacles+ if (InBounds((int)(playerp->legs[4]), (int)(playerp->legs[5])) && !eval_move(t, (int)(playerp->legs[4]), (int)(playerp->legs[5]), NULL)) {+ float t;+ t = playerp->legs[4]; playerp->legs[4] = playerp->legs[6]; playerp->legs[6] = t;+ t = playerp->legs[5]; playerp->legs[5] = playerp->legs[7]; playerp->legs[7] = t;+ }+ if (InBounds((int)(playerp->legs[12]), (int)(playerp->legs[13])) && !eval_move(t, (int)(playerp->legs[12]), (int)(playerp->legs[13]), NULL)) {+ float t;+ t = playerp->legs[12]; playerp->legs[12] = playerp->legs[14]; playerp->legs[14] = t;+ t = playerp->legs[13]; playerp->legs[13] = playerp->legs[15]; playerp->legs[15] = t;+ }+ //Keeping legs distance+ if ((powf((playerp->legs[4] - playerp->legs[12]), 2) + powf((playerp->legs[5]-playerp->legs[13]), 2))<16) {+ float tvx, tvy;+ tvx = -gvy;+ tvy = gvx;+ if (tvx || tvy) {+ playerp->accs[2] -= 0.2*tvx/hypotf(tvx, tvy);+ playerp->accs[3] -= 0.2*tvy/hypotf(tvx, tvy);+ playerp->accs[6] += 0.2*tvx/hypotf(tvx, tvy);+ playerp->accs[7] += 0.2*tvy/hypotf(tvx, tvy);+ }+ }+ if ((powf((playerp->legs[0] - playerp->legs[8]), 2) + powf((playerp->legs[1]-playerp->legs[9]), 2))<16) {+ float tvx, tvy;+ tvx = -gvy;+ tvy = gvx;+ if (tvx || tvy) {+ playerp->accs[0] -= 0.2*tvx/hypotf(tvx, tvy);+ playerp->accs[1] -= 0.2*tvy/hypotf(tvx, tvy);+ playerp->accs[4] += 0.2*tvx/hypotf(tvx, tvy);+ playerp->accs[5] += 0.2*tvy/hypotf(tvx, tvy);+ }+ }+ //If legs touch something+ Element_STKM_interact(playerp, i, (int)(playerp->legs[4]+0.5), (int)(playerp->legs[5]+0.5));+ Element_STKM_interact(playerp, i, (int)(playerp->legs[12]+0.5), (int)(playerp->legs[13]+0.5));+ Element_STKM_interact(playerp, i, (int)(playerp->legs[4]+0.5), (int)playerp->legs[5]);+ Element_STKM_interact(playerp, i, (int)(playerp->legs[12]+0.5), (int)playerp->legs[13]);+ if (!parts[i].type)+ return 1;+ parts[i].ctype = playerp->elem;+ return 0;+}+void Element_STKM_interact(playerst *playerp, int i, int x, int y) {+ int r;+ if (x<0 || y<0 || x>=XRES || y>=YRES || !parts[i].type)+ return;+ r = PMAPAT(x, y);+ if (r) {+ int damage = 0;+ if (TYP(r)==PT_SPRK && playerp->elem!=PT_LIGH) { //If on charge+ damage += rng_between(32, 51);+ }+ if (!IsHeatInsulator(&parts[ID(r)]) && ((playerp->elem!=PT_LIGH && p_temp(&parts[ID(r)])>=323) || p_temp(&parts[ID(r)])<=243) && (!playerp->rocketBoots || TYP(r)!=PT_PLSM)) {+ damage += 2;+ playerp->accs[3] -= 1;+ }+ if (elements[TYP(r)].Properties&PROP_DEADLY)+ switch (TYP(r)) {+ case PT_ACID:+ damage += 5;+ break;+ default:+ damage++;+ break;+ }+ if (elements[TYP(r)].Properties&PROP_RADIOACTIVE)+ damage++;+ if (damage) {+ if (damage > parts[i].life) {+ STKM_die(playerp, i);+ return;+ }+ parts[i].life -= damage;+ }+ if (TYP(r)==PT_PRTI && parts[i].type) {+ int nnx, count=1;//gives rx=0, ry=1 in update_PRTO+ parts[ID(r)].tmp = (int)((p_temp(&parts[ID(r)])-73.15f)/100+1);+ if (parts[ID(r)].tmp>=CHANNELS) parts[ID(r)].tmp = CHANNELS-1;+ else if (parts[ID(r)].tmp<0) parts[ID(r)].tmp = 0;+ (void)nnx;+ int type = parts[i].type;+ if (portal_put(parts[ID(r)].tmp, count, &parts[i])) {+ kill_part(i);+ //stop new STKM/fighters being created to replace the ones in the portal:+ playerp->spwn = 1;+ if (type==PT_FIGH)+ fighcount++;+ }+ }+ if ((TYP(r)==PT_BHOL || TYP(r)==PT_NBHL) && parts[i].type) {+ if (!legacy_enable) {+ p_set_temp(&parts[ID(r)], restrict_flt(p_temp(&parts[ID(r)])+p_temp(&parts[i])/2, MIN_TEMP, MAX_TEMP));+ }+ kill_part(i);+ }+ if ((TYP(r)==PT_VOID || (TYP(r)==PT_PVOD && parts[ID(r)].life==10)) && (!parts[ID(r)].ctype || (parts[ID(r)].ctype==parts[i].type)!=(parts[ID(r)].tmp&1)) && parts[i].type) {+ kill_part(i);+ }+ }+}+void Element_STKM_init_legs(playerst *playerp, int i) {+ int x, y;+ x = (int)(p_x(&parts[i])+0.5f);+ y = (int)(p_y(&parts[i])+0.5f);+ playerp->legs[0] = (float)(x-1);+ playerp->legs[1] = (float)(y+6);+ playerp->legs[2] = (float)(x-1);+ playerp->legs[3] = (float)(y+6);+ playerp->legs[4] = (float)(x-3);+ playerp->legs[5] = (float)(y+12);+ playerp->legs[6] = (float)(x-3);+ playerp->legs[7] = (float)(y+12);+ playerp->legs[8] = (float)(x+1);+ playerp->legs[9] = (float)(y+6);+ playerp->legs[10] = (float)(x+1);+ playerp->legs[11] = (float)(y+6);+ playerp->legs[12] = (float)(x+3);+ playerp->legs[13] = (float)(y+12);+ playerp->legs[14] = (float)(x+3);+ playerp->legs[15] = (float)(y+12);+ for (int i = 0; i < 8; i++)+ playerp->accs[i] = 0;+ playerp->comm = 0;+ playerp->pcomm = 0;+ playerp->frames = 0;+ playerp->spwn = 0;+ playerp->fan = false;+ playerp->rocketBoots = false;+}+void Element_STKM_set_element(playerst *playerp, int element) {+ if (elements[element].Falldown != 0+ || elements[element].Properties&TYPE_GAS+ || elements[element].Properties&TYPE_LIQUID+ || elements[element].Properties&TYPE_ENERGY+ || element == PT_LOLZ || element == PT_LOVE) {+ if (!playerp->rocketBoots || element != PT_PLSM) {+ playerp->elem = element;+ playerp->fan = false;+ }+ }+ if (element == PT_TESC || element == PT_LIGH) {+ playerp->elem = PT_LIGH;+ playerp->fan = false;+ }+}++/* ---------------------------------------------------------------- STKM2 */+int el_STKM2_update(UPDATE_FUNC_ARGS) {+ Element_STKM_run_stickman(&player2, UPDATE_FUNC_SUBCALL_ARGS);+ return 0;+}+void el_STKM2_create(ELEMENT_CREATE_FUNC_ARGS) {+ int spawnID = create_part(-3, x, y, PT_SPAWN2, -1);+ if (spawnID >= 0)+ player2.spawnID = spawnID;+}+bool el_STKM2_createAllowed(ELEMENT_CREATE_ALLOWED_FUNC_ARGS) {+ return elementCount[PT_STKM2] <= 0 && !player2.spwn;+}+void el_STKM2_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) {+ if (to == PT_STKM2) {+ Element_STKM_init_legs(&player2, i);+ player2.spwn = 1;+ } else+ player2.spwn = 0;+}++/* ---------------------------------------------------------------- FIGH */+int el_FIGH_update(UPDATE_FUNC_ARGS) {+ if (parts[i].tmp < 0 || parts[i].tmp >= MAX_FIGHTERS) {+ kill_part(i);+ return 1;+ }+ playerst* figh = &fighters[(unsigned char)parts[i].tmp];+ int tarx = 0, tary = 0;+ parts[i].tmp2 = 0; //0 - stay in place, 1 - seek a stick man+ //Set target cords+ if (player2.spwn) {+ if (player.spwn && (powf((float)player.legs[2]-x, 2) + powf((float)player.legs[3]-y, 2))<=+ (powf((float)player2.legs[2]-x, 2) + powf((float)player2.legs[3]-y, 2))) {+ tarx = (int)player.legs[2];+ tary = (int)player.legs[3];+ } else {+ tarx = (int)player2.legs[2];+ tary = (int)player2.legs[3];+ }+ parts[i].tmp2 = 1;+ } else if (player.spwn) {+ tarx = (int)player.legs[2];+ tary = (int)player.legs[3];+ parts[i].tmp2 = 1;+ }+ switch (parts[i].tmp2) {+ case 1:+ if ((powf((float)(tarx-x), 2) + powf((float)(tary-y), 2))<600) {+ if (figh->elem == PT_LIGH || figh->elem == PT_NEUT+ || elements[figh->elem].Properties & (PROP_DEADLY | PROP_RADIOACTIVE)+ || elements[figh->elem].DefaultProperties.temp >= 323 || elements[figh->elem].DefaultProperties.temp <= 243)+ figh->comm = (int)figh->comm | 0x08;+ } else if (tarx<x) {+ if(figh->rocketBoots || !(eval_move(PT_FIGH, (int)(figh->legs[4])-10, (int)(figh->legs[5])+6, NULL)+ && eval_move(PT_FIGH, (int)(figh->legs[4])-10, (int)(figh->legs[5])+3, NULL)))+ figh->comm = 0x01;+ else+ figh->comm = 0x02;+ if (figh->rocketBoots) {+ if (tary<y)+ figh->comm = (int)figh->comm | 0x04;+ } else if (!eval_move(PT_FIGH, (int)(figh->legs[4])-4, (int)(figh->legs[5])-1, NULL)+ || !eval_move(PT_FIGH, (int)(figh->legs[12])-4, (int)(figh->legs[13])-1, NULL)+ || eval_move(PT_FIGH, 2*(int)(figh->legs[4])-(int)(figh->legs[6]), (int)(figh->legs[5])+5, NULL))+ figh->comm = (int)figh->comm | 0x04;+ } else {+ if (figh->rocketBoots || !(eval_move(PT_FIGH, (int)(figh->legs[12])+10, (int)(figh->legs[13])+6, NULL)+ && eval_move(PT_FIGH, (int)(figh->legs[12])+10, (int)(figh->legs[13])+3, NULL)))+ figh->comm = 0x02;+ else+ figh->comm = 0x01;+ if (figh->rocketBoots) {+ if (tary<y)+ figh->comm = (int)figh->comm | 0x04;+ } else if (!eval_move(PT_FIGH, (int)(figh->legs[4])+4, (int)(figh->legs[5])-1, NULL)+ || !eval_move(PT_FIGH, (int)(figh->legs[4])+4, (int)(figh->legs[5])-1, NULL)+ || eval_move(PT_FIGH, 2*(int)(figh->legs[12])-(int)(figh->legs[14]), (int)(figh->legs[13])+5, NULL))+ figh->comm = (int)figh->comm | 0x04;+ }+ break;+ default:+ figh->comm = 0;+ break;+ }+ figh->pcomm = figh->comm;+ Element_STKM_run_stickman(figh, UPDATE_FUNC_SUBCALL_ARGS);+ return 0;+}+bool el_FIGH_createAllowed(ELEMENT_CREATE_ALLOWED_FUNC_ARGS) {+ return Element_FIGH_CanAlloc();+}+void el_FIGH_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) {+ if (to == PT_FIGH) {+ parts[i].tmp = Element_FIGH_Alloc();+ if (parts[i].tmp >= 0)+ Element_FIGH_NewFighter(parts[i].tmp, i, PT_DUST);+ } else {+ FIGH_Free((unsigned char)parts[i].tmp);+ }+}+bool Element_FIGH_CanAlloc(void) {+ return fighcount < MAX_FIGHTERS;+}+int Element_FIGH_Alloc(void) {+ if (fighcount >= MAX_FIGHTERS)+ return -1;+ int i = 0;+ while (i < MAX_FIGHTERS && fighters[i].spwn==1)+ i++;+ if (i < MAX_FIGHTERS) {+ fighters[i].spwn = 1;+ fighters[i].elem = PT_DUST;+ fighcount++;+ return i;+ } else return -1;+}+static void FIGH_Free(unsigned char i) {+ if (i >= MAX_FIGHTERS) return; /* (the original's array has room for any unsigned char: 100) */+ if (fighters[i].spwn) {+ fighters[i].spwn = 0;+ fighcount--;+ }+}+void Element_FIGH_NewFighter(int fighterID, int i, int elem) {+ Element_STKM_init_legs(&fighters[fighterID], i);+ if (elem > 0 && elem < PT_NUM)+ fighters[fighterID].elem = elem;+ fighters[fighterID].spwn = 1;+}+diff --git a/games/numpowder/src/elements.h b/games/numpowder/src/elements.hnew file mode 100644index 00000000..c4542acb--- /dev/null+++ b/games/numpowder/src/elements.h@@ -0,0 +1,252 @@+/* NumPowder: The Powder Toy's elements, their numbers and properties (generated by tools/gen_elements.py+ * from the original's element files: do not edit). */+#ifndef NP_ELEMENTS_H+#define NP_ELEMENTS_H+#include "simdefs.h"++enum {+ PT_NONE = 0,+ PT_DUST = 1,+ PT_WATR = 2,+ PT_OIL = 3,+ PT_FIRE = 4,+ PT_STNE = 5,+ PT_LAVA = 6,+ PT_GUNP = 7,+ PT_NITR = 8,+ PT_CLNE = 9,+ PT_GAS = 10,+ PT_PLEX = 11,+ PT_GOO = 12,+ PT_ICEI = 13,+ PT_METL = 14,+ PT_SPRK = 15,+ PT_SNOW = 16,+ PT_WOOD = 17,+ PT_NEUT = 18,+ PT_PLUT = 19,+ PT_PLNT = 20,+ PT_ACID = 21,+ PT_VOID = 22,+ PT_WTRV = 23,+ PT_CNCT = 24,+ PT_DSTW = 25,+ PT_SALT = 26,+ PT_SLTW = 27,+ PT_DMND = 28,+ PT_BMTL = 29,+ PT_BRMT = 30,+ PT_PHOT = 31,+ PT_URAN = 32,+ PT_WAX = 33,+ PT_MWAX = 34,+ PT_PSCN = 35,+ PT_NSCN = 36,+ PT_LNTG = 37,+ PT_INSL = 38,+ PT_BHOL = 39,+ PT_WHOL = 40,+ PT_RBDM = 41,+ PT_LRBD = 42,+ PT_NTCT = 43,+ PT_SAND = 44,+ PT_GLAS = 45,+ PT_PTCT = 46,+ PT_BGLA = 47,+ PT_THDR = 48,+ PT_PLSM = 49,+ PT_ETRD = 50,+ PT_NICE = 51,+ PT_NBLE = 52,+ PT_BTRY = 53,+ PT_LCRY = 54,+ PT_STKM = 55,+ PT_SWCH = 56,+ PT_SMKE = 57,+ PT_DESL = 58,+ PT_COAL = 59,+ PT_LO2 = 60,+ PT_O2 = 61,+ PT_INWR = 62,+ PT_YEST = 63,+ PT_DYST = 64,+ PT_THRM = 65,+ PT_GLOW = 66,+ PT_BRCK = 67,+ PT_CFLM = 68,+ PT_FIRW = 69,+ PT_FUSE = 70,+ PT_FSEP = 71,+ PT_AMTR = 72,+ PT_BCOL = 73,+ PT_PCLN = 74,+ PT_HSWC = 75,+ PT_IRON = 76,+ PT_MORT = 77,+ PT_LIFE = 78,+ PT_DLAY = 79,+ PT_CO2 = 80,+ PT_DRIC = 81,+ PT_CBNW = 82,+ PT_STOR = 83,+ PT_PVOD = 84,+ PT_CONV = 85,+ PT_CAUS = 86,+ PT_LIGH = 87,+ PT_TESC = 88,+ PT_DEST = 89,+ PT_SPNG = 90,+ PT_RIME = 91,+ PT_FOG = 92,+ PT_BCLN = 93,+ PT_LOVE = 94,+ PT_DEUT = 95,+ PT_WARP = 96,+ PT_PUMP = 97,+ PT_FWRK = 98,+ PT_PIPE = 99,+ PT_FRZZ = 100,+ PT_FRZW = 101,+ PT_GRAV = 102,+ PT_BIZR = 103,+ PT_BIZRG = 104,+ PT_BIZRS = 105,+ PT_INST = 106,+ PT_ISOZ = 107,+ PT_ISZS = 108,+ PT_PRTI = 109,+ PT_PRTO = 110,+ PT_PSTE = 111,+ PT_PSTS = 112,+ PT_ANAR = 113,+ PT_VINE = 114,+ PT_INVIS = 115,+ PT_E116 = 116,+ PT_SPAWN2 = 117,+ PT_SPAWN = 118,+ PT_SHLD1 = 119,+ PT_SHLD2 = 120,+ PT_SHLD3 = 121,+ PT_SHLD4 = 122,+ PT_LOLZ = 123,+ PT_WIFI = 124,+ PT_FILT = 125,+ PT_ARAY = 126,+ PT_BRAY = 127,+ PT_STKM2 = 128,+ PT_BOMB = 129,+ PT_C5 = 130,+ PT_SING = 131,+ PT_QRTZ = 132,+ PT_PQRT = 133,+ PT_EMP = 134,+ PT_BREC = 135,+ PT_ELEC = 136,+ PT_ACEL = 137,+ PT_DCEL = 138,+ PT_BANG = 139,+ PT_IGNT = 140,+ PT_BOYL = 141,+ PT_GEL = 142,+ PT_TRON = 143,+ PT_TTAN = 144,+ PT_EXOT = 145,+ PT_EMBR = 146,+ PT_H2 = 147,+ PT_SOAP = 148,+ PT_NBHL = 149,+ PT_NWHL = 150,+ PT_MERC = 151,+ PT_PBCN = 152,+ PT_GPMP = 153,+ PT_CLST = 154,+ PT_WIRE = 155,+ PT_GBMB = 156,+ PT_FIGH = 157,+ PT_FRAY = 158,+ PT_RPEL = 159,+ PT_PPIP = 160,+ PT_DTEC = 161,+ PT_DMG = 162,+ PT_TSNS = 163,+ PT_VIBR = 164,+ PT_BVBR = 165,+ PT_CRAY = 166,+ PT_PSTN = 167,+ PT_FRME = 168,+ PT_GOLD = 169,+ PT_TUNG = 170,+ PT_PSNS = 171,+ PT_PROT = 172,+ PT_VIRS = 173,+ PT_VRSS = 174,+ PT_VRSG = 175,+ PT_GRVT = 176,+ PT_DRAY = 177,+ PT_CRMC = 178,+ PT_HEAC = 179,+ PT_SAWD = 180,+ PT_POLO = 181,+ PT_RFRG = 182,+ PT_RFGL = 183,+ PT_LSNS = 184,+ PT_LDTC = 185,+ PT_SLCN = 186,+ PT_PTNM = 187,+ PT_VSNS = 188,+ PT_ROCK = 189,+ PT_LITH = 190,+ PT_RSST = 191,+ PT_RSSS = 192,+ PT_BASE = 193,+ PT_SEED = 194,+ PT_COUNT = 195+};++typedef struct {+ const char * Identifier;+ const char * Name;+ uint32_t Colour;+ uint8_t MenuVisible;+ uint8_t MenuSection;+ uint8_t Enabled;+ float Advection;+ float AirDrag;+ float AirLoss;+ float Loss;+ float Collision;+ float Gravity;+ float NewtonianGravity;+ float Diffusion;+ float HotAir;+ int8_t Falldown;+ int16_t Flammable;+ int16_t Explosive;+ int16_t Meltable;+ int16_t Hardness;+ uint32_t PhotonReflectWavelengths;+ int16_t Weight;+ uint8_t HeatConduct;+ float HeatCapacity;+ const char * Description;+ uint32_t Properties;+ uint32_t CarriesTypeIn;+ float LowPressure;+ int16_t LowPressureTransition;+ float HighPressure;+ int16_t HighPressureTransition;+ float LowTemperature;+ int16_t LowTemperatureTransition;+ float HighTemperature;+ int16_t HighTemperatureTransition;+ struct { float temp; int life, ctype, tmp, tmp2, tmp3, tmp4; } DefaultProperties;+ int (*Update)(UPDATE_FUNC_ARGS);+ int (*Graphics)(GRAPHICS_FUNC_ARGS);+ void (*Create)(ELEMENT_CREATE_FUNC_ARGS);+ bool (*CreateAllowed)(ELEMENT_CREATE_ALLOWED_FUNC_ARGS);+ void (*ChangeType)(ELEMENT_CHANGETYPE_FUNC_ARGS);+ bool (*CtypeDraw)(CTYPEDRAW_FUNC_ARGS);+} Element;+extern const Element elements[PT_NUM];++#endifdiff --git a/games/numpowder/src/elements_data.c b/games/numpowder/src/elements_data.cnew file mode 100644index 00000000..b59b60d4--- /dev/null+++ b/games/numpowder/src/elements_data.c@@ -0,0 +1,7959 @@+/* NumPowder: The Powder Toy's element table (generated by tools/gen_elements.py: do not edit). Each element's+ * functions are weak: one not ported yet is NULL. */+#include "sim.h"++int Element_BIZR_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int Element_BIZR_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int Element_COAL_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int Element_COAL_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int Element_FIRE_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int Element_NTCT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+bool Element_PCLN_ctypeDraw(CTYPEDRAW_FUNC_ARGS) __attribute__((weak));+int Element_PIPE_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int Element_PIPE_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int Element_QRTZ_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int Element_QRTZ_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int Element_RFRG_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int Element_STKM_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int Element_VIBR_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int Element_VIBR_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int Element_VIRS_update(UPDATE_FUNC_ARGS) __attribute__((weak));+bool basicCtypeDraw(CTYPEDRAW_FUNC_ARGS) __attribute__((weak));+bool ctypeDrawVInCtype(CTYPEDRAW_FUNC_ARGS) __attribute__((weak));+bool ctypeDrawVInTmp(CTYPEDRAW_FUNC_ARGS) __attribute__((weak));+int el_ACEL_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_ACEL_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_ACID_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_ACID_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_AMTR_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_AMTR_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_ANAR_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_ARAY_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_BANG_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_BASE_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_BASE_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_BCLN_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_BMTL_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_BOMB_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_BOMB_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_BOYL_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_BRAY_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_BRCK_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_BREC_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_BRMT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_BTRY_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_C5_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_C5_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_CAUS_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_CBNW_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_CBNW_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_CFLM_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_CFLM_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_CLNE_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_CLST_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_CLST_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_CLST_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_CO2_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_CONV_update(UPDATE_FUNC_ARGS) __attribute__((weak));+bool el_CRAY_ctypeDraw(CTYPEDRAW_FUNC_ARGS) __attribute__((weak));+int el_CRAY_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_CRMC_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_CRMC_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_CRMC_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_DCEL_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_DCEL_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_DEST_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_DEST_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_DEUT_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_DEUT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_DLAY_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_DLAY_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_DMG_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_DMG_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_DRAY_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_DSTW_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_DTEC_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_ELEC_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_ELEC_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_ELEC_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_EMBR_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_EMBR_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_EMP_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+void el_ETRD_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) __attribute__((weak));+int el_EXOT_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_EXOT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_FIGH_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) __attribute__((weak));+bool el_FIGH_createAllowed(ELEMENT_CREATE_ALLOWED_FUNC_ARGS) __attribute__((weak));+int el_FIGH_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_FILT_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_FILT_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+void el_FIRE_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_FIRE_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_FIRW_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_FIRW_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_FOG_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_FRAY_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_FRME_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_FRZW_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_FRZZ_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_FSEP_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_FUSE_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_FWRK_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_GBMB_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_GBMB_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_GEL_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_GEL_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_GLAS_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_GLAS_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_GLOW_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_GLOW_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_GOLD_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_GOLD_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_GOO_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_GPMP_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_GPMP_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_GRAV_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_GRAV_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_GRVT_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_GRVT_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_GRVT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_H2_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_HEAC_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_HSWC_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_HSWC_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_ICEI_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_IGNT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_INVIS_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_INVIS_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_IRON_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_ISOZ_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_ISZS_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_LAVA_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_LAVA_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_LCRY_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_LCRY_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_LDTC_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_LIFE_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_LIFE_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+void el_LIGH_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_LIGH_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_LIGH_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_LITH_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_LITH_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_LSNS_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_MERC_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_MORT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_NBHL_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_NBLE_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_NEUT_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_NEUT_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_NEUT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_NWHL_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_O2_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_PBCN_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_PBCN_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_PCLN_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_PCLN_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_PHOT_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_PHOT_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_PHOT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_PLNT_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_PLNT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_PLSM_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_PLSM_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_PLUT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_POLO_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_POLO_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_PQRT_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+void el_PROT_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_PROT_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_PROT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_PRTI_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_PRTI_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_PRTO_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_PRTO_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_PSNS_update(UPDATE_FUNC_ARGS) __attribute__((weak));+bool el_PSTN_ctypeDraw(CTYPEDRAW_FUNC_ARGS) __attribute__((weak));+int el_PSTN_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_PSTN_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_PTCT_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_PTNM_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_PTNM_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_PTNM_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_PUMP_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_PUMP_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_PVOD_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_PVOD_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_QRTZ_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_RIME_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_ROCK_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_ROCK_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_RPEL_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_RSSS_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_RSST_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_SEED_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_SEED_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_SEED_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_SHLD1_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_SHLD2_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_SHLD3_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_SHLD4_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_SING_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_SING_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_SLCN_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_SLCN_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_SLCN_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_SLTW_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_SMKE_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_SNOW_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_SOAP_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) __attribute__((weak));+int el_SOAP_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_SOAP_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_SPAWN2_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) __attribute__((weak));+bool el_SPAWN2_createAllowed(ELEMENT_CREATE_ALLOWED_FUNC_ARGS) __attribute__((weak));+void el_SPAWN_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) __attribute__((weak));+bool el_SPAWN_createAllowed(ELEMENT_CREATE_ALLOWED_FUNC_ARGS) __attribute__((weak));+int el_SPNG_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_SPNG_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_SPRK_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_SPRK_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_STKM2_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) __attribute__((weak));+void el_STKM2_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+bool el_STKM2_createAllowed(ELEMENT_CREATE_ALLOWED_FUNC_ARGS) __attribute__((weak));+int el_STKM2_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_STKM_changeType(ELEMENT_CHANGETYPE_FUNC_ARGS) __attribute__((weak));+void el_STKM_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+bool el_STKM_createAllowed(ELEMENT_CREATE_ALLOWED_FUNC_ARGS) __attribute__((weak));+int el_STKM_update(UPDATE_FUNC_ARGS) __attribute__((weak));+bool el_STOR_ctypeDraw(CTYPEDRAW_FUNC_ARGS) __attribute__((weak));+int el_STOR_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_STOR_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_SWCH_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_SWCH_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_TESC_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_THDR_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_THDR_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_TRON_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_TRON_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_TRON_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_TSNS_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_TTAN_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_TUNG_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_TUNG_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_TUNG_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_URAN_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_VINE_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_VINE_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_VIRS_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_VRSG_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_VRSS_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_VSNS_update(UPDATE_FUNC_ARGS) __attribute__((weak));+void el_WARP_create(ELEMENT_CREATE_FUNC_ARGS) __attribute__((weak));+int el_WARP_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_WARP_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_WATR_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_WIFI_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_WIFI_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_WIRE_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_WIRE_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_WOOD_graphics(GRAPHICS_FUNC_ARGS) __attribute__((weak));+int el_WOOD_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_WTRV_update(UPDATE_FUNC_ARGS) __attribute__((weak));+int el_YEST_update(UPDATE_FUNC_ARGS) __attribute__((weak));++const Element elements[PT_NUM] = {+ [PT_NONE] = {+ .Identifier = "DEFAULT_PT_NONE",+ .Name = "NONE",+ .Colour = 0x000000,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Erases particles.",+ .Properties = 0,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_DUST] = {+ .Identifier = "DEFAULT_PT_DUST",+ .Name = "DUST",+ .Colour = 0xFFE0A0,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 10,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 30,+ .PhotonReflectWavelengths = 0x3FFFFFC0,+ .Weight = 85,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Very light dust. Flammable.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_WATR] = {+ .Identifier = "DEFAULT_PT_WATR",+ .Name = "WATR",+ .Colour = 0x2030D0,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 30,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "Water. Conducts electricity, freezes, and extinguishes fires.",+ .Properties = TYPE_LIQUID | PROP_CONDUCTS | PROP_LIFE_DEC | PROP_NEUTPASS | PROP_PHOTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 273.15f,+ .LowTemperatureTransition = PT_ICEI,+ .HighTemperature = 373.0f,+ .HighTemperatureTransition = PT_WTRV,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_WATR_update,+ },+ [PT_OIL] = {+ .Identifier = "DEFAULT_PT_OIL",+ .Name = "OIL",+ .Colour = 0x404010,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 20,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 5,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 20,+ .HeatConduct = 42,+ .HeatCapacity = 1,+ .Description = "Flammable, turns into GAS at low pressure or high temperature.",+ .Properties = TYPE_LIQUID | PROP_NEUTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 333.0f,+ .HighTemperatureTransition = PT_GAS,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_FIRE] = {+ .Identifier = "DEFAULT_PT_FIRE",+ .Name = "FIRE",+ .Colour = 0xFF1000,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.9f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.97f,+ .Loss = 0.20f,+ .Collision = 0.0f,+ .Gravity = -0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.001f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 2,+ .HeatConduct = 88,+ .HeatCapacity = 1,+ .Description = "Ignites flammable materials. Heats air.",+ .Properties = TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 2773.0f,+ .HighTemperatureTransition = PT_PLSM,+ .DefaultProperties = {.temp = R_TEMP + 400.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_FIRE_update,+ .Graphics = el_FIRE_graphics,+ .Create = el_FIRE_create,+ },+ [PT_STNE] = {+ .Identifier = "DEFAULT_PT_STNE",+ .Name = "STNE",+ .Colour = 0xA0A0A0,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.3f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 5,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 90,+ .HeatConduct = 150,+ .HeatCapacity = 1,+ .Description = "Stone. Heavy particles, meltable.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 983.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_LAVA] = {+ .Identifier = "DEFAULT_PT_LAVA",+ .Name = "LAVA",+ .Colour = 0xE05010,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.3f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.15f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.0003f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 2,+ .PhotonReflectWavelengths = 0x3FF00000,+ .Weight = 45,+ .HeatConduct = 60,+ .HeatCapacity = 1,+ .Description = "Molten lava. Ignites flammable materials. Generated when metals and other materials melt, solidifies when cold.",+ .Properties = TYPE_LIQUID|PROP_LIFE_DEC,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = MAX_TEMP,+ .LowTemperatureTransition = ST,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 1500.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_FIRE_update,+ .Graphics = el_LAVA_graphics,+ .Create = el_LAVA_create,+ },+ [PT_GUNP] = {+ .Identifier = "DEFAULT_PT_GUNP",+ .Name = "GUN",+ .Colour = 0xC0C0D0,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.80f,+ .Collision = -0.1f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 600,+ .Explosive = 1,+ .Meltable = 0,+ .Hardness = 10,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 85,+ .HeatConduct = 97,+ .HeatCapacity = 1,+ .Description = "Gunpowder. Light dust, explodes on contact with fire or spark.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 673.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_NITR] = {+ .Identifier = "DEFAULT_PT_NITR",+ .Name = "NITR",+ .Colour = 0x20E010,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.5f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.92f,+ .Loss = 0.97f,+ .Collision = 0.0f,+ .Gravity = 0.2f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 1000,+ .Explosive = 2,+ .Meltable = 0,+ .Hardness = 3,+ .PhotonReflectWavelengths = 0x0007C000,+ .Weight = 23,+ .HeatConduct = 50,+ .HeatCapacity = 1,+ .Description = "Nitroglycerin. Pressure sensitive explosive. Mix with CLST to make TNT.",+ .Properties = TYPE_LIQUID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 673.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_CLNE] = {+ .Identifier = "DEFAULT_PT_CLNE",+ .Name = "CLNE",+ .Colour = 0xFFD010,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Clone. Duplicates any particles it touches.",+ .Properties = TYPE_SOLID | PROP_PHOTPASS | PROP_NOCTYPEDRAW,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_CLNE_update,+ .CtypeDraw = ctypeDrawVInTmp,+ },+ [PT_GAS] = {+ .Identifier = "DEFAULT_PT_GAS",+ .Name = "GAS",+ .Colour = 0xE0FF20,+ .MenuVisible = 1,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 1.0f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.30f,+ .Collision = -0.1f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.75f,+ .HotAir = 0.001f * CFDS,+ .Falldown = 0,+ .Flammable = 600,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 42,+ .HeatCapacity = 1,+ .Description = "Diffuses quickly and is flammable. Liquefies into OIL under pressure.",+ .Properties = TYPE_GAS | PROP_NEUTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 6.0f,+ .HighPressureTransition = PT_OIL,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 573.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_PLEX] = {+ .Identifier = "DEFAULT_PT_PLEX",+ .Name = "C-4",+ .Colour = 0xD080E0,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 1000,+ .Explosive = 2,+ .Meltable = 50,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x1F00003E,+ .Weight = 100,+ .HeatConduct = 88,+ .HeatCapacity = 1,+ .Description = "Solid pressure sensitive explosive.",+ .Properties = TYPE_SOLID | PROP_NEUTPENETRATE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 673.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_GOO] = {+ .Identifier = "DEFAULT_PT_GOO",+ .Name = "GOO",+ .Colour = 0x804000,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.97f,+ .Loss = 0.50f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 12,+ .PhotonReflectWavelengths = 0x3FFAAA00,+ .Weight = 100,+ .HeatConduct = 75,+ .HeatCapacity = 1,+ .Description = "Deforms and disappears under pressure.",+ .Properties = TYPE_SOLID | PROP_NEUTPENETRATE|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_GOO_update,+ },+ [PT_ICEI] = {+ .Identifier = "DEFAULT_PT_ICEI",+ .Name = "ICE",+ .Colour = 0xA0C0FF,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = -0.0003f* CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 46,+ .HeatCapacity = 1,+ .Description = "Crushes under pressure. Cools down air.",+ .Properties = TYPE_SOLID|PROP_LIFE_DEC|PROP_NEUTPASS,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 0.8f,+ .HighPressureTransition = PT_SNOW,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 252.05f,+ .HighTemperatureTransition = ST,+ .DefaultProperties = {.temp = R_TEMP - 50.0f + 273.15f, .life = 0, .ctype = PT_WATR, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_ICEI_update,+ },+ [PT_METL] = {+ .Identifier = "DEFAULT_PT_METL",+ .Name = "METL",+ .Colour = 0x404060,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Metal, the basic conductor. Meltable.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1273.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_SPRK] = {+ .Identifier = "DEFAULT_PT_SPRK",+ .Name = "SPRK",+ .Colour = 0xFFFF80,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.001f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x00000000,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Electricity. The basis of all electronics in TPT, travels along conductive elements.",+ .Properties = TYPE_SOLID|PROP_LIFE_DEC,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SPRK_update,+ .Graphics = el_SPRK_graphics,+ },+ [PT_SNOW] = {+ .Identifier = "DEFAULT_PT_SNOW",+ .Name = "SNOW",+ .Colour = 0xC0E0FF,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.90f,+ .Collision = -0.1f,+ .Gravity = 0.05f,+ .NewtonianGravity = 1,+ .Diffusion = 0.01f,+ .HotAir = -0.00005f* CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x03FFFFFF,+ .Weight = 50,+ .HeatConduct = 46,+ .HeatCapacity = 1,+ .Description = "Light particles. Created when ICE breaks under pressure.",+ .Properties = TYPE_PART|PROP_NEUTPASS,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 252.05f,+ .HighTemperatureTransition = ST,+ .DefaultProperties = {.temp = R_TEMP - 30.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SNOW_update,+ },+ [PT_WOOD] = {+ .Identifier = "DEFAULT_PT_WOOD",+ .Name = "WOOD",+ .Colour = 0xC0A040,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 20,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 16,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 164,+ .HeatCapacity = 1,+ .Description = "Wood, flammable.",+ .Properties = TYPE_SOLID | PROP_NEUTPENETRATE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 873.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_WOOD_update,+ .Graphics = el_WOOD_graphics,+ },+ [PT_NEUT] = {+ .Identifier = "DEFAULT_PT_NEUT",+ .Name = "NEUT",+ .Colour = 0x20E0FF,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 1.00f,+ .Collision = -0.99f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.01f,+ .HotAir = 0.002f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = -1,+ .HeatConduct = 60,+ .HeatCapacity = 1,+ .Description = "Neutrons. Interact with matter in odd ways.",+ .Properties = TYPE_ENERGY|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 4.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_NEUT_update,+ .Graphics = el_NEUT_graphics,+ .Create = el_NEUT_create,+ },+ [PT_PLUT] = {+ .Identifier = "DEFAULT_PT_PLUT",+ .Name = "PLUT",+ .Colour = 0x407020,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.4f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x001FCE00,+ .Weight = 90,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Plutonium. Heavy, fissile particles. Generates neutrons under pressure.",+ .Properties = TYPE_PART|PROP_NEUTPASS|PROP_RADIOACTIVE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 4.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PLUT_update,+ },+ [PT_PLNT] = {+ .Identifier = "DEFAULT_PT_PLNT",+ .Name = "PLNT",+ .Colour = 0x0CAC00,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 20,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 10,+ .PhotonReflectWavelengths = 0x0007C000,+ .Weight = 100,+ .HeatConduct = 65,+ .HeatCapacity = 1,+ .Description = "Plant, drinks water and grows.",+ .Properties = TYPE_SOLID|PROP_NEUTPENETRATE|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 573.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PLNT_update,+ .Graphics = el_PLNT_graphics,+ },+ [PT_ACID] = {+ .Identifier = "DEFAULT_PT_ACID",+ .Name = "ACID",+ .Colour = 0xED55FF,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 40,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x1FE001FE,+ .Weight = 10,+ .HeatConduct = 34,+ .HeatCapacity = 1,+ .Description = "Dissolves almost everything.",+ .Properties = TYPE_LIQUID|PROP_DEADLY,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 75, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_ACID_update,+ .Graphics = el_ACID_graphics,+ },+ [PT_VOID] = {+ .Identifier = "DEFAULT_PT_VOID",+ .Name = "VOID",+ .Colour = 0x790B0B,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = -0.0003f* CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Hole, will drain away any particles.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .CtypeDraw = basicCtypeDraw,+ },+ [PT_WTRV] = {+ .Identifier = "DEFAULT_PT_WTRV",+ .Name = "WTRV",+ .Colour = 0xA0A0FF,+ .MenuVisible = 1,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 1.0f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.30f,+ .Collision = -0.1f,+ .Gravity = -0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.75f,+ .HotAir = 0.0003f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 4,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 48,+ .HeatCapacity = 1,+ .Description = "Steam. Produced from hot water.",+ .Properties = TYPE_GAS,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 371.0f,+ .LowTemperatureTransition = ST,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 100.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_WTRV_update,+ },+ [PT_CNCT] = {+ .Identifier = "DEFAULT_PT_CNCT",+ .Name = "CNCT",+ .Colour = 0xC0C0C0,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.3f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 2,+ .Hardness = 2,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 55,+ .HeatConduct = 100,+ .HeatCapacity = 1,+ .Description = "Concrete. Can stack on itself or ROCK, collapses with pressure.",+ .Properties = TYPE_PART|PROP_HOT_GLOW,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1123.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_DSTW] = {+ .Identifier = "DEFAULT_PT_DSTW",+ .Name = "DSTW",+ .Colour = 0x1020C0,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 30,+ .HeatConduct = 23,+ .HeatCapacity = 1,+ .Description = "Distilled water, does not conduct electricity.",+ .Properties = TYPE_LIQUID | PROP_NEUTPASS | PROP_PHOTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 273.15f,+ .LowTemperatureTransition = PT_ICEI,+ .HighTemperature = 373.0f,+ .HighTemperatureTransition = PT_WTRV,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_DSTW_update,+ },+ [PT_SALT] = {+ .Identifier = "DEFAULT_PT_SALT",+ .Name = "SALT",+ .Colour = 0xFFFFFF,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.3f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 5,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 75,+ .HeatConduct = 110,+ .HeatCapacity = 1,+ .Description = "Salt, dissolves in water.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1173.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_SLTW] = {+ .Identifier = "DEFAULT_PT_SLTW",+ .Name = "SLTW",+ .Colour = 0x4050F0,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 35,+ .HeatConduct = 75,+ .HeatCapacity = 1,+ .Description = "Saltwater, conducts electricity, difficult to freeze.",+ .Properties = TYPE_LIQUID | PROP_CONDUCTS | PROP_LIFE_DEC | PROP_NEUTPENETRATE | PROP_PHOTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 252.05f,+ .LowTemperatureTransition = PT_ICEI,+ .HighTemperature = 383.0f,+ .HighTemperatureTransition = ST,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SLTW_update,+ },+ [PT_DMND] = {+ .Identifier = "DEFAULT_PT_DMND",+ .Name = "DMND",+ .Colour = 0xCCFFFF,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 186,+ .HeatCapacity = 1,+ .Description = "Diamond. Indestructible.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_BMTL] = {+ .Identifier = "DEFAULT_PT_BMTL",+ .Name = "BMTL",+ .Colour = 0x505070,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Breakable metal. Common conductive building material, can melt and break under pressure.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 1.0f,+ .HighPressureTransition = ST,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1273.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_BMTL_update,+ },+ [PT_BRMT] = {+ .Identifier = "DEFAULT_PT_BRMT",+ .Name = "BRMT",+ .Colour = 0x705060,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.3f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 2,+ .Hardness = 2,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 90,+ .HeatConduct = 211,+ .HeatCapacity = 1,+ .Description = "Broken metal. Created when iron rusts or when metals break from pressure.",+ .Properties = TYPE_PART|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1273.0f,+ .HighTemperatureTransition = ST,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_BRMT_update,+ },+ [PT_PHOT] = {+ .Identifier = "DEFAULT_PT_PHOT",+ .Name = "PHOT",+ .Colour = 0xFFFFFF,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 1.00f,+ .Collision = -0.99f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = -1,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Photons. Refract through glass, and different elements change its color. Can ignite flammable materials.",+ .Properties = TYPE_ENERGY | PROP_PHOTPASS | PROP_LIFE_DEC | PROP_LIFE_KILL_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 900.0f + 273.15f, .life = 680, .ctype = 0x3FFFFFFF, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PHOT_update,+ .Graphics = el_PHOT_graphics,+ .Create = el_PHOT_create,+ },+ [PT_URAN] = {+ .Identifier = "DEFAULT_PT_URAN",+ .Name = "URAN",+ .Colour = 0x707020,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.4f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x003FC000,+ .Weight = 90,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Uranium. Heavy particles. Generates heat under pressure.",+ .Properties = TYPE_PART | PROP_RADIOACTIVE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 30.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_URAN_update,+ },+ [PT_WAX] = {+ .Identifier = "DEFAULT_PT_WAX",+ .Name = "WAX",+ .Colour = 0xF0F0BB,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 10,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 44,+ .HeatCapacity = 1,+ .Description = "Flammable, melts at moderately high temperatures.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 319.0f,+ .HighTemperatureTransition = PT_MWAX,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_MWAX] = {+ .Identifier = "DEFAULT_PT_MWAX",+ .Name = "MWAX",+ .Colour = 0xE0E0AA,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.3f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.15f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000001f* CFDS,+ .Falldown = 2,+ .Flammable = 5,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 2,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 25,+ .HeatConduct = 44,+ .HeatCapacity = 1,+ .Description = "Liquid Wax. Hardens into WAX at 45 degrees.",+ .Properties = TYPE_LIQUID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 318.0f,+ .LowTemperatureTransition = PT_WAX,+ .HighTemperature = 673.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 28.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_PSCN] = {+ .Identifier = "DEFAULT_PT_PSCN",+ .Name = "PSCN",+ .Colour = 0x805050,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x00000000,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "P-Type Silicon, Will transfer current to any conductor. Enables powered materials.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1687.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_NSCN] = {+ .Identifier = "DEFAULT_PT_NSCN",+ .Name = "NSCN",+ .Colour = 0x505080,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x00000000,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "N-Type Silicon, Will not transfer current to P-Type Silicon. Disables powered materials.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1687.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_LNTG] = {+ .Identifier = "DEFAULT_PT_LNTG",+ .Name = "LN2",+ .Colour = 0x80A0DF,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 30,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Liquid Nitrogen. Very cold, disappears whenever it touches anything warmer.",+ .Properties = TYPE_LIQUID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 63.0f,+ .LowTemperatureTransition = PT_NICE,+ .HighTemperature = 77.0f,+ .HighTemperatureTransition = PT_NONE,+ .DefaultProperties = {.temp = 70.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_INSL] = {+ .Identifier = "DEFAULT_PT_INSL",+ .Name = "INSL",+ .Colour = 0x9EA3B6,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 7,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 10,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Insulator. Blocks heat, electricity, and radiation.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_BHOL] = {+ .Identifier = "DEFAULT_PT_BHOL",+ .Name = "VACU",+ .Colour = 0x303030,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = -0.01f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 255,+ .HeatCapacity = 1,+ .Description = "Vacuum, sucks in other particles and heats up.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 70.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_WHOL] = {+ .Identifier = "DEFAULT_PT_WHOL",+ .Name = "VENT",+ .Colour = 0xEFEFEF,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.010f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 255,+ .HeatCapacity = 1,+ .Description = "Air vent, creates pressure and pushes other particles away.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP - 16.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_RBDM] = {+ .Identifier = "DEFAULT_PT_RBDM",+ .Name = "RBDM",+ .Colour = 0xCCCCCC,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 1000,+ .Explosive = 1,+ .Meltable = 50,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 240,+ .HeatCapacity = 1,+ .Description = "Rubidium. Explosive, especially on contact with water. Low melting point.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 312.0f,+ .HighTemperatureTransition = PT_LRBD,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_LRBD] = {+ .Identifier = "DEFAULT_PT_LRBD",+ .Name = "LRBD",+ .Colour = 0xAAAAAA,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.3f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.15f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000001f* CFDS,+ .Falldown = 2,+ .Flammable = 1000,+ .Explosive = 1,+ .Meltable = 0,+ .Hardness = 2,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 45,+ .HeatConduct = 170,+ .HeatCapacity = 1,+ .Description = "Liquid Rubidium.",+ .Properties = TYPE_LIQUID|PROP_CONDUCTS|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 311.0f,+ .LowTemperatureTransition = PT_RBDM,+ .HighTemperature = 961.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 45.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_NTCT] = {+ .Identifier = "DEFAULT_PT_NTCT",+ .Name = "NTCT",+ .Colour = 0x505040,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "NTC Thermistor. Conducts with PSCN and NSCN, but only when heated above 100C.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1687.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_NTCT_update,+ },+ [PT_SAND] = {+ .Identifier = "DEFAULT_PT_SAND",+ .Name = "SAND",+ .Colour = 0xFFD090,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.3f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 5,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 90,+ .HeatConduct = 150,+ .HeatCapacity = 1,+ .Description = "Sand, Heavy particles. Melts into glass.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1973.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_GLAS] = {+ .Identifier = "DEFAULT_PT_GLAS",+ .Name = "GLAS",+ .Colour = 0x404040,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 150,+ .HeatCapacity = 1,+ .Description = "Glass. Meltable. Shatters under pressure, and refracts photons.",+ .Properties = TYPE_SOLID | PROP_NEUTPASS | PROP_PHOTPASS | PROP_HOT_GLOW | PROP_SPARKSETTLE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1973.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_GLAS_update,+ .Create = el_GLAS_create,+ },+ [PT_PTCT] = {+ .Identifier = "DEFAULT_PT_PTCT",+ .Name = "PTCT",+ .Colour = 0x405050,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "PTC Thermistor. Conducts with PSCN and NSCN, but only when cooled below 100C.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1687.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PTCT_update,+ },+ [PT_BGLA] = {+ .Identifier = "DEFAULT_PT_BGLA",+ .Name = "BGLA",+ .Colour = 0x606060,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.3f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 5,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 90,+ .HeatConduct = 150,+ .HeatCapacity = 1,+ .Description = "Broken Glass, heavy particles formed when glass breaks under pressure. Meltable. Bagels.",+ .Properties = TYPE_PART | PROP_NEUTPASS | PROP_PHOTPASS | PROP_HOT_GLOW | PROP_DEADLY,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1973.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_THDR] = {+ .Identifier = "DEFAULT_PT_THDR",+ .Name = "THDR",+ .Colour = 0xFFFFA0,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.0f,+ .Loss = 0.30f,+ .Collision = -0.99f,+ .Gravity = 0.6f,+ .NewtonianGravity = 1,+ .Diffusion = 0.62f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 1,+ .HeatCapacity = 1,+ .Description = "Lightning! Very hot, inflicts damage upon most materials, and transfers current to metals.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 9000.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_THDR_update,+ .Graphics = el_THDR_graphics,+ },+ [PT_PLSM] = {+ .Identifier = "DEFAULT_PT_PLSM",+ .Name = "PLSM",+ .Colour = 0xBB99FF,+ .MenuVisible = 1,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 0.9f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.97f,+ .Loss = 0.20f,+ .Collision = 0.0f,+ .Gravity = -0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.30f,+ .HotAir = 0.001f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 5,+ .HeatCapacity = 1,+ .Description = "Plasma, extremely hot.",+ .Properties = TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = MAX_TEMP, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_FIRE_update,+ .Graphics = el_PLSM_graphics,+ .Create = el_PLSM_create,+ },+ [PT_ETRD] = {+ .Identifier = "DEFAULT_PT_ETRD",+ .Name = "ETRD",+ .Colour = 0x404040,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Electrode. Creates plasma arcs with electricity. (Use sparingly)",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .ChangeType = el_ETRD_changeType,+ },+ [PT_NICE] = {+ .Identifier = "DEFAULT_PT_NICE",+ .Name = "NICE",+ .Colour = 0xC0E0FF,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = -0.0005f* CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 46,+ .HeatCapacity = 1,+ .Description = "Nitrogen Ice. Very cold, will melt into LN2 when heated only slightly.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 63.1f,+ .HighTemperatureTransition = PT_LNTG,+ .DefaultProperties = {.temp = 35.0f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_NBLE] = {+ .Identifier = "DEFAULT_PT_NBLE",+ .Name = "NBLE",+ .Colour = 0xEB4917,+ .MenuVisible = 1,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 1.0f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.30f,+ .Collision = -0.1f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.75f,+ .HotAir = 0.001f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFF8000,+ .Weight = 1,+ .HeatConduct = 106,+ .HeatCapacity = 1,+ .Description = "Noble Gas. Ionizes into plasma when sparked. Diffuses.",+ .Properties = TYPE_GAS|PROP_CONDUCTS|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_NBLE_update,+ },+ [PT_BTRY] = {+ .Identifier = "DEFAULT_PT_BTRY",+ .Name = "BTRY",+ .Colour = 0x858505,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Battery. Generates infinite electricity.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 2273.0f,+ .HighTemperatureTransition = PT_PLSM,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_BTRY_update,+ },+ [PT_LCRY] = {+ .Identifier = "DEFAULT_PT_LCRY",+ .Name = "LCRY",+ .Colour = 0x505050,+ .MenuVisible = 1,+ .MenuSection = SC_POWERED,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Liquid Crystal. Changes colour when charged. (PSCN Charges, NSCN Discharges)",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1273.0f,+ .HighTemperatureTransition = PT_BGLA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_LCRY_update,+ .Graphics = el_LCRY_graphics,+ },+ [PT_STKM] = {+ .Identifier = "DEFAULT_PT_STKM",+ .Name = "STKM",+ .Colour = 0xFFE0A0,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.5f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.2f,+ .Loss = 1.0f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 0.0f,+ .Diffusion = 0.0f,+ .HotAir = 0.00f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 50,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Stickman. Don't kill him! Control with the arrow keys.",+ .Properties = PROP_NOCTYPEDRAW,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 620.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 14.6f + 273.15f, .life = 100, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_STKM_update,+ .Graphics = Element_STKM_graphics,+ .Create = el_STKM_create,+ .CreateAllowed = el_STKM_createAllowed,+ .ChangeType = el_STKM_changeType,+ },+ [PT_SWCH] = {+ .Identifier = "DEFAULT_PT_SWCH",+ .Name = "SWCH",+ .Colour = 0x103B11,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Switch. Only conducts when switched on. (PSCN switches on, NSCN switches off)",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SWCH_update,+ .Graphics = el_SWCH_graphics,+ },+ [PT_SMKE] = {+ .Identifier = "DEFAULT_PT_SMKE",+ .Name = "SMKE",+ .Colour = 0x222222,+ .MenuVisible = 1,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 0.9f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.97f,+ .Loss = 0.20f,+ .Collision = 0.0f,+ .Gravity = -0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.001f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 88,+ .HeatCapacity = 1,+ .Description = "Smoke, created by fire.",+ .Properties = TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 625.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 320.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Graphics = el_SMKE_graphics,+ },+ [PT_DESL] = {+ .Identifier = "DEFAULT_PT_DESL",+ .Name = "DESL",+ .Colour = 0x440000,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 1.0f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.0f,+ .HotAir = 0.0f * CFDS,+ .Falldown = 2,+ .Flammable = 2,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 5,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 15,+ .HeatConduct = 42,+ .HeatCapacity = 1,+ .Description = "Liquid diesel. Explodes under high pressure and temperatures.",+ .Properties = TYPE_LIQUID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 5.0f,+ .HighPressureTransition = PT_FIRE,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 335.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_COAL] = {+ .Identifier = "DEFAULT_PT_COAL",+ .Name = "COAL",+ .Colour = 0x222222,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.0f,+ .HotAir = 0.0f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 18,+ .PhotonReflectWavelengths = 0x00000000,+ .Weight = 100,+ .HeatConduct = 200,+ .HeatCapacity = 1,+ .Description = "Coal, Burns very slowly. Gets red when hot.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 110, .ctype = 0, .tmp = 50, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_COAL_update,+ .Graphics = Element_COAL_graphics,+ },+ [PT_LO2] = {+ .Identifier = "DEFAULT_PT_LO2",+ .Name = "LOXY",+ .Colour = 0x80A0EF,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 5000,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 30,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Liquid Oxygen. Very cold. Reacts with fire.",+ .Properties = TYPE_LIQUID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 90.1f,+ .HighTemperatureTransition = PT_O2,+ .DefaultProperties = {.temp = 80.0f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_O2] = {+ .Identifier = "DEFAULT_PT_O2",+ .Name = "OXYG",+ .Colour = 0x80A0FF,+ .MenuVisible = 1,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 2.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.30f,+ .Collision = -0.1f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 3.0f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Oxygen gas. Ignites easily.",+ .Properties = TYPE_GAS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 90.0f,+ .LowTemperatureTransition = PT_LO2,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_O2_update,+ },+ [PT_INWR] = {+ .Identifier = "DEFAULT_PT_INWR",+ .Name = "INWR",+ .Colour = 0x544141,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Insulated wire. Only conducts to PSCN, NSCN, WIFI, and SWCH.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1687.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_YEST] = {+ .Identifier = "DEFAULT_PT_YEST",+ .Name = "YEST",+ .Colour = 0xEEE0C0,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 15,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 31,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 80,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Yeast, grows when warm (~37C).",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 373.0f,+ .HighTemperatureTransition = PT_DYST,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_YEST_update,+ },+ [PT_DYST] = {+ .Identifier = "DEFAULT_PT_DYST",+ .Name = "DYST",+ .Colour = 0xBBB0A0,+ .MenuVisible = 0,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 20,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 30,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 80,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Dead Yeast.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 473.0f,+ .HighTemperatureTransition = PT_DUST,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_THRM] = {+ .Identifier = "DEFAULT_PT_THRM",+ .Name = "THRM",+ .Colour = 0xA08090,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.3f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 2,+ .Hardness = 2,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 90,+ .HeatConduct = 211,+ .HeatCapacity = 1,+ .Description = "Thermite. Burns into extremely hot molten metal.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_GLOW] = {+ .Identifier = "DEFAULT_PT_GLOW",+ .Name = "GLOW",+ .Colour = 0x445464,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.3f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.15f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 2,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 40,+ .HeatConduct = 44,+ .HeatCapacity = 1,+ .Description = "Glow, Glows under pressure.",+ .Properties = TYPE_LIQUID | PROP_PHOTPASS | PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 20.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_GLOW_update,+ .Graphics = el_GLOW_graphics,+ },+ [PT_BRCK] = {+ .Identifier = "DEFAULT_PT_BRCK",+ .Name = "BRCK",+ .Colour = 0x808080,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Brick, breakable building material.",+ .Properties = TYPE_SOLID|PROP_HOT_GLOW,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 8.8f,+ .HighPressureTransition = PT_STNE,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1223.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Graphics = el_BRCK_graphics,+ },+ [PT_CFLM] = {+ .Identifier = "DEFAULT_PT_HFLM",+ .Name = "CFLM",+ .Colour = 0x8080FF,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.9f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.97f,+ .Loss = 0.20f,+ .Collision = 0.0f,+ .Gravity = -0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.0005f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 2,+ .HeatConduct = 88,+ .HeatCapacity = 1,+ .Description = "Sub-zero flame.",+ .Properties = TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 0.0f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Graphics = el_CFLM_graphics,+ .Create = el_CFLM_create,+ },+ [PT_FIRW] = {+ .Identifier = "DEFAULT_PT_FIRW",+ .Name = "FIRW",+ .Colour = 0xFFA040,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.2f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 28,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 55,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Fireworks! Colorful, set off by fire.",+ .Properties = TYPE_PART|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_FIRW_update,+ .Graphics = el_FIRW_graphics,+ },+ [PT_FUSE] = {+ .Identifier = "DEFAULT_PT_FUSE",+ .Name = "FUSE",+ .Colour = 0x0A5706,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.0f,+ .HotAir = 0.0f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 19,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 200,+ .HeatCapacity = 1,+ .Description = "Burns slowly. Ignites at very high temperatures or when sparked.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 50, .ctype = 0, .tmp = 50, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_FUSE_update,+ },+ [PT_FSEP] = {+ .Identifier = "DEFAULT_PT_FSEP",+ .Name = "FSEP",+ .Colour = 0x63AD5F,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 27,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 70,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Fuse Powder. Burns slowly like FUSE.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 50, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_FSEP_update,+ },+ [PT_AMTR] = {+ .Identifier = "DEFAULT_PT_AMTR",+ .Name = "AMTR",+ .Colour = 0x808080,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.80f,+ .Collision = 0.00f,+ .Gravity = 0.10f,+ .NewtonianGravity = 1,+ .Diffusion = 1.00f,+ .HotAir = 0.0000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Anti-Matter, destroys a majority of particles.",+ .Properties = TYPE_GAS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_AMTR_update,+ .Graphics = el_AMTR_graphics,+ },+ [PT_BCOL] = {+ .Identifier = "DEFAULT_PT_BCOL",+ .Name = "BCOL",+ .Colour = 0x333333,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.3f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 2,+ .PhotonReflectWavelengths = 0x00000000,+ .Weight = 90,+ .HeatConduct = 150,+ .HeatCapacity = 1,+ .Description = "Broken Coal. Heavy particles, burns slowly.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 110, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_COAL_update,+ .Graphics = Element_COAL_graphics,+ },+ [PT_PCLN] = {+ .Identifier = "DEFAULT_PT_PCLN",+ .Name = "PCLN",+ .Colour = 0x3B3B0A,+ .MenuVisible = 1,+ .MenuSection = SC_POWERED,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Powered clone. When activated, duplicates any particles it touches.",+ .Properties = TYPE_SOLID | PROP_PHOTPASS | PROP_NOCTYPEDRAW,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PCLN_update,+ .Graphics = el_PCLN_graphics,+ .CtypeDraw = Element_PCLN_ctypeDraw,+ },+ [PT_HSWC] = {+ .Identifier = "DEFAULT_PT_HSWC",+ .Name = "HSWC",+ .Colour = 0x3B0A0A,+ .MenuVisible = 1,+ .MenuSection = SC_POWERED,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Heat switch. Conducts heat only when activated.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_HSWC_update,+ .Graphics = el_HSWC_graphics,+ },+ [PT_IRON] = {+ .Identifier = "DEFAULT_PT_IRON",+ .Name = "IRON",+ .Colour = 0x707070,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 49,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Rusts with salt, can be used for electrolysis of WATR.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1687.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_IRON_update,+ },+ [PT_MORT] = {+ .Identifier = "DEFAULT_PT_MORT",+ .Name = "MORT",+ .Colour = 0xE0E0E0,+ .MenuVisible = 0,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 1.00f,+ .Collision = -0.99f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.01f,+ .HotAir = 0.002f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = -1,+ .HeatConduct = 60,+ .HeatCapacity = 1,+ .Description = "Steam Train.",+ .Properties = TYPE_GAS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 4.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_MORT_update,+ },+ [PT_LIFE] = {+ .Identifier = "DEFAULT_PT_LIFE",+ .Name = "LIFE",+ .Colour = 0x0CAC00,+ .MenuVisible = 0,+ .MenuSection = SC_LIFE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 40,+ .HeatCapacity = 1,+ .Description = "Game Of Life! B3/S23",+ .Properties = TYPE_SOLID|PROP_LIFE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 9000.0f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Graphics = el_LIFE_graphics,+ .Create = el_LIFE_create,+ },+ [PT_DLAY] = {+ .Identifier = "DEFAULT_PT_DLAY",+ .Name = "DLAY",+ .Colour = 0x753590,+ .MenuVisible = 1,+ .MenuSection = SC_POWERED,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Conducts with temperature-dependent delay. (use HEAT/COOL).",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 4.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_DLAY_update,+ .Graphics = el_DLAY_graphics,+ },+ [PT_CO2] = {+ .Identifier = "DEFAULT_PT_CO2",+ .Name = "CO2",+ .Colour = 0x666666,+ .MenuVisible = 1,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 2.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.30f,+ .Collision = -0.1f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 1.0f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 88,+ .HeatCapacity = 1,+ .Description = "Carbon Dioxide. Heavy gas, drifts downwards. Carbonates water and turns to dry ice when cold.",+ .Properties = TYPE_GAS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 194.65f,+ .LowTemperatureTransition = PT_DRIC,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_CO2_update,+ },+ [PT_DRIC] = {+ .Identifier = "DEFAULT_PT_DRIC",+ .Name = "DRIC",+ .Colour = 0xE0E0E0,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = -0.0005f* CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 2,+ .HeatCapacity = 1,+ .Description = "Dry Ice, formed when CO2 is cooled.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 195.65f,+ .HighTemperatureTransition = PT_CO2,+ .DefaultProperties = {.temp = 172.65f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_CBNW] = {+ .Identifier = "DEFAULT_PT_CBNW",+ .Name = "BUBW",+ .Colour = 0x2030D0,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 30,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "Carbonated water. Slowly releases CO2.",+ .Properties = TYPE_LIQUID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_NEUTPENETRATE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 273.15f,+ .LowTemperatureTransition = PT_ICEI,+ .HighTemperature = 373.0f,+ .HighTemperatureTransition = PT_WTRV,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_CBNW_update,+ .Graphics = el_CBNW_graphics,+ },+ [PT_STOR] = {+ .Identifier = "DEFAULT_PT_STOR",+ .Name = "STOR",+ .Colour = 0x50DFDF,+ .MenuVisible = 1,+ .MenuSection = SC_POWERED,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Storage. Captures and stores a single particle. Releases when charged with PSCN, also passes to PIPE.",+ .Properties = TYPE_SOLID | PROP_NOCTYPEDRAW,+ .CarriesTypeIn = (1u << FIELD_CTYPE) | (1u << FIELD_TMP),+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_STOR_update,+ .Graphics = el_STOR_graphics,+ .CtypeDraw = el_STOR_ctypeDraw,+ },+ [PT_PVOD] = {+ .Identifier = "DEFAULT_PT_PVOD",+ .Name = "PVOD",+ .Colour = 0x792020,+ .MenuVisible = 1,+ .MenuSection = SC_POWERED,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Powered VOID. When activated, destroys entering particles.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PVOD_update,+ .Graphics = el_PVOD_graphics,+ .CtypeDraw = basicCtypeDraw,+ },+ [PT_CONV] = {+ .Identifier = "DEFAULT_PT_CONV",+ .Name = "CONV",+ .Colour = 0x0AAB0A,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Converter. Converts everything into whatever it first touches.",+ .Properties = TYPE_SOLID | PROP_NOCTYPEDRAW,+ .CarriesTypeIn = (1u << FIELD_CTYPE) | (1u << FIELD_TMP),+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_CONV_update,+ .CtypeDraw = ctypeDrawVInCtype,+ },+ [PT_CAUS] = {+ .Identifier = "DEFAULT_PT_CAUS",+ .Name = "CAUS",+ .Colour = 0x80FFA0,+ .MenuVisible = 1,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 2.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.30f,+ .Collision = -0.1f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 1.50f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Caustic Gas, acts like ACID.",+ .Properties = TYPE_GAS|PROP_DEADLY,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 75, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_CAUS_update,+ },+ [PT_LIGH] = {+ .Identifier = "DEFAULT_PT_LIGH",+ .Name = "LIGH",+ .Colour = 0xFFFFC0,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Lightning. Change the brush size to set the size of the lightning.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_LIGH_update,+ .Graphics = el_LIGH_graphics,+ .Create = el_LIGH_create,+ },+ [PT_TESC] = {+ .Identifier = "DEFAULT_PT_TESC",+ .Name = "TESC",+ .Colour = 0x707040,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Tesla coil! Creates lightning when sparked.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Create = el_TESC_create,+ },+ [PT_DEST] = {+ .Identifier = "DEFAULT_PT_DEST",+ .Name = "DEST",+ .Colour = 0xFF3311,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = -0.05f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.4f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 101,+ .HeatConduct = 150,+ .HeatCapacity = 1,+ .Description = "More destructive Bomb, can break through virtually anything.",+ .Properties = TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_DEST_update,+ .Graphics = el_DEST_graphics,+ },+ [PT_SPNG] = {+ .Identifier = "DEFAULT_PT_SPNG",+ .Name = "SPNG",+ .Colour = 0xFFBE30,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.00f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.00f,+ .Loss = 0.00f,+ .Collision = 0.00f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 20,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 31,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Sponge, absorbs water. Is not a moving solid.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 2730.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SPNG_update,+ .Graphics = el_SPNG_graphics,+ },+ [PT_RIME] = {+ .Identifier = "DEFAULT_PT_RIME",+ .Name = "RIME",+ .Colour = 0xCCCCCC,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.00f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.00f,+ .Loss = 0.00f,+ .Collision = 0.00f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 32,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 100,+ .HeatCapacity = 1,+ .Description = "Solid, created when steam cools rapidly and goes through deposition, skipping the liquid phase.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 273.15f,+ .HighTemperatureTransition = ST,+ .DefaultProperties = {.temp = -30.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_RIME_update,+ },+ [PT_FOG] = {+ .Identifier = "DEFAULT_PT_FOG",+ .Name = "FOG",+ .Colour = 0xAAAAAA,+ .MenuVisible = 1,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 0.8f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.4f,+ .Loss = 0.70f,+ .Collision = -0.1f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.99f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 30,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 100,+ .HeatCapacity = 1,+ .Description = "Fog, created when an electric current is passed through RIME.",+ .Properties = TYPE_GAS|PROP_LIFE_DEC,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 373.15f,+ .HighTemperatureTransition = PT_WTRV,+ .DefaultProperties = {.temp = 243.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_FOG_update,+ },+ [PT_BCLN] = {+ .Identifier = "DEFAULT_PT_BCLN",+ .Name = "BCLN",+ .Colour = 0xFFD040,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.97f,+ .Loss = 0.50f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 12,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Breakable Clone.",+ .Properties = TYPE_SOLID | PROP_PHOTPASS | PROP_LIFE_DEC | PROP_LIFE_KILL_DEC | PROP_NOCTYPEDRAW,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_BCLN_update,+ .CtypeDraw = ctypeDrawVInTmp,+ },+ [PT_LOVE] = {+ .Identifier = "DEFAULT_PT_LOVE",+ .Name = "LOVE",+ .Colour = 0xFF30FF,+ .MenuVisible = 0,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.0f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 40,+ .HeatCapacity = 1,+ .Description = "Love...",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 373.0f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_DEUT] = {+ .Identifier = "DEFAULT_PT_DEUT",+ .Name = "DEUT",+ .Colour = 0x00153F,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 19,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 31,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Deuterium oxide. Gets more concentrated when cold, explodes with neutrons or protons.",+ .Properties = TYPE_LIQUID|PROP_NEUTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 10, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_DEUT_update,+ .Graphics = el_DEUT_graphics,+ },+ [PT_WARP] = {+ .Identifier = "DEFAULT_PT_WARP",+ .Name = "WARP",+ .Colour = 0x101010,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.8f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.9f,+ .Loss = 0.70f,+ .Collision = -0.1f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 3.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 30,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 100,+ .HeatCapacity = 1,+ .Description = "Displaces other elements.",+ .Properties = TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_WARP_update,+ .Graphics = el_WARP_graphics,+ .Create = el_WARP_create,+ },+ [PT_PUMP] = {+ .Identifier = "DEFAULT_PT_PUMP",+ .Name = "PUMP",+ .Colour = 0x0A0A3B,+ .MenuVisible = 1,+ .MenuSection = SC_POWERED,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 9,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Pressure pump. Changes pressure to its temp when activated. (use HEAT/COOL).",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 273.15f, .life = 10, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PUMP_update,+ .Graphics = el_PUMP_graphics,+ },+ [PT_FWRK] = {+ .Identifier = "DEFAULT_PT_FWRK",+ .Name = "FWRK",+ .Colour = 0x666666,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.4f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 97,+ .HeatConduct = 100,+ .HeatCapacity = 1,+ .Description = "Original version of fireworks, activated by heat/neutrons.",+ .Properties = TYPE_PART|PROP_LIFE_DEC,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_FWRK_update,+ },+ [PT_PIPE] = {+ .Identifier = "DEFAULT_PT_PIPE",+ .Name = "PIPE",+ .Colour = 0x444444,+ .MenuVisible = 1,+ .MenuSection = SC_FORCE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "PIPE, moves particles around. Once the BRCK generates, erase some for the exit. Then the PIPE generates and is usable.",+ .Properties = TYPE_SOLID | PROP_LIFE_DEC,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 10.0f,+ .HighPressureTransition = PT_BRMT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 295.15f, .life = 60, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_PIPE_update,+ .Graphics = Element_PIPE_graphics,+ },+ [PT_FRZZ] = {+ .Identifier = "DEFAULT_PT_FRZZ",+ .Name = "FRZZ",+ .Colour = 0xC0E0FF,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.90f,+ .Collision = -0.1f,+ .Gravity = 0.05f,+ .NewtonianGravity = 1,+ .Diffusion = 0.01f,+ .HotAir = -0.00005f* CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 50,+ .HeatConduct = 46,+ .HeatCapacity = 1,+ .Description = "Freeze powder. When melted, forms ice that always cools. Spreads with regular water.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 1.8f,+ .HighPressureTransition = PT_SNOW,+ .LowTemperature = 50.0f,+ .LowTemperatureTransition = PT_ICEI,+ .HighTemperature = 273.15f,+ .HighTemperatureTransition = PT_FRZW,+ .DefaultProperties = {.temp = 253.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_FRZZ_update,+ },+ [PT_FRZW] = {+ .Identifier = "DEFAULT_PT_FRZW",+ .Name = "FRZW",+ .Colour = 0x1020C0,+ .MenuVisible = 0,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 30,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "Freeze water. Hybrid liquid formed when Freeze powder melts.",+ .Properties = TYPE_LIQUID | PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 53.0f,+ .LowTemperatureTransition = PT_ICEI,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 120.0f, .life = 100, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_FRZW_update,+ },+ [PT_GRAV] = {+ .Identifier = "DEFAULT_PT_GRAV",+ .Name = "GRAV",+ .Colour = 0x202020,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 1.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 10,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 30,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 85,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Very light dust. Changes colour based on velocity.",+ .Properties = TYPE_PART | PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_GRAV_update,+ .Graphics = el_GRAV_graphics,+ },+ [PT_BIZR] = {+ .Identifier = "DEFAULT_PT_BIZR",+ .Name = "BIZR",+ .Colour = 0x00FF77,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 30,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "Bizarre... contradicts the normal state changes. Paints other elements with its deco color.",+ .Properties = TYPE_LIQUID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 100.0f,+ .LowTemperatureTransition = PT_BIZRG,+ .HighTemperature = 400.0f,+ .HighTemperatureTransition = PT_BIZRS,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0x47FFFF, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_BIZR_update,+ .Graphics = Element_BIZR_graphics,+ },+ [PT_BIZRG] = {+ .Identifier = "DEFAULT_PT_BIZRG",+ .Name = "BIZG",+ .Colour = 0x00FFBB,+ .MenuVisible = 0,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 1.0f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.30f,+ .Collision = -0.1f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 2.75f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 42,+ .HeatCapacity = 1,+ .Description = "Bizarre gas.",+ .Properties = TYPE_GAS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 100.0f,+ .HighTemperatureTransition = PT_BIZR,+ .DefaultProperties = {.temp = R_TEMP - 200.0f + 273.15f, .life = 0, .ctype = 0x47FFFF, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_BIZR_update,+ .Graphics = Element_BIZR_graphics,+ },+ [PT_BIZRS] = {+ .Identifier = "DEFAULT_PT_BIZRS",+ .Name = "BIZS",+ .Colour = 0x00E455,+ .MenuVisible = 0,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Bizarre solid.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 400.0f,+ .LowTemperatureTransition = PT_BIZR,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 300.0f + 273.15f, .life = 0, .ctype = 0x47FFFF, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_BIZR_update,+ .Graphics = Element_BIZR_graphics,+ },+ [PT_INST] = {+ .Identifier = "DEFAULT_PT_INST",+ .Name = "INST",+ .Colour = 0x404039,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Instantly conducts, PSCN to charge, NSCN to take.",+ .Properties = TYPE_SOLID|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_ISOZ] = {+ .Identifier = "DEFAULT_PT_ISOZ",+ .Name = "ISOZ",+ .Colour = 0xAA30D0,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 24,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "Isotope-Z. Radioactive liquid, decays into photons when touching PHOT or under negative pressure.",+ .Properties = TYPE_LIQUID | PROP_NEUTPENETRATE | PROP_PHOTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 160.0f,+ .LowTemperatureTransition = PT_ISZS,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_ISOZ_update,+ },+ [PT_ISZS] = {+ .Identifier = "DEFAULT_PT_ISZS",+ .Name = "ISZS",+ .Colour = 0x662089,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = -0.0007f* CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Solid form of ISOZ, slowly decays into PHOT.",+ .Properties = TYPE_SOLID | PROP_PHOTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 300.0f,+ .HighTemperatureTransition = PT_ISOZ,+ .DefaultProperties = {.temp = 140.00f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_ISZS_update,+ },+ [PT_PRTI] = {+ .Identifier = "DEFAULT_PT_PRTI",+ .Name = "PRTI",+ .Colour = 0xEB5917,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = -0.005f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Portal IN. Particles go in here. Also has temperature dependent channels. (same as WIFI)",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PRTI_update,+ .Graphics = el_PRTI_graphics,+ },+ [PT_PRTO] = {+ .Identifier = "DEFAULT_PT_PRTO",+ .Name = "PRTO",+ .Colour = 0x0020EB,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.005f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Portal OUT. Particles come out here. Also has temperature dependent channels. (same as WIFI)",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PRTO_update,+ .Graphics = el_PRTO_graphics,+ },+ [PT_PSTE] = {+ .Identifier = "DEFAULT_PT_PSTE",+ .Name = "PSTE",+ .Colour = 0xAA99AA,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 18,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 31,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "Colloid, Hardens under pressure.",+ .Properties = TYPE_LIQUID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 0.5f,+ .HighPressureTransition = PT_PSTS,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 747.0f,+ .HighTemperatureTransition = PT_BRCK,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_PSTS] = {+ .Identifier = "DEFAULT_PT_PSTS",+ .Name = "PSTS",+ .Colour = 0x776677,+ .MenuVisible = 0,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 18,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "Solid form of PSTE.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = 0.5f,+ .LowPressureTransition = PT_PSTE,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_ANAR] = {+ .Identifier = "DEFAULT_PT_ANAR",+ .Name = "ANAR",+ .Colour = 0xFFFFEE,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = -0.7f,+ .AirDrag = -0.02f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.80f,+ .Collision = 0.1f,+ .Gravity = -0.1f,+ .NewtonianGravity = -1.f,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 29,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 85,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Anti-air. Very light gravity-defying dust. Burns cold instead of hot.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_ANAR_update,+ },+ [PT_VINE] = {+ .Identifier = "DEFAULT_PT_VINE",+ .Name = "VINE",+ .Colour = 0x079A00,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 20,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 10,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 65,+ .HeatCapacity = 1,+ .Description = "Vine, can grow along WOOD.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 573.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 1, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_VINE_update,+ .Graphics = el_VINE_graphics,+ },+ [PT_INVIS] = {+ .Identifier = "DEFAULT_PT_INVIS",+ .Name = "INVS",+ .Colour = 0x00CCCC,+ .MenuVisible = 1,+ .MenuSection = SC_SENSOR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 15,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 164,+ .HeatCapacity = 1,+ .Description = "Invisible under pressure, allowing particles through.",+ .Properties = TYPE_SOLID | PROP_NEUTPASS | PROP_PHOTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_INVIS_update,+ .Graphics = el_INVIS_graphics,+ },+ [PT_E116] = {+ .Identifier = "DEFAULT_PT_116",+ .Name = "EQVE",+ .Colour = 0xFFE0A0,+ .MenuVisible = 0,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 30,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 85,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "A failed shared velocity test.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_SPAWN2] = {+ .Identifier = "DEFAULT_PT_SPAWN2",+ .Name = "SPWN2",+ .Colour = 0xAAAAAA,+ .MenuVisible = 0,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "STK2 spawn point.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .CreateAllowed = el_SPAWN2_createAllowed,+ .ChangeType = el_SPAWN2_changeType,+ },+ [PT_SPAWN] = {+ .Identifier = "DEFAULT_PT_SPAWN",+ .Name = "SPWN",+ .Colour = 0xAAAAAA,+ .MenuVisible = 0,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "STKM spawn point.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .CreateAllowed = el_SPAWN_createAllowed,+ .ChangeType = el_SPAWN_changeType,+ },+ [PT_SHLD1] = {+ .Identifier = "DEFAULT_PT_SHLD1",+ .Name = "SHLD",+ .Colour = 0xAAAAAA,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Shield. Grows around spark, broken by pressure.",+ .Properties = TYPE_SOLID|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 7.0f,+ .HighPressureTransition = PT_NONE,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SHLD1_update,+ },+ [PT_SHLD2] = {+ .Identifier = "DEFAULT_PT_SHLD2",+ .Name = "SHD2",+ .Colour = 0x777777,+ .MenuVisible = 0,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Shield lvl 2.",+ .Properties = TYPE_SOLID|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 15.0f,+ .HighPressureTransition = PT_NONE,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SHLD2_update,+ },+ [PT_SHLD3] = {+ .Identifier = "DEFAULT_PT_SHLD3",+ .Name = "SHD3",+ .Colour = 0x444444,+ .MenuVisible = 0,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Shield lvl 3.",+ .Properties = TYPE_SOLID|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 25.0f,+ .HighPressureTransition = PT_NONE,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SHLD3_update,+ },+ [PT_SHLD4] = {+ .Identifier = "DEFAULT_PT_SHLD4",+ .Name = "SHD4",+ .Colour = 0x212121,+ .MenuVisible = 0,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Shield lvl 4.",+ .Properties = TYPE_SOLID|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 40.0f,+ .HighPressureTransition = PT_NONE,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SHLD4_update,+ },+ [PT_LOLZ] = {+ .Identifier = "DEFAULT_PT_LOLZ",+ .Name = "LOLZ",+ .Colour = 0x569212,+ .MenuVisible = 0,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.0f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 40,+ .HeatCapacity = 1,+ .Description = "Lolz",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 373.0f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_WIFI] = {+ .Identifier = "DEFAULT_PT_WIFI",+ .Name = "WIFI",+ .Colour = 0x40A060,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 2,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Wireless transmitter, transfers spark to any other wifi on the same temperature channel.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 15.0f,+ .HighPressureTransition = PT_BRMT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_WIFI_update,+ .Graphics = el_WIFI_graphics,+ },+ [PT_FILT] = {+ .Identifier = "DEFAULT_PT_FILT",+ .Name = "FILT",+ .Colour = 0x000056,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Filter. Changes color of PHOT and BIZR. Color depends on temperature.",+ .Properties = TYPE_SOLID | PROP_PHOTPASS | PROP_NOAMBHEAT | PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Graphics = el_FILT_graphics,+ .Create = el_FILT_create,+ },+ [PT_ARAY] = {+ .Identifier = "DEFAULT_PT_ARAY",+ .Name = "ARAY",+ .Colour = 0xFFBB00,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Ray Emitter. Rays create points when they collide.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_ARAY_update,+ },+ [PT_BRAY] = {+ .Identifier = "DEFAULT_PT_BRAY",+ .Name = "BRAY",+ .Colour = 0xFFFFFF,+ .MenuVisible = 0,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Ray Point. Rays create points when they collide.",+ .Properties = TYPE_SOLID|PROP_LIFE_DEC|PROP_LIFE_KILL,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 30, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Graphics = el_BRAY_graphics,+ },+ [PT_STKM2] = {+ .Identifier = "DEFAULT_PT_STKM2",+ .Name = "STK2",+ .Colour = 0x6464FF,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.5f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.2f,+ .Loss = 1.0f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 0.0f,+ .Diffusion = 0.0f,+ .HotAir = 0.00f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 50,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Second stickman. Don't kill him! Control with wasd.",+ .Properties = PROP_NOCTYPEDRAW,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 620.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 14.6f + 273.15f, .life = 100, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_STKM2_update,+ .Graphics = Element_STKM_graphics,+ .Create = el_STKM2_create,+ .CreateAllowed = el_STKM2_createAllowed,+ .ChangeType = el_STKM2_changeType,+ },+ [PT_BOMB] = {+ .Identifier = "DEFAULT_PT_BOMB",+ .Name = "BOMB",+ .Colour = 0xFFF288,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 30,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "Bomb. Explodes and destroys all surrounding particles when it touches something.",+ .Properties = TYPE_PART|PROP_SPARKSETTLE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_BOMB_update,+ .Graphics = el_BOMB_graphics,+ },+ [PT_C5] = {+ .Identifier = "DEFAULT_PT_C5",+ .Name = "C-5",+ .Colour = 0x2050E0,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 88,+ .HeatCapacity = 1,+ .Description = "Cold explosive, set off by anything cold.",+ .Properties = TYPE_SOLID | PROP_NEUTPENETRATE | PROP_PHOTPASS | PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_C5_update,+ .Graphics = el_C5_graphics,+ },+ [PT_SING] = {+ .Identifier = "DEFAULT_PT_SING",+ .Name = "SING",+ .Colour = 0x242424,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.36f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.80f,+ .Collision = 0.1f,+ .Gravity = 0.12f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = -0.001f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 86,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Singularity. Creates huge amounts of negative pressure and destroys everything.",+ .Properties = TYPE_PART|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SING_update,+ .Create = el_SING_create,+ },+ [PT_QRTZ] = {+ .Identifier = "DEFAULT_PT_QRTZ",+ .Name = "QRTZ",+ .Colour = 0xAADDDD,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 3,+ .HeatCapacity = 1,+ .Description = "Quartz, breakable mineral. Conducts but becomes brittle when cold. Scatters photons.",+ .Properties = TYPE_SOLID | PROP_PHOTPASS | PROP_HOT_GLOW | PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 2573.15f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_QRTZ_update,+ .Graphics = Element_QRTZ_graphics,+ .Create = el_QRTZ_create,+ },+ [PT_PQRT] = {+ .Identifier = "DEFAULT_PT_PQRT",+ .Name = "PQRT",+ .Colour = 0x88BBBB,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.27f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 90,+ .HeatConduct = 3,+ .HeatCapacity = 1,+ .Description = "Powdered quartz, broken form of QRTZ.",+ .Properties = TYPE_PART | PROP_PHOTPASS | PROP_HOT_GLOW,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 2573.15f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_QRTZ_update,+ .Graphics = Element_QRTZ_graphics,+ .Create = el_PQRT_create,+ },+ [PT_EMP] = {+ .Identifier = "DEFAULT_PT_EMP",+ .Name = "EMP",+ .Colour = 0x66AAFF,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.0f,+ .HotAir = 0.0f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 3,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 121,+ .HeatCapacity = 1,+ .Description = "Electromagnetic pulse. Breaks activated electronics.",+ .Properties = TYPE_SOLID|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Graphics = el_EMP_graphics,+ },+ [PT_BREC] = {+ .Identifier = "DEFAULT_PT_BREC",+ .Name = "BREL",+ .Colour = 0x707060,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.18f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 2,+ .Hardness = 2,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 90,+ .HeatConduct = 211,+ .HeatCapacity = 1,+ .Description = "Broken electronics. Formed from EMP blasts, and when constantly sparked while under pressure, turns to EXOT.",+ .Properties = TYPE_PART|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_BREC_update,+ },+ [PT_ELEC] = {+ .Identifier = "DEFAULT_PT_ELEC",+ .Name = "ELEC",+ .Colour = 0xDFEFFF,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 1.00f,+ .Collision = -0.99f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = -1,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Electrons. Sparks electronics, reacts with NEUT and WATR.",+ .Properties = TYPE_ENERGY|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 200.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_ELEC_update,+ .Graphics = el_ELEC_graphics,+ .Create = el_ELEC_create,+ },+ [PT_ACEL] = {+ .Identifier = "DEFAULT_PT_ACEL",+ .Name = "ACEL",+ .Colour = 0x0099CC,+ .MenuVisible = 1,+ .MenuSection = SC_FORCE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Accelerator, speeds up nearby elements.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_ACEL_update,+ .Graphics = el_ACEL_graphics,+ },+ [PT_DCEL] = {+ .Identifier = "DEFAULT_PT_DCEL",+ .Name = "DCEL",+ .Colour = 0x99CC00,+ .MenuVisible = 1,+ .MenuSection = SC_FORCE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Decelerator, slows down nearby elements.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_DCEL_update,+ .Graphics = el_DCEL_graphics,+ },+ [PT_BANG] = {+ .Identifier = "DEFAULT_PT_BANG",+ .Name = "TNT",+ .Colour = 0xC05050,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 88,+ .HeatCapacity = 1,+ .Description = "TNT, explodes all at once.",+ .Properties = TYPE_SOLID | PROP_NEUTPENETRATE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_BANG_update,+ },+ [PT_IGNT] = {+ .Identifier = "DEFAULT_PT_IGNT",+ .Name = "IGNC",+ .Colour = 0xC0B050,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 88,+ .HeatCapacity = 1,+ .Description = "Ignition cord. Burns slowly with fire and sparks.",+ .Properties = TYPE_SOLID | PROP_NEUTPENETRATE | PROP_SPARKSETTLE | PROP_LIFE_KILL,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 673.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 3, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_IGNT_update,+ },+ [PT_BOYL] = {+ .Identifier = "DEFAULT_PT_BOYL",+ .Name = "BOYL",+ .Colour = 0x0A3200,+ .MenuVisible = 1,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 1.0f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.30f,+ .Collision = -0.1f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.18f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 42,+ .HeatCapacity = 1,+ .Description = "Boyle, variable pressure gas. Expands when heated.",+ .Properties = TYPE_GAS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_BOYL_update,+ },+ [PT_GEL] = {+ .Identifier = "DEFAULT_PT_GEL",+ .Name = "GEL",+ .Colour = 0xFF9900,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 19,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 35,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "A liquid with variable viscosity and heat conductivity. Absorbs water.",+ .Properties = TYPE_LIQUID|PROP_LIFE_DEC|PROP_NEUTPENETRATE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_GEL_update,+ .Graphics = el_GEL_graphics,+ },+ [PT_TRON] = {+ .Identifier = "DEFAULT_PT_TRON",+ .Name = "TRON",+ .Colour = 0xA9FF00,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 40,+ .HeatCapacity = 1,+ .Description = "Smart particles, Travels in straight lines and avoids obstacles. Grows with time.",+ .Properties = TYPE_SOLID|PROP_LIFE_DEC|PROP_LIFE_KILL,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 0.0f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_TRON_update,+ .Graphics = el_TRON_graphics,+ .Create = el_TRON_create,+ },+ [PT_TTAN] = {+ .Identifier = "DEFAULT_PT_TTAN",+ .Name = "TTAN",+ .Colour = 0x909090,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 48,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Titanium. Higher melting temperature than most other metals, blocks all air pressure.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_HOT_GLOW|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1941.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_TTAN_update,+ },+ [PT_EXOT] = {+ .Identifier = "DEFAULT_PT_EXOT",+ .Name = "EXOT",+ .Colour = 0x247BFE,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.3f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.15f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.0003f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 2,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 46,+ .HeatConduct = 250,+ .HeatCapacity = 1,+ .Description = "Exotic matter. Explodes with excess exposure to electrons. Has many other odd reactions.",+ .Properties = TYPE_LIQUID|PROP_NEUTPASS,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 1000, .ctype = 0, .tmp = 244, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_EXOT_update,+ .Graphics = el_EXOT_graphics,+ },+ [PT_EMBR] = {+ .Identifier = "DEFAULT_PT_EMBR",+ .Name = "EMBR",+ .Colour = 0xFFF288,+ .MenuVisible = 0,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.001f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.90f,+ .Collision = 0.0f,+ .Gravity = 0.07f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 21,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 30,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "Sparks. Formed by explosions.",+ .Properties = TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL|PROP_SPARKSETTLE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 500.0f + 273.15f, .life = 50, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_EMBR_update,+ .Graphics = el_EMBR_graphics,+ },+ [PT_H2] = {+ .Identifier = "DEFAULT_PT_H2",+ .Name = "HYGN",+ .Colour = 0x5070FF,+ .MenuVisible = 1,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 2.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.30f,+ .Collision = -0.10f,+ .Gravity = 0.00f,+ .NewtonianGravity = 1,+ .Diffusion = 3.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Hydrogen. Combusts with OXYG to make WATR. Undergoes fusion at high temperature and pressure.",+ .Properties = TYPE_GAS | PROP_PHOTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_H2_update,+ },+ [PT_SOAP] = {+ .Identifier = "DEFAULT_PT_SOAP",+ .Name = "SOAP",+ .Colour = 0xF5F5DC,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 19,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 35,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "Soap. Creates bubbles, washes off deco color, and cures virus.",+ .Properties = TYPE_LIQUID|PROP_NEUTPENETRATE|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = -1, .tmp2 = -1, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SOAP_update,+ .Graphics = el_SOAP_graphics,+ .ChangeType = el_SOAP_changeType,+ },+ [PT_NBHL] = {+ .Identifier = "DEFAULT_PT_NBHL",+ .Name = "BHOL",+ .Colour = 0x202020,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 186,+ .HeatCapacity = 1,+ .Description = "Black hole, sucks in particles using gravity. (Requires Newtonian gravity)",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_NBHL_update,+ },+ [PT_NWHL] = {+ .Identifier = "DEFAULT_PT_NWHL",+ .Name = "WHOL",+ .Colour = 0xFFFFFF,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 186,+ .HeatCapacity = 1,+ .Description = "White hole, pushes away other particles with gravity. (Requires Newtonian gravity)",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_NWHL_update,+ },+ [PT_MERC] = {+ .Identifier = "DEFAULT_PT_MERC",+ .Name = "MERC",+ .Colour = 0x736B6D,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.3f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 18,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 91,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Mercury. Volume changes with temperature, Conductive.",+ .Properties = TYPE_LIQUID|PROP_CONDUCTS|PROP_NEUTABSORB|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 10, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_MERC_update,+ },+ [PT_PBCN] = {+ .Identifier = "DEFAULT_PT_PBCN",+ .Name = "PBCN",+ .Colour = 0x3B1D0A,+ .MenuVisible = 1,+ .MenuSection = SC_POWERED,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.97f,+ .Loss = 0.50f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 12,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Powered breakable clone.",+ .Properties = TYPE_SOLID | PROP_PHOTPASS | PROP_NOCTYPEDRAW,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PBCN_update,+ .Graphics = el_PBCN_graphics,+ .CtypeDraw = Element_PCLN_ctypeDraw,+ },+ [PT_GPMP] = {+ .Identifier = "DEFAULT_PT_GPMP",+ .Name = "GPMP",+ .Colour = 0x0A3B3B,+ .MenuVisible = 1,+ .MenuSection = SC_POWERED,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Gravity pump. Changes gravity to its temp when activated. (use HEAT/COOL)",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 10, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_GPMP_update,+ .Graphics = el_GPMP_graphics,+ },+ [PT_CLST] = {+ .Identifier = "DEFAULT_PT_CLST",+ .Name = "CLST",+ .Colour = 0xE4A4A4,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.2f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 2,+ .Hardness = 2,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 55,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Clay dust. Produces paste when mixed with water.",+ .Properties = TYPE_PART,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1256.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_CLST_update,+ .Graphics = el_CLST_graphics,+ .Create = el_CLST_create,+ },+ [PT_WIRE] = {+ .Identifier = "DEFAULT_PT_WIRE",+ .Name = "WWLD",+ .Colour = 0xFFCC00,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 250,+ .HeatCapacity = 1,+ .Description = "WireWorld wires, conducts based on a set of GOL-like rules.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_WIRE_update,+ .Graphics = el_WIRE_graphics,+ },+ [PT_GBMB] = {+ .Identifier = "DEFAULT_PT_GBMB",+ .Name = "GBMB",+ .Colour = 0x1144BB,+ .MenuVisible = 1,+ .MenuSection = SC_FORCE,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 30,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "Gravity bomb. Sticks to the first object it touches then produces a strong gravity push.",+ .Properties = TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_GBMB_update,+ .Graphics = el_GBMB_graphics,+ },+ [PT_FIGH] = {+ .Identifier = "DEFAULT_PT_FIGH",+ .Name = "FIGH",+ .Colour = 0xFFE0A0,+ .MenuVisible = 1,+ .MenuSection = SC_SPECIAL,+ .Enabled = 1,+ .Advection = 0.5f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.2f,+ .Loss = 1.0f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 0.0f,+ .Diffusion = 0.0f,+ .HotAir = 0.00f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 50,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Fighter. Tries to kill stickmen. You must first give it an element to kill him with.",+ .Properties = PROP_NOCTYPEDRAW,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 620.0f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 14.6f + 273.15f, .life = 100, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_FIGH_update,+ .Graphics = Element_STKM_graphics,+ .CreateAllowed = el_FIGH_createAllowed,+ .ChangeType = el_FIGH_changeType,+ },+ [PT_FRAY] = {+ .Identifier = "DEFAULT_PT_FRAY",+ .Name = "FRAY",+ .Colour = 0x00BBFF,+ .MenuVisible = 1,+ .MenuSection = SC_FORCE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Force Emitter. Pushes or pulls objects based on its temperature. Use like ARAY.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 20.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_FRAY_update,+ },+ [PT_RPEL] = {+ .Identifier = "DEFAULT_PT_RPEL",+ .Name = "RPEL",+ .Colour = 0x99CC00,+ .MenuVisible = 1,+ .MenuSection = SC_FORCE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Repels or attracts particles based on its temperature.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 20.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_RPEL_update,+ .CtypeDraw = basicCtypeDraw,+ },+ [PT_PPIP] = {+ .Identifier = "DEFAULT_PT_PPIP",+ .Name = "PPIP",+ .Colour = 0x444466,+ .MenuVisible = 1,+ .MenuSection = SC_POWERED,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Powered version of PIPE, use PSCN/NSCN to Activate/Deactivate.",+ .Properties = TYPE_SOLID | PROP_LIFE_DEC,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 295.15f, .life = 60, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_PIPE_update,+ .Graphics = Element_PIPE_graphics,+ },+ [PT_DTEC] = {+ .Identifier = "DEFAULT_PT_DTEC",+ .Name = "DTEC",+ .Colour = 0xFD9D18,+ .MenuVisible = 1,+ .MenuSection = SC_SENSOR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Detector, creates a spark when something with its ctype is nearby.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 2, .tmp3 = 0, .tmp4 = 0},+ .Update = el_DTEC_update,+ .CtypeDraw = ctypeDrawVInTmp,+ },+ [PT_DMG] = {+ .Identifier = "DEFAULT_PT_DMG",+ .Name = "DMG",+ .Colour = 0x88FF88,+ .MenuVisible = 1,+ .MenuSection = SC_FORCE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 30,+ .HeatConduct = 29,+ .HeatCapacity = 1,+ .Description = "Generates damaging pressure and breaks any elements it hits.",+ .Properties = TYPE_PART|PROP_SPARKSETTLE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP - 2.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_DMG_update,+ .Graphics = el_DMG_graphics,+ },+ [PT_TSNS] = {+ .Identifier = "DEFAULT_PT_TSNS",+ .Name = "TSNS",+ .Colour = 0xFD00D5,+ .MenuVisible = 1,+ .MenuSection = SC_SENSOR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Temperature sensor, creates a spark when there's a nearby particle with a greater temperature.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 2, .tmp3 = 0, .tmp4 = 0},+ .Update = el_TSNS_update,+ },+ [PT_VIBR] = {+ .Identifier = "DEFAULT_PT_VIBR",+ .Name = "VIBR",+ .Colour = 0x005000,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.85f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Vibranium. Stores energy and releases it in violent explosions.",+ .Properties = TYPE_SOLID|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_VIBR_update,+ .Graphics = Element_VIBR_graphics,+ },+ [PT_BVBR] = {+ .Identifier = "DEFAULT_PT_BVBR",+ .Name = "BVBR",+ .Colour = 0x005000,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.3f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.95f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.15f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.0000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 67,+ .HeatConduct = 164,+ .HeatCapacity = 1,+ .Description = "Broken vibranium.",+ .Properties = TYPE_PART|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_VIBR_update,+ .Graphics = Element_VIBR_graphics,+ },+ [PT_CRAY] = {+ .Identifier = "DEFAULT_PT_CRAY",+ .Name = "CRAY",+ .Colour = 0xBBFF00,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Particle Ray Emitter. Creates a beam of particles set by its ctype, with a range set by tmp.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_CRAY_update,+ .CtypeDraw = el_CRAY_ctypeDraw,+ },+ [PT_PSTN] = {+ .Identifier = "DEFAULT_PT_PSTN",+ .Name = "PSTN",+ .Colour = 0xAA9999,+ .MenuVisible = 1,+ .MenuSection = SC_FORCE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Piston, pushes particles. PSCN extends, NSCN retracts",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 10.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PSTN_update,+ .Graphics = el_PSTN_graphics,+ .CtypeDraw = el_PSTN_ctypeDraw,+ },+ [PT_FRME] = {+ .Identifier = "DEFAULT_PT_FRME",+ .Name = "FRME",+ .Colour = 0x999988,+ .MenuVisible = 1,+ .MenuSection = SC_FORCE,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Frame, can be used with pistons to push many particles.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Graphics = el_FRME_graphics,+ },+ [PT_GOLD] = {+ .Identifier = "DEFAULT_PT_GOLD",+ .Name = "GOLD",+ .Colour = 0xDCAD2C,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3C038100,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Corrosion resistant metal, will reverse corrosion of iron. Excellent conductor.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_HOT_GLOW|PROP_LIFE_DEC|PROP_NEUTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1337.0f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_GOLD_update,+ .Graphics = el_GOLD_graphics,+ },+ [PT_TUNG] = {+ .Identifier = "DEFAULT_PT_TUNG",+ .Name = "TUNG",+ .Colour = 0x505050,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Tungsten. Brittle metal with a very high melting point.",+ .Properties = TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 3695.0f,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_TUNG_update,+ .Graphics = el_TUNG_graphics,+ .Create = el_TUNG_create,+ },+ [PT_PSNS] = {+ .Identifier = "DEFAULT_PT_PSNS",+ .Name = "PSNS",+ .Colour = 0xDB2020,+ .MenuVisible = 1,+ .MenuSection = SC_SENSOR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Pressure sensor, creates a spark when the pressure is greater than its temperature.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 4.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PSNS_update,+ },+ [PT_PROT] = {+ .Identifier = "DEFAULT_PT_PROT",+ .Name = "PROT",+ .Colour = 0x990000,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 1.00f,+ .Collision = -.99f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = -1,+ .HeatConduct = 61,+ .HeatCapacity = 1,+ .Description = "Protons. Transfer heat to materials, and remove sparks.",+ .Properties = TYPE_ENERGY,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 75, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PROT_update,+ .Graphics = el_PROT_graphics,+ .Create = el_PROT_create,+ },+ [PT_VIRS] = {+ .Identifier = "DEFAULT_PT_VIRS",+ .Name = "VIRS",+ .Colour = 0xFE11F6,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 20,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 31,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Virus. Turns everything it touches into virus.",+ .Properties = TYPE_LIQUID|PROP_DEADLY,+ .CarriesTypeIn = 1u << FIELD_TMP2,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 305.0f,+ .LowTemperatureTransition = PT_VRSS,+ .HighTemperature = 673.0f,+ .HighTemperatureTransition = PT_VRSG,+ .DefaultProperties = {.temp = 72.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 250},+ .Update = Element_VIRS_update,+ .Graphics = el_VIRS_graphics,+ },+ [PT_VRSS] = {+ .Identifier = "DEFAULT_PT_VRSS",+ .Name = "VRSS",+ .Colour = 0xD408CD,+ .MenuVisible = 0,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Solid Virus. Turns everything it touches into virus.",+ .Properties = TYPE_SOLID|PROP_DEADLY,+ .CarriesTypeIn = 1u << FIELD_TMP2,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 305.0f,+ .HighTemperatureTransition = PT_VIRS,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 250},+ .Update = Element_VIRS_update,+ .Graphics = el_VRSS_graphics,+ },+ [PT_VRSG] = {+ .Identifier = "DEFAULT_PT_VRSG",+ .Name = "VRSG",+ .Colour = 0xFE68FE,+ .MenuVisible = 0,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 1.0f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.30f,+ .Collision = -0.1f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.75f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 500,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Gas Virus. Turns everything it touches into virus.",+ .Properties = TYPE_GAS|PROP_DEADLY,+ .CarriesTypeIn = 1u << FIELD_TMP2,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = 673.0f,+ .LowTemperatureTransition = PT_VIRS,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 522.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 250},+ .Update = Element_VIRS_update,+ .Graphics = el_VRSG_graphics,+ },+ [PT_GRVT] = {+ .Identifier = "DEFAULT_PT_GRVT",+ .Name = "GRVT",+ .Colour = 0x00EE76,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 1.00f,+ .Loss = 1.00f,+ .Collision = -.99f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = -1,+ .HeatConduct = 61,+ .HeatCapacity = 1,+ .Description = "Gravitons. Create Newtonian Gravity.",+ .Properties = TYPE_ENERGY|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 7, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_GRVT_update,+ .Graphics = el_GRVT_graphics,+ .Create = el_GRVT_create,+ },+ [PT_DRAY] = {+ .Identifier = "DEFAULT_PT_DRAY",+ .Name = "DRAY",+ .Colour = 0xFFAA22,+ .MenuVisible = 1,+ .MenuSection = SC_ELEC,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Duplicator ray. Replicates a line of particles in front of it.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_DRAY_update,+ .CtypeDraw = ctypeDrawVInCtype,+ },+ [PT_CRMC] = {+ .Identifier = "DEFAULT_PT_CRMC",+ .Name = "CRMC",+ .Colour = 0xD6D1D4,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.00f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 35,+ .HeatCapacity = 1,+ .Description = "Ceramic. Gets stronger under pressure.",+ .Properties = TYPE_SOLID | PROP_NEUTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 2887.15f,+ .HighTemperatureTransition = ST,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_CRMC_update,+ .Graphics = el_CRMC_graphics,+ .Create = el_CRMC_create,+ },+ [PT_HEAC] = {+ .Identifier = "DEFAULT_PT_HEAC",+ .Name = "HEAC",+ .Colour = 0xCB6351,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Rapid heat conductor.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1887.15f,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_HEAC_update,+ },+ [PT_SAWD] = {+ .Identifier = "DEFAULT_PT_SAWD",+ .Name = "SAWD",+ .Colour = 0xF0F0A0,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.7f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 10,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 29,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 18,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Sawdust. Floats on water.",+ .Properties = TYPE_PART | PROP_NEUTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ },+ [PT_POLO] = {+ .Identifier = "DEFAULT_PT_POLO",+ .Name = "POLO",+ .Colour = 0x506030,+ .MenuVisible = 1,+ .MenuSection = SC_NUCLEAR,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.4f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x000FF200,+ .Weight = 90,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Polonium, highly radioactive. Decays into NEUT and heats up.",+ .Properties = TYPE_PART|PROP_NEUTPASS|PROP_RADIOACTIVE|PROP_LIFE_DEC|PROP_DEADLY,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 526.95f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = 388.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_POLO_update,+ .Graphics = el_POLO_graphics,+ },+ [PT_RFRG] = {+ .Identifier = "DEFAULT_PT_RFRG",+ .Name = "RFRG",+ .Colour = 0x72D2D4,+ .MenuVisible = 1,+ .MenuSection = SC_GAS,+ .Enabled = 1,+ .Advection = 1.2f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.99f,+ .Loss = 0.30f,+ .Collision = -0.1f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 1.3f,+ .HotAir = 0.0001f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 21,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 1,+ .HeatConduct = 3,+ .HeatCapacity = 1,+ .Description = "Refrigerant. Heats up and liquefies under pressure.",+ .Properties = TYPE_GAS|PROP_DEADLY,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 2,+ .HighPressureTransition = PT_RFGL,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_RFRG_update,+ },+ [PT_RFGL] = {+ .Identifier = "DEFAULT_PT_RFGL",+ .Name = "RFGL",+ .Colour = 0x84C2CF,+ .MenuVisible = 0,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.6f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.95f,+ .Collision = 0.0f,+ .Gravity = 0.1f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 21,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 10,+ .HeatConduct = 3,+ .HeatCapacity = 1,+ .Description = "Liquid refrigerant.",+ .Properties = TYPE_LIQUID|PROP_DEADLY,+ .CarriesTypeIn = 0,+ .LowPressure = 2,+ .LowPressureTransition = PT_RFRG,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = Element_RFRG_update,+ },+ [PT_LSNS] = {+ .Identifier = "DEFAULT_PT_LSNS",+ .Name = "LSNS",+ .Colour = 0x336699,+ .MenuVisible = 1,+ .MenuSection = SC_SENSOR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Life sensor, creates a spark when there's a nearby particle with a life higher than its temperature.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 4.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 2, .tmp3 = 0, .tmp4 = 0},+ .Update = el_LSNS_update,+ },+ [PT_LDTC] = {+ .Identifier = "DEFAULT_PT_LDTC",+ .Name = "LDTC",+ .Colour = 0x66ff66,+ .MenuVisible = 1,+ .MenuSection = SC_SENSOR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Linear detector. Scans in 8 directions for particles with its ctype and creates a spark on the opposite side.",+ .Properties = TYPE_SOLID | PROP_NOCTYPEDRAW,+ .CarriesTypeIn = 1u << FIELD_CTYPE,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_LDTC_update,+ .CtypeDraw = ctypeDrawVInCtype,+ },+ [PT_SLCN] = {+ .Identifier = "DEFAULT_PT_SLCN",+ .Name = "SLCN",+ .Colour = 0xBCCDDF,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.4f,+ .AirDrag = 0.04f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.27f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 90,+ .HeatConduct = 100,+ .HeatCapacity = 1,+ .Description = "Powdered Silicon. A key ingredient in producing multiple materials.",+ .Properties = TYPE_PART | PROP_CONDUCTS | PROP_HOT_GLOW | PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 3538.15f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SLCN_update,+ .Graphics = el_SLCN_graphics,+ .Create = el_SLCN_create,+ },+ [PT_PTNM] = {+ .Identifier = "DEFAULT_PT_PTNM",+ .Name = "PTNM",+ .Colour = 0xD5E0EB,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 1,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 251,+ .HeatCapacity = 1,+ .Description = "Platinum. Catalyzes certain reactions.",+ .Properties = TYPE_SOLID | PROP_CONDUCTS | PROP_LIFE_DEC | PROP_HOT_GLOW | PROP_SPARKSETTLE,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1768.0f + 273.15f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_PTNM_update,+ .Graphics = el_PTNM_graphics,+ .Create = el_PTNM_create,+ },+ [PT_VSNS] = {+ .Identifier = "DEFAULT_PT_VSNS",+ .Name = "VSNS",+ .Colour = 0x7C9C00,+ .MenuVisible = 1,+ .MenuSection = SC_SENSOR,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 0,+ .HeatCapacity = 1,+ .Description = "Velocity sensor, creates a spark when there's a nearby particle with velocity higher than its temperature.",+ .Properties = TYPE_SOLID,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = 4.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 2, .tmp3 = 0, .tmp4 = 0},+ .Update = el_VSNS_update,+ },+ [PT_ROCK] = {+ .Identifier = "DEFAULT_PT_ROCK",+ .Name = "ROCK",+ .Colour = 0x727272,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.94f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 5,+ .Hardness = 1,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 200,+ .HeatCapacity = 1,+ .Description = "Solid, melts into various elements.",+ .Properties = TYPE_SOLID | PROP_HOT_GLOW,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = 120,+ .HighPressureTransition = PT_STNE,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 1943.15f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Graphics = el_ROCK_graphics,+ .Create = el_ROCK_create,+ },+ [PT_LITH] = {+ .Identifier = "DEFAULT_PT_LITH",+ .Name = "LITH",+ .Colour = 0xB6AABF,+ .MenuVisible = 1,+ .MenuSection = SC_EXPLOSIVE,+ .Enabled = 1,+ .Advection = 0.2f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.96f,+ .Loss = 0.95f,+ .Collision = -0.1f,+ .Gravity = 0.2f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 14,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 17,+ .HeatConduct = 70,+ .HeatCapacity = 1,+ .Description = "Lithium. Reactive element that explodes on contact with water.",+ .Properties = TYPE_PART | PROP_LIFE_DEC,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 453.65f,+ .HighTemperatureTransition = PT_LAVA,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_LITH_update,+ .Graphics = el_LITH_graphics,+ },+ [PT_RSST] = {+ .Identifier = "DEFAULT_PT_RSST",+ .Name = "RSST",+ .Colour = 0xF95B49,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.3f,+ .AirDrag = 0.02f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.80f,+ .Collision = 0.0f,+ .Gravity = 0.15f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 50,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 33,+ .HeatConduct = 55,+ .HeatCapacity = 1,+ .Description = "Resist. Solidifies on contact with photons, is destroyed by electrons and spark.",+ .Properties = TYPE_LIQUID | PROP_CONDUCTS | PROP_LIFE_DEC | PROP_NEUTPASS | PROP_PHOTPASS,+ .CarriesTypeIn = (1u << FIELD_CTYPE) | (1u << FIELD_TMP),+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 20.0f + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_RSST_update,+ },+ [PT_RSSS] = {+ .Identifier = "DEFAULT_PT_RSSS",+ .Name = "RSSS",+ .Colour = 0xC43626,+ .MenuVisible = 1,+ .MenuSection = SC_SOLIDS,+ .Enabled = 1,+ .Advection = 0.0f,+ .AirDrag = 0.00f * CFDS,+ .AirLoss = 0.90f,+ .Loss = 0.00f,+ .Collision = 0.0f,+ .Gravity = 0.0f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 0,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 100,+ .HeatConduct = 130,+ .HeatCapacity = 1,+ .Description = "Solidified resist. Blocks pressure and insulates electricity. Liquefies on contact with neutrons.",+ .Properties = TYPE_SOLID|PROP_NEUTPASS,+ .CarriesTypeIn = (1u << FIELD_CTYPE) | (1u << FIELD_TMP),+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_RSSS_update,+ },+ [PT_BASE] = {+ .Identifier = "DEFAULT_PT_BASE",+ .Name = "BASE",+ .Colour = 0x90D5FF,+ .MenuVisible = 1,+ .MenuSection = SC_LIQUID,+ .Enabled = 1,+ .Advection = 0.5f,+ .AirDrag = 0.01f * CFDS,+ .AirLoss = 0.97f,+ .Loss = 0.96f,+ .Collision = 0.0f,+ .Gravity = 0.08f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 2,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 0,+ .PhotonReflectWavelengths = 0x3FFFFFFF,+ .Weight = 16,+ .HeatConduct = 31,+ .HeatCapacity = 1.5f,+ .Description = "Corrosive liquid. Rusts conductive solids, neutralizes acid.",+ .Properties = TYPE_LIQUID|PROP_DEADLY,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = ITH,+ .HighTemperatureTransition = NT,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 76, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_BASE_update,+ .Graphics = el_BASE_graphics,+ },+ [PT_SEED] = {+ .Identifier = "DEFAULT_PT_SEED",+ .Name = "SEED",+ .Colour = 0x88E788,+ .MenuVisible = 1,+ .MenuSection = SC_POWDERS,+ .Enabled = 1,+ .Advection = 0.95f,+ .AirDrag = 0.005f * CFDS,+ .AirLoss = 0.98f,+ .Loss = 0.80,+ .Collision = -0.01f,+ .Gravity = 0.05f,+ .NewtonianGravity = 1,+ .Diffusion = 0.00f,+ .HotAir = 0.000f * CFDS,+ .Falldown = 1,+ .Flammable = 0,+ .Explosive = 0,+ .Meltable = 0,+ .Hardness = 19,+ .PhotonReflectWavelengths = 0xE00,+ .Weight = 36,+ .HeatConduct = 32,+ .HeatCapacity = 1,+ .Description = "Seeds. Put on sand and add water to grow a tree.",+ .Properties = TYPE_PART | PROP_NEUTPASS,+ .CarriesTypeIn = 0,+ .LowPressure = IPL,+ .LowPressureTransition = NT,+ .HighPressure = IPH,+ .HighPressureTransition = NT,+ .LowTemperature = ITL,+ .LowTemperatureTransition = NT,+ .HighTemperature = 673.15f,+ .HighTemperatureTransition = PT_FIRE,+ .DefaultProperties = {.temp = R_TEMP + 273.15f, .life = 0, .ctype = 0, .tmp = 0, .tmp2 = 0, .tmp3 = 0, .tmp4 = 0},+ .Update = el_SEED_update,+ .Graphics = el_SEED_graphics,+ .Create = el_SEED_create,+ },+};diff --git a/games/numpowder/src/font.c b/games/numpowder/src/font.cnew file mode 100644index 00000000..570c7a77--- /dev/null+++ b/games/numpowder/src/font.c@@ -0,0 +1,166 @@+/* NumPowder: text in The Powder Toy's font (FontReader.cpp; RasterDrawMethodsImpl.h's BlendChar, AddChar,+ * BlendText, TextSize, TextFit), drawn into a band of the screen. */+#include "font.h"++static uint32_t code_colour(uint8_t c, uint32_t cur, bool *underline) {+ switch (c) {+ case 'U': *underline = !*underline; return cur;+ case 'w': return 0xFFFFFF;+ case 'g': return 0xC0C0C0;+ case 'o': return 0xFFD820;+ case 'r': return 0xFF0000;+ case 'l': return 0xFF4B4B;+ case 'b': return 0x0000FF;+ case 't': return 0x20AAFF;+ case 'u': return 0x9353D3;+ }+ return cur;+}++int font_draw_char(Band *b, int x, int y, uint8_t c, uint32_t rgb, int alpha, int mode) {+ int g = font_glyph(c), w = font_widths[g];+ const uint8_t *p = font_bits + font_offsets[g];+ int top = y - 2;+ /* (the whole glyph is skipped when it misses the band) */+ if (top >= b->y0 + b->h || top + FONT_H <= b->y0 || x >= b->x0 + b->w || x + w <= b->x0) return w;+ /* (only the glyph's rows in the band) */+ int r0 = b->y0 - top, r1 = b->y0 + b->h - top;+ if (r0 < 0) r0 = 0;+ if (r1 > FONT_H) r1 = FONT_H;+ int levels[4] = {0, alpha / 3, 2 * alpha / 3, alpha};+ for (int r = r0; r < r1; r++) {+ int sy = top + r - b->y0, bit = r * w;+ uint16_t *row = b->px + sy * b->w;+ for (int k = 0; k < w; k++, bit++) {+ int a = (p[bit >> 2] >> ((bit & 3) * 2)) & 3;+ if (!a) continue;+ int sx = x + k - b->x0;+ if ((unsigned)sx >= (unsigned)b->w) continue;+ row[sx] = mode == FONT_ADD ? px_add(row[sx], rgb, levels[a]) : px_blend(row[sx], rgb, levels[a]);+ }+ }+ return w;+}++int font_draw(Band *b, int x, int y, const char *s, uint32_t rgb, int alpha, int mode) {+ const uint8_t *t = (const uint8_t *)s;+ uint32_t col = rgb;+ bool underline = false;+ int px = x;+ for (; *t; t++) {+ uint8_t c = *t;+ /* (a line below the band: nothing more to draw in it; above it, its underline too: only its colour codes to+ * follow. A glyph covers FONT_H rows from y - 2, the underline is row y + FONT_H) */+ if (y - 2 >= b->y0 + b->h) break;+ bool above = y + FONT_H < b->y0;+ if (c == '\n') {+ px = x, y += FONT_H;+ } else if (above && c >= 0x20) {+ px += font_char_width(c);+ } else if (c == 0x0F) {+ if (!t[1] || !t[2] || !t[3]) break;+ col = (uint32_t)t[1] << 16 | (uint32_t)t[2] << 8 | t[3];+ t += 3;+ } else if (c == 0x0E) {+ col = rgb;+ } else if (c == 0x01) {+ col ^= 0xFFFFFF;+ } else if (c == '\b') {+ if (!t[1]) break;+ col = code_colour(t[1], col, &underline);+ t++;+ } else {+ int dx = font_draw_char(b, px, y, c, col, alpha, mode);+ if (underline) {+ int sy = y + FONT_H - b->y0;+ for (int k = 0; k < dx; k++) {+ int sx = px + k - b->x0;+ if (sy >= 0 && sy < b->h && sx >= 0 && sx < b->w) b->px[sy * b->w + sx] = px_blend(b->px[sy * b->w + sx], col, alpha);+ }+ }+ px += dx;+ }+ }+ return px - x;+}++void font_draw_outline(Band *b, int x, int y, const char *s, uint32_t rgb, int alpha) {+ font_draw(b, x - 1, y - 1, s, 0, 0x78, FONT_BLEND);+ font_draw(b, x - 1, y + 1, s, 0, 0x78, FONT_BLEND);+ font_draw(b, x + 1, y - 1, s, 0, 0x78, FONT_BLEND);+ font_draw(b, x + 1, y + 1, s, 0, 0x78, FONT_BLEND);+ font_draw(b, x, y, s, rgb, alpha, FONT_BLEND);+}++int font_text_width(const char *s) {+ const uint8_t *t = (const uint8_t *)s;+ int w = 0, cur = 0;+ for (; *t; t++) {+ if (*t == '\n') {+ if (cur > w) w = cur;+ cur = 0;+ } else if (*t == 0x0F) {+ if (!t[1] || !t[2] || !t[3]) break;+ t += 3;+ } else if (*t == 0x0E || *t == 0x01) {+ } else if (*t == '\b') {+ if (!t[1]) break;+ t++;+ } else {+ cur += font_char_width(*t);+ }+ }+ return cur > w ? cur : w;+}++int font_text_lines(const char *s) {+ int n = 1;+ for (; *s; s++) n += *s == '\n';+ return n;+}++int font_text_fit(const char *s, int width) {+ const uint8_t *t = (const uint8_t *)s;+ int cur = 0, i = 0;+ for (; t[i]; i++) {+ if (t[i] == '\n') {+ cur = 0;+ } else if (t[i] == 0x0F) {+ if (!t[i + 1] || !t[i + 2] || !t[i + 3]) break;+ i += 3;+ } else if (t[i] == 0x0E || t[i] == 0x01) {+ } else if (t[i] == '\b') {+ if (!t[i + 1]) break;+ i++;+ } else {+ int dx = font_char_width(t[i]);+ if (cur + dx / 2 >= width) return i;+ cur += dx;+ }+ }+ return i;+}++int font_draw_big(Band *b, int x, int y, const char *s, uint32_t rgb) {+ int px = x, top = y - 4;+ uint16_t c565 = rgb565(rgb);+ for (const uint8_t *t = (const uint8_t *)s; *t; t++) {+ int g = font_glyph(*t), w = font_widths[g];+ const uint8_t *p = font_bits + font_offsets[g];+ if (top < b->y0 + b->h && top + 2 * FONT_H > b->y0)+ for (int r = 0; r < FONT_H; r++)+ for (int k = 0; k < w; k++) {+ int bit = r * w + k, a = (p[bit >> 2] >> ((bit & 3) * 2)) & 3;+ if (!a) continue;+ for (int dy = 0; dy < 2; dy++)+ for (int dx = 0; dx < 2; dx++) {+ int sx = px + 2 * k + dx - b->x0, sy = top + 2 * r + dy - b->y0;+ if ((unsigned)sx >= (unsigned)b->w || (unsigned)sy >= (unsigned)b->h) continue;+ uint16_t *d = &b->px[sy * b->w + sx];+ *d = a == 3 ? c565 : px_blend(*d, rgb, a * 85);+ }+ }+ px += 2 * w;+ }+ return px - x;+}diff --git a/games/numpowder/src/font.h b/games/numpowder/src/font.hnew file mode 100644index 00000000..24be5b90--- /dev/null+++ b/games/numpowder/src/font.h@@ -0,0 +1,82 @@+/* NumPowder: The Powder Toy's font and text drawing (FontReader.cpp, RasterDrawMethodsImpl.h's BlendText).+ *+ * Text is one byte per character: ASCII from 0x20, FONT_DEG (0x7F) the degree sign, 0x80 + n the icon glyph+ * U+E000 + n (FONT_ICON(0x41) is the walls' section icon, U+E041), FONT_DOT the middle dot and the keypad's symbols+ * FONT_LEFT, FONT_RIGHT, FONT_UP, FONT_DOWN (the arrow keys) and FONT_DEL (the delete key). As in the original:+ * - '\n' starts a new line FONT_H pixels lower;+ * - "\x0F" then three bytes r, g, b sets the colour (a 0 byte ends the string: write 1 for it);+ * - "\x0E" goes back to the colour given; "\x01" inverts the colour;+ * - '\b' then a letter picks a colour: w white, g grey, o orange, r red, l light red, b blue, t teal,+ * u purple; "\bU" underlines.+ * A glyph covers FONT_H rows from 2 pixels above the y given (the original's offset of -2). */+#ifndef NP_FONT_H+#define NP_FONT_H+#include <stdbool.h>+#include <stdint.h>++#define FONT_H 12+#define FONT_GLYPHS 214+#define FONT_DEG "\x7F"+#define FONT_ICON(n) (0x80 + (n))+#define FONT_DOT "\xEF"+#define FONT_LEFT "\xF0"+#define FONT_RIGHT "\xF1"+#define FONT_UP "\xF2"+#define FONT_DOWN "\xF3"+#define FONT_DEL "\xF4"+extern const uint8_t font_widths[FONT_GLYPHS];+extern const uint16_t font_offsets[FONT_GLYPHS];+extern const uint8_t font_bits[];++/* a screen band: w x h RGB565 pixels covering the screen from (x0, y0); drawing is clipped to it */+typedef struct {+ uint16_t *px;+ int x0, y0, w, h;+} Band;++static inline int font_glyph(uint8_t c) {+ return c >= 0x20 && c <= 0xF4 ? c - 0x20 : FONT_GLYPHS - 1;+}+static inline int font_char_width(uint8_t c) { return font_widths[font_glyph(c)]; }+/* the size of a text as the original's TextSize: width of the widest line, height FONT_H - 2 per line */+int font_text_width(const char *s);+int font_text_lines(const char *s);+/* how many bytes of s fit in width (TextFit: a character fits if half of it does) */+int font_text_fit(const char *s, int width);++/* the colour and blending of a text */+enum { FONT_BLEND, FONT_ADD };+/* BlendText (or AddChar for FONT_ADD): returns the width drawn on the last line */+int font_draw(Band *b, int x, int y, const char *s, uint32_t rgb, int alpha, int mode);+/* BlendTextOutline: the text over a dark outline */+void font_draw_outline(Band *b, int x, int y, const char *s, uint32_t rgb, int alpha);+/* one glyph */+int font_draw_char(Band *b, int x, int y, uint8_t c, uint32_t rgb, int alpha, int mode);+/* a text at twice the size (titles), without colour codes: returns its width */+int font_draw_big(Band *b, int x, int y, const char *s, uint32_t rgb);++/* colours: 0xRRGGBB to RGB565 and back */+static inline uint16_t rgb565(uint32_t c) {+ return (uint16_t)(((c >> 8) & 0xF800) | ((c >> 5) & 0x07E0) | ((c >> 3) & 0x001F));+}+static inline uint32_t rgb888(uint16_t c) {+ uint32_t r = c >> 11, g = (c >> 5) & 63, b = c & 31;+ return (r << 3 | r >> 2) << 16 | (g << 2 | g >> 4) << 8 | (b << 3 | b >> 2);+}+/* a pixel of a band: blended (the original's RGB::Blend), added (RGB::Add) */+static inline uint16_t px_blend(uint16_t d, uint32_t c, int a) {+ if (a >= 255) return rgb565(c);+ if (a <= 0) return d;+ /* (in RGB565, 32 levels of alpha: the three channels at once, spread over 32 bits) */+ uint32_t a5 = (uint32_t)(a + 4) >> 3, s = rgb565(c);+ uint32_t dd = (d | (uint32_t)d << 16) & 0x07E0F81Fu, ss = (s | s << 16) & 0x07E0F81Fu;+ uint32_t r = ((ss * a5 + dd * (32 - a5)) >> 5) & 0x07E0F81Fu;+ return (uint16_t)(r | r >> 16);+}+static inline uint16_t px_add(uint16_t d, uint32_t c, int a) {+ uint32_t o = rgb888(d);+ uint32_t r = (o >> 16 & 255) + a * (c >> 16 & 255) / 255, g = (o >> 8 & 255) + a * (c >> 8 & 255) / 255;+ uint32_t bl = (o & 255) + a * (c & 255) / 255;+ return rgb565((r > 255 ? 255 : r) << 16 | (g > 255 ? 255 : g) << 8 | (bl > 255 ? 255 : bl));+}+#endifdiff --git a/games/numpowder/src/font_data.c b/games/numpowder/src/font_data.cnew file mode 100644index 00000000..239baace--- /dev/null+++ b/games/numpowder/src/font_data.c@@ -0,0 +1,269 @@+/* NumPowder: The Powder Toy's font (resources/font.bz2), the glyphs the interface uses (generated by+ * tools/gen_font.py: do not edit). Each glyph is 12 rows of its width in pixels, 2 bits of alpha each, four to+ * a byte, low bits first (FontReader.cpp). Indexed as font.h's text codes: ASCII from 0x20, 0x7F the degree+ * sign, 0x80 to 0xEE the icons U+E000 to U+E06E, 0xEF the middle dot, 0xF0 to 0xF4 the keypad's symbols (left, right,+ * up, down, delete: drawn by gen_font.py), then U+FFFD. */+#include "font.h"++const uint8_t font_widths[FONT_GLYPHS] = {+ 5, 3, 5, 6, 6, 7, 6, 3, 4, 4, 6, 6, 4, 5, 3, 6, 6, 5, 6, 6, 6, 6, 6, 6,+ 6, 6, 3, 4, 6, 6, 6, 6, 8, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6, 7, 6, 8, 7, 7,+ 6, 7, 6, 6, 6, 7, 6, 8, 7, 6, 7, 4, 5, 4, 4, 6, 3, 5, 5, 5, 5, 5, 4, 5,+ 5, 4, 4, 5, 4, 6, 5, 5, 5, 5, 4, 5, 4, 5, 5, 6, 5, 5, 5, 4, 2, 4, 6, 4,+ 8, 12, 12, 10, 12, 10, 10, 10, 10, 10, 10, 10, 12, 6, 10, 10, 12, 10, 8, 11, 11, 12, 12, 9,+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 11, 11, 8, 10, 10, 10, 10, 9, 4, 3, 3, 5, 5,+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 3, 3, 5, 6, 6, 10, 10, 9, 11, 10, 10, 10, 9, 10,+ 10, 10, 10, 10, 10, 10, 10, 9, 9, 11, 11, 10, 10, 10, 10, 10, 5, 8, 9, 10, 10, 10, 10, 10,+ 11, 10, 10, 10, 12, 10, 10, 9, 6, 4, 7, 10, 9, 18, 11, 5, 6, 5, 8, 8, 10, 10,+};+const uint16_t font_offsets[FONT_GLYPHS] = {+ 0, 15, 24, 39, 57, 75, 96, 114, 123, 135, 147, 165, 183, 195, 210, 219,+ 237, 255, 270, 288, 306, 324, 342, 360, 378, 396, 414, 423, 435, 453, 471, 489,+ 507, 531, 549, 567, 585, 603, 621, 639, 657, 675, 687, 705, 726, 744, 768, 789,+ 810, 828, 849, 867, 885, 903, 924, 942, 966, 987, 1005, 1026, 1038, 1053, 1065, 1077,+ 1095, 1104, 1119, 1134, 1149, 1164, 1179, 1191, 1206, 1221, 1233, 1245, 1260, 1272, 1290, 1305,+ 1320, 1335, 1350, 1362, 1377, 1389, 1404, 1419, 1437, 1452, 1467, 1482, 1494, 1500, 1512, 1530,+ 1542, 1566, 1602, 1638, 1668, 1704, 1734, 1764, 1794, 1824, 1854, 1884, 1914, 1950, 1968, 1998,+ 2028, 2064, 2094, 2118, 2151, 2184, 2220, 2256, 2283, 2310, 2337, 2364, 2391, 2418, 2445, 2472,+ 2499, 2526, 2553, 2583, 2616, 2649, 2673, 2703, 2733, 2763, 2793, 2820, 2832, 2841, 2850, 2865,+ 2880, 2895, 2910, 2925, 2940, 2955, 2970, 2985, 3000, 3015, 3027, 3036, 3045, 3060, 3078, 3096,+ 3126, 3156, 3183, 3216, 3246, 3276, 3306, 3333, 3363, 3393, 3423, 3453, 3483, 3513, 3543, 3573,+ 3600, 3627, 3660, 3693, 3723, 3753, 3783, 3813, 3843, 3858, 3882, 3909, 3939, 3969, 3999, 4029,+ 4059, 4092, 4122, 4152, 4182, 4218, 4248, 4278, 4305, 4323, 4335, 4356, 4386, 4413, 4467, 4500,+ 4515, 4533, 4548, 4572, 4596, 4626,+};+const uint8_t font_bits[4656] = {+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x1C, 0xC3, 0x20,+ 0x00, 0x47, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x4C, 0x37, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x80, 0x19, 0xCC, 0xE0, 0x3F, 0xCC, 0xF0, 0x2F, 0xCC, 0x90, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x30, 0xD0, 0x3F, 0x33, 0xE1, 0x07, 0xF4, 0x12, 0x33, 0xFF, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xE2,+ 0xCC, 0x1C, 0xDE, 0x01, 0x3C, 0x40, 0xB7, 0x34, 0x33, 0x8B, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7D,+ 0x30, 0x0C, 0x13, 0xD0, 0x32, 0xB3, 0x33, 0x1C, 0x7D, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x34, 0x07, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x1D, 0x07, 0x03, 0x07, 0x1D, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x1D, 0x34,+ 0x30, 0x34, 0x1D, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0xD0, 0x1C, 0x64, 0xF0, 0x3F, 0x64, 0xD0, 0x1C, 0x44,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x30, 0xE0, 0x2F, 0x30, 0x00, 0x02, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0D, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0xFC, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x07, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x80, 0x02, 0x0C, 0xA0, 0x00, 0x03, 0x28, 0xC0, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0xF8, 0xE0, 0x39, 0x07, 0x33, 0x32, 0x03, 0xB3, 0x38, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0F,+ 0x36, 0xC0, 0x00, 0x03, 0x0C, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xB1, 0x34, 0x41, 0x03, 0x0A, 0x2C,+ 0x70, 0x00, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x71, 0x34, 0x01, 0x03, 0x1E, 0x00, 0x33, 0x34,+ 0xFE, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x03, 0x37, 0x1C, 0x73, 0x34, 0xBF, 0x03, 0x30, 0x40, 0x03,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x33, 0x00, 0x57, 0xE0, 0x2F, 0x00, 0x13, 0x30, 0xFE, 0x01, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xF4, 0xD3, 0x00, 0x07, 0xF0, 0x1F, 0x03, 0x33, 0x34, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0xFF, 0x07, 0x34, 0x80, 0x03, 0x0E, 0x38, 0xD0, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0xFC, 0xB1, 0x34, 0x03, 0xD3, 0x1F, 0x03, 0x73, 0x34, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,+ 0xB1, 0x34, 0x03, 0xC3, 0x3F, 0x40, 0x23, 0x30, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04,+ 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x04, 0x00, 0x0C, 0x0D, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0xC0, 0xC3, 0x0B, 0x1B, 0xC0, 0x0B, 0xC0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0xF0, 0x3F, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x80, 0x0F,+ 0x90, 0x83, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFD, 0x71, 0x30, 0x81, 0x03, 0x0E, 0x34, 0x00,+ 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x0F, 0x1D, 0x30, 0xE7, 0x37, 0x73, 0x1C, 0xE3,+ 0x2F, 0x07, 0x00, 0xFD, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0xD0, 0x1D, 0x47, 0x33, 0x30,+ 0xFF, 0x33, 0x30, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x30, 0x38, 0x43, 0xF3, 0x1F, 0x43, 0x33,+ 0x34, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF4, 0xD1, 0x34, 0x03, 0x31, 0x00, 0x03, 0x70, 0x34, 0xFD,+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x30, 0x1D, 0x43, 0x33, 0x30, 0x03, 0x33, 0x34, 0xFF, 0x01, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x32, 0x00, 0x03, 0xF0, 0x0B, 0x03, 0x30, 0x10, 0xFF, 0x03, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0xFF, 0x33, 0x10, 0x03, 0xF0, 0x0B, 0x03, 0x30, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0xF4, 0xD1, 0x34, 0x03, 0x30, 0x3E, 0x03, 0x73, 0x34, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x47, 0x33, 0x30, 0x03, 0xF3, 0x3F, 0x03, 0x33, 0x30, 0x47, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1D, 0x0C, 0x0C,+ 0x0C, 0x0C, 0x0C, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0x01, 0x0C, 0xC0, 0x00, 0x0C, 0xC0, 0x10, 0x0D, 0x7F,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x34, 0x4C, 0x03, 0x37, 0xC0, 0x0B, 0x30, 0x0B, 0x0C, 0x0B, 0x47,+ 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x30, 0x00, 0x03, 0x30, 0x00, 0x03, 0x30, 0x10, 0xFF, 0x02,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x30, 0x1F, 0x3D, 0x7B, 0x3B, 0xE3, 0x32, 0x83, 0x30, 0x03, 0x30,+ 0x03, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xD0, 0x3C, 0x30, 0x37, 0xCC, 0x28, 0x33, 0xDC,+ 0x0C, 0x3C, 0x03, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x1F, 0x74, 0x1C, 0x07, 0xCD, 0x00, 0x33,+ 0xD0, 0x1C, 0x1D, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x30, 0x1D, 0x43, 0x73, 0x34, 0xFF,+ 0x31, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x1F, 0x34, 0x1D, 0x07, 0xCD, 0x00, 0x33, 0xDC,+ 0x1C, 0x1D, 0xFD, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x31, 0x34, 0x03, 0xF3, 0x0F, 0xD7, 0x30,+ 0x34, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xB1, 0x31, 0x07, 0xD0, 0x0F, 0x90, 0x23, 0x34, 0xFE,+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x13, 0x13, 0x30, 0x00, 0x03, 0x30, 0x00, 0x03, 0x74, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xC0, 0x0C, 0x30, 0x03, 0xCC, 0x00, 0x33, 0xD0, 0x2C, 0x1D, 0xFD, 0x01, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x33, 0x30, 0x03, 0xB3, 0x38, 0xCD, 0xC1, 0x0D, 0x30, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x30, 0x43, 0x30, 0xC7, 0x34, 0xCD, 0x1C, 0xED, 0x1E, 0x2C, 0x0E, 0x0C, 0x0C,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xC0, 0x34, 0x1C, 0xB8, 0x03, 0x3D, 0xC0, 0x2D, 0x34, 0x1C,+ 0x03, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xB3, 0x38, 0xDC, 0x40, 0x07, 0x30, 0x00, 0x03, 0x30,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xFF, 0x00, 0x2D, 0xC0, 0x02, 0x2C, 0xD0, 0x02, 0x6C, 0x00, 0xFF,+ 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2F, 0x03, 0x03, 0x03, 0x03, 0x03, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x30, 0x80, 0x02, 0x0C, 0xA0, 0x00, 0x03, 0x28, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x30, 0x30, 0x30, 0x30,+ 0x30, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1D, 0x37, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x08, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7D, 0x04, 0xC3, 0xCF, 0x30, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x70, 0xC0, 0x00, 0x7F, 0x5C, 0x33, 0xCC, 0x30, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3D,+ 0x5C, 0x32, 0xC0, 0x24, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x30, 0xF8, 0x38, 0x33, 0xCC, 0x31, 0xFD,+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7D, 0x0C, 0xF3, 0xCB, 0x00, 0xBD, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x3D, 0x07, 0x03, 0x2F, 0x03, 0x03, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBC, 0x2C, 0x33, 0x4C,+ 0x3F, 0xC0, 0x04, 0xE3, 0x07, 0x00, 0x00, 0x00, 0x30, 0xC0, 0x00, 0x7F, 0x9C, 0x33, 0xCC, 0x30, 0xC7, 0x01, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x04, 0x1C, 0x00, 0x0D, 0x0C, 0x0C, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x34, 0x30,+ 0x30, 0x30, 0x30, 0x1E, 0x00, 0x00, 0x00, 0x30, 0xC0, 0x10, 0xE3, 0xEC, 0xF0, 0xC1, 0x1C, 0xC3, 0x01, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x47, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9B, 0x71,+ 0x37, 0x33, 0x33, 0x32, 0x43, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x1C, 0x33, 0xCC, 0x30,+ 0xD3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7D, 0x1C, 0x33, 0xCC, 0x34, 0x7D, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x1C, 0x33, 0xCC, 0x34, 0x7F, 0x0C, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0xFD, 0x1D, 0x33, 0xCC, 0x34, 0xFD, 0x00, 0x03, 0x0C, 0x50, 0x00, 0x00, 0x00, 0x00, 0x33, 0x1F, 0x07, 0x03, 0x03, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x0C, 0xC1, 0x43, 0x30, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C,+ 0x0C, 0x3F, 0x0C, 0x0C, 0x1C, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC7, 0x0D, 0x33, 0xCC, 0x34, 0xFD,+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x0C, 0x33, 0xCD, 0x2D, 0x2C, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x33, 0x32, 0x33, 0x73, 0x37, 0xCD, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0xD3, 0x2C, 0xD3, 0xC7, 0x38, 0xC7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x0C, 0x73,+ 0x4C, 0x37, 0x74, 0xC0, 0xF0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xC4, 0xC2, 0xC2, 0x12, 0xFF, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x38, 0x0C, 0x0C, 0x03, 0x0C, 0x0C, 0x38, 0x00, 0x00, 0x00, 0x00, 0x32, 0x33, 0x33, 0x13, 0x00,+ 0x00, 0x00, 0x0B, 0x0C, 0x0C, 0x30, 0x0C, 0x0C, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1D, 0x72,+ 0x37, 0xD2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2D, 0x33, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x1F, 0x00, 0x7F, 0x00, 0xFF, 0x01, 0xFF, 0x07, 0xFF, 0x1F, 0xFF, 0x7F,+ 0xFF, 0x1B, 0xBF, 0x01, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xFF, 0x00, 0x00, 0xF8, 0xF0, 0x3F,+ 0xEE, 0x2C, 0x30, 0xCB, 0x0B, 0x30, 0x42, 0xC3, 0x33, 0x00, 0x03, 0x30, 0x00, 0xF3, 0x33, 0x00, 0x03, 0x30, 0x00, 0xFF,+ 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC2, 0x00, 0x00, 0xCB, 0x00, 0x00, 0xEE, 0xC0, 0xFF, 0xF8, 0xB0, 0xC0,+ 0xFF, 0x2C, 0xC0, 0x00, 0x0C, 0xCF, 0x00, 0x0C, 0xC0, 0x00, 0xCC, 0xCF, 0x00, 0x0C, 0xC0, 0x00, 0xFC, 0xFF, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x70, 0x00, 0x00, 0xF3, 0xFF, 0xD3, 0x03, 0xE0, 0x3C, 0x3F, 0x38, 0x03, 0xD0,+ 0x33, 0xFF, 0x38, 0x03, 0xE0, 0xF0, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00,+ 0x8B, 0xF7, 0x0C, 0x13, 0x9F, 0x3B, 0x37, 0x00, 0xC0, 0x23, 0xFF, 0xFF, 0x8B, 0x03, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0x7F, 0x80, 0x03, 0x2C, 0x0D, 0x00, 0x37, 0x00, 0xC0, 0xF3,+ 0xFF, 0x3C, 0xFF, 0xCF, 0x03, 0x00, 0xDC, 0x00, 0x70, 0x38, 0xC0, 0x02, 0xFD, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0xFC, 0x03, 0xF0, 0xFF, 0xC0, 0xFF, 0x3F, 0xFC, 0xFF, 0xC3, 0xFF, 0x3F, 0xFC, 0xFF, 0x03, 0xFF, 0x0F, 0xC0,+ 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x3F, 0x00, 0xC0, 0x03, 0x00, 0x3C, 0xF0, 0xC0, 0xC3,+ 0x3A, 0x3C, 0x0B, 0xCE, 0x2B, 0x80, 0x7E, 0x00, 0xD0, 0x03, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0xC0, 0xFF, 0x3F, 0xFC, 0xFF, 0xC3, 0xFF, 0x3F, 0xFC, 0xFF, 0xC3, 0xFF, 0x3F, 0xFC, 0xFF, 0xC3, 0xFF, 0x3F, 0xFC,+ 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0x7F, 0x80, 0x03, 0x2C, 0x0D, 0x0F, 0x37, 0xF0, 0xC0, 0xF3,+ 0xFF, 0x3C, 0xFF, 0xCF, 0x03, 0x0F, 0xDC, 0xF0, 0x70, 0x38, 0xC0, 0x02, 0xFD, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40,+ 0x1F, 0x00, 0xAD, 0x07, 0xB0, 0xC5, 0x00, 0x17, 0x0C, 0x70, 0xD0, 0x00, 0x0C, 0x03, 0xBC, 0xEF, 0xB3, 0x11, 0xE0, 0x07,+ 0x05, 0x3C, 0x52, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0xC0, 0x3F, 0x00, 0xFC, 0x03, 0xC0,+ 0x3F, 0x00, 0xF0, 0x00, 0xC0, 0x30, 0xC0, 0xFF, 0x3F, 0xFC, 0xFF, 0xC3, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0xFC, 0xFF, 0x0F, 0xFC, 0xFF, 0x3F, 0xFC, 0x00, 0x00, 0xFC, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB8, 0xE0, 0x2F, 0xFF,+ 0xE3, 0x2F, 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0x7F, 0x80, 0xFF, 0x2F, 0xFD, 0xFF,+ 0xF7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDF, 0xFF, 0x7F, 0xF8, 0xFF, 0x02, 0xFD, 0x07, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x02, 0x00, 0xC8, 0x07, 0x10, 0xC3, 0x00, 0x31, 0x0D, 0x00, 0xFD, 0x01, 0x00, 0x74,+ 0x00, 0x00, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xC1, 0x07,+ 0xF0, 0xC1, 0x07, 0xF0, 0xC1, 0x07, 0xF0, 0xC1, 0x07, 0xF0, 0xC1, 0x07, 0xF0, 0xC1, 0x07, 0xF0, 0xC1, 0x07, 0xF0, 0xC1,+ 0x07, 0x50, 0x41, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x80, 0xFF, 0x8B, 0x1E, 0xD0, 0x2E, 0x00, 0xF0, 0x00,+ 0xE0, 0xFF, 0x0B, 0x00, 0x0F, 0x00, 0xB8, 0x03, 0xB0, 0xE2, 0xFF, 0x02, 0x50, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x07,+ 0x03, 0x1E, 0x03, 0x73, 0x03, 0xEF, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0xFF, 0xFF, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xFE, 0x02, 0xBE, 0xC1, 0xD0, 0x01, 0xF0, 0x3F, 0xE0, 0x0B, 0x1F, 0x1C, 0xD0,+ 0x4A, 0x03, 0x6C, 0xB3, 0x00, 0xC3, 0x4D, 0x7E, 0xD0, 0xBF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x80, 0x2A, 0x00, 0xAA, 0x0A, 0x80, 0x2A, 0xFC, 0xA0, 0xF2, 0x3F, 0xA0, 0xFC, 0x03, 0xC8, 0xFF, 0x00, 0xF2,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0xC0, 0x07, 0xAA, 0xEA, 0x1F, 0xFF,+ 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xAA, 0xEA, 0x1F, 0x00, 0xC0, 0x07, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x03, 0x00, 0xD0, 0x03, 0x00, 0xF4, 0xAB, 0xAA, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF,+ 0xFF, 0xFD, 0xFF, 0xFF, 0xF4, 0xAB, 0xAA, 0xD0, 0x03, 0x00, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0xE0, 0xFF, 0x3F, 0xFE, 0xFF, 0xA0, 0xEA, 0xA3, 0x80, 0xEF, 0x02, 0xFE, 0x0B, 0xF8, 0xAF, 0xEA, 0xFF, 0x2F, 0xFE, 0x2F,+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x2D, 0xFE, 0x2F, 0x00, 0x00, 0xF0, 0xFF, 0x06, 0x00,+ 0x64, 0xFE, 0x0A, 0x05, 0x90, 0x00, 0x00, 0x02, 0x40, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x0F, 0x1C,+ 0xD8, 0x18, 0x30, 0x39, 0xA0, 0xF0, 0xC0, 0xC1, 0x83, 0x07, 0xDB, 0xFF, 0xC9, 0xFF, 0x0F, 0xF8, 0x0B, 0x00, 0x00, 0x00,+ 0x00, 0x40, 0x44, 0x04, 0x20, 0x11, 0x84, 0x48, 0x10, 0x12, 0x42, 0x88, 0x04, 0x32, 0x22, 0xCC, 0x8C, 0x00, 0x03, 0x03,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0x01, 0xD0, 0x01, 0x80, 0x07, 0x40, 0x7B, 0x00, 0xFF, 0x02,+ 0xBC, 0x0F, 0xE0, 0x2B, 0x40, 0x7F, 0xD0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x04, 0x00, 0x14, 0x00, 0x90, 0x01, 0x80, 0x0A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xCF, 0xBD, 0x3C, 0x00, 0xF0, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xCF, 0xBD, 0x3C, 0x00,+ 0xF0, 0xFF, 0xFF, 0x00, 0x03, 0x00, 0x0C, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF,+ 0xFF, 0x03, 0x00, 0xCF, 0xBD, 0x3C, 0x00, 0xF0, 0xFF, 0xFF, 0x00, 0x74, 0x00, 0x40, 0x07, 0x00, 0x34, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0xCF, 0xBD, 0x3C, 0x00, 0xF0, 0xFF, 0xFF, 0x74, 0x00, 0x74,+ 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xF0, 0xFF, 0xC3,+ 0xFF, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,+ 0x3F, 0x00, 0xC0, 0x07, 0x00, 0xBD, 0x02, 0xE8, 0xB3, 0xE0, 0x3C, 0xAC, 0xC3, 0x03, 0x0F, 0x3C, 0x00, 0xC0, 0x03, 0x00,+ 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8C, 0x0C, 0x1C, 0xB9, 0xD1, 0x6C, 0x73, 0x0E, 0x70, 0x34, 0x70,+ 0x0A, 0x68, 0xD3, 0xFF, 0x1F, 0xBC, 0x99, 0x8F, 0x8B, 0x8B, 0x7B, 0x9B, 0x79, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x3F, 0x00, 0xC0, 0x0F, 0x00, 0xFC, 0x0F, 0x00, 0xFF, 0x03, 0xF0, 0xFF,+ 0x03, 0xFF, 0xFF, 0xC3, 0xFF, 0xFF, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x1F, 0xCB,+ 0x30, 0xC3, 0x3F, 0xC7, 0x00, 0x7E, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF,+ 0xC3, 0xFF, 0x3F, 0x0C, 0x00, 0xC3, 0xFC, 0x33, 0x0C, 0x24, 0xC3, 0xC0, 0x31, 0x0C, 0x06, 0xC3, 0x30, 0x30, 0x0C, 0x00,+ 0xC3, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x3F, 0x30, 0x00, 0x03, 0xC3, 0x30, 0x30, 0x3F, 0xFF, 0xFF, 0x3F,+ 0x3C, 0x00, 0xFF, 0xFF, 0xFF, 0x0C, 0x0C, 0xC3, 0xC0, 0x00, 0x0C, 0xFC, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0xC0, 0xFF, 0x00, 0xFC, 0x0F, 0xC0, 0xFF, 0x00, 0xFC, 0x0F, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,+ 0x03, 0x00, 0x3C, 0x00, 0xC0, 0x03, 0xF0, 0x3F, 0x00, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x02,+ 0xFF, 0x3F, 0x8E, 0xCB, 0xBE, 0x99, 0xFF, 0x8B, 0xFF, 0x9B, 0xF9, 0x8E, 0xCB, 0xF2, 0xFF, 0x03, 0xFE, 0x02, 0x00, 0x00,+ 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x70, 0x78, 0x38, 0x0C, 0xC3, 0x30, 0xEE,+ 0x1D, 0x00, 0x40, 0xB7, 0xCB, 0x30, 0x0C, 0xC3, 0xD2, 0xD2, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7D, 0x4C, 0x33, 0xCC, 0x30, 0xC7, 0xF4, 0x01, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xF0, 0x90, 0x03, 0x0C, 0x30, 0xF4, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x7D, 0x08, 0x03, 0x06, 0x06, 0x06, 0xFC, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0x44, 0x83, 0x07, 0x34,+ 0xC2, 0xF4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x60, 0x63, 0xCC, 0x3F, 0xC0, 0x00, 0x03, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x0C, 0xF0, 0x07, 0x34, 0xC1, 0xF8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0xBD, 0x0C, 0xF1, 0xC2, 0x34, 0xC3, 0xF4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x03, 0x06, 0x06,+ 0x0C, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7D, 0x0C, 0xD3, 0xC7, 0x34, 0xC3, 0xF4, 0x01, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x7D, 0x0C, 0x63, 0x0C, 0x3E, 0xC0, 0xF8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,+ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x0C, 0xCF, 0xF3, 0x3C, 0xCF, 0x33, 0x00, 0x00, 0x00, 0xC0, 0x3C,+ 0xCF, 0xF3, 0x3C, 0x0F, 0x03, 0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00,+ 0x00, 0x00, 0x00, 0x74, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0xDC, 0xC0, 0x0C, 0x99, 0x31, 0x30, 0x89, 0x41, 0x07, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x03, 0x30, 0xC0, 0x0F, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0xD0, 0x7F, 0x40, 0xFF, 0x1F, 0xFC, 0xFF, 0x43, 0xFF,+ 0x1F, 0x40, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE4, 0x06, 0x90, 0x91, 0x01, 0x06, 0x24, 0x30, 0x90,+ 0x1B, 0x46, 0x6E, 0x96, 0xB9, 0x91, 0xE4, 0x06, 0x0C, 0x18, 0x90, 0x40, 0x46, 0x06, 0x90, 0x1B, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x8F, 0x80, 0xBC, 0xAA, 0xFA, 0x80, 0xC0, 0xAB, 0xAA, 0x8F, 0x80, 0xFC, 0xFF,+ 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0xC0, 0xC0, 0x00, 0x30, 0x30, 0x00,+ 0xFF, 0x3F, 0x80, 0xFF, 0x0B, 0xD0, 0xFF, 0x01, 0x90, 0x1A, 0x00, 0xA0, 0x02, 0x00, 0xA8, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x80, 0x00, 0x81, 0x24, 0x10, 0x85, 0x00, 0x20, 0x66, 0x40, 0x15, 0x45, 0x62, 0x90, 0x4D, 0xD0, 0xF1, 0x23,+ 0x01, 0xFD, 0x41, 0x41, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x06, 0x00, 0xB8, 0x00, 0xD0, 0x1F, 0x00, 0xFE,+ 0x02, 0xF4, 0x7F, 0x80, 0xFF, 0x0B, 0xFC, 0xEF, 0xC0, 0xFF, 0x0D, 0xF4, 0x77, 0x00, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x20, 0x00, 0x00, 0x3C, 0x00, 0xD4, 0x01, 0xD0, 0x06, 0x40, 0x7F, 0x00, 0xFD, 0x01, 0xF4, 0x07, 0xD0, 0x1F,+ 0x00, 0x7F, 0x00, 0xD0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0x06, 0xE4, 0x6F, 0x24, 0x2E, 0x26,+ 0x74, 0xA0, 0x95, 0x95, 0xFE, 0xFD, 0xF6, 0xD1, 0x47, 0x03, 0x07, 0xA4, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x2F,+ 0x80, 0x5F, 0x2F, 0x0C, 0x00, 0xC3, 0x00, 0x30, 0x0C, 0x00, 0xC3, 0x01, 0x34, 0x34, 0xC0, 0x01, 0x07, 0x0D, 0xD0, 0x75,+ 0x00, 0xF4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0xF4, 0x01, 0xC0, 0x3F,+ 0x00, 0xF0, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0xF0, 0x00, 0xE0, 0xEF, 0x00, 0xBB, 0x0B, 0xA0, 0xAA, 0x00, 0xAA, 0x0A, 0x80, 0x19, 0x00, 0x64, 0x02, 0x00, 0x05,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x10, 0x2D, 0x80,+ 0xE7, 0x0B, 0xBE, 0xF8, 0xFA, 0x02, 0xFE, 0x0B, 0x80, 0x2F, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,+ 0x00, 0xF8, 0x02, 0xE0, 0xBF, 0x80, 0xAF, 0x2F, 0xBE, 0xE0, 0xDB, 0x02, 0x78, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x20, 0x00, 0x40, 0x07, 0x50, 0xFE, 0x16, 0xFD, 0xFF,+ 0x41, 0xFF, 0x07, 0xE0, 0x2F, 0x00, 0xDF, 0x03, 0x34, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x1A,+ 0x00, 0x09, 0x06, 0x20, 0x80, 0x00, 0x02, 0x08, 0xFC, 0xFF, 0xC3, 0x00, 0x30, 0x0C, 0x00, 0xC3, 0x00, 0x30, 0x0C, 0x00,+ 0xC3, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0xAA, 0x0A, 0xF0, 0xFF, 0x00, 0xAA, 0x0A, 0xF0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x02,+ 0xFF, 0x3F, 0xFE, 0xDF, 0xFE, 0x1F, 0xFE, 0x1D, 0xFE, 0x12, 0xFE, 0x2E, 0xFE, 0xF2, 0xFE, 0x03, 0xFE, 0x02, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x0C, 0x00, 0x13, 0x00, 0xD1, 0x00, 0xCC, 0x00, 0x80, 0x00, 0x80, 0x0B,+ 0x80, 0xBF, 0x80, 0xFF, 0x8B, 0xFF, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x2F, 0xFC, 0xFF,+ 0x0F, 0x1F, 0xD0, 0xC3, 0x03, 0xF0, 0xF0, 0x00, 0x3C, 0x3C, 0x00, 0x0F, 0x1F, 0xD0, 0xC3, 0xFF, 0xFF, 0xE0, 0xFF, 0x2F,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0xC0,+ 0x03, 0x00, 0x00, 0x00, 0x00, 0x3C, 0xCF, 0x03, 0xCF, 0xF3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB9, 0x91,+ 0xE3, 0x46, 0x2E, 0x1B, 0xB9, 0x61, 0xE4, 0x06, 0x91, 0x1B, 0x41, 0x6E, 0x24, 0xB9, 0x91, 0xE3, 0x46, 0x2E, 0x1B, 0xB9,+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x0C, 0xC0, 0x23, 0x00, 0x80, 0x08,+ 0x00, 0x20, 0x0F, 0xC0, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x2F,+ 0xC0, 0x01, 0x0D, 0x06, 0x40, 0x32, 0x00, 0x30, 0x03, 0x00, 0x33, 0x00, 0x30, 0x06, 0x40, 0xC2, 0x01, 0x0D, 0xE0, 0x2F,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x20, 0x23, 0x80, 0x32, 0x0A, 0x0D, 0xC3,+ 0xD1, 0x10, 0x1C, 0x0D, 0xC0, 0x81, 0x02, 0x0A, 0xE0, 0x2F, 0x00, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0xFC, 0x03, 0xB0, 0xE0, 0x00, 0x03, 0x0C, 0x30, 0xC0, 0x00, 0x0B, 0x0E, 0xC0, 0x3F, 0x00, 0xAC, 0x03, 0xC0, 0x3A,+ 0x00, 0xAC, 0x03, 0x00, 0x00, 0xF0, 0xC6, 0x1B, 0x6F, 0xBC, 0xF1, 0xC6, 0x1B, 0x6F, 0xBC, 0xF1, 0x06, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F, 0xE4, 0x6F,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x3E, 0x00, 0xF9, 0x00, 0xE4, 0x03, 0x90, 0x0F, 0x40, 0x3E, 0x00, 0xF9,+ 0x00, 0xE4, 0x03, 0x90, 0x0F, 0x40, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0,+ 0x3F, 0x00, 0xFF, 0x03, 0xF0, 0x3F, 0x00, 0xFF, 0x03, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x08, 0x82, 0xE0, 0xBA, 0x2E, 0x08, 0x82, 0x80, 0x20, 0x08, 0xAE, 0xEB, 0x82, 0x20, 0x08, 0x08,+ 0x82, 0xE0, 0xBA, 0x2E, 0x08, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x03, 0x30,+ 0xFC, 0x00, 0x43, 0x07, 0xFC, 0x20, 0x40, 0x07, 0x30, 0x20, 0x00, 0x03, 0x00, 0xFC, 0x00, 0x40, 0x07, 0x00, 0x20, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0xC0, 0x20, 0x1D, 0x20, 0x61, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x84, 0x01, 0x24,+ 0xB4, 0xF1, 0x01, 0xFE, 0x0F, 0xD0, 0x0F, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x90,+ 0x1A, 0x40, 0xFE, 0x06, 0xE4, 0x6F, 0x40, 0xFE, 0x06, 0x90, 0x1A, 0x00, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x81, 0x88, 0x88, 0x58, 0x55, 0x55, 0xF5, 0x0F,+ 0x40, 0x55, 0x55, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,+ 0x10, 0x00, 0x00, 0x02, 0x00, 0x64, 0x00, 0xA5, 0x6B, 0x01, 0x64, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0xFF, 0x86, 0xC0, 0x00, 0x2C, 0x40, 0xFE, 0x0B,+ 0xE4, 0xBF, 0x0C, 0xC0, 0xF2, 0x6F, 0x08, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00,+ 0xF4, 0x01, 0xC0, 0x30, 0x00, 0x0D, 0x07, 0xF0, 0xF0, 0x40, 0x5F, 0x1F, 0xFC, 0xFA, 0xD3, 0xFF, 0x7F, 0xFF, 0xF0, 0xDF,+ 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x1E, 0x00, 0x80, 0x07, 0x00,+ 0xE0, 0x01, 0x00, 0x78, 0x60, 0x00, 0x24, 0x98, 0x01, 0x80, 0x42, 0x06, 0x00, 0x00, 0x19, 0x00, 0x00, 0x04, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF4, 0x07, 0xC0, 0xD5, 0x00, 0x1C, 0x0C, 0xC0, 0xC1, 0x00, 0xF4, 0x1F,+ 0x00, 0x40, 0x07, 0x00, 0xD0, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x68, 0x00, 0xA2,+ 0x02, 0x80, 0x0A, 0x00, 0x25, 0x00, 0x44, 0x08, 0x10, 0x01, 0x40, 0x04, 0x00, 0x14, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x0F, 0xF0, 0x3F, 0xC0, 0xFF, 0x00, 0xFF, 0x03, 0xFC, 0x0F, 0xF0, 0x3E, 0xC0, 0xE6,+ 0x00, 0x46, 0x02, 0x04, 0x04, 0x00, 0x00, 0x00, 0xCD, 0xF1, 0x3F, 0xFD, 0x41, 0x06, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xC0, 0x74,+ 0x30, 0x34, 0x1C, 0x0D, 0xFF, 0xC1, 0x00, 0xFC, 0x03, 0x0C, 0xC0, 0x3F, 0xC0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0xC0, 0x00, 0x00, 0x03,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xC0, 0xF3, 0xC0, 0x03, 0xCF, 0x03, 0xF0, 0x03, 0xC0, 0x0F, 0xC0, 0xF3, 0xC0,+ 0x03, 0xCF, 0x03, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x03, 0x00, 0x00, 0x30, 0xC0, 0x00, 0x00, 0x00,+ 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x00, 0x03, 0x30, 0x00, 0x00,+ 0xC0, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xBF, 0xC0, 0x55, 0xA5, 0x70, 0x69, 0x99, 0x9C, 0x4B, 0xFF, 0xA7, 0x52,+ 0xF5, 0x05, 0x55, 0x71, 0x56, 0x2A, 0x1C, 0x96, 0xC3, 0x07, 0x26, 0xF4, 0xFD, 0x43, 0x7D, 0x15, 0x54, 0xFF, 0xC3, 0xFF,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x74, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,+ 0x3C, 0xF0, 0xC3, 0x3F, 0xF0, 0x03, 0x3C, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xC0, 0x03, 0x3F, 0xFC,+ 0xF3, 0xC3, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0xF0, 0x03,+ 0xFC, 0x0F, 0xFF, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0xFF, 0x3F, 0xFC, 0x0F, 0xF0, 0x03, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+ 0x00, 0xF0, 0xFF, 0xC3, 0x00, 0x30, 0xC3, 0x0C, 0x33, 0x30, 0x30, 0xC3, 0x0C, 0xC3, 0x00, 0x30, 0xF0, 0xFF, 0x03, 0x00,+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x00, 0xD0, 0x1F, 0x40, 0x8B, 0x07, 0x3D, 0xF3, 0xF1, 0x3F,+ 0x3F, 0xFD, 0xF8, 0x41, 0xFF, 0x07, 0xD0, 0x1C, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,+};diff --git a/games/numpowder/src/gol.c b/games/numpowder/src/gol.cnew file mode 100644index 00000000..428d0ca4--- /dev/null+++ b/games/numpowder/src/gol.c@@ -0,0 +1,181 @@+/* NumPowder: The Powder Toy's Game of Life (Simulation::SimulateGoL, the built-in types of SimulationData.cpp,+ * GOLString.cpp).+ *+ * The original counts neighbours into gol[YRES][XRES][5], 32-bit lists of the kinds around each cell (128 KB+ * here). This builds each cell's list when it's looked at, from its 8 neighbours, in the order the original's+ * would have (by particle id), so the outcome is the same; the living cells that count are marked in a bitmap+ * first. (A LIFE particle under another particle isn't seen there: the original would count it.) */+#include "simpriv.h"++/* rulesets: bits 0..8 stay with that many neighbours, 9..16 begin with that many minus 8, 17..20 the number of+ * states minus 2 */+const BuiltinGOL builtinGol[NGOL] = {+ {"GOL", GT_GOL, 0x0080C, 0x0CAC00, 0x0CAC00, "Game Of Life: Begin 3/Stay 23"},+ {"HLIF", GT_HLIF, 0x0480C, 0xFF0000, 0xFF0000, "High Life: B36/S23"},+ {"ASIM", GT_ASIM, 0x038F0, 0x0000FF, 0x0000FF, "Assimilation: B345/S4567"},+ {"2X2", GT_2x2, 0x04826, 0xFFFF00, 0xFFFF00, "2X2: B36/S125"},+ {"DANI", GT_DANI, 0x1C9D8, 0x00FFFF, 0x00FFFF, "Day and Night: B3678/S34678"},+ {"AMOE", GT_AMOE, 0x0A92A, 0xFF00FF, 0xFF00FF, "Amoeba: B357/S1358"},+ {"MOVE", GT_MOVE, 0x14834, 0xFFFFFF, 0xFFFFFF, "'Move' particles. Does not move things.. it is a life type: B368/S245"},+ {"PGOL", GT_PGOL, 0x0A90C, 0xE05010, 0xE05010, "Pseudo Life: B357/S238"},+ {"DMOE", GT_DMOE, 0x1E9E0, 0x500000, 0x500000, "Diamoeba: B35678/S5678"},+ {"3-4", GT_34, 0x01818, 0x500050, 0x500050, "3-4: B34/S34"},+ {"LLIF", GT_LLIF, 0x03820, 0x505050, 0x505050, "Long Life: B345/S5"},+ {"STAN", GT_STAN, 0x1C9EC, 0x5000FF, 0x5000FF, "Stains: B3678/S235678"},+ {"SEED", GT_SEED, 0x00400, 0xFBEC7D, 0xFBEC7D, "Seeds: B2/S"},+ {"MAZE", GT_MAZE, 0x0083E, 0xA8E4A0, 0xA8E4A0, "Maze: B3/S12345"},+ {"COAG", GT_COAG, 0x189EC, 0x9ACD32, 0x9ACD32, "Coagulations: B378/S235678"},+ {"WALL", GT_WALL, 0x1F03C, 0x0047AB, 0x0047AB, "Walled cities: B45678/S2345"},+ {"GNAR", GT_GNAR, 0x00202, 0xE5B73B, 0xE5B73B, "Gnarl: B1/S1"},+ {"REPL", GT_REPL, 0x0AAAA, 0x259588, 0x259588, "Replicator: B1357/S1357"},+ {"MYST", GT_MYST, 0x139E1, 0x0C3C00, 0x0C3C00, "Mystery: B3458/S05678"},+ {"LOTE", GT_LOTE, 0x48938, 0xFF0000, 0xFFFF00, "Living on the Edge: B37/S3458/4"},+ {"FRG2", GT_FRG2, 0x20816, 0x006432, 0x00FF5A, "Like Frogs rule: B3/S124/3"},+ {"STAR", GT_STAR, 0x98478, 0x000040, 0x0000E6, "Like Star Wars rule: B278/S3456/6"},+ {"FROG", GT_FROG, 0x21806, 0x006400, 0x00FF00, "Frogs: B34/S12/3"},+ {"BRAN", GT_BRAN, 0x25440, 0xFFFF00, 0x969600, "Brian 6: B246/S6/3"},+};++/* the GoL space is BORDER narrower on each side than the simulation, and wraps around */+static inline int wrapx(int x) { return ((x + XRES - 3 * BORDER) % (XRES - 2 * BORDER)) + BORDER; }+static inline int wrapy(int y) { return ((y + YRES - 3 * BORDER) % (YRES - 2 * BORDER)) + BORDER; }++static inline bool counts(int x, int y) {+ int k = y * XRES + x;+ return sim_scratch[k >> 3] >> (k & 7) & 1;+}++void SimulateGoL(void) {+ CGOL = 0;+ /* the living cells (at full state) count for their neighbours; the others die a step */+ memset(sim_scratch, 0, (XRES * YRES + 7) / 8);+ for (int i = 0; i < parts_active; ++i) {+ Particle *part = &parts[i];+ if (part->type != PT_LIFE) continue;+ int x = (part->x + 32) / 64, y = (part->y + 32) / 64;+ if (x < BORDER || y < BORDER || x >= XRES - BORDER || y >= YRES - BORDER) continue;+ unsigned int ruleset = (unsigned int)part->ctype;+ if (ruleset < NGOL) ruleset = (unsigned int)builtinGol[ruleset].ruleset;+ if (part->tmp2 == (int)((ruleset >> 17) & 0xF) + 1) {+ if (pmap_id[y][x] == i + 1) {+ int k = y * XRES + x;+ sim_scratch[k >> 3] |= (uint8_t)(1 << (k & 7));+ }+ } else if (!(bmap[y / WCELL][x / WCELL] == WL_STASIS && emap[y / WCELL][x / WCELL] < 8)) {+ part->tmp2 -= 1;+ }+ }+ for (int y = BORDER; y < YRES - BORDER; ++y)+ for (int x = BORDER; x < XRES - BORDER; ++x) {+ int r = PMAPAT(x, y);+ if (r && TYP(r) != PT_LIFE) continue;+ /* the neighbours that count, in the order they'd have added to the list: by particle id */+ struct { int id, golnum, xx, yy; } nb[8];+ int n = 0;+ for (int yy = -1; yy <= 1; ++yy)+ for (int xx = -1; xx <= 1; ++xx) {+ if (!xx && !yy) continue;+ int sx = wrapx(x - xx), sy = wrapy(y - yy); /* (a cell at sx, sy adds to sx + xx, sy + yy) */+ if (!counts(sx, sy)) continue;+ int id = pmap_id[sy][sx] - 1;+ unsigned golnum = (unsigned)parts[id].ctype;+ if (golnum < NGOL) golnum += 1;+ int k = n++;+ while (k > 0 && nb[k - 1].id > id) nb[k] = nb[k - 1], k--;+ nb[k].id = id, nb[k].golnum = (int)golnum, nb[k].xx = xx, nb[k].yy = yy;+ }+ if (!r && !n) continue;+ /* the original's list: up to 5 kinds, each with its count and the place of its first */+ unsigned int list[5] = {0, 0, 0, 0, 0};+ int kinds = 0;+ for (int k = 0; k < n; k++) {+ int l;+ for (l = 0; l < kinds; l++)+ if ((int)(list[l] & 0x001FFFFFU) == nb[k].golnum) {+ list[l] += 1U << 21;+ break;+ }+ if (l == kinds && kinds < 5) list[kinds++] = ((nb[k].yy & 3) << 26) | ((nb[k].xx & 3) << 24) | (unsigned)nb[k].golnum;+ }+ unsigned int neighbours = (unsigned int)n;+ if (bmap[y / WCELL][x / WCELL] == WL_STASIS && emap[y / WCELL][x / WCELL] < 8) continue;+ if (r) {+ Particle *part = &parts[ID(r)];+ unsigned int ruleset = (unsigned int)part->ctype;+ if (ruleset < NGOL) ruleset = (unsigned int)builtinGol[ruleset].ruleset;+ if (!((ruleset >> neighbours) & 1) && part->tmp2 == (int)(ruleset >> 17) + 1) part->tmp2 -= 1; /* start dying */+ } else {+ unsigned int golnumToCreate = 0xFFFFFFFFU, createFromEntry = 0U;+ unsigned int majority = neighbours / 2 + neighbours % 2;+ for (int l = 0; l < kinds; ++l) {+ unsigned int golnum = list[l] & 0x001FFFFFU, ruleset = golnum;+ if (golnum - 1 < NGOL) {+ ruleset = (unsigned int)builtinGol[golnum - 1].ruleset;+ golnum -= 1;+ }+ if ((ruleset >> (neighbours + 8)) & 1 && ((list[l] >> 21) & 7) + 1 >= majority && golnum < golnumToCreate) {+ golnumToCreate = golnum;+ createFromEntry = list[l];+ }+ }+ if (golnumToCreate != 0xFFFFFFFFU) {+ /* 0x200000: no need to look for colours, they're set from the parent */+ int i = create_part(-1, x, y, PT_LIFE, (int)(golnumToCreate | 0x200000));+ if (i >= 0) {+ int xx = (createFromEntry >> 24) & 3, yy = (createFromEntry >> 26) & 3;+ if (xx == 3) xx = -1;+ if (yy == 3) yy = -1;+ int sample = PMAPAT(wrapx(x - xx), wrapy(y - yy));+ parts[i].tmp = parts[ID(sample)].tmp;+ }+ }+ }+ }+ for (int y = BORDER; y < YRES - BORDER; ++y)+ for (int x = BORDER; x < XRES - BORDER; ++x) {+ int r = PMAPAT(x, y);+ if (r && TYP(r) == PT_LIFE && parts[ID(r)].tmp2 <= 0) kill_part(ID(r));+ }+}++/* ---------------------------------------------------------------- rules as text (GOLString.cpp) */+int ParseGOLString(const char *it) {+ unsigned begin = 0, stay = 0, states = 2;+ if (*it == 'B') it++; /* must begin with a B */+ else return -1;+ for (; *it >= '1' && *it <= '8'; ++it) begin |= 1U << (*it - '0'); /* 1 to 8 */+ if (!begin) return -1;+ if (it[0] == '/' && it[1] == 'S') it += 2; /* then /S */+ else return -1;+ for (; *it >= '0' && *it <= '8'; ++it) stay |= 1U << (*it - '0'); /* 0 to 8 */+ if (*it) { /* optionally the number of states */+ if (*it == '/') it++;+ else return -1;+ states = 0;+ if (!*it) return -1;+ for (; *it; it++) {+ if (*it < '0' || *it > '9' || states > 1000) return -1;+ states = states * 10 + (unsigned)(*it - '0');+ }+ if (states < 2 || states > 17) return -1;+ }+ return (int)(stay | (begin << 8) | ((states - 2) << 17));+}++void SerialiseGOLRule(int rule, char *out) {+ *out++ = 'B';+ for (int i = 1; i < 9; ++i)+ if ((rule >> (i + 8)) & 1) *out++ = (char)('0' + i);+ *out++ = '/';+ *out++ = 'S';+ for (int i = 0; i < 9; ++i)+ if ((rule >> i) & 1) *out++ = (char)('0' + i);+ int st = (rule >> 17) & 0xF;+ if (st) {+ *out++ = '/';+ st += 2;+ if (st >= 10) *out++ = (char)('0' + st / 10);+ *out++ = (char)('0' + st % 10);+ }+ *out = 0;+}diff --git a/games/numpowder/src/gravity.c b/games/numpowder/src/gravity.cnew file mode 100644index 00000000..67d8ad81--- /dev/null+++ b/games/numpowder/src/gravity.c@@ -0,0 +1,138 @@+/* NumPowder: The Powder Toy's Newtonian gravity (gravity/Fft.cpp, Simulation's gravity functions). The original+ * convolves the masses with a point mass's field by FFT, on a thread that hands back the result a frame later;+ * on 25 x 16 cells, a direct sum over the cells with mass is cheap. As in the original, the field used in a frame+ * is that of the masses two frames before (one frame in the thread, one to take its result), and it's only+ * computed again when the masses or the gravity walls change. */+#include "simpriv.h"++float gravx[YACELLS][XACELLS], gravy[YACELLS][XACELLS]; /* gravOut */+float gravmass[YACELLS][XACELLS]; /* gravIn.mass */+uint8_t gravmask[YACELLS][XACELLS]; /* gravIn.mask (1: 0xFFFFFFFF, 0: 0) */+/* the worker's input (the masses and mask handed over last frame), and whether it has a result to take */+float grav_work_mass[YACELLS][XACELLS];+uint8_t grav_work_mask[YACELLS][XACELLS];+bool grav_work_pending, grav_force_recalc = true;+#define work_mass grav_work_mass+#define work_mask grav_work_mask+#define work_pending grav_work_pending+#define force_recalc grav_force_recalc++/* M_GRAV / d^3 for d = (dx, dy), dx 0..XACELLS-1, dy 0..YACELLS-1 (the kernel, by symmetry) */+static float kern[YACELLS][XACELLS];+static bool kern_done;+static void make_kernel(void) {+ for (int dy = 0; dy < YACELLS; dy++)+ for (int dx = 0; dx < XACELLS; dx++) {+ float d = hypotf((float)dx, (float)dy);+ kern[dy][dx] = (dx || dy) ? M_GRAV / (d * d * d) : 0.0f;+ }+ kern_done = true;+}++/* the worker's job (GravityImpl::Work): the field of the masses in the mask, zero outside the mask */+static void work(void) {+ if (!kern_done) make_kernel();+ memset(gravx, 0, sizeof gravx);+ memset(gravy, 0, sizeof gravy);+ for (int qy = 0; qy < YACELLS; qy++)+ for (int qx = 0; qx < XACELLS; qx++) {+ float m = work_mask[qy][qx] ? work_mass[qy][qx] : 0.f;+ if (m == 0.f) continue;+ for (int y = 0; y < YACELLS; y++) {+ int dy = y - qy, ady = dy < 0 ? -dy : dy;+ for (int x = 0; x < XACELLS; x++) {+ int dx = x - qx, adx = dx < 0 ? -dx : dx;+ float k = m * kern[ady][adx]; /* the force at (x, y) points to the mass */+ gravx[y][x] -= k * (float)dx;+ gravy[y][x] -= k * (float)dy;+ }+ }+ }+ for (int y = 0; y < YACELLS; y++)+ for (int x = 0; x < XACELLS; x++)+ if (!work_mask[y][x]) gravx[y][x] = gravy[y][x] = 0;+}++/* Gravity::Exchange, at the start of a frame: take the last result, hand over the new masses if they changed */+void grav_exchange(void) {+ if (!ngrav_enable) return;+ if (work_pending) {+ work();+ work_pending = false;+ }+ if (force_recalc || memcmp(work_mass, gravmass, sizeof work_mass) || memcmp(work_mask, gravmask, sizeof work_mask)) {+ memcpy(work_mass, gravmass, sizeof work_mass);+ memcpy(work_mask, gravmask, sizeof work_mask);+ work_pending = true;+ }+ force_recalc = false;+}++/* ResetNewtonianGravity({}, {}) */+void grav_reset(void) {+ memset(gravmass, 0, sizeof gravmass);+ memset(gravmask, 1, sizeof gravmask);+ memset(gravx, 0, sizeof gravx);+ memset(gravy, 0, sizeof gravy);+ memset(work_mass, 0, sizeof work_mass);+ memset(work_mask, 1, sizeof work_mask);+ work_pending = false;+ force_recalc = true;+ gravWallChanged = true;+}++/* EnableNewtonianGravity */+void grav_enable(bool enable) {+ if (ngrav_enable && !enable) {+ memset(gravx, 0, sizeof gravx);+ memset(gravy, 0, sizeof gravy);+ work_pending = false;+ force_recalc = true;+ }+ if (!ngrav_enable && enable) {+ memset(work_mass, 0, sizeof work_mass);+ memset(work_mask, 1, sizeof work_mask);+ force_recalc = true;+ }+ ngrav_enable = enable;+ settings.newtonian_gravity = enable;+}++/* the cells inside boxes of gravity walls get no gravity (UpdateGravityMask): filled from the edges through the+ * cells without a gravity wall (an air cell has one when any of its wall cells is one) */+static bool grav_wall(int x, int y) {+ for (int j = 0; j < ACELL / WCELL; j++)+ for (int i = 0; i < ACELL / WCELL; i++)+ if (bmap[y * (ACELL / WCELL) + j][x * (ACELL / WCELL) + i] == WL_GRAV) return true;+ return false;+}+void UpdateGravityMask(void) {+ memset(gravmask, 0, sizeof gravmask);+ uint16_t *stack = (uint16_t *)(void *)sim_scratch; /* (each cell pushes at most 4) */+ _Static_assert(XACELLS * YACELLS * 4 * 2 <= SCRATCH, "the gravity mask's stack fits the scratch RAM");+ int n = 0;+#define CHECK(px, py) \+ do { \+ int cx_ = (px), cy_ = (py); \+ if (!(grav_wall(cx_, cy_) || gravmask[cy_][cx_])) { \+ gravmask[cy_][cx_] = 1; \+ if (cx_ > 0) stack[n++] = (uint16_t)(cy_ * XACELLS + cx_ - 1); \+ if (cx_ < XACELLS - 1) stack[n++] = (uint16_t)(cy_ * XACELLS + cx_ + 1); \+ if (cy_ > 0) stack[n++] = (uint16_t)((cy_ - 1) * XACELLS + cx_); \+ if (cy_ < YACELLS - 1) stack[n++] = (uint16_t)((cy_ + 1) * XACELLS + cx_); \+ } \+ } while (0)+ for (int x = 0; x < XACELLS; ++x) {+ CHECK(x, 0);+ CHECK(x, YACELLS - 1);+ }+ for (int y = 1; y < YACELLS - 1; ++y) {+ CHECK(0, y);+ CHECK(XACELLS - 1, y);+ }+ while (n > 0) {+ int c = stack[--n];+ CHECK(c % XACELLS, c / XACELLS);+ }+#undef CHECK+}diff --git a/games/numpowder/src/icon.png b/games/numpowder/src/icon.pngnew file mode 100644index 00000000..b6a19b9dBinary files /dev/null and b/games/numpowder/src/icon.png differdiff --git a/games/numpowder/src/input.c b/games/numpowder/src/input.cnew file mode 100644index 00000000..a50ddd0d--- /dev/null+++ b/games/numpowder/src/input.c@@ -0,0 +1,32 @@+/* NumPowder: keys, as pressed this tick or held, with repeats. */+#include "input.h"++Input input;++void input_update(void) {+ uint32_t now = plat_keys();+ int tk = plat_text_key();+ input.text_key = (int8_t)(tk >= 0 && tk != input.text_held ? tk : -1);+ input.text_held = (int8_t)tk;+ if (input.typing) {+ /* 4, 6, 8, 2 and 5 type digits (or letters), + and - their signs, not the arrows, OK and the zoom */+ static const struct { int8_t tk; uint16_t k; } alias[] = {+ {TK_FOUR, K_LEFT}, {TK_SIX, K_RIGHT}, {TK_EIGHT, K_UP}, {TK_TWO, K_DOWN}, {TK_FIVE, K_OK}, {TK_PLUS, K_PLUS},+ {TK_MINUS, K_MINUS}};+ for (unsigned i = 0; i < sizeof alias / sizeof alias[0]; i++)+ if (tk == alias[i].tk) now &= ~(uint32_t)alias[i].k;+ }+ input.pressed = now & ~input.held;+ input.released = input.held & ~now;+ input.held = now;+ input.repeat = input.pressed;+ for (int i = 0; i < 16; i++) {+ if (now & (1u << i)) {+ input.held_ticks[i]++;+ /* a held key repeats after 12 ticks, then every 3 */+ if (input.held_ticks[i] > 12 && (input.held_ticks[i] - 12) % 3 == 0) input.repeat |= 1u << i;+ } else {+ input.held_ticks[i] = 0;+ }+ }+}diff --git a/games/numpowder/src/input.h b/games/numpowder/src/input.hnew file mode 100644index 00000000..1ea1f2d1--- /dev/null+++ b/games/numpowder/src/input.h@@ -0,0 +1,21 @@+/* NumPowder: keys, as pressed this tick or held, with repeats. */+#ifndef NP_INPUT_H+#define NP_INPUT_H+#include "plat.h"++typedef struct {+ uint32_t held; /* K_* held now */+ uint32_t pressed; /* went down this tick */+ uint32_t repeat; /* pressed, or held long enough to repeat (arrows, + and -) */+ uint32_t released;+ uint16_t held_ticks[16];+ int8_t text_key; /* a typing key that went down this tick (TK_*), -1 none */+ int8_t text_held; /* the typing key held, -1 none */+ bool typing; /* a text is being typed: the typing keys don't also act as the arrows, OK, + and - */+} Input;+extern Input input;+void input_update(void);+static inline bool key_pressed(uint32_t k) { return (input.pressed & k) != 0; }+static inline bool key_repeat(uint32_t k) { return (input.repeat & k) != 0; }+static inline bool key_held(uint32_t k) { return (input.held & k) != 0; }+#endifdiff --git a/games/numpowder/src/main.c b/games/numpowder/src/main.cnew file mode 100644index 00000000..d4c68f27--- /dev/null+++ b/games/numpowder/src/main.c@@ -0,0 +1,128 @@+/* NumPowder: The Powder Toy on the NumWorks calculator, the game's loop.+ *+ * Inspired by The Powder Toy, not affiliated with its developers. Elements, font and icons ported from The+ * Powder Toy's source code (GPL-3.0) by Stanislaw K Skowronek, Simon Robertshaw and its contributors. Made by+ * Mason Chen as part of NumPlay. */+#include "ui.h"++#ifndef HOST+const char eadk_app_name[] __attribute__((section(".rodata.eadk_app_name"))) = "NumPowder";+const uint32_t eadk_api_level __attribute__((section(".rodata.eadk_api_level"))) = 0;+#endif++/* the frame time: as fast as it goes, up to the original's 60 frames a second */+#define FRAME_MS 16++static uint32_t fps_last, fps_frames;++/* a frame: the keys, the simulation, the stickmen, the drawing */+bool game_frame(void) {+ input_update();+ if (!ui_tick()) return false;+ bool run = !sys_pause || ui.step;+ ui.step = false;+ bool modal = ui.mode == MODE_CONFIRM || ui.mode == MODE_SAVES || ui.mode == MODE_TEXT;+ if (modal) run = false;+ sim_frame(run);+ int right = tool_is_element(ui.tool[1]) ? TYP(ui.tool[1]) : 0;+ stkm_frame(right);+ /* the interface's overlay lives on this stack until the frame is drawn */+ Overlay o;+ ov_reset(&o);+ bool panel = false;+ int push_w = ui_draw(&o, &panel);+ render_frame(&o, panel, push_w);+ /* FPS, as the original's: frames over the last half second */+ fps_frames++;+ uint32_t now = plat_millis();+ if (now - fps_last >= 500) {+ ui.fps100 = fps_frames * 100000u / (now - fps_last);+ fps_frames = 0, fps_last = now;+ }+ return true;+}++#ifdef TEST_SCENE+/* speed tests (make EXTRA=-DTEST_SCENE=n): a busy simulation from the start */+static void test_scene(void) {+ /* 1: still elements (about 4800 particles); 2: with fire, plasma and lava (glowing). (Void edges, as the first+ * measures were made with: what falls out goes) */+ settings.edge_mode = EDGE_VOID;+ sim_settings_changed();+ static const uint8_t still[] = {PT_STNE, PT_GLAS, PT_METL, PT_WOOD, PT_BRCK, PT_DMND, PT_IRON, PT_CNCT};+ static const uint8_t hot[] = {PT_SAND, PT_WATR, PT_STNE, PT_OIL, PT_GLAS, PT_LAVA, PT_FIRE, PT_PLSM, PT_METL, PT_SALT};+ for (int y = 4; y < YRES - 4; y++)+ for (int x = 2; x < XRES - 2; x++) {+ int k = x / 10 + y / 16 * 3;+ create_part(-1, x, y, TEST_SCENE == 1 ? still[k % sizeof still] : hot[k % sizeof hot], -1);+ }+ ui.intro = 0;+}+#endif++void game_init(void) {+ sim_init();+ render_init();+ ui_init();+#ifdef TEST_SCENE+ test_scene();+#endif+#ifdef PERF_HASH+ ui.debug = false;+#endif+ fps_last = plat_millis();+}++#ifndef HOST+uint32_t perf_frames __attribute__((used));+uint32_t perf_ms __attribute__((used));+uint32_t perf_max __attribute__((used));+uint32_t perf_render __attribute__((used)); /* the drawing's ms, all frames (render_frame) */+#ifdef PERF_HASH+/* the same simulation before and after a change (make EXTRA="-DSIM_SCENE=n -DPERF_HASH=frames", with tools/emu.py):+ * after that many frames of the simulation, a hash of its state, then the app waits on the frame drawn (the HUD and+ * its FPS hidden, so the screen can be compared too) */+uint32_t perf_hash __attribute__((used));+static void hash_mix(uint32_t *h, const void *p, size_t n) {+ for (size_t k = 0; k < n; k++) *h = (*h ^ ((const uint8_t *)p)[k]) * 16777619u;+}+static uint32_t state_hash(void) {+ uint32_t h = 2166136261u;+ for (int i = 0; i < parts_active; i++)+ if (parts[i].type) hash_mix(&h, &i, sizeof i), hash_mix(&h, &parts[i], sizeof(Particle));+ hash_mix(&h, pv, sizeof pv), hash_mix(&h, vx, sizeof vx), hash_mix(&h, vy, sizeof vy), hash_mix(&h, hv, sizeof hv);+ hash_mix(&h, gravx, sizeof gravx), hash_mix(&h, gravy, sizeof gravy), hash_mix(&h, bmap, sizeof bmap);+ hash_mix(&h, emap, sizeof emap), hash_mix(&h, rng_state, sizeof rng_state), hash_mix(&h, &temp_dither, sizeof temp_dither);+ return h;+}+#endif++int main(void) {+ /* the particle map lives on this stack (12.8 KB): the heap is the particles' */+ uint16_t pmap_mem[YRES][XRES] __attribute__((aligned(8))); /* (cleared a word at a time) */+ pmap_id = pmap_mem;+ plat_begin();+ game_init();+ uint32_t next = plat_millis();+ for (;;) {+ uint32_t t0 = plat_millis();+ if (!game_frame()) break;+#ifdef PERF_HASH+ if (frameCount >= PERF_HASH) {+ perf_hash = state_hash();+ for (;;) plat_sleep(1000); /* (read by the emulator: quitting would clear the RAM) */+ }+#endif+ perf_frames++;+ perf_render += render_ms_total;+ uint32_t dt = plat_millis() - t0;+ perf_ms += dt;+ if (perf_frames > 30 && dt > perf_max) perf_max = dt;+ next += FRAME_MS;+ uint32_t now = plat_millis();+ if ((int32_t)(next - now) > 0) plat_sleep(next - now);+ else next = now;+ }+ return plat_end();+}+#endifdiff --git a/games/numpowder/src/plat.h b/games/numpowder/src/plat.hnew file mode 100644index 00000000..fcd4be4f--- /dev/null+++ b/games/numpowder/src/plat.h@@ -0,0 +1,52 @@+/* NumPowder: the platform (the calculator, or a computer for tests).+ *+ * plat_eadk.c: the calculator's EADK display, keyboard, time and files.+ * plat_host.c: a frame buffer that tests save as images, scripted keys and+ * simulated time (tests/play.c). */+#ifndef NP_PLAT_H+#define NP_PLAT_H+#include <stdbool.h>+#include <stddef.h>+#include <stdint.h>++#define SCREEN_W 320+#define SCREEN_H 240++/* keys held now, as bits */+enum {+ K_LEFT = 1 << 0, K_RIGHT = 1 << 1, K_UP = 1 << 2, K_DOWN = 1 << 3,+ K_OK = 1 << 4, /* OK, EXE */+ K_BACK = 1 << 5, /* Back */+ K_HOME = 1 << 6, /* Home, On/Off */+ K_TOOLBOX = 1 << 7, /* toolbox: the element menu */+ K_VAR = 1 << 8, /* var: the display and options menu */+ K_SHIFT = 1 << 9, /* shift: with arrows, a faster cursor; with OK, a line */+ K_ALPHA = 1 << 10, /* alpha: pause */+ K_PLUS = 1 << 11, K_MINUS = 1 << 12, /* the brush's size */+ K_BACKSPACE = 1 << 13,+ K_ANY = 1 << 14+};+uint32_t plat_keys(void);+/* the keys that type (a save's name): the one held now, as its number on the NumWorks keyboard (TK_EXP to TK_ANS,+ * row by row; Epsilon's eadk_key_t), -1 none. Some of them are also K_* keys above (4, 6, 8, 2, 5, + and -) */+enum { TK_EXP = 18, TK_SQUARE = 29, TK_SEVEN = 30, TK_RPAREN = 34, TK_FOUR = 36, TK_FIVE = 37, TK_SIX = 38,+ TK_DIVISION = 40, TK_ONE = 42, TK_TWO = 43, TK_PLUS = 45, TK_MINUS = 46, TK_ZERO = 48, TK_ANS = 51, TK_EIGHT = 31 };+int plat_text_key(void);+uint32_t plat_millis(void);+void plat_sleep(uint32_t ms);+void plat_push(int x, int y, int w, int h, const uint16_t *px);+void plat_fill(int x, int y, int w, int h, uint16_t c);+/* reads back what the screen shows (the persistent display's trails) */+void plat_pull(int x, int y, int w, int h, uint16_t *px);+bool plat_save(const char *name, const void *data, uint32_t len);+const uint8_t *plat_load(const char *name, uint32_t *len); /* NULL if absent */+/* a file of len bytes to write in place (the calculator's storage is RAM): plat_reserve gives its+ * bytes, plat_reserved says they are written; NULL if there is no room */+uint8_t *plat_reserve(const char *name, uint32_t len);+void plat_reserved(const char *name, uint32_t len);+bool plat_remove(const char *name);+void plat_begin(void);+int plat_end(void);+/* an N0110 or N0115 (216 MHz, the N0120 has 550) */+bool plat_slow(void);+#endifdiff --git a/games/numpowder/src/plat_eadk.c b/games/numpowder/src/plat_eadk.cnew file mode 100644index 00000000..c33b0de2--- /dev/null+++ b/games/numpowder/src/plat_eadk.c@@ -0,0 +1,58 @@+/* NumPowder on the calculator: EADK display, keyboard, time and files. */+#include <eadk.h>+#include "../../common/epsilon_app.h"+#include "../../common/epsilon_files.h"+#include "plat.h"++#define KEY(k) ((uint64_t)1 << (k))++uint32_t plat_keys(void) {+ uint64_t k = eadk_keyboard_scan();+ uint32_t r = 0;+ if (k & (KEY(eadk_key_left) | KEY(eadk_key_four))) r |= K_LEFT;+ if (k & (KEY(eadk_key_right) | KEY(eadk_key_six))) r |= K_RIGHT;+ if (k & (KEY(eadk_key_up) | KEY(eadk_key_eight))) r |= K_UP;+ if (k & (KEY(eadk_key_down) | KEY(eadk_key_two))) r |= K_DOWN;+ if (k & (KEY(eadk_key_ok) | KEY(eadk_key_exe) | KEY(eadk_key_five))) r |= K_OK;+ if (k & KEY(eadk_key_back)) r |= K_BACK;+ if (k & (KEY(eadk_key_home) | KEY(eadk_key_on_off))) r |= K_HOME;+ if (k & KEY(eadk_key_toolbox)) r |= K_TOOLBOX;+ if (k & KEY(eadk_key_var)) r |= K_VAR;+ if (k & KEY(eadk_key_shift)) r |= K_SHIFT;+ if (k & KEY(eadk_key_alpha)) r |= K_ALPHA;+ if (k & KEY(eadk_key_plus)) r |= K_PLUS;+ if (k & KEY(eadk_key_minus)) r |= K_MINUS;+ if (k & KEY(eadk_key_backspace)) r |= K_BACKSPACE;+ if (k) r |= K_ANY;+ return r;+}++int plat_text_key(void) {+ uint64_t k = eadk_keyboard_scan();+ for (int i = TK_EXP; i <= TK_ANS; i++)+ if (k & KEY(i)) return i;+ return -1;+}++uint32_t plat_millis(void) { return (uint32_t)eadk_timing_millis(); }+void plat_sleep(uint32_t ms) { eadk_timing_msleep(ms); }+void plat_push(int x, int y, int w, int h, const uint16_t *px) {+ eadk_display_push_rect((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, px);+}+void plat_pull(int x, int y, int w, int h, uint16_t *px) {+ eadk_display_pull_rect((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, px);+}+void plat_fill(int x, int y, int w, int h, uint16_t c) {+ if (w > 0 && h > 0) eadk_display_push_rect_uniform((eadk_rect_t){(uint16_t)x, (uint16_t)y, (uint16_t)w, (uint16_t)h}, c);+}+bool plat_save(const char *name, const void *data, uint32_t len) { return ef_write(name, data, len); }+const uint8_t *plat_load(const char *name, uint32_t *len) { return ef_read(name, len); }+uint8_t *plat_reserve(const char *name, uint32_t len) {+ uint32_t n;+ return ef_write(name, NULL, len) ? (uint8_t *)(uintptr_t)ef_read(name, &n) : NULL; /* (the storage is RAM) */+}+void plat_reserved(const char *name, uint32_t len) { (void)name, (void)len; }+bool plat_remove(const char *name) { return ef_remove(name); }+void plat_begin(void) { np_app_begin(); }+int plat_end(void) { return np_app_end(); }+bool plat_slow(void) { return epsilon_slow_model(); }diff --git a/games/numpowder/src/plat_host.c b/games/numpowder/src/plat_host.cnew file mode 100644index 00000000..a155a708--- /dev/null+++ b/games/numpowder/src/plat_host.c@@ -0,0 +1,80 @@+/* NumPowder on a computer: the screen goes to a frame buffer that tests save as images,+ * keys come from a script, time is simulated. */+#include <stdio.h>+#include <stdlib.h>+#include "plat.h"++uint16_t host_fb[SCREEN_W * SCREEN_H];+uint32_t host_time; /* ms */+uint32_t host_keys;++int host_text_key = -1; /* the typing key held (TK_*), -1 none */+uint32_t plat_keys(void) { return host_keys; }+int plat_text_key(void) { return host_text_key; }+uint32_t plat_millis(void) { return host_time; }+void plat_sleep(uint32_t ms) { host_time += ms; }+void plat_push(int x, int y, int w, int h, const uint16_t *px) {+ for (int r = 0; r < h; r++)+ for (int c = 0; c < w; c++)+ if ((unsigned)(x + c) < SCREEN_W && (unsigned)(y + r) < SCREEN_H) host_fb[(y + r) * SCREEN_W + x + c] = px[r * w + c];+}+void plat_pull(int x, int y, int w, int h, uint16_t *px) {+ for (int r = 0; r < h; r++)+ for (int c = 0; c < w; c++)+ px[r * w + c] = (unsigned)(x + c) < SCREEN_W && (unsigned)(y + r) < SCREEN_H ? host_fb[(y + r) * SCREEN_W + x + c] : 0;+}+void plat_fill(int x, int y, int w, int h, uint16_t c) {+ for (int r = 0; r < h; r++)+ for (int k = 0; k < w; k++)+ if ((unsigned)(x + k) < SCREEN_W && (unsigned)(y + r) < SCREEN_H) host_fb[(y + r) * SCREEN_W + x + k] = c;+}++static char save_dir[256] = "build/host-saves";+void host_save_dir(const char *d) { snprintf(save_dir, sizeof save_dir, "%s", d); }+bool plat_save(const char *name, const void *data, uint32_t len) {+ char p[512];+ snprintf(p, sizeof p, "%s/%s", save_dir, name);+ FILE *f = fopen(p, "wb");+ if (!f) return false;+ bool ok = fwrite(data, 1, len, f) == len;+ fclose(f);+ return ok;+}+static uint8_t loaded[1 << 17];+const uint8_t *plat_load(const char *name, uint32_t *len) {+ char p[512];+ snprintf(p, sizeof p, "%s/%s", save_dir, name);+ FILE *f = fopen(p, "rb");+ if (!f) return NULL;+ *len = (uint32_t)fread(loaded, 1, sizeof loaded, f);+ fclose(f);+ return loaded;+}+static uint8_t reserved[1 << 17];+bool host_storage_full; /* tests: no room for any file */+uint8_t *plat_reserve(const char *name, uint32_t len) {+ (void)name;+ return len <= sizeof reserved && !host_storage_full ? reserved : NULL;+}+void plat_reserved(const char *name, uint32_t len) { plat_save(name, reserved, len); }+bool plat_remove(const char *name) {+ char p[512];+ snprintf(p, sizeof p, "%s/%s", save_dir, name);+ return remove(p) == 0;+}+void plat_begin(void) {}+int plat_end(void) { return 0; }+bool plat_slow(void) { return false; }++/* writes the screen as a PPM image */+void host_shot(const char *path) {+ FILE *f = fopen(path, "wb");+ if (!f) return;+ fprintf(f, "P6\n%d %d\n255\n", SCREEN_W, SCREEN_H);+ for (int i = 0; i < SCREEN_W * SCREEN_H; i++) {+ uint16_t c = host_fb[i];+ uint8_t rgb[3] = {(uint8_t)((c >> 11) * 255 / 31), (uint8_t)(((c >> 5) & 63) * 255 / 63), (uint8_t)((c & 31) * 255 / 31)};+ fwrite(rgb, 1, 3, f);+ }+ fclose(f);+}diff --git a/games/numpowder/src/render.c b/games/numpowder/src/render.cnew file mode 100644index 00000000..7f18bba4--- /dev/null+++ b/games/numpowder/src/render.c@@ -0,0 +1,1182 @@+/* NumPowder: The Powder Toy's renderer (Renderer.cpp: render_parts, render_fire, DrawWalls, draw_air, draw_grav,+ * draw_other; Gradient.cpp; Pixel.h's blending), drawn in bands (render.h).+ *+ * A frame, as the original's RenderSimulation:+ * - the fire glow's cells first take the powered walls' glow and every particle's fire (render_parts' fire part,+ * in the particles' order, so the glow is the original's);+ * - then for each band of 4 particle rows (one row of the glow's cells), into 24-bit pixels: the air (draw_air)+ * or the persistent trails, the gravity field's lines (draw_grav), the streamlines, every particle whose+ * drawing reaches the band (render_parts), the fire glow of the cells around (render_fire, which then lets the+ * cells above fade), the EMP's flash (draw_other);+ * - each band shown 3 x 3 pixels a particle, the walls' patterns at the screen's resolution (DrawWalls), the+ * stickmen, then the interface's overlay. */+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("O3") /* (a hot path: a few KB of flash for speed) */+#endif+#include "render.h"+#include <string.h>++RenderSettings ren = {RENDER_BASC | RENDER_FIRE | RENDER_SPRK | RENDER_EFFE, 0, COLOUR_DEFAULT, false, true, false};++const RenderPreset render_presets[PRESET_COUNT] = {+ {"Alternative Velocity Display", RENDER_EFFE | RENDER_BASC, DISPLAY_AIRC, 0, false},+ {"Velocity Display", RENDER_EFFE | RENDER_BASC, DISPLAY_AIRV, 0, false},+ {"Pressure Display", RENDER_EFFE | RENDER_BASC, DISPLAY_AIRP, 0, false},+ {"Persistent Display", RENDER_EFFE | RENDER_BASC, DISPLAY_PERS, 0, false},+ {"Fire Display", RENDER_FIRE | RENDER_SPRK | RENDER_EFFE | RENDER_BASC, 0, 0, false},+ {"Blob Display", RENDER_FIRE | RENDER_SPRK | RENDER_EFFE | RENDER_BLOB, 0, 0, false},+ {"Heat Display", RENDER_BASC, DISPLAY_AIRH, COLOUR_HEAT, false},+ {"Fancy Display", RENDER_FIRE | RENDER_SPRK | RENDER_GLOW | RENDER_BLUR | RENDER_EFFE | RENDER_BASC, DISPLAY_WARP, 0, false},+ {"Nothing Display", RENDER_BASC, 0, 0, false},+ {"Heat Gradient Display", RENDER_BASC, 0, COLOUR_GRAD, false},+ {"Life Gradient Display", RENDER_BASC, 0, COLOUR_LIFE, false},+ {"Dynamic Heat Display", RENDER_BASC, DISPLAY_AIRH, COLOUR_HEAT, true},+ {"Vorticity Display", RENDER_EFFE | RENDER_BASC, DISPLAY_AIRW, 0, false},+ {"Destructibility Display", RENDER_BASC, 0, COLOUR_DEST, false},+};++uint32_t render_ms_parts, render_ms_total;+int render_found;++/* ---------------------------------------------------------------- the fire glow (fire_r, fire_g, fire_b) */+static uint8_t fire_r[YACELLS][XACELLS], fire_g[YACELLS][XACELLS], fire_b[YACELLS][XACELLS];+static uint32_t fire_nz; /* the rows of cells that may glow (a bit each): the others are skipped */+static uint32_t frame_no;++/* prepare_alpha(CELL, 1.0f): each cell's glow over the 3 x 3 cells around it, the sum over its 4 x 4 particles of+ * expf(-0.1f * (i * i + j * j)) for i, j from -CELL to CELL - 1 (worked out once: it never changes) */+static const uint8_t fire_alpha[ACELL * 3][ACELL * 3] = {+ {0, 1, 4, 7, 9, 11, 11, 9, 6, 3, 1, 0},+ {1, 5, 12, 21, 28, 33, 33, 28, 19, 10, 3, 0},+ {4, 12, 26, 44, 60, 70, 70, 60, 40, 21, 8, 0},+ {7, 21, 44, 75, 103, 121, 121, 103, 68, 37, 14, 0},+ {9, 28, 60, 103, 141, 165, 165, 141, 94, 51, 19, 0},+ {11, 33, 70, 121, 165, 193, 193, 165, 109, 59, 22, 0},+ {11, 33, 70, 121, 165, 193, 193, 165, 109, 59, 22, 0},+ {9, 28, 60, 103, 141, 165, 165, 141, 94, 51, 19, 0},+ {6, 19, 40, 68, 94, 109, 109, 94, 62, 34, 12, 0},+ {3, 10, 21, 37, 51, 59, 59, 51, 34, 18, 6, 0},+ {1, 3, 8, 14, 19, 22, 22, 19, 12, 6, 2, 0},+ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},+};++void render_clear_accumulation(void) {+ memset(fire_r, 0, sizeof fire_r);+ memset(fire_g, 0, sizeof fire_g);+ memset(fire_b, 0, sizeof fire_b);+ fire_nz = 0;+}++void render_apply(uint32_t render_mode, uint32_t display_mode, uint32_t colour_mode) {+ if ((!(render_mode & FIREMODE) && (ren.render_mode & FIREMODE)) ||+ (!(display_mode & DISPLAY_PERS) && (ren.display_mode & DISPLAY_PERS)))+ render_clear_accumulation();+ ren.render_mode = render_mode, ren.display_mode = display_mode, ren.colour_mode = colour_mode;+}++int render_preset_now(void) {+ for (int i = 0; i < PRESET_COUNT; i++)+ if (render_presets[i].render_mode == ren.render_mode && render_presets[i].display_mode == ren.display_mode &&+ render_presets[i].colour_mode == ren.colour_mode && render_presets[i].hdisp_auto == ren.hdisp_auto)+ return i;+ return -1;+}+void render_apply_preset(int preset) {+ const RenderPreset *p = &render_presets[preset];+ render_apply(p->render_mode, p->display_mode, p->colour_mode);+ ren.hdisp_auto = p->hdisp_auto;+}++/* the heat display's range (RendererStats' hdispLimitMin and Max, Renderer::AdjustHdispLimit): MIN_TEMP to+ * MAX_TEMP, or in Dynamic Heat Display the coldest to the hottest shown, shrinking towards them slowly */+static float hdisp_min, hdisp_max = MAX_TEMP;+static void hdisp_adjust(void) {+ if (!ren.hdisp_auto) {+ hdisp_min = MIN_TEMP, hdisp_max = MAX_TEMP;+ return;+ }+ float lo = MAX_TEMP, hi = MIN_TEMP;+ if (ren.colour_mode & COLOUR_HEAT)+ for (int i = 0; i < parts_active; i++) {+ const Particle *p = &parts[i];+ int t = p->type;+ if (!t || !elements[t].HeatConduct || !InBounds(p_cx(p), p_cy(p))) continue;+ float v = p_temp(p);+ lo = fminf(lo, v), hi = fmaxf(hi, v);+ }+ if (aheat_enable && (ren.display_mode & DISPLAY_AIR) && (ren.display_mode & DISPLAY_AIRH))+ for (int y = 0; y < YACELLS; y++)+ for (int x = 0; x < XACELLS; x++) lo = fminf(lo, hv[y][x]), hi = fmaxf(hi, hv[y][x]);+ /* (they shrink towards the new range slowly, to prevent rapid flashes, but expand at once; a degree apart) */+ hi = fmaxf(hi, hdisp_max - (hdisp_max - hi) * 0.05f);+ lo = fminf(lo, hdisp_min + (lo - hdisp_min) * 0.05f);+ hi = fminf(MAX_TEMP, fmaxf(hi, lo + 1));+ lo = fmaxf(MIN_TEMP, fminf(lo, hi - 1));+ if (isnan(lo)) lo = MIN_TEMP;+ if (isnan(hi)) hi = MAX_TEMP;+ hdisp_max = fminf(fmaxf(hi, MIN_TEMP), MAX_TEMP);+ hdisp_min = fminf(fmaxf(lo, MIN_TEMP), hdisp_max);+}+static inline uint32_t heat_colour(float temp) {+ return heat_table_at((int)((temp - hdisp_min) / (hdisp_max - hdisp_min) * 1024));+}++void render_init(void) { render_clear_accumulation(); }++/* ---------------------------------------------------------------- the colour tables (Gradient, PopulateTables) */+typedef struct { uint32_t c; float p; } Stop;+static uint32_t blend888(uint32_t d, uint32_t c, int a) {+ if (a >= 255) return c & 0xFFFFFF;+ uint32_t r = (uint16_t)(a * (c >> 16 & 255) + (255 - a) * (d >> 16 & 255)) / 255;+ uint32_t g = (uint16_t)(a * (c >> 8 & 255) + (255 - a) * (d >> 8 & 255)) / 255;+ uint32_t b = (uint16_t)(a * (c & 255) + (255 - a) * (d & 255)) / 255;+ return r << 16 | g << 8 | b;+}+static uint32_t gradient(const Stop *s, int n, int res, int i) {+ if (i < 0) i = 0;+ if (i > res - 1) i = res - 1;+ float point = i / (float)res;+ int k = -1;+ while (k < n - 1 && s[k + 1].p <= point) k++;+ if (k < 0 || k >= n - 1) return 0;+ float f = (point - s[k].p) / (s[k + 1].p - s[k].p);+ return blend888(s[k].c, s[k + 1].c, (uint8_t)(f * 255));+}+static const Stop flame[] = {{0x000000, 0.00f}, {0x60300F, 0.50f}, {0xDFBF6F, 0.90f}, {0xAF9F0F, 1.00f}};+static const Stop plasma[] = {{0x000000, 0.00f}, {0x301040, 0.25f}, {0x301060, 0.50f}, {0xAFFFFF, 0.90f},+ {0xAFFFFF, 1.00f}};+static const Stop heat[] = {{0x2B00FF, 0.00f}, {0x003CFF, 0.01f}, {0x00C0FF, 0.05f}, {0x00FFEB, 0.08f},+ {0x00FF14, 0.19f}, {0x4BFF00, 0.25f}, {0xC8FF00, 0.37f}, {0xFFDC00, 0.45f},+ {0xFF0000, 0.71f}, {0xFF00DC, 1.00f}};+static const Stop clfm[] = {{0x000000, 0.00f}, {0x0A0917, 0.10f}, {0x19163C, 0.20f}, {0x28285E, 0.30f},+ {0x343E77, 0.40f}, {0x49769A, 0.60f}, {0x57A0B4, 0.80f}, {0x5EC4C6, 1.00f}};+static const Stop firw[] = {{0xFF00FF, 0.00f}, {0x0000FF, 0.20f}, {0x00FFFF, 0.40f}, {0x00FF00, 0.60f},+ {0xFFFF00, 0.80f}, {0xFF0000, 1.00f}};+#define NSTOPS(a) ((int)(sizeof(a) / sizeof(a[0])))+uint32_t flame_table_at(int i) { return gradient(flame, NSTOPS(flame), 200, i); }+uint32_t plasma_table_at(int i) { return gradient(plasma, NSTOPS(plasma), 200, i); }+uint32_t heat_table_at(int i) { return gradient(heat, NSTOPS(heat), 1024, i); }+uint32_t clfm_table_at(int i) { return gradient(clfm, NSTOPS(clfm), 200, i); }+uint32_t firw_table_at(int i) { return gradient(firw, NSTOPS(firw), 200, i); }++/* HeatToColour, for the air's heat */+static inline uint32_t heat_colour(float temp);+static uint32_t heat_to_colour(float temp) {+ uint32_t c = heat_colour(temp);+ return (uint32_t)(uint8_t)((c >> 16 & 255) * 0.7f) << 16 | (uint32_t)(uint8_t)((c >> 8 & 255) * 0.7f) << 8 |+ (uint8_t)((c & 255) * 0.7f);+}++/* ---------------------------------------------------------------- the graphics functions' random numbers */+static uint32_t grng;+static void grng_seed(uint32_t i) {+ uint32_t x = i * 2654435761u ^ frame_no * 0x9E3779B9u;+ x ^= x >> 16, x *= 0x7FEB352Du, x ^= x >> 15, x *= 0x846CA68Bu, x ^= x >> 16;+ grng = x | 1;+}+static inline uint32_t grng_u32(void) {+ grng ^= grng << 13, grng ^= grng >> 17, grng ^= grng << 5;+ return grng;+}+uint32_t ren_rng_gen(void) { return grng_u32() >> 1; }+int ren_rng_between(int lower, int upper) { return lower + (int)(grng_u32() % (uint32_t)(upper - lower + 1)); }+bool ren_rng_chance(int numerator, unsigned denominator) {+ if (numerator <= 0) return false;+ return grng_u32() % denominator < (unsigned)numerator;+}++__attribute__((weak)) uint32_t part_dcolour(const Particle *p) { (void)p; return 0; }++/* SimulationData::DestructibilityScore */+static int destructibility(int t) {+ if (t <= 0 || t >= PT_NUM) return 0;+ if (t == PT_CLNE || t == PT_PCLN) return 100; /* (nonzero Hardness, yet indestructible) */+ const Element *e = &elements[t];+ uint32_t prop = e->Properties;+ if (prop & TYPE_ENERGY) return 10;+ if (prop & TYPE_GAS) return 20;+ if (prop & TYPE_LIQUID) return 30;+ if (prop & TYPE_PART) return 40;+ if (e->Flammable > 0) return 50;+ if (e->HighPressureTransition != NT || e->LowPressureTransition != NT) return 60;+ if (e->HighTemperatureTransition != NT || e->LowTemperatureTransition != NT) return 70;+ if (e->Hardness > 0) return 80;+ if (t == PT_VIBR || t == PT_RSSS || t == PT_HEAC) return 90;+ return 100;+}++/* ---------------------------------------------------------------- a particle's look (render_parts) */+typedef struct { int pm, ca, cr, cg, cb, fa, fr, fg, fb; } Shade;++/* Element::defaultGraphics: radioactive elements glow, liquids blur, gases are a haze of fire */+int default_graphics(GRAPHICS_FUNC_ARGS) {+ uint32_t props = elements[cpart->type].Properties;+ if (props & PROP_RADIOACTIVE) *pixel_mode |= PMODE_GLOW;+ if (props & TYPE_LIQUID) *pixel_mode |= PMODE_BLUR;+ if (props & TYPE_GAS) {+ *pixel_mode &= ~PMODE;+ *pixel_mode |= FIRE_BLEND;+ *firer = *colr / 2;+ *fireg = *colg / 2;+ *fireb = *colb / 2;+ *firea = 125;+ *pixel_mode |= DECO_FIRE;+ }+ return 1;+}+/* the modes default_graphics gives an element (with PMODE_FLAT, which it starts with) */+static int default_modes(int t) {+ uint32_t props = elements[t].Properties;+ int pm = PMODE_FLAT;+ if (props & PROP_RADIOACTIVE) pm |= PMODE_GLOW;+ if (props & TYPE_LIQUID) pm |= PMODE_BLUR;+ if (props & TYPE_GAS) pm = (pm & ~PMODE) | FIRE_BLEND | DECO_FIRE;+ return pm;+}+/* render_parts' pixel modes as the render mode allows them */+static inline int allowed_modes(int pm, uint32_t rm) {+ if ((pm & FIRE_ADD) && !(rm & FIRE_ADD)) pm |= PMODE_GLOW;+ if ((pm & FIRE_BLEND) && !(rm & FIRE_BLEND)) pm |= PMODE_BLUR;+ if ((pm & PMODE_BLUR) && !(rm & PMODE_BLUR)) pm |= PMODE_FLAT;+ if ((pm & PMODE_GLOW) && !(rm & PMODE_GLOW)) pm |= PMODE_BLEND;+ if (rm & PMODE_BLOB) pm |= PMODE_BLOB;+ return pm & (int)rm;+}++static void shade(int i, const Particle *p, int t, int nx, int ny, Shade *s) {+ const Element *el = &elements[t];+ uint32_t colour = el->Colour;+ s->pm = PMODE_FLAT, s->ca = 255;+ s->cr = colour >> 16 & 255, s->cg = colour >> 8 & 255, s->cb = colour & 255;+ s->fa = s->fr = s->fg = s->fb = 0;+ uint32_t dc = ren.decorations ? part_dcolour(p) : 0;+ int deca = dc >> 24 & 255, decr = dc >> 16 & 255, decg = dc >> 8 & 255, decb = dc & 255;+ uint32_t rm = ren.render_mode, cm = ren.colour_mode;+ /* (an element without graphics of its own, but for gases: its colour with the default graphics' modes, what the+ * rest would come to) */+ if (!el->Graphics && !cm && !deca && !(el->Properties & (PROP_HOT_GLOW | TYPE_GAS))) {+ int base = PMODE_FLAT;+ if (t != PT_DUST && t != PT_SAWD && t != PT_DRAY) { /* (element_graphics: default_graphics) */+ if (el->Properties & PROP_RADIOACTIVE) base |= PMODE_GLOW;+ if (el->Properties & TYPE_LIQUID) base |= PMODE_BLUR;+ }+ s->pm = allowed_modes(base, rm);+ return;+ }+ GraphicsFn g = element_graphics(t);+ if (!(cm & COLOUR_BASC) && g) {+ grng_seed((uint32_t)i);+ g(p, nx, ny, &s->pm, &s->ca, &s->cr, &s->cg, &s->cb, &s->fa, &s->fr, &s->fg, &s->fb);+ }+ if ((el->Properties & PROP_HOT_GLOW) && p_temp(p) > el->HighTemperature - 800.0f) {+ float ht = el->HighTemperature, temp = p_temp(p);+ float gradv = 3.14159265f / (2 * ht - (ht - 800.0f));+ int caddress = (int)(temp > ht ? ht - (ht - 800.0f) : temp - (ht - 800.0f));+ s->cr += (int)(sinf(gradv * caddress) * 226);+ s->cg += (int)(-sinf(gradv * caddress * 4.55f) * 34);+ s->cb += (int)(-sinf(gradv * caddress * 2.22f) * 64);+ }+ int pm = allowed_modes(s->pm, rm);+ if (cm & COLOUR_HEAT) {+ s->fa = 255;+ uint32_t c = heat_colour(p_temp(p));+ s->fr = s->cr = c >> 16 & 255, s->fg = s->cg = c >> 8 & 255, s->fb = s->cb = c & 255;+ s->ca = 255;+ if (pm & (FIREMODE | PMODE_GLOW)) pm = (pm & ~(FIREMODE | PMODE_GLOW)) | PMODE_BLUR;+ else if ((pm & (PMODE_BLEND | PMODE_ADD)) == (PMODE_BLEND | PMODE_ADD)) pm = (pm & ~(PMODE_BLEND | PMODE_ADD)) | PMODE_FLAT;+ else if (!pm) pm |= PMODE_FLAT;+ } else if (cm & COLOUR_LIFE) {+ int q = p->life < 5 ? p->life : (int)sqrtf((float)p->life);+ s->cr = s->cg = s->cb = (int)(sinf(0.4f * q) * 100 + 128);+ s->ca = 255;+ if (pm & (FIREMODE | PMODE_GLOW)) pm = (pm & ~(FIREMODE | PMODE_GLOW)) | PMODE_BLUR;+ else if ((pm & (PMODE_BLEND | PMODE_ADD)) == (PMODE_BLEND | PMODE_ADD)) pm = (pm & ~(PMODE_BLEND | PMODE_ADD)) | PMODE_FLAT;+ else if (!pm) pm |= PMODE_FLAT;+ } else if (cm & COLOUR_BASC) {+ s->cr = colour >> 16 & 255, s->cg = colour >> 8 & 255, s->cb = colour & 255;+ pm = PMODE_FLAT;+ } else if (cm & COLOUR_DEST) {+ int score = destructibility(t);+ s->cr = s->cg = s->cb = score < 100 ? (int)(score * 1.3f) : 255;+ pm = PMODE_FLAT;+ }+ if (!(cm & ~COLOUR_GRAD) && deca) {+ deca++;+ if (!(pm & NO_DECO)) {+ s->cr = (deca * decr + (256 - deca) * s->cr) >> 8;+ s->cg = (deca * decg + (256 - deca) * s->cg) >> 8;+ s->cb = (deca * decb + (256 - deca) * s->cb) >> 8;+ }+ if (pm & DECO_FIRE) {+ s->fr = (deca * decr + (256 - deca) * s->fr) >> 8;+ s->fg = (deca * decg + (256 - deca) * s->fg) >> 8;+ s->fb = (deca * decb + (256 - deca) * s->fb) >> 8;+ }+ }+ if (cm & COLOUR_GRAD) {+ int q = (int)(p_temp(p) - 40);+ float v = sinf(0.05f * q) * 16;+ s->cr = (int)(v + s->cr), s->cg = (int)(v + s->cg), s->cb = (int)(v + s->cb);+ if (pm & (FIREMODE | PMODE_GLOW)) pm = (pm & ~(FIREMODE | PMODE_GLOW)) | PMODE_BLUR;+ }+#define CLAMP255(v) ((v) = (v) > 255 ? 255 : (v) < 0 ? 0 : (v))+ CLAMP255(s->cr), CLAMP255(s->cg), CLAMP255(s->cb), CLAMP255(s->ca);+ CLAMP255(s->fr), CLAMP255(s->fg), CLAMP255(s->fb), CLAMP255(s->fa);+ s->pm = pm;+}++/* the modes a particle of each element may be drawn with this frame, as shade() changes them */+static int frame_modes(int t) {+ int pm = PMODE_FLAT | (int)el_graphics_modes[t];+ uint32_t rm = ren.render_mode, cm = ren.colour_mode;+ if (cm & (COLOUR_BASC | COLOUR_DEST)) return PMODE_FLAT;+ GraphicsFn g = element_graphics(t);+ if (g == NULL) pm = PMODE_FLAT;+ else if (g == default_graphics) pm = default_modes(t);+ pm = allowed_modes(pm, rm);+ if (cm & (COLOUR_HEAT | COLOUR_LIFE | COLOUR_GRAD))+ if (pm & (FIREMODE | PMODE_GLOW)) pm = (pm & ~(FIREMODE | PMODE_GLOW)) | PMODE_BLUR;+ return pm;+}++/* how many rows away from its own a particle's drawing reaches: REACH_DYN works it out for the particle */+enum { REACH_DYN = 126, REACH_ALL = 127, FIRES = 128 };+static uint8_t reach_of[PT_COUNT]; /* the reach, and FIRES if its fire may glow */+static void frame_tables(void) {+ for (int t = 0; t < PT_COUNT; t++) {+ int pm = frame_modes(t), r = 0;+ if (pm & PMODE_BLOB) r = 1;+ if (pm & PMODE_BLUR) r = 3;+ if (pm & PMODE_GLOW) r = 5;+ if (pm & (EFFECT_GRAVIN | EFFECT_GRAVOUT)) r = 16;+ if (pm & (PMODE_SPARK | PMODE_FLARE | EFFECT_LINES)) r = REACH_DYN;+ if (pm & PMODE_LFLARE) r = REACH_ALL;+ if (pm & PSPEC_STICKMAN) r = 0;+ reach_of[t] = (uint8_t)(r | ((pm & FIREMODE) ? FIRES : 0));+ }+}+static int dyn_reach(const Particle *p, int t) {+ int pm = frame_modes(t), r = (pm & PMODE_GLOW) ? 5 : (pm & PMODE_BLUR) ? 3 : 1;+ if (pm & PMODE_SPARK) {+ float g = 4.0f * p->life + 19;+ int n = 0;+ while (g > 0.5f && n < YRES) g /= 1.5f, n++;+ if (n > r) r = n;+ }+ if (pm & PMODE_FLARE) {+ float g = 19 + fabsf(p_vx(p)) * 17 + fabsf(p_vy(p)) * 17;+ if (g > 255) g = 255;+ int n = 0;+ while (g > 0.5f && n < YRES) g /= 1.2f, n++;+ if (n > r) r = n;+ }+ if ((pm & EFFECT_LINES) && t == PT_SOAP && (p->ctype & 3) == 3 && p->tmp >= 0 && p->tmp < npart_max) {+ float dx = p_x(&parts[p->tmp]) - p_cx(p), dy = p_y(&parts[p->tmp]) - p_cy(p);+ SOAP_neighbourLoop(&dx, &dy);+ int n = abs((int)(p_cy(p) + dy + 0.5f) - p_cy(p)) + 1;+ if (n > r) r = n;+ }+ return r;+}++/* how far a particle's drawing reaches this frame (REACH_ALL: everywhere) */+static int part_reach(const Particle *p, int t) {+ int r = reach_of[t] & ~FIRES;+ /* (PIPE and PPIP reach as far as what they carry) */+ if ((t == PT_PIPE || t == PT_PPIP) && TYP(p->ctype) > 0 && TYP(p->ctype) < PT_COUNT) {+ r = reach_of[TYP(p->ctype)] & ~FIRES;+ if (r == REACH_DYN) r = REACH_ALL;+ }+ return r == REACH_DYN ? dyn_reach(p, t) : r;+}++/* ---------------------------------------------------------------- the band's 24-bit pixels */+/* a band's particle rows: 8 (two rows of the glow's cells), 4 when the gravity lens needs three bands at once */+static int brows = 2 * ACELL;+#define BAND_ROWS brows+#define COVERED 0x1000000u /* drawn over (PMODE_FLAT): the walls' patterns don't show */+static uint32_t (*pb)[XRES];+static int pb_y0;++static inline bool in_band(int x, int y) { return (unsigned)x < XRES && (unsigned)(y - pb_y0) < (unsigned)BAND_ROWS; }+static inline void pb_draw(int x, int y, uint32_t c) {+ if (in_band(x, y)) pb[y - pb_y0][x] = (c & 0xFFFFFF) | COVERED;+}+static inline void pb_blend(int x, int y, int r, int g, int b, int a) {+ if (!in_band(x, y)) return;+ uint32_t *d = &pb[y - pb_y0][x];+ a &= 255;+ if (a == 255) {+ *d = (uint32_t)r << 16 | g << 8 | b | COVERED;+ return;+ }+ uint32_t o = *d;+ uint32_t nr = (uint16_t)(a * r + (255 - a) * (o >> 16 & 255)) / 255;+ uint32_t ng = (uint16_t)(a * g + (255 - a) * (o >> 8 & 255)) / 255;+ uint32_t nb = (uint16_t)(a * b + (255 - a) * (o & 255)) / 255;+ *d = nr << 16 | ng << 8 | nb | (o & COVERED);+}+static inline void pb_add(int x, int y, int r, int g, int b, int a) {+ if (!in_band(x, y)) return;+ uint32_t *d = &pb[y - pb_y0][x], o = *d;+ a &= 255;+ uint32_t nr = (o >> 16 & 255) + (uint16_t)(a * r) / 255;+ uint32_t ng = (o >> 8 & 255) + (uint16_t)(a * g) / 255;+ uint32_t nb = (o & 255) + (uint16_t)(a * b) / 255;+ *d = (nr > 255 ? 255 : nr) << 16 | (ng > 255 ? 255 : ng) << 8 | (nb > 255 ? 255 : nb) | (o & COVERED);+}+/* RasterizeLine: a line's pixels, both ends included */+typedef void (*PixFn)(int x, int y, int r, int g, int b, int a);+static void pb_line(int x1, int y1, int x2, int y2, int r, int g, int b, int a, PixFn fn) {+ int dx = abs(x2 - x1), dy = abs(y2 - y1), sx = x1 < x2 ? 1 : -1, sy = y1 < y2 ? 1 : -1;+ /* (skipped when it can't cross the band) */+ if ((y1 < pb_y0 && y2 < pb_y0) || (y1 >= pb_y0 + BAND_ROWS && y2 >= pb_y0 + BAND_ROWS)) return;+ int err = dx - dy;+ for (int n = 0; n <= dx + dy + 1; n++) {+ fn(x1, y1, r, g, b, a);+ if (x1 == x2 && y1 == y2) break;+ int e2 = 2 * err;+ if (e2 > -dy) err -= dy, x1 += sx;+ if (e2 < dx) err += dx, y1 += sy;+ }+}++/* orbitalparts_get (orbitalparts.h): PRTI and PRTO's four orbiting dots */+static void orbitalparts_get(int block1, int block2, int resblock1[4], int resblock2[4]) {+ resblock1[0] = (block1 & 0x000000FF);+ resblock1[1] = (block1 & 0x0000FF00) >> 8;+ resblock1[2] = (block1 & 0x00FF0000) >> 16;+ resblock1[3] = (block1 & 0xFF000000) >> 24;+ resblock2[0] = (block2 & 0x000000FF);+ resblock2[1] = (block2 & 0x0000FF00) >> 8;+ resblock2[2] = (block2 & 0x00FF0000) >> 16;+ resblock2[3] = (block2 & 0xFF000000) >> 24;+}++/* render_parts' drawing of one particle, clipped to the band */+static int drawing_budget;+static void draw_part(int i, const Particle *p, int t, int nx, int ny, Shade *s) {+ int pm = s->pm, cr = s->cr, cg = s->cg, cb = s->cb, ca = s->ca;+ if (pm == PMODE_FLAT) {+ pb_draw(nx, ny, (uint32_t)cr << 16 | cg << 8 | cb);+ return;+ }+ if (pm & EFFECT_LINES) {+ if (t == PT_SOAP && (p->ctype & 3) == 3 && p->tmp >= 0 && p->tmp < npart_max) {+ const Particle *q = &parts[p->tmp];+ float dx = p_x(q) - nx, dy = p_y(q) - ny;+ SOAP_neighbourLoop(&dx, &dy); /* (across the edges when they loop, the short way) */+ pb_line(nx, ny, (int)(nx + dx + 0.5f), (int)(ny + dy + 0.5f), cr, cg, cb, ca, pb_blend);+ }+ }+ if (pm & PMODE_FLAT) pb_draw(nx, ny, (uint32_t)cr << 16 | cg << 8 | cb);+ if (pm & PMODE_BLEND) pb_blend(nx, ny, cr, cg, cb, ca);+ if (pm & PMODE_ADD) pb_add(nx, ny, cr, cg, cb, ca);+ if (pm & PMODE_BLOB) {+ pb_draw(nx, ny, (uint32_t)cr << 16 | cg << 8 | cb);+ pb_blend(nx + 1, ny, cr, cg, cb, 223);+ pb_blend(nx - 1, ny, cr, cg, cb, 223);+ pb_blend(nx, ny + 1, cr, cg, cb, 223);+ pb_blend(nx, ny - 1, cr, cg, cb, 223);+ pb_blend(nx + 1, ny - 1, cr, cg, cb, 112);+ pb_blend(nx - 1, ny - 1, cr, cg, cb, 112);+ pb_blend(nx + 1, ny + 1, cr, cg, cb, 112);+ pb_blend(nx - 1, ny + 1, cr, cg, cb, 112);+ }+ if (pm & PMODE_GLOW) {+ int cola1 = (5 * ca) / 255;+ pb_add(nx, ny, cr, cg, cb, (192 * ca) / 255);+ pb_add(nx + 1, ny, cr, cg, cb, (96 * ca) / 255);+ pb_add(nx - 1, ny, cr, cg, cb, (96 * ca) / 255);+ pb_add(nx, ny + 1, cr, cg, cb, (96 * ca) / 255);+ pb_add(nx, ny - 1, cr, cg, cb, (96 * ca) / 255);+ for (int x = 1; x < 6; x++) {+ pb_add(nx, ny - x, cr, cg, cb, cola1);+ pb_add(nx, ny + x, cr, cg, cb, cola1);+ pb_add(nx - x, ny, cr, cg, cb, cola1);+ pb_add(nx + x, ny, cr, cg, cb, cola1);+ for (int y = 1; y < 6; y++) {+ if (x + y > 7) continue;+ pb_add(nx + x, ny - y, cr, cg, cb, cola1);+ pb_add(nx - x, ny + y, cr, cg, cb, cola1);+ pb_add(nx + x, ny + y, cr, cg, cb, cola1);+ pb_add(nx - x, ny - y, cr, cg, cb, cola1);+ }+ }+ }+ if (pm & PMODE_BLUR) {+ for (int x = -3; x < 4; x++)+ for (int y = -3; y < 4; y++) {+ int ax = abs(x), ay = abs(y);+ if (ax + ay < 2 && !(ax == 2 || ay == 2)) pb_blend(x + nx, y + ny, cr, cg, cb, 30);+ if (ax + ay <= 3 && ax + ay) pb_blend(x + nx, y + ny, cr, cg, cb, 20);+ if (ax + ay == 2) pb_blend(x + nx, y + ny, cr, cg, cb, 10);+ }+ }+ if (pm & PMODE_SPARK) {+ float flicker = (float)(grng_u32() % 20);+ float gradv = 4 * p->life + flicker;+ for (int x = 0; gradv > 0.5f && drawing_budget > 0; x++) {+ int r = cr * (int)gradv / 255, g = cg * (int)gradv / 255, b = cb * (int)gradv / 255;+ r = r > 255 ? 255 : r, g = g > 255 ? 255 : g, b = b > 255 ? 255 : b;+ pb_add(nx + x, ny, r, g, b, 255);+ pb_add(nx - x, ny, r, g, b, 255);+ pb_add(nx, ny + x, r, g, b, 255);+ pb_add(nx, ny - x, r, g, b, 255);+ gradv = gradv / 1.5f;+ drawing_budget--;+ }+ }+ if (pm & (PMODE_FLARE | PMODE_LFLARE)) {+ for (int k = 0; k < 2; k++) {+ int mode = k ? PMODE_LFLARE : PMODE_FLARE;+ if (!(pm & mode)) continue;+ float flicker = (float)(grng_u32() % 20);+ float gradv = flicker + fabsf(p_vx(p)) * 17 + fabsf(p_vy(p)) * 17;+ int a4 = (int)(gradv * 4 > 255 ? 255 : gradv * 4), a2 = (int)(gradv * 2 > 255 ? 255 : gradv * 2);+ pb_blend(nx, ny, cr, cg, cb, a4);+ pb_blend(nx + 1, ny, cr, cg, cb, a2);+ pb_blend(nx - 1, ny, cr, cg, cb, a2);+ pb_blend(nx, ny + 1, cr, cg, cb, a2);+ pb_blend(nx, ny - 1, cr, cg, cb, a2);+ if (gradv > 255) gradv = 255;+ pb_blend(nx + 1, ny - 1, cr, cg, cb, (int)gradv);+ pb_blend(nx - 1, ny - 1, cr, cg, cb, (int)gradv);+ pb_blend(nx + 1, ny + 1, cr, cg, cb, (int)gradv);+ pb_blend(nx - 1, ny + 1, cr, cg, cb, (int)gradv);+ float div = k ? 1.01f : 1.2f;+ for (int x = 1; gradv > 0.5f && drawing_budget > 0; x++) {+ /* (a whole arm past the band in rows and columns is skipped, its remaining length counted) */+ pb_add(nx + x, ny, cr, cg, cb, (int)gradv);+ pb_add(nx - x, ny, cr, cg, cb, (int)gradv);+ pb_add(nx, ny + x, cr, cg, cb, (int)gradv);+ pb_add(nx, ny - x, cr, cg, cb, (int)gradv);+ gradv = gradv / div;+ drawing_budget--;+ if (x > XRES && x > YRES) {+ while (gradv > 0.5f && drawing_budget > 0) gradv /= div, drawing_budget--;+ break;+ }+ }+ }+ }+ if (pm & (EFFECT_GRAVIN | EFFECT_GRAVOUT)) {+ int orbd[4], orbl[4];+ /* (the distances: the original's 32-bit life is life and tmp2 here, el_special.c) */+ orbitalparts_get((int)((uint32_t)(uint16_t)p->life | (uint32_t)(uint16_t)p->tmp2 << 16), p->ctype, orbd, orbl);+ int other = (pm & EFFECT_GRAVIN) ? PT_PRTI : PT_PRTO;+ for (int r = 0; r < 4; r++) {+ float ddist = (float)orbd[r] / 16.0f;+ float drad = ((float)orbl[r] * 3.14159265f / 180.0f) * 1.41421356f;+ int nxo = (int)(ddist * cosf(drad)), nyo = (int)(ddist * sinf(drad));+ if (ny + nyo > 0 && ny + nyo < YRES && nx + nxo > 0 && nx + nxo < XRES && TYP(PMAPAT(nx + nxo, ny + nyo)) != other)+ pb_add(nx + nxo, ny + nyo, cr, cg, cb, 255 - orbd[r]);+ }+ }+ (void)i;+}++/* render_parts' fire: a particle's glow added to its cell (in the particles' order, before any band) */+static void fire_part(int nx, int ny, Shade *s) {+ int pm = s->pm, firea = s->fa;+ if (!firea) return;+ int cy = ny / ACELL, cx = nx / ACELL;+ fire_nz |= 1u << cy;+ uint8_t *r = &fire_r[cy][cx], *g = &fire_g[cy][cx], *b = &fire_b[cy][cx];+ if (pm & FIRE_BLEND) {+ firea /= 2;+ *r = (uint8_t)((firea * s->fr + (255 - firea) * *r) >> 8);+ *g = (uint8_t)((firea * s->fg + (255 - firea) * *g) >> 8);+ *b = (uint8_t)((firea * s->fb + (255 - firea) * *b) >> 8);+ }+ if (pm & FIRE_ADD) {+ firea /= 8;+ int fr = ((firea * s->fr) >> 8) + *r, fg = ((firea * s->fg) >> 8) + *g, fb = ((firea * s->fb) >> 8) + *b;+ *r = (uint8_t)(fr > 255 ? 255 : fr), *g = (uint8_t)(fg > 255 ? 255 : fg), *b = (uint8_t)(fb > 255 ? 255 : fb);+ }+ if (pm & FIRE_SPARK) {+ firea /= 4;+ *r = (uint8_t)((firea * s->fr + (255 - firea) * *r) >> 8);+ *g = (uint8_t)((firea * s->fg + (255 - firea) * *g) >> 8);+ *b = (uint8_t)((firea * s->fb + (255 - firea) * *b) >> 8);+ }+}++/* a particle the original's loop draws: on the grid, not under a photon (unless an energy particle or a stickman) */+static inline bool drawn_at(const Particle *p, int t, int *nx, int *ny) {+ *nx = p_cx(p), *ny = p_cy(p);+ if (*nx >= XRES || *nx < 0 || *ny >= YRES || *ny < 0) return false;+ if (photons_id[*ny][*nx] && !(elements[t].Properties & TYPE_ENERGY) && t != PT_STKM && t != PT_STKM2 && t != PT_FIGH)+ return false;+ return true;+}++/* the powered walls' glow (DrawWalls' end), then every particle's fire (render_parts) */+static void fire_pass(void) {+ for (int y = 0; y < YWCELLS; y++)+ for (int x = 0; x < XWCELLS; x++) {+ int wt = bmap[y][x];+ if (!wt || wt >= UI_WALLCOUNT || !emap[y][x] || !walltypes[wt].eglow) continue;+ uint32_t glow = walltypes[wt].eglow;+ /* (alpha 255: the cell's old glow doesn't count) */+ int cy = y * WCELL / ACELL, cx = x * WCELL / ACELL;+ fire_nz |= 1u << cy;+ fire_r[cy][cx] = (uint8_t)((255 * (glow >> 16 & 255)) >> 8);+ fire_g[cy][cx] = (uint8_t)((255 * (glow >> 8 & 255)) >> 8);+ fire_b[cy][cx] = (uint8_t)((255 * (glow & 255)) >> 8);+ }+ if (!(ren.render_mode & FIREMODE)) return;+ Shade s;+ for (int i = 0; i < parts_active; i++) {+ const Particle *p = &parts[i];+ int t = p->type, nx, ny;+ if (!t || !(reach_of[t] & FIRES) || !drawn_at(p, t, &nx, &ny)) continue;+ shade(i, p, t, nx, ny, &s);+ fire_part(nx, ny, &s);+ }+}++/* the bytes of a and b added, each at most 255 (UQADD8) */+static inline uint32_t sat_add8(uint32_t a, uint32_t b) {+#if defined(__ARM_FEATURE_SIMD32) && __ARM_FEATURE_SIMD32+ uint32_t r;+ __asm__("uqadd8 %0, %1, %2" : "=r"(r) : "r"(a), "r"(b));+ return r;+#else+ uint32_t r = 0;+ for (int k = 0; k < 32; k += 8) {+ uint32_t v = (a >> k & 255) + (b >> k & 255);+ r |= (v > 255 ? 255 : v) << k;+ }+ return r;+#endif+}++/* render_fire for the band: the glow of the cells around it */+static void fire_glow(int c0, int n) {+ for (int j = c0 - 1; j <= c0 + n; j++) {+ if (j < 0 || j >= YACELLS || !(fire_nz >> j & 1)) continue;+ /* (only the glow's rows in the band) */+ int y0 = pb_y0 - j * ACELL, y1 = pb_y0 + BAND_ROWS - j * ACELL;+ if (y0 < -ACELL) y0 = -ACELL;+ if (y1 > 2 * ACELL) y1 = 2 * ACELL;+ /* (the alphas' last row and column are 0: they add nothing) */+ if (y1 > 2 * ACELL - 1) y1 = 2 * ACELL - 1;+ for (int i = 0; i < XACELLS; i++) {+ int r = fire_r[j][i], g = fire_g[j][i], b = fire_b[j][i];+ if (!(r | g | b)) continue;+ int x0 = i ? -ACELL : 0, x1 = i < XACELLS - 1 ? 2 * ACELL - 1 : ACELL;+ for (int y = y0; y < y1; y++) {+ uint32_t *row = pb[j * ACELL + y - pb_y0] + i * ACELL;+ const uint8_t *al = fire_alpha[y + ACELL] + ACELL;+ for (int x = x0; x < x1; x++) {+ int a = al[x];+ /* each channel plus a / 255 of the glow's, at most 255 (COVERED kept) */+ row[x] = sat_add8(row[x], (uint32_t)((a * r) / 255) << 16 | (uint32_t)((a * g) / 255) << 8 | (uint32_t)((a * b) / 255));+ }+ }+ }+ }+}+/* render_fire's fading of a row of cells (in the original's order: the cells above already faded) */+static void fire_fade(int j) {+ /* (a row with no glow around stays dark) */+ if (!((fire_nz << 1) >> j & 7)) return;+ bool any = false;+ for (int i = 0; i < XACELLS; i++) {+ int r = fire_r[j][i] * 8, g = fire_g[j][i] * 8, b = fire_b[j][i] * 8;+ for (int y = -1; y < 2; y++)+ for (int x = -1; x < 2; x++)+ if ((x || y) && i + x >= 0 && j + y >= 0 && i + x < XACELLS && j + y < YACELLS)+ r += fire_r[j + y][i + x], g += fire_g[j + y][i + x], b += fire_b[j + y][i + x];+ r /= 16, g /= 16, b /= 16;+ fire_r[j][i] = (uint8_t)(r > 4 ? r - 4 : 0);+ fire_g[j][i] = (uint8_t)(g > 4 ? g - 4 : 0);+ fire_b[j][i] = (uint8_t)(b > 4 ? b - 4 : 0);+ any |= fire_r[j][i] | fire_g[j][i] | fire_b[j][i];+ }+ fire_nz = any ? fire_nz | 1u << j : fire_nz & ~(1u << j);+}++/* ---------------------------------------------------------------- the band's background */+/* draw_air: a cell's colour */+static uint32_t air_colour(int y, int x) {+ uint32_t dm = ren.display_mode;+ if (dm & DISPLAY_AIRP) {+ float pres = pv[y][x];+ return pres > 0.0f ? (uint32_t)clamp_flt(pres, 0.0f, 8.0f) << 16 : (uint32_t)clamp_flt(-pres, 0.0f, 8.0f);+ }+ if (dm & DISPLAY_AIRV)+ return (uint32_t)clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f) << 16 | (uint32_t)clamp_flt(pv[y][x], 0.0f, 8.0f) << 8 |+ (uint32_t)clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f);+ if (dm & DISPLAY_AIRH) return heat_to_colour(hv[y][x]);+ if (dm & DISPLAY_AIRC) {+ int r = (int)clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + (int)clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f);+ int g = (int)clamp_flt(fabsf(vx[y][x]), 0.0f, 20.0f) + (int)clamp_flt(fabsf(vy[y][x]), 0.0f, 24.0f);+ int b = (int)clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + (int)clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f);+ if (pv[y][x] > 0.0f) r += (int)clamp_flt(pv[y][x], 0.0f, 16.0f);+ else b += (int)clamp_flt(-pv[y][x], 0.0f, 16.0f);+ r = r > 255 ? 255 : r, g = g > 255 ? 255 : g, b = b > 255 ? 255 : b;+ /* (the original's RGB keeps the low 8 bits of what it's given) */+ return (uint32_t)(uint8_t)r << 16 | (uint32_t)(uint8_t)g << 8 | (uint8_t)b;+ }+ if (dm & DISPLAY_AIRW) {+ /* Air::vorticity: positive (clockwise) red, negative blue */+ float w = 0.0f;+ if (x > 1 && x < XACELLS - 2 && y > 1 && y < YACELLS - 2) w = 4 * ((vy[y][x + 1] - vy[y][x - 1]) - (vx[y + 1][x] - vx[y - 1][x])) * 0.5f;+ return w > 0.0f ? (uint32_t)clamp_flt(w, 0.0f, 8.0f) << 16 : (uint32_t)clamp_flt(-w, 0.0f, 8.0f);+ }+ return 0;+}++/* the persistent display's trails: the last frame's pixels (as the screen shows them), fading */+typedef struct { int16_t x0, y0, x1, y1; } SRect;+#define PERS_RECTS 12+static SRect pers_skip[PERS_RECTS]; /* the overlay's text and boxes last frame: not trails */+static int npers_skip;+static void pers_background(uint16_t *tmp) {+ for (int h = 0; h < BAND_ROWS / 2; h++) {+ int sy0 = pb_y0 * PX_SCALE + h * 6;+ plat_pull(SIM_X, sy0, SIM_W, 6, tmp);+ for (int r = 0; r < 2; r++) {+ int y = pb_y0 + h * 2 + r, sy = y * PX_SCALE + 1;+ for (int x = 0; x < XRES; x++) {+ int sx = SIM_X + x * PX_SCALE + 1;+ bool skip = false;+ for (int k = 0; k < npers_skip && !skip; k++)+ skip = sx >= pers_skip[k].x0 && sx < pers_skip[k].x1 && sy >= pers_skip[k].y0 && sy < pers_skip[k].y1;+ /* (not the overlay's last frame, nor the walls, which the original draws again over the trails) */+ uint16_t c = skip || bmap[y / WCELL][x / WCELL] ? 0 : tmp[(sy - sy0) * SIM_W + sx - SIM_X];+ /* Decay: each component down by one a frame, here by one step of the screen's 5 or 6 bits every 8 or 4+ * frames, spread over the pixels */+ int phase = (int)frame_no + x * 3 + y * 5;+ int rr = c >> 11, gg = (c >> 5) & 63, bb = c & 31;+ if (rr && !(phase & 7)) rr--;+ if (gg && !(phase & 3)) gg--;+ if (bb && !((phase + 4) & 7)) bb--;+ pb[y - pb_y0][x] = rgb888((uint16_t)(rr << 11 | gg << 5 | bb));+ }+ }+ }+}++/* draw_grav: the Newtonian gravity field's lines */+static void grav_lines(void) {+ for (int y = 0; y < YACELLS; y++)+ for (int x = 0; x < XACELLS; x++) {+ float gx = gravx[y][x], gy = gravy[y][x];+ float agx = fabsf(gx), agy = fabsf(gy);+ if (agx <= 0.001f && agy <= 0.001f) continue;+ float npx = (float)(x * ACELL), npy = (float)(y * ACELL), dist = agx + agy;+ int a = (uint8_t)(int)(dist * 20.0f);+ for (int i = 0; i < 4; ++i) {+ npx -= gx * 0.5f, npy -= gy * 0.5f;+ pb_add((int)(npx + 0.5f), (int)(npy + 0.5f), 255, 255, 255, a);+ }+ }+}++/* DrawWalls' streamlines: from each streamline wall, a line following the air */+static void streamlines(void) {+ for (int y = 0; y < YWCELLS; y++)+ for (int x = 0; x < XWCELLS; x++) {+ if (bmap[y][x] != WL_STREAM) continue;+ float xf = x * WCELL + WCELL * 0.5f, yf = y * WCELL + WCELL * 0.5f;+ int oldX = (int)(xf + 0.5f), oldY = (int)(yf + 0.5f);+ float xVel = vx[oldY / ACELL][oldX / ACELL] * 0.125f, yVel = vy[oldY / ACELL][oldX / ACELL] * 0.125f;+ if (!xVel && !yVel) {+ pb_add(oldX, oldY, 255, 255, 255, 255);+ continue;+ }+ bool changed = false;+ for (int t = 0; t < 1024; t++) {+ int newX = (int)(xf + 0.5f), newY = (int)(yf + 0.5f);+ if (newX != oldX || newY != oldY) changed = true, oldX = newX, oldY = newY;+ if (changed && (newX < 0 || newX >= XRES || newY < 0 || newY >= YRES)) break;+ pb_add(newX, newY, 255, 255, 255, 64);+ if (changed && newX >= 0 && newY >= 0 && newX < XRES && newY < YRES) {+ int wallX = newX / WCELL, wallY = newY / WCELL;+ xVel = vx[newY / ACELL][newX / ACELL] * 0.125f, yVel = vy[newY / ACELL][newX / ACELL] * 0.125f;+ if (wallX != x && wallY != y && bmap[wallY][wallX] == WL_STREAM) break;+ }+ xf += xVel, yf += yVel;+ }+ }+}++/* draw_other: the EMP's flash over everything */+static void emp_flash(void) {+ int emp = emp_decor;+ if (emp > 40) emp = 40;+ if (emp < 0) emp = 0;+ if (!(ren.render_mode & EFFECT) || emp <= 0) return;+ int r = (int)(emp * 2.5), g = (int)(100 + emp * 1.5), b = 255, a = (int)((1.0 * emp / 110) * 255);+ if (r > 255) r = 255;+ if (g > 255) g = 255;+ for (int y = pb_y0; y < pb_y0 + BAND_ROWS; y++)+ for (int x = 0; x < XRES; x++) pb_blend(x, y, r, g, b, a);+}++/* ---------------------------------------------------------------- walls, at the screen's resolution */+/* DrawWalls' patterns, with the original's 4-pixel cells' patterns kept at the screen's pixels: a wall's pixel at+ * (sx, sy), or -1 where the wall shows what's behind */+static int32_t wall_px(int wt, bool powered, int sx, int sy, int i, int j) {+ const WallType *w = &walltypes[wt];+ uint32_t pc = w->colour, gc = w->eglow;+ switch (w->drawstyle) {+ case 0:+ if (wt == WL_EWALL || wt == WL_STASIS) {+ bool on = (powered) ^ (wt == WL_STASIS);+ return (on ? (sx & sy & 1) : !(sx & sy & 1)) ? (int32_t)pc : -1;+ }+ if (wt == WL_WALLELEC) return !(sy & 1) && !(sx & 1) ? (int32_t)pc : 0x808080;+ if (wt == WL_EHOLE) {+ if (powered) return !(sy & 1) && !(sx & 1) ? 0x000000 : 0x242424;+ return !(sy & 1) && !(sx & 1) ? 0x242424 : -1;+ }+ return -1;+ case 1: return !(sy & 1) && (sx & 1) == ((sy >> 1) & 1) ? (int32_t)pc : -1;+ case 2: return !(sy & 1) && !(sx & 1) ? (int32_t)pc : -1;+ case 3: return (int32_t)pc;+ case 4: {+ int d = ((i - j) % (WCELL * PX_SCALE) + WCELL * PX_SCALE) % (WCELL * PX_SCALE);+ return d == 0 ? (int32_t)pc : d == 1 ? (int32_t)gc : 0x202020;+ }+ }+ return -1;+}++/* ---------------------------------------------------------------- stickmen, at the screen's resolution */+static inline int scr(float v) { return (int)v * PX_SCALE + 1; }+static void stickman_draw(Band *b, int i) {+ const Particle *p = &parts[i];+ int t = p->type, nx, ny;+ if (!drawn_at(p, t, &nx, &ny)) return;+ const playerst *cp;+ if (t == PT_STKM) cp = &player;+ else if (t == PT_STKM2) cp = &player2;+ else if (t == PT_FIGH && p->tmp >= 0 && p->tmp < MAX_FIGHTERS) cp = &fighters[(unsigned char)p->tmp];+ else return;+ uint32_t col, leg;+ if (ren.colour_mode == COLOUR_HEAT) {+ col = heat_colour(p_temp(p));+ } else if (cp->fan) {+ col = 0x8080FF;+ } else if (cp->elem < PT_NUM && cp->elem > 0) {+ col = elements[cp->elem].Colour;+ } else {+ col = 0x8080FF;+ }+ leg = ren.colour_mode == COLOUR_HEAT ? col : t == PT_STKM2 ? 0x6464FF : 0xFFFFFF;+ int x = SIM_X + scr((float)nx), y = scr((float)ny);+ if (t == PT_FIGH) {+ band_line(b, x, y + 6, x + 6, y, col, 255, false);+ band_line(b, x + 6, y, x, y - 6, col, 255, false);+ band_line(b, x, y - 6, x - 6, y, col, 255, false);+ band_line(b, x - 6, y, x, y + 6, col, 255, false);+ } else {+ band_line(b, x - 6, y + 6, x + 6, y + 6, col, 255, false);+ band_line(b, x - 6, y - 6, x + 6, y - 6, col, 255, false);+ band_line(b, x - 6, y - 6, x - 6, y + 6, col, 255, false);+ band_line(b, x + 6, y - 6, x + 6, y + 6, col, 255, false);+ }+ int hx = x, hy = scr((float)(ny + 3));+ band_line(b, hx, hy, SIM_X + scr(cp->legs[0]), scr(cp->legs[1]), leg, 255, false);+ band_line(b, SIM_X + scr(cp->legs[0]), scr(cp->legs[1]), SIM_X + scr(cp->legs[4]), scr(cp->legs[5]), leg, 255, false);+ band_line(b, hx, hy, SIM_X + scr(cp->legs[8]), scr(cp->legs[9]), leg, 255, false);+ band_line(b, SIM_X + scr(cp->legs[8]), scr(cp->legs[9]), SIM_X + scr(cp->legs[12]), scr(cp->legs[13]), leg, 255, false);+ if (cp->rocketBoots)+ for (int l = 0; l < 2; l++) {+ int fx = SIM_X + scr(cp->legs[l * 8 + 4]), fy = scr(cp->legs[l * 8 + 5]);+ bool on = (cp->comm & 0x04) || ((cp->comm & 0x01) && l == 0) || ((cp->comm & 0x02) && l == 1);+ band_fill(b, fx - 1, fy - 1, 3, 3, on ? 0x00FF00 : 0xFF0000, 255);+ band_fill(b, fx - 4, fy - 1, 3, 3, 0xFF00FF, 223);+ band_fill(b, fx + 2, fy - 1, 3, 3, 0xFF00FF, 223);+ band_fill(b, fx - 1, fy - 4, 3, 3, 0xFF00FF, 223);+ band_fill(b, fx - 1, fy + 2, 3, 3, 0xFF00FF, 223);+ band_fill(b, fx + 2, fy - 4, 3, 3, 0xFF00FF, 112);+ band_fill(b, fx - 4, fy - 4, 3, 3, 0xFF00FF, 112);+ band_fill(b, fx + 2, fy + 2, 3, 3, 0xFF00FF, 112);+ band_fill(b, fx - 4, fy + 2, 3, 3, 0xFF00FF, 112);+ }+}++/* ---------------------------------------------------------------- a frame */+#define SBAND 6 /* screen rows a band */+static bool any_stream, any_wall_row[YWCELLS], air_on;+static int16_t stkm_ids[2 + MAX_FIGHTERS]; /* the stickmen to draw this frame */+static int nstkm;+static uint32_t tparts;++/* the band each particle is drawn in, worked out once a frame rather than every particle tested in every band: a+ * nibble a particle (8 a word, in sim_scratch, which the simulation doesn't hold anything in between its frames),+ * the band when its drawing stays in one, BAND_MANY when it may reach others (tested in each band, as before),+ * BAND_NONE when it isn't drawn. Each band visits its particles in the same order as before. */+#define BAND_NONE 0xEu+#define BAND_MANY 0xFu+/* (NULL: every particle tested in every band, when there are more bands than nibbles have room for) */+static uint32_t *band_sort(int nbands) {+ int band_words = (parts_active + 7) / 8;+ if (nbands > (int)BAND_NONE || band_words * 4 > SCRATCH) return NULL;+ uint32_t *band_nib = (uint32_t *)(void *)sim_scratch;+ for (int w = 0; w < band_words; w++) {+ uint32_t word = 0;+ for (int k = 7; k >= 0; k--) {+ int i = w * 8 + k, t, nx, ny;+ uint32_t v = BAND_NONE;+ const Particle *p = &parts[i];+ if (i < parts_active && (t = p->type) && drawn_at(p, t, &nx, &ny)) {+ int r = part_reach(p, t);+ /* the bands whose rows [b * BAND_ROWS, (b + 1) * BAND_ROWS) come within r of the particle's row */+ v = r == 0 ? (uint32_t)(ny / BAND_ROWS) : (ny - r) / BAND_ROWS == (ny + r) / BAND_ROWS && ny >= r ? (uint32_t)(ny / BAND_ROWS) : BAND_MANY;+ }+ word = word << 4 | v;+ }+ band_nib[w] = word;+ }+ return band_nib;+}++/* a particle drawn by render_parts in the band */+static inline void band_part(int i, const Particle *p, int t, Shade *s) {+ int nx = p_cx(p), ny = p_cy(p);+ shade(i, p, t, nx, ny, s);+ draw_part(i, p, t, nx, ny, s);+ if (ny >= pb_y0 && ny < pb_y0 + BAND_ROWS) render_found++;+}++/* a band of particle rows into pb (from pb_y0): the background, the particles, the fire glow, the EMP's flash */+static void band_render(int cr, uint16_t *tmp, const uint32_t *band_nib) {+ pb_y0 = cr * BAND_ROWS;+ int c0 = pb_y0 / ACELL, nc = BAND_ROWS / ACELL;+ /* Clear and RenderBackground */+ if (ren.display_mode & DISPLAY_PERS) {+ pers_background(tmp);+ } else {+ /* (cleared a word at a time: the library's memset goes a byte at a time) */+ uint32_t *d = pb[0], *e = d + BAND_ROWS * XRES;+ while (d < e) d[0] = d[1] = d[2] = d[3] = 0, d += 4;+ }+ if (air_on)+ for (int k = 0; k < nc; k++)+ for (int x = 0; x < XACELLS; x++) {+ uint32_t c = air_colour(c0 + k, x);+ for (int y = 0; y < ACELL; y++)+ for (int i = 0; i < ACELL; i++) pb[k * ACELL + y][x * ACELL + i] = c;+ }+ if (ren.grav_field) grav_lines();+ if (any_stream) streamlines();+ /* render_parts */+ uint32_t tp = plat_millis();+ drawing_budget = 1000000;+ Shade s;+ if (band_nib) {+ /* the particles whose nibble is this band's or BAND_MANY (a nibble is 0 in x where it equals the band's,+ * 0 in ~w where it's BAND_MANY), in order */+ uint32_t mine = (uint32_t)cr * 0x11111111u;+ for (int w = 0, band_words = (parts_active + 7) / 8; w < band_words; w++) {+ uint32_t word = band_nib[w], x = word ^ mine, m = ~word;+ x = ~(((x & 0x77777777u) + 0x77777777u) | x) & 0x88888888u;+ m = ~(((m & 0x77777777u) + 0x77777777u) | m) & 0x88888888u;+ for (uint32_t hit = x | m; hit; hit &= hit - 1) {+ int k = __builtin_ctz(hit) >> 2, i = w * 8 + k;+ const Particle *p = &parts[i];+ int t = p->type;+ if (m >> (k * 4) & 8) { /* BAND_MANY */+ int r = part_reach(p, t), ny = p_cy(p);+ if (ny < pb_y0 - r || ny >= pb_y0 + BAND_ROWS + r) continue;+ }+ band_part(i, p, t, &s);+ }+ }+ } else {+ for (int i = 0; i < parts_active; i++) {+ const Particle *p = &parts[i];+ int t = p->type, nx, ny;+ if (!t) continue;+ int r = part_reach(p, t);+ ny = p_cy(p);+ if (ny < pb_y0 - r || ny >= pb_y0 + BAND_ROWS + r) continue;+ if (!drawn_at(p, t, &nx, &ny)) continue;+ band_part(i, p, t, &s);+ }+ }+ tparts += plat_millis() - tp;+ /* render_fire */+ if (ren.render_mode & FIREMODE) {+ fire_glow(c0, nc);+ /* (the rows the next band's glow doesn't need, in order) */+ for (int j = c0 - 1; j < c0 + nc - 1; j++)+ if (j >= 0) fire_fade(j);+ if (c0 + nc == YACELLS) fire_fade(YACELLS - 1);+ }+ emp_flash();+}++/* render_gravlensing: the frame's pixels moved by Newtonian gravity, red the least and blue the most. Here a band+ * sees the band above and below it (the moves are cut to 4 particles) */+static uint32_t (*lens_ring[3])[XRES];+static int lens_band;+static inline uint32_t lens_src(int x, int y, int comp) {+ int b = y / BAND_ROWS;+ if (b < lens_band - 1) b = lens_band - 1, y = b * BAND_ROWS;+ if (b > lens_band + 1) b = lens_band + 1, y = b * BAND_ROWS + BAND_ROWS - 1;+ return lens_ring[b % 3][y - b * BAND_ROWS][x] >> comp & 255;+}+static uint32_t lens_px(int x, int y) {+ float fx = gravx[y / ACELL][x / ACELL], fy = gravy[y / ACELL][x / ACELL];+ int rx = (int)(x - fx * 0.75f + 0.5f), ry = (int)(y - fy * 0.75f + 0.5f);+ int gx = (int)(x - fx * 0.875f + 0.5f), gy = (int)(y - fy * 0.875f + 0.5f);+ int bx = (int)(x - fx + 0.5f), by = (int)(y - fy + 0.5f);+ if (!InBounds(rx, ry) || !InBounds(gx, gy) || !InBounds(bx, by)) return 0;+ return lens_src(rx, ry, 16) << 16 | lens_src(gx, gy, 8) << 8 | lens_src(bx, by, 0) |+ (lens_ring[lens_band % 3][y - lens_band * BAND_ROWS][x] & COVERED);+}++/* a band shown: 3 x 3 pixels a particle, the walls' patterns, the stickmen, the overlay */+/* a particle's 3 x 3 pixels at d (rows w apart): its colour, or a wall's pattern with the colour added (the+ * original draws the walls first) */+static void show_cell(uint16_t *d, int w, int x, int y, uint32_t c, int wt) {+ if (!wt || wt >= UI_WALLCOUNT || (c & COVERED) || walltypes[wt].drawstyle == 3) {+ /* (no pattern, or a wall all of its colour: the colour added, the same in all 9) */+ if (wt && wt < UI_WALLCOUNT && !(c & COVERED)) c = sat_add8(c & 0xFFFFFF, walltypes[wt].colour & 0xFFFFFF);+ uint16_t v = rgb565(c);+ d[0] = d[1] = d[2] = v;+ d[w] = d[w + 1] = d[w + 2] = v;+ d[2 * w] = d[2 * w + 1] = d[2 * w + 2] = v;+ return;+ }+ bool powered = emap[y / WCELL][x / WCELL] != 0;+ int cx0 = (x / WCELL) * WCELL * PX_SCALE, cy0 = (y / WCELL) * WCELL * PX_SCALE;+ for (int k = 0; k < PX_SCALE; k++)+ for (int m = 0; m < PX_SCALE; m++) {+ int sx = x * PX_SCALE + m, sy = y * PX_SCALE + k;+ int32_t wp = wall_px(wt, powered, sx, sy, sx - cx0, sy - cy0);+ uint32_t out = c;+ if (wp >= 0) {+ uint32_t rr = (wp >> 16 & 255) + (c >> 16 & 255), gg = (wp >> 8 & 255) + (c >> 8 & 255);+ uint32_t bb = (wp & 255) + (c & 255);+ out = (rr > 255 ? 255 : rr) << 16 | (gg > 255 ? 255 : gg) << 8 | (bb > 255 ? 255 : bb);+ }+ d[k * w + m] = rgb565(out);+ }+}++static int push_w; /* the sim's bands go to the screen up to here (an unchanging menu at the right isn't redrawn) */+static void band_show(int cr, uint32_t (*src)[XRES], bool lens, const Overlay *o, uint16_t *sbuf) {+ int y0 = cr * BAND_ROWS, w = SCREEN_W;+ _Static_assert(WCELL == 2 && XRES % 2 == 0, "two particles a wall cell");+ for (int h = 0; h < BAND_ROWS / 2; h++) {+ Band b = {sbuf, 0, y0 * PX_SCALE + h * SBAND, w, SBAND};+ for (int r = 0; r < 2; r++) {+ int y = y0 + h * 2 + r;+ uint16_t *row = sbuf + r * PX_SCALE * w + SIM_X;+ const uint8_t *walls = any_wall_row[y / WCELL] ? bmap[y / WCELL] : NULL;+ if (lens) {+ for (int x = 0; x < XRES; x++) show_cell(row + x * PX_SCALE, w, x, y, lens_px(x, y), walls ? walls[x / WCELL] : 0);+ continue;+ }+ /* two particles (a wall cell) at a time: without a wall pattern showing, three words a row */+ const uint32_t *sp = src[y - y0];+ uint32_t *d0 = (uint32_t *)(void *)row, *d1 = (uint32_t *)(void *)(row + w), *d2 = (uint32_t *)(void *)(row + 2 * w);+ for (int x = 0; x < XRES; x += 2, sp += 2, d0 += 3, d1 += 3, d2 += 3) {+ int wt = walls ? walls[x / WCELL] : 0;+ if (wt && wt < UI_WALLCOUNT && !(sp[0] & sp[1] & COVERED)) {+ show_cell(row + x * PX_SCALE, w, x, y, sp[0], wt);+ show_cell(row + (x + 1) * PX_SCALE, w, x + 1, y, sp[1], wt);+ continue;+ }+ uint32_t a = rgb565(sp[0]), b = rgb565(sp[1]);+ uint32_t w0 = a | a << 16, w1 = a | b << 16, w2 = b | b << 16;+ d0[0] = w0, d0[1] = w1, d0[2] = w2;+ d1[0] = w0, d1[1] = w1, d1[2] = w2;+ d2[0] = w0, d2[1] = w1, d2[2] = w2;+ }+ }+ /* (the screen's sides by the sim: black, under the overlay) */+ for (int r = 0; r < SBAND; r++) {+ uint32_t *l = (uint32_t *)(void *)(sbuf + r * w), *rr = (uint32_t *)(void *)(sbuf + r * w + SIM_X + SIM_W);+ for (int k = 0; k < SIM_X / 2; k++) l[k] = 0;+ for (int k = 0; k < (SCREEN_W - SIM_X - SIM_W) / 2; k++) rr[k] = 0;+ }+ /* the streamline walls' mark (DrawWalls: glyph U+E00D) */+ if (any_stream)+ for (int y = 0; y < YWCELLS; y++)+ for (int x = 0; x < XWCELLS; x++)+ if (bmap[y][x] == WL_STREAM)+ font_draw_char(&b, SIM_X + x * WCELL * PX_SCALE, y * WCELL * PX_SCALE, FONT_ICON(0x0D), 0xFFFFFF, 128, FONT_BLEND);+ if (ren.render_mode & PSPEC_STICKMAN)+ for (int k = 0; k < nstkm; k++) stickman_draw(&b, stkm_ids[k]);+ if (o) ov_draw(o, &b);+ if (push_w < w)+ /* (the rows packed, a word at a time, forwards: each moves down) */+ for (int r = 1; r < SBAND; r++) {+ uint32_t *d = (uint32_t *)(void *)(sbuf + r * push_w), *sp = (uint32_t *)(void *)(sbuf + r * w);+ for (int k = 0; k < push_w / 2; k++) d[k] = sp[k];+ }+ plat_push(0, b.y0, push_w, SBAND, sbuf);+ }+}++void render_frame(const Overlay *o, bool panel, int sim_push_w) {+ uint32_t t0 = plat_millis();+ push_w = panel ? SCREEN_W : sim_push_w;+ frame_no++;+ /* the bands' pixels: one, or three when the gravity lens needs the bands around */+ bool lens = (ren.display_mode & DISPLAY_WARP) && ngrav_enable;+ int nring = lens ? 3 : 1;+ brows = lens ? ACELL : 2 * ACELL;+ int nbands = YRES / brows;+ uint32_t ring[nring * brows][XRES];+ uint16_t sbuf[SCREEN_W * SBAND] __attribute__((aligned(4)));+ frame_tables();+ hdisp_adjust();+ fire_pass();+ nstkm = 0;+ if (elementCount[PT_STKM] || elementCount[PT_STKM2] || elementCount[PT_FIGH])+ for (int i = 0; i < parts_active && nstkm < 2 + MAX_FIGHTERS; i++) {+ int t = parts[i].type;+ if (t == PT_STKM || t == PT_STKM2 || t == PT_FIGH) stkm_ids[nstkm++] = (int16_t)i;+ }+ any_stream = false;+ for (int y = 0; y < YWCELLS; y++) {+ any_wall_row[y] = false;+ for (int x = 0; x < XWCELLS; x++)+ if (bmap[y][x] && bmap[y][x] < UI_WALLCOUNT) any_wall_row[y] = true, any_stream |= bmap[y][x] == WL_STREAM;+ }+ air_on = (ren.display_mode & DISPLAY_AIR) && !(!aheat_enable && (ren.display_mode & DISPLAY_AIRH));+ render_found = 0;+ tparts = 0;+ const uint32_t *nib = band_sort(nbands);+ for (int k = 0; k < nring; k++) lens_ring[k] = ring + k * brows;+ for (int cr = 0; cr <= nbands; cr++) {+ if (cr < nbands) {+ pb = ring + (cr % nring) * brows;+ band_render(cr, sbuf, nib);+ } else if (lens) {+ memset(ring + (cr % nring) * brows, 0, sizeof(uint32_t) * XRES * brows); /* (below the sim: nothing) */+ }+ int show = lens ? cr - 1 : cr;+ if (show < 0 || show >= nbands) continue;+ lens_band = show;+ band_show(show, ring + (show % nring) * brows, lens, o, sbuf);+ }+ /* the overlay's text and boxes, which the persistent display's trails leave out next frame */+ npers_skip = 0;+ for (int k = 0; o && k < o->n && npers_skip < PERS_RECTS; k++) {+ const OvOp *op = &o->op[k];+ if (op->kind == OV_FILL || (op->kind >= OV_TEXT && op->kind <= OV_TEXT_BIG)) {+ int x0 = op->x - 1, y0 = op->y - 3, x1 = op->x + op->w + 1, y1 = op->y + op->h + 1;+ if (x0 < SIM_X + SIM_W && y0 < SIM_H) pers_skip[npers_skip++] = (SRect){(int16_t)x0, (int16_t)y0, (int16_t)x1, (int16_t)y1};+ }+ }+ if (panel)+ for (int y = SIM_H; y < SCREEN_H; y += SBAND) {+ Band b = {sbuf, 0, y, SCREEN_W, SBAND};+ memset(sbuf, 0, sizeof sbuf);+ if (o) ov_draw(o, &b);+ plat_push(0, y, SCREEN_W, SBAND, sbuf);+ }+ render_ms_parts = tparts;+ render_ms_total = plat_millis() - t0;+}diff --git a/games/numpowder/src/render.h b/games/numpowder/src/render.hnew file mode 100644index 00000000..02d800da--- /dev/null+++ b/games/numpowder/src/render.h@@ -0,0 +1,174 @@+/* NumPowder: The Powder Toy's renderer (Renderer.cpp, ElementGraphics.h, RendererSettings.h), for the calculator.+ *+ * The original draws the simulation one pixel per particle into a frame, then the interface over it. There is no+ * frame in RAM here: the sim area is drawn in bands of 4 particle rows (the fire glow's cells), each into a small+ * buffer of 24-bit pixels as the original's (so its blending and glows add up the same), then shown 3 x 3 pixels+ * a particle in bands of 6 screen rows, the walls' patterns and the interface's overlay (render_ovl.c) drawn over+ * them, and pushed to the screen. */+#ifndef NP_RENDER_H+#define NP_RENDER_H+#include "font.h"+#include <stddef.h>+#include "plat.h"+#include "simpriv.h" /* (restrict_flt, clamp_flt, the elements' shared functions) */++/* ---------------------------------------------------------------- ElementGraphics.h */+#define PMODE 0x00000FFF+#define PMODE_NONE 0x00000000+#define PMODE_FLAT 0x00000001+#define PMODE_BLOB 0x00000002+#define PMODE_BLUR 0x00000004+#define PMODE_GLOW 0x00000008+#define PMODE_SPARK 0x00000010+#define PMODE_FLARE 0x00000020+#define PMODE_LFLARE 0x00000040+#define PMODE_ADD 0x00000080+#define PMODE_BLEND 0x00000100+#define PSPEC_STICKMAN 0x00000200+#define OPTIONS 0x0000F000+#define NO_DECO 0x00001000+#define DECO_FIRE 0x00002000+#define FIREMODE 0x00FF0000+#define FIRE_ADD 0x00010000+#define FIRE_BLEND 0x00020000+#define FIRE_SPARK 0x00040000+#define EFFECT 0xFF000000u+#define EFFECT_GRAVIN 0x01000000+#define EFFECT_GRAVOUT 0x02000000+#define EFFECT_LINES 0x04000000+#define EFFECT_DBGLINES 0x08000000+#define RENDER_EFFE (OPTIONS | PSPEC_STICKMAN | EFFECT | PMODE_SPARK | PMODE_FLARE | PMODE_LFLARE)+#define RENDER_FIRE (OPTIONS | PSPEC_STICKMAN | PMODE_ADD | PMODE_BLEND | FIRE_ADD | FIRE_BLEND)+#define RENDER_SPRK (OPTIONS | PSPEC_STICKMAN | PMODE_ADD | PMODE_BLEND | FIRE_SPARK)+#define RENDER_GLOW (OPTIONS | PSPEC_STICKMAN | PMODE_GLOW | PMODE_ADD | PMODE_BLEND)+#define RENDER_BLUR (OPTIONS | PSPEC_STICKMAN | PMODE_BLUR | PMODE_ADD | PMODE_BLEND)+#define RENDER_BLOB (OPTIONS | PSPEC_STICKMAN | PMODE_BLOB | PMODE_ADD | PMODE_BLEND)+#define RENDER_BASC (OPTIONS | PSPEC_STICKMAN | PMODE_FLAT | PMODE_ADD | PMODE_BLEND | EFFECT_LINES)+#define RENDER_NONE (OPTIONS | PSPEC_STICKMAN | PMODE_FLAT)+#define COLOUR_HEAT 0x00000001+#define COLOUR_LIFE 0x00000002+#define COLOUR_GRAD 0x00000004+#define COLOUR_BASC 0x00000008+#define COLOUR_DEST 0x00000010+#define COLOUR_DEFAULT 0x00000000+#define DISPLAY_AIRC 0x00000001+#define DISPLAY_AIRP 0x00000002+#define DISPLAY_AIRV 0x00000004+#define DISPLAY_AIRH 0x00000008+#define DISPLAY_AIRW 0x00000080+#define DISPLAY_AIR 0x0000008F+#define DISPLAY_WARP 0x00000010+#define DISPLAY_PERS 0x00000020+#define DISPLAY_EFFE 0x00000040++/* ---------------------------------------------------------------- RendererSettings */+typedef struct {+ uint32_t render_mode, display_mode, colour_mode;+ bool grav_field; /* gravityFieldEnabled: Newtonian gravity's field lines ("G") */+ bool decorations; /* decorationLevel: decorationEnabled or decorationDisabled ("D") */+ bool hdisp_auto; /* wantHdispLimitMin and Max HdispLimitAuto (Dynamic Heat Display), else MIN_TEMP, MAX_TEMP */+} RenderSettings;+extern RenderSettings ren;++/* the original's display presets (Renderer::renderModePresets), in the order of its render options' buttons */+typedef struct {+ const char *name;+ uint32_t render_mode, display_mode, colour_mode;+ bool hdisp_auto;+} RenderPreset;+enum { PRESET_ALTAIR, PRESET_VELOCITY, PRESET_PRESSURE, PRESET_PERSISTENT, PRESET_FIRE, PRESET_BLOB, PRESET_HEAT,+ PRESET_FANCY, PRESET_NOTHING, PRESET_HEATGRAD, PRESET_LIFEGRAD, PRESET_DYNHEAT, PRESET_VORTICITY, PRESET_DEST,+ PRESET_COUNT };+extern const RenderPreset render_presets[PRESET_COUNT];+int render_preset_now(void); /* the preset the settings match, -1 none */+void render_apply(uint32_t render_mode, uint32_t display_mode, uint32_t colour_mode); /* ApplySettings */+void render_apply_preset(int preset); /* LoadRenderPreset */+void render_clear_accumulation(void); /* ClearAccumulation: the fire glow and the persistent trails */+void render_init(void);++/* ---------------------------------------------------------------- the elements' graphics (render_el*.c) */+/* random numbers for the graphics functions (the original's gfctx.rng): the same for a particle all frame */+uint32_t ren_rng_gen(void);+int ren_rng_between(int lower, int upper);+bool ren_rng_chance(int numerator, unsigned denominator);+/* the original's colour tables (Renderer::PopulateTables), as 0xRRGGBB */+uint32_t flame_table_at(int i);+uint32_t plasma_table_at(int i);+uint32_t heat_table_at(int i);+uint32_t clfm_table_at(int i);+uint32_t firw_table_at(int i);+/* a particle's decoration colour (0xAARRGGBB, 0 none): decorations aren't kept, unless the core keeps some */+uint32_t part_dcolour(const Particle *p);+/* the pixel modes an element's graphics function may give, besides PMODE_FLAT (for which bands it reaches) */+extern const uint32_t el_graphics_modes[PT_COUNT];+/* an element's graphics function as the original has it: its own, else Element::defaultGraphics (the elements+ * whose files set none, DUST, SAWD and DRAY, have none) */+typedef int (*GraphicsFn)(GRAPHICS_FUNC_ARGS);+int default_graphics(GRAPHICS_FUNC_ARGS);+static inline GraphicsFn element_graphics(int t) {+ if (elements[t].Graphics) return elements[t].Graphics;+ return t == PT_DUST || t == PT_SAWD || t == PT_DRAY ? NULL : default_graphics;+}+/* the shared ones (elements_data.c names them) */+int Element_BIZR_graphics(GRAPHICS_FUNC_ARGS);+int Element_COAL_graphics(GRAPHICS_FUNC_ARGS);+int Element_PIPE_graphics(GRAPHICS_FUNC_ARGS);+int Element_QRTZ_graphics(GRAPHICS_FUNC_ARGS);+int Element_STKM_graphics(GRAPHICS_FUNC_ARGS);+int Element_VIBR_graphics(GRAPHICS_FUNC_ARGS);++/* ---------------------------------------------------------------- the overlay: the interface over the sim */+/* a list of things to draw, made once a frame and drawn into each band they cross */+enum { OV_FILL, OV_RECT, OV_TEXT, OV_TEXT_OUTLINE, OV_TEXT_ADD, OV_TEXT_BIG, OV_XOR_LINE, OV_LINE, OV_CALL, OV_XOR_RECT };+typedef void (*OvFn)(Band *b, const void *ctx);+typedef struct {+ uint8_t kind, alpha;+ int16_t x, y, w, h; /* (lines: x, y to w, h) */+ uint32_t rgb; /* (text: its offset in the pool; call: the context's index) */+ uint16_t text;+} OvOp;+#define OV_MAX 128+#define OV_POOL 1024+#define OV_CALLS 12+typedef struct {+ int n, ntext, ncalls;+ bool full;+ OvOp op[OV_MAX];+ char pool[OV_POOL];+ OvFn fn[OV_CALLS];+ const void *ctx[OV_CALLS];+} Overlay;+void ov_reset(Overlay *o);+void ov_fill(Overlay *o, int x, int y, int w, int h, uint32_t rgb, int alpha); /* BlendFilledRect */+void ov_rect(Overlay *o, int x, int y, int w, int h, uint32_t rgb, int alpha); /* BlendRect: 1 pixel */+void ov_frame(Overlay *o, int x, int y, int w, int h, int thick, uint32_t rgb); /* a frame `thick` wide, outside */+void ov_text(Overlay *o, int x, int y, const char *s, uint32_t rgb, int alpha); /* BlendText */+void ov_text_outline(Overlay *o, int x, int y, const char *s, uint32_t rgb, int alpha);+void ov_text_add(Overlay *o, int x, int y, const char *s, uint32_t rgb, int alpha); /* AddChar */+void ov_text_big(Overlay *o, int x, int y, const char *s, uint32_t rgb); /* twice the size */+void ov_line(Overlay *o, int x1, int y1, int x2, int y2, uint32_t rgb, int alpha); /* BlendLine */+void ov_xor_line(Overlay *o, int x1, int y1, int x2, int y2); /* XorLine */+void ov_xor_rect(Overlay *o, int x, int y, int w, int h); /* (dotted) XorDottedRect */+void ov_call(Overlay *o, OvFn fn, const void *ctx);+void ov_draw(const Overlay *o, Band *b);+/* a pixel as the original's XorPixel: light grey over dark, dark grey over light */+static inline uint16_t px_xor(uint16_t d) {+ uint32_t c = rgb888(d);+ return 2 * (c >> 16 & 255) + 3 * (c >> 8 & 255) + (c & 255) < 512 ? rgb565(0xC0C0C0) : rgb565(0x404040);+}+void band_fill(Band *b, int x, int y, int w, int h, uint32_t rgb, int alpha);+void band_line(Band *b, int x1, int y1, int x2, int y2, uint32_t rgb, int alpha, bool xor);++/* ---------------------------------------------------------------- a frame */+/* the sim's area (in the middle of the screen's width, at its top) and the bottom panel below it */+#define SIM_W (XRES * PX_SCALE)+#define SIM_H (YRES * PX_SCALE)+#define SIM_X ((SCREEN_W - SIM_W) / 2)+_Static_assert(SIM_X % 2 == 0, "the sim's rows are written a word at a time");+/* draws a frame: the sim's rows always (the overlay over them; up to sim_push_w, unless `panel`: an unchanging window+ * at their right isn't sent again), the bottom panel when `panel` (it doesn't change often) */+void render_frame(const Overlay *o, bool panel, int sim_push_w); /* (sim_push_w even) */+/* the time the last frame's parts took, ms (for the speed tests) */+extern uint32_t render_ms_parts, render_ms_total;+extern int render_found; /* particles drawn last frame */+#endifdiff --git a/games/numpowder/src/render_el.c b/games/numpowder/src/render_el.cnew file mode 100644index 00000000..35cb61c0--- /dev/null+++ b/games/numpowder/src/render_el.c@@ -0,0 +1,551 @@+/* NumPowder: the elements' graphics functions, A to G (src/simulation/elements/<NAME>.cpp's graphics()), and the+ * modes each may give (for which bands its drawing reaches: render.c).+ *+ * As the original's, with: `gfctx.rng` the renderer's ren_rng_*, `gfctx.sim->currentTick` currentTick,+ * `gfctx.ren->decorationLevel` ren.decorations, `cpart->dcolour` part_dcolour(cpart) (decorations aren't kept:+ * 0), the fixed-point fields through their accessors, the colour tables as 0xRRGGBB. */+#include "render.h"++const uint32_t el_graphics_modes[PT_COUNT] = {+ [PT_ACEL] = PMODE_GLOW,+ [PT_ACID] = PMODE_BLUR,+ [PT_BASE] = PMODE_BLUR | PMODE_SPARK,+ [PT_BIZR] = FIRE_ADD | PMODE_BLUR,+ [PT_BIZRG] = FIRE_ADD | PMODE_BLUR,+ [PT_BIZRS] = FIRE_ADD | PMODE_BLUR,+ [PT_BOMB] = PMODE_FLARE,+ [PT_BRAY] = PMODE_BLEND | PMODE_GLOW,+ [PT_BRCK] = FIRE_ADD,+ [PT_C5] = FIRE_ADD | PMODE_ADD,+ [PT_CFLM] = FIRE_ADD,+ [PT_DCEL] = PMODE_GLOW,+ [PT_DEST] = PMODE_LFLARE | PMODE_SPARK,+ [PT_DEUT] = PMODE_GLOW | FIRE_ADD | PMODE_BLUR,+ [PT_DMG] = PMODE_FLARE,+ [PT_ELEC] = FIRE_ADD,+ [PT_EMBR] = FIRE_ADD | PMODE_BLEND | PMODE_GLOW | PMODE_SPARK | PMODE_ADD,+ [PT_EXOT] = PMODE_FLARE | FIRE_ADD | PMODE_BLUR,+ [PT_FILT] = PMODE_BLEND,+ [PT_FIRE] = FIRE_ADD,+ [PT_FIRW] = PMODE_GLOW,+ [PT_GBMB] = PMODE_FLARE | PMODE_SPARK,+ [PT_GEL] = PMODE_BLUR,+ [PT_GLOW] = FIRE_ADD | PMODE_GLOW | PMODE_ADD | PMODE_BLUR,+ [PT_GRAV] = FIRE_ADD | PMODE_ADD | PMODE_GLOW | PMODE_FLARE,+ [PT_GRVT] = FIRE_BLEND,+ [PT_INVIS] = PMODE_BLEND,+ [PT_LAVA] = FIRE_ADD | PMODE_BLUR,+ [PT_LIGH] = PMODE_GLOW | FIRE_ADD | DECO_FIRE,+ [PT_LITH] = PMODE_FLARE | PMODE_GLOW,+ [PT_NEUT] = FIRE_ADD,+ [PT_PHOT] = FIRE_ADD | PMODE_ADD,+ /* (PIPE and PPIP draw what they carry: render.c asks that element) */+ [PT_PIPE] = PMODE_GLOW | PMODE_BLUR | PMODE_BLEND | PMODE_ADD | FIRE_ADD | FIRE_BLEND | FIRE_SPARK,+ [PT_PPIP] = PMODE_GLOW | PMODE_BLUR | PMODE_BLEND | PMODE_ADD | FIRE_ADD | FIRE_BLEND | FIRE_SPARK,+ [PT_PLSM] = PMODE_GLOW | PMODE_ADD | FIRE_ADD,+ [PT_POLO] = PMODE_GLOW,+ [PT_PROT] = FIRE_BLEND,+ [PT_PRTI] = EFFECT_DBGLINES | EFFECT_GRAVIN | PMODE_ADD,+ [PT_PRTO] = EFFECT_DBGLINES | EFFECT_GRAVOUT | PMODE_ADD,+ [PT_PTNM] = PMODE_FLARE,+ [PT_ROCK] = FIRE_ADD,+ [PT_SLCN] = PMODE_FLARE | PMODE_GLOW | PMODE_SPARK,+ [PT_SMKE] = FIRE_BLEND,+ [PT_SOAP] = EFFECT_LINES | PMODE_BLUR,+ [PT_SPRK] = FIRE_SPARK,+ [PT_STKM] = PSPEC_STICKMAN,+ [PT_STKM2] = PSPEC_STICKMAN,+ [PT_FIGH] = PSPEC_STICKMAN,+ [PT_STOR] = PMODE_GLOW,+ [PT_SWCH] = PMODE_GLOW,+ [PT_THDR] = FIRE_ADD,+ [PT_TRON] = PMODE_GLOW | FIRE_ADD | PMODE_FLARE | PMODE_BLEND,+ [PT_TUNG] = FIRE_ADD,+ [PT_VIBR] = FIRE_BLEND,+ [PT_BVBR] = FIRE_BLEND,+ [PT_VIRS] = PMODE_BLUR,+ [PT_VRSG] = FIRE_BLEND,+ [PT_WIFI] = EFFECT_DBGLINES,+};++/* the colour of a photon's wavelengths (PHOT, BRAY, C5, BIZR, FILT) */+static void wavelength_colour(int wl, int *colr, int *colg, int *colb) {+ int x;+ *colr = *colg = *colb = 0;+ for (x = 0; x < 12; x++) {+ *colr += (wl >> (x + 18)) & 1;+ *colb += (wl >> x) & 1;+ }+ for (x = 0; x < 12; x++) *colg += (wl >> (x + 9)) & 1;+ x = 624 / (*colr + *colg + *colb + 1);+ *colr *= x;+ *colg *= x;+ *colb *= x;+}++int el_ACEL_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->tmp) *pixel_mode |= PMODE_GLOW;+ return 0;+}++int el_ACID_graphics(GRAPHICS_FUNC_ARGS) {+ int s = cpart->life;+ if (s > 75) s = 75; /* These two should not be here. */+ if (s < 49) s = 49;+ s = (s - 49) * 3;+ if (s == 0) s = 1;+ *colr += s * 4;+ *colg += s * 1;+ *colb += s * 2;+ *pixel_mode |= PMODE_BLUR;+ return 0;+}++int el_AMTR_graphics(GRAPHICS_FUNC_ARGS) {+ /* don't render AMTR as a gas: this function just overrides the default graphics */+ return 1;+}++int el_BASE_graphics(GRAPHICS_FUNC_ARGS) {+ int s = cpart->life;+ if (s <= 25) *colr = 0x33, *colg = 0x4C, *colb = 0xD8;+ else if (s <= 50) *colr = 0x58, *colg = 0x83, *colb = 0xE8;+ else if (s <= 75) *colr = 0x7D, *colg = 0xBA, *colb = 0xF7;+ *pixel_mode |= PMODE_BLUR;+ if (cpart->tmp == 1) *pixel_mode |= PMODE_SPARK;+ return 0;+}++/* BIZR, BIZRG, BIZRS */+int Element_BIZR_graphics(GRAPHICS_FUNC_ARGS) {+ float brightness = fabsf(p_vx(cpart)) + fabsf(p_vy(cpart));+ if (cpart->ctype & 0x3FFFFFFF) wavelength_colour(cpart->ctype, colr, colg, colb);+ if (brightness > 0) {+ brightness /= 5;+ *firea = 255;+ *fireg = (int)(*colg * brightness);+ *fireb = (int)(*colb * brightness);+ *firer = (int)(*colr * brightness);+ *pixel_mode |= FIRE_ADD;+ }+ *pixel_mode |= PMODE_BLUR;+ return 0;+}++int el_BOMB_graphics(GRAPHICS_FUNC_ARGS) {+ *pixel_mode |= PMODE_FLARE;+ return 1;+}++int el_BRAY_graphics(GRAPHICS_FUNC_ARGS) {+ int trans = 255;+ if (cpart->tmp == 0) {+ trans = cpart->life * 7;+ if (trans > 255) trans = 255;+ if (cpart->ctype & 0x3FFFFFFF) wavelength_colour(cpart->ctype, colr, colg, colb);+ } else if (cpart->tmp == 1) {+ trans = cpart->life / 4;+ if (trans > 255) trans = 255;+ if (cpart->ctype & 0x3FFFFFFF) wavelength_colour(cpart->ctype, colr, colg, colb);+ } else if (cpart->tmp == 2) {+ trans = cpart->life * 100;+ if (trans > 255) trans = 255;+ *colr = 255;+ *colg = 150;+ *colb = 50;+ }+ *cola = trans;+ *pixel_mode &= ~PMODE;+ *pixel_mode |= PMODE_BLEND | PMODE_GLOW;+ return 0;+}++int el_BRCK_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->tmp == 1) {+ *pixel_mode |= FIRE_ADD;+ *colb += 100;+ *firea = 40;+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ }+ return 0;+}++int el_C5_graphics(GRAPHICS_FUNC_ARGS) {+ if (!cpart->ctype) return 0;+ wavelength_colour(cpart->ctype, colr, colg, colb);+ *firea = 100;+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ *pixel_mode &= ~PMODE_FLAT;+ *pixel_mode |= FIRE_ADD | PMODE_ADD | NO_DECO;+ return 0;+}++int el_CBNW_graphics(GRAPHICS_FUNC_ARGS) {+ int z = cpart->tmp2 - 20; /* speckles! */+ *colr += z * 1;+ *colg += z * 2;+ *colb += z * 8;+ return 0;+}++int el_CFLM_graphics(GRAPHICS_FUNC_ARGS) {+ uint32_t color = clfm_table_at(cpart->life / 2);+ *colr = color >> 16 & 255;+ *colg = color >> 8 & 255;+ *colb = color & 255;+ *firea = 255;+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ *pixel_mode = PMODE_NONE; /* Clear default, don't draw pixel */+ *pixel_mode |= FIRE_ADD;+ return 0;+}++int el_CLST_graphics(GRAPHICS_FUNC_ARGS) {+ int z = (cpart->tmp - 5) * 16; /* speckles! */+ *colr += z;+ *colg += z;+ *colb += z;+ return 0;+}++/* COAL and BCOL */+#define COAL_FREQUENCY (3.14159265f / (2 * 300.0f - (300.0f - 200.0f)))+int Element_COAL_graphics(GRAPHICS_FUNC_ARGS) {+ *colr += (int)((cpart->tmp2 - 295.15f) / 3);+ if (*colr > 170) *colr = 170;+ if (*colr < *colg) *colr = *colg;+ *colg = *colb = *colr;+ /* ((cpart->temp-295.15f) > 300.0f-200.0f) */+ if (p_temp(cpart) > 395.15f) {+ int q = (int)((p_temp(cpart) > 595.15f) ? 200.0f : p_temp(cpart) - 395.15f);+ *colr += (int)(sinf(COAL_FREQUENCY * q) * 226);+ *colg += (int)(-sinf(COAL_FREQUENCY * q * 4.55f) * 34);+ *colb += (int)(-sinf(COAL_FREQUENCY * q * 2.22f) * 64);+ }+ return 0;+}++int el_CRMC_graphics(GRAPHICS_FUNC_ARGS) {+ int z = (cpart->tmp2 - 2) * 8;+ *colr += z;+ *colg += z;+ *colb += z;+ return 0;+}++int el_DCEL_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->tmp) *pixel_mode |= PMODE_GLOW;+ return 0;+}++int el_DEST_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->life) *pixel_mode |= PMODE_LFLARE;+ else *pixel_mode |= PMODE_SPARK;+ return 0;+}++int el_DEUT_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->life >= 240) {+ *firea = 60;+ *firer = *colr += 255;+ *fireg = *colg += 255;+ *fireb = *colb += 255;+ *pixel_mode |= PMODE_GLOW | FIRE_ADD;+ } else if (cpart->life > 0) {+ *colr += cpart->life * 1;+ *colg += cpart->life * 2;+ *colb += cpart->life * 3;+ *pixel_mode |= PMODE_BLUR;+ } else {+ *pixel_mode |= PMODE_BLUR;+ }+ return 0;+}++int el_DLAY_graphics(GRAPHICS_FUNC_ARGS) {+ int stage = (int)(((float)cpart->life / (p_temp(cpart) - 273.15f)) * 100.0f);+ *colr += stage;+ *colg += stage;+ *colb += stage;+ return 0;+}++int el_DMG_graphics(GRAPHICS_FUNC_ARGS) {+ *pixel_mode |= PMODE_FLARE;+ return 1;+}++int el_ELEC_graphics(GRAPHICS_FUNC_ARGS) {+ *firea = 70;+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ *pixel_mode |= FIRE_ADD;+ return 0;+}++int el_EMBR_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->ctype & 0xFFFFFF) {+ int maxComponent;+ *colr = (cpart->ctype & 0xFF0000) >> 16;+ *colg = (cpart->ctype & 0x00FF00) >> 8;+ *colb = (cpart->ctype & 0x0000FF);+ maxComponent = *colr;+ if (*colg > maxComponent) maxComponent = *colg;+ if (*colb > maxComponent) maxComponent = *colb;+ if (maxComponent < 60) { /* make sure it isn't too dark to see */+ float multiplier = 60.0f / maxComponent;+ *colr = (int)(*colr * multiplier);+ *colg = (int)(*colg * multiplier);+ *colb = (int)(*colb * multiplier);+ }+ } else if (cpart->tmp != 0) {+ *colr = *colg = *colb = 255;+ }+ uint32_t dc = part_dcolour(cpart);+ if (ren.decorations && dc && (dc & 0xFF000000)) {+ int a = (dc >> 24) & 0xFF;+ *colr = (a * ((dc >> 16) & 0xFF) + (255 - a) * *colr) >> 8;+ *colg = (a * ((dc >> 8) & 0xFF) + (255 - a) * *colg) >> 8;+ *colb = (a * ((dc)&0xFF) + (255 - a) * *colb) >> 8;+ }+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ if (cpart->tmp == 1) {+ *pixel_mode = FIRE_ADD | PMODE_BLEND | PMODE_GLOW;+ *firea = (cpart->life - 15) * 4;+ *cola = (cpart->life + 15) * 4;+ } else if (cpart->tmp == 2) {+ *pixel_mode = PMODE_FLAT | FIRE_ADD;+ *firea = 255;+ } else {+ *pixel_mode = PMODE_SPARK | PMODE_ADD;+ if (cpart->life < 64) *cola = 4 * cpart->life;+ }+ return 0;+}++int el_EMP_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->life) {+ *colr = (int)(cpart->life * 1.5f);+ *colg = (int)(cpart->life * 1.5f);+ *colb = 200 - (cpart->life);+ }+ return 0;+}++int el_EXOT_graphics(GRAPHICS_FUNC_ARGS) {+ float q = p_temp(cpart);+ int b = cpart->tmp, c = cpart->tmp2;+ if (cpart->life < 1001) {+ if (ren_rng_chance(cpart->tmp2 - 1, 1000)) {+ float frequency = 0.04045f;+ *colr = (int)(sinf(frequency * c + 4) * 127 + 150);+ *colg = (int)(sinf(frequency * c + 6) * 127 + 150);+ *colb = (int)(sinf(frequency * c + 8) * 127 + 150);+ *firea = 100;+ *firer = 0;+ *fireg = 0;+ *fireb = 0;+ *pixel_mode |= PMODE_FLAT;+ *pixel_mode |= PMODE_FLARE;+ } else {+ float frequency = 0.00045f;+ *colr = (int)(sinf(frequency * q + 4) * 127 + (b / 1.7f));+ *colg = (int)(sinf(frequency * q + 6) * 127 + (b / 1.7f));+ *colb = (int)(sinf(frequency * q + 8) * 127 + (b / 1.7f));+ *cola = cpart->tmp / 6;+ *firea = *cola;+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ *pixel_mode |= FIRE_ADD;+ *pixel_mode |= PMODE_BLUR;+ }+ } else {+ float frequency = 0.01300f;+ *colr = (int)(sinf(frequency * q + 6.00f) * 127 + ((b / 2.9f) + 80));+ *colg = (int)(sinf(frequency * q + 6.00f) * 127 + ((b / 2.9f) + 80));+ *colb = (int)(sinf(frequency * q + 6.00f) * 127 + ((b / 2.9f) + 80));+ *cola = cpart->tmp / 6;+ *firea = *cola;+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ *pixel_mode |= FIRE_ADD;+ *pixel_mode |= PMODE_BLUR;+ }+ return 0;+}++/* Element_FILT_getWavelengths */+static int filt_wavelengths(const Particle *cpart) {+ if (cpart->ctype & 0x3FFFFFFF) return cpart->ctype;+ int temp_bin = (int)((p_temp(cpart) - 273.0f) * 0.025f);+ if (temp_bin < 0) temp_bin = 0;+ if (temp_bin > 25) temp_bin = 25;+ return 0x1F << temp_bin;+}+int el_FILT_graphics(GRAPHICS_FUNC_ARGS) {+ wavelength_colour(filt_wavelengths(cpart), colr, colg, colb);+ if (cpart->life > 0 && cpart->life <= 4) *cola = 127 + cpart->life * 30;+ else *cola = 127;+ *pixel_mode &= ~PMODE;+ *pixel_mode |= PMODE_BLEND;+ return 0;+}++int el_FIRE_graphics(GRAPHICS_FUNC_ARGS) {+ uint32_t color = flame_table_at(cpart->life);+ *colr = color >> 16 & 255;+ *colg = color >> 8 & 255;+ *colb = color & 255;+ *firea = 255;+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ *pixel_mode = PMODE_NONE; /* Clear default, don't draw pixel */+ *pixel_mode |= FIRE_ADD;+ return 0;+}++int el_FIRW_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->tmp > 0) *pixel_mode |= PMODE_GLOW;+ return 0;+}++int el_FRME_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->tmp) {+ *colr += 30;+ *colg += 30;+ *colb += 30;+ }+ return 0;+}++int el_GBMB_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->life <= 0) *pixel_mode |= PMODE_FLARE;+ else *pixel_mode |= PMODE_SPARK;+ return 0;+}++int el_GEL_graphics(GRAPHICS_FUNC_ARGS) {+ int q = cpart->tmp;+ *colr = q * (32 - 255) / 120 + 255;+ *colg = q * (48 - 186) / 120 + 186;+ *colb = q * 208 / 120;+ *pixel_mode |= PMODE_BLUR;+ return 0;+}++int el_GLOW_graphics(GRAPHICS_FUNC_ARGS) {+ *firer = 16 + (int)(restrict_flt(p_temp(cpart) - (273.15f + 34.0f), 0, 128) / 2.0f);+ *fireg = 16 + (int)(restrict_flt((float)cpart->ctype, 0, 128) / 2.0f);+ *fireb = 16 + (int)(restrict_flt((float)cpart->tmp, 0, 128) / 2.0f);+ *firea = 64;+ *colr = (int)restrict_flt(64.0f + p_temp(cpart) - (273.15f + 34.0f), 0, 255);+ *colg = (int)restrict_flt(64.0f + cpart->ctype, 0, 255);+ *colb = (int)restrict_flt(64.0f + cpart->tmp, 0, 255);+ int rng = ren_rng_between(1, 32);+ if (((*colr) + (*colg) + (*colb)) > (256 + rng)) {+ *colr -= 54;+ *colg -= 54;+ *colb -= 54;+ *pixel_mode |= FIRE_ADD;+ *pixel_mode |= PMODE_GLOW | PMODE_ADD;+ *pixel_mode &= ~PMODE_FLAT;+ } else {+ *pixel_mode |= PMODE_BLUR;+ }+ return 0;+}++int el_GOLD_graphics(GRAPHICS_FUNC_ARGS) {+ int rndstore = (int)ren_rng_gen();+ *colr += (rndstore % 10) - 5;+ rndstore >>= 4;+ *colg += (rndstore % 10) - 5;+ rndstore >>= 4;+ *colb += (rndstore % 10) - 5;+ return 0;+}++int el_GPMP_graphics(GRAPHICS_FUNC_ARGS) {+ int lifemod = ((cpart->life > 10 ? 10 : cpart->life) * 19);+ *colg += lifemod;+ *colb += lifemod;+ return 0;+}++int el_GRAV_graphics(GRAPHICS_FUNC_ARGS) {+ int GRAV_R, GRAV_B, GRAV_G, GRAV_R2, GRAV_B2, GRAV_G2;+ GRAV_R = abs((currentTick % 120) - 60);+ GRAV_G = abs(((currentTick + 60) % 120) - 60);+ GRAV_B = abs(((currentTick + 120) % 120) - 60);+ GRAV_R2 = abs((currentTick % 60) - 30);+ GRAV_G2 = abs(((currentTick + 30) % 60) - 30);+ GRAV_B2 = abs(((currentTick + 60) % 60) - 30);+ float vx_ = p_vx(cpart), vy_ = p_vy(cpart);+ *colr = 20;+ *colg = 20;+ *colb = 20;+ if (vx_ > 0) {+ *colr += (int)(vx_ * GRAV_R);+ *colg += (int)(vx_ * GRAV_G);+ *colb += (int)(vx_ * GRAV_B);+ }+ if (vy_ > 0) {+ *colr += (int)(vy_ * GRAV_G);+ *colg += (int)(vy_ * GRAV_B);+ *colb += (int)(vy_ * GRAV_R);+ }+ if (vx_ < 0) {+ *colr -= (int)(vx_ * GRAV_B);+ *colg -= (int)(vx_ * GRAV_R);+ *colb -= (int)(vx_ * GRAV_G);+ }+ if (vy_ < 0) {+ *colr -= (int)(vy_ * GRAV_R2);+ *colg -= (int)(vy_ * GRAV_G2);+ *colb -= (int)(vy_ * GRAV_B2);+ }+ if (cpart->life) {+ *pixel_mode = FIRE_ADD | PMODE_ADD | PMODE_GLOW | PMODE_FLARE;+ *firer = *colr * 3 < 255 ? *colr * 3 : 255;+ *fireg = *colg * 3 < 255 ? *colg * 3 : 255;+ *fireb = *colb * 3 < 255 ? *colb * 3 : 255;+ *firea = (cpart->life + 15) * 4;+ *cola = (cpart->life + 15) * 4;+ } else {+ *pixel_mode = PMODE_ADD;+ }+ return 0;+}++int el_GRVT_graphics(GRAPHICS_FUNC_ARGS) {+ *firea = 5;+ *firer = 0;+ *fireg = 250;+ *fireb = 170;+ *pixel_mode |= FIRE_BLEND;+ return 1;+}++int el_PHOT_graphics(GRAPHICS_FUNC_ARGS) {+ wavelength_colour(cpart->ctype, colr, colg, colb);+ *firea = 100;+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ *pixel_mode &= ~PMODE_FLAT;+ *pixel_mode |= FIRE_ADD | PMODE_ADD | NO_DECO;+ if (cpart->flags & FLAG_PHOTDECO) *pixel_mode &= ~NO_DECO;+ return 0;+}diff --git a/games/numpowder/src/render_el2.c b/games/numpowder/src/render_el2.cnew file mode 100644index 00000000..7182e26f--- /dev/null+++ b/games/numpowder/src/render_el2.c@@ -0,0 +1,596 @@+/* NumPowder: the elements' graphics functions, H to Z (src/simulation/elements/<NAME>.cpp's graphics()), as in+ * render_el.c. */+#include "render.h"++int el_HSWC_graphics(GRAPHICS_FUNC_ARGS) {+ int lifemod = ((cpart->life > 10 ? 10 : cpart->life) * 19);+ *colr += lifemod;+ return 0;+}++int el_INVIS_graphics(GRAPHICS_FUNC_ARGS) {+ /* pv[ny/CELL][nx/CELL]>4.0f || pv[ny/CELL][nx/CELL]<-4.0f */+ if (cpart->tmp2) {+ *cola = 100;+ *colr = 15;+ *colg = 0;+ *colb = 150;+ *pixel_mode = PMODE_BLEND;+ }+ return 0;+}++int el_LAVA_graphics(GRAPHICS_FUNC_ARGS) {+ *colr = cpart->life * 2 + 0xE0;+ *colg = cpart->life * 1 + 0x50;+ *colb = cpart->life / 2 + 0x10;+ if (*colr > 255) *colr = 255;+ if (*colg > 192) *colg = 192;+ if (*colb > 128) *colb = 128;+ *firea = 40;+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ *pixel_mode |= FIRE_ADD;+ *pixel_mode |= PMODE_BLUR;+ return 0;+}++int el_LCRY_graphics(GRAPHICS_FUNC_ARGS) {+ uint32_t dc = part_dcolour(cpart);+ if (ren.decorations && dc && (dc & 0xFF000000)) {+ *colr = (dc >> 16) & 0xFF;+ *colg = (dc >> 8) & 0xFF;+ *colb = (dc)&0xFF;+ if (cpart->tmp2 < 10) {+ *colr /= 10 - cpart->tmp2;+ *colg /= 10 - cpart->tmp2;+ *colb /= 10 - cpart->tmp2;+ }+ } else {+ *colr = *colg = *colb = 0x50 + ((cpart->tmp2 > 10 ? 10 : cpart->tmp2) * 10);+ }+ *pixel_mode |= NO_DECO;+ return 0;+}++/* LIFE: the built-in types' two colours (the original keeps them in dcolour and tmp, which the calculator's+ * particle doesn't: they're the type's own here, as the original draws them with decorations off) */+int el_LIFE_graphics(GRAPHICS_FUNC_ARGS) {+ uint32_t colour1 = 0xFFFFFF, colour2 = 0x000000;+ int ruleset = cpart->ctype;+ if (ruleset >= 0 && ruleset < NGOL) {+ colour1 = builtinGol[ruleset].colour;+ colour2 = builtinGol[ruleset].colour2;+ ruleset = builtinGol[ruleset].ruleset;+ }+ int states = ((ruleset >> 17) & 0xF) + 2;+ if (states == 2) {+ *colr = colour1 >> 16 & 255;+ *colg = colour1 >> 8 & 255;+ *colb = colour1 & 255;+ } else {+ float mul = (cpart->tmp2 - 1) / (float)(states - 2);+ *colr = (int)((colour1 >> 16 & 255) * mul + (colour2 >> 16 & 255) * (1.f - mul));+ *colg = (int)((colour1 >> 8 & 255) * mul + (colour2 >> 8 & 255) * (1.f - mul));+ *colb = (int)((colour1 & 255) * mul + (colour2 & 255) * (1.f - mul));+ }+ *pixel_mode |= NO_DECO;+ return 0;+}++int el_LIGH_graphics(GRAPHICS_FUNC_ARGS) {+ *firea = 120;+ *firer = *colr = 235;+ *fireg = *colg = 245;+ *fireb = *colb = 255;+ *pixel_mode |= PMODE_GLOW | FIRE_ADD | DECO_FIRE;+ return 1;+}++int el_LITH_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->life >= 1000) { /* Exploding lith */+ *colr = 0xFF;+ *colg = 0xA0;+ *colb = 0x40;+ *pixel_mode |= PMODE_FLARE | PMODE_GLOW;+ } else if (cpart->ctype > 0) { /* Charged lith */+ int mult = ren_rng_between(cpart->ctype / 3, cpart->ctype) / 15;+ if (mult > 6) mult = 6;+ *colr -= 30 * mult;+ *colb += 20 * mult;+ *pixel_mode |= PMODE_FLARE | PMODE_GLOW;+ }+ return 0;+}++int el_NEUT_graphics(GRAPHICS_FUNC_ARGS) {+ *firea = 120;+ *firer = 10;+ *fireg = 80;+ *fireb = 120;+ *pixel_mode |= FIRE_ADD;+ return 1;+}++int el_PBCN_graphics(GRAPHICS_FUNC_ARGS) {+ int lifemod = ((cpart->life > 10 ? 10 : cpart->life) * 10);+ *colr += lifemod;+ *colg += lifemod / 2;+ return 0;+}++int el_PCLN_graphics(GRAPHICS_FUNC_ARGS) {+ int lifemod = ((cpart->life > 10 ? 10 : cpart->life) * 10);+ *colr += lifemod;+ *colg += lifemod;+ return 0;+}++/* PIPE and PPIP: what they carry is drawn as its own element (props_pipe_to_part: its type in ctype, its life in+ * tmp2, its tmp in tmp3, its ctype in tmp4) */+__attribute__((weak)) int tmp4_get(int i) { (void)i; return 0; }+int Element_PIPE_graphics(GRAPHICS_FUNC_ARGS) {+ int t = TYP(cpart->ctype);+ if (t > 0 && t < PT_NUM && elements[t].Enabled) {+ if (t == PT_STKM || t == PT_STKM2 || t == PT_FIGH) return 0;+ uint32_t colour = elements[t].Colour;+ *colr = colour >> 16 & 255;+ *colg = colour >> 8 & 255;+ *colb = colour & 255;+ GraphicsFn g = element_graphics(t);+ if (g) {+ Particle tpart;+ memset(&tpart, 0, sizeof tpart);+ tpart.type = (uint8_t)t;+ tpart.temp = cpart->temp;+ tpart.life = cpart->tmp2;+ tpart.tmp = cpart->tmp3;+ ptrdiff_t id = cpart - parts;+ tpart.ctype = id >= 0 && id < npart_max ? tmp4_get((int)id) : 0;+ tpart.x = cpart->x, tpart.y = cpart->y;+ g(&tpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb);+ }+ } else {+ switch (cpart->tmp & PFLAG_COLORS) {+ case PFLAG_COLOR_RED: *colr = 50, *colg = 1, *colb = 1; break;+ case PFLAG_COLOR_GREEN: *colr = 1, *colg = 50, *colb = 1; break;+ case PFLAG_COLOR_BLUE: *colr = 1, *colg = 1, *colb = 50; break;+ default: break;+ }+ }+ return 0;+}++/* PLNT.cpp's leafColor */+static const uint8_t leafColor[8][3] = {+ {243, 246, 244}, /* White */+ {255, 223, 50}, /* Yellow */+ {255, 183, 197}, /* Pink */+ {250, 0, 25}, /* Red */+ {128, 206, 196}, /* Cyan / light blue */+ {127, 255, 0}, /* Bright green */+ {0, 74, 178}, /* Blue */+ {12, 172, 0}, /* Usual PLNT green */+};+#define PLNT_DIR 3+#define PLNT_COLOUR 6+#define PLNT_LIFE 12+int el_PLNT_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->ctype == 0) {+ float maxtemp = (float)cpart->tmp2 > p_temp(cpart) ? (float)cpart->tmp2 : p_temp(cpart);+ if (maxtemp > 300) {+ *colr += (int)restrict_flt((maxtemp - 300) / 5, 0, 58);+ *colg -= (int)restrict_flt((maxtemp - 300) / 2, 0, 102);+ *colb += (int)restrict_flt((maxtemp - 300) / 5, 0, 70);+ }+ if (maxtemp < 273) {+ *colg += (int)restrict_flt((273 - maxtemp) / 4, 0, 255);+ *colb += (int)restrict_flt((273 - maxtemp) / 1.5f, 0, 255);+ }+ } else {+ /* Set tree-grown PLNT color */+ int colour = (cpart->ctype >> PLNT_COLOUR) & 0x3f;+ int cyan = (colour & 0x30) != 0, magenta = (colour & 0x0C) != 0, yellow = (colour & 0x03) != 0;+ int ind = 4 * cyan + 2 * magenta + yellow;+ if (0 <= ind && ind < 8) {+ *colr = leafColor[ind][0];+ *colg = leafColor[ind][1];+ *colb = leafColor[ind][2];+ }+ }+ return 0;+}++int el_PLSM_graphics(GRAPHICS_FUNC_ARGS) {+ uint32_t color = plasma_table_at(cpart->life);+ *colr = color >> 16 & 255;+ *colg = color >> 8 & 255;+ *colb = color & 255;+ *firea = 255;+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ *pixel_mode = PMODE_GLOW | PMODE_ADD; /* Clear default, don't draw pixel */+ *pixel_mode |= FIRE_ADD;+ return 0;+}++#define POLO_LIMIT 5+int el_POLO_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->tmp >= POLO_LIMIT) {+ *colr = 0x70;+ *colg = 0x70;+ *colb = 0x70;+ } else {+ *pixel_mode |= PMODE_GLOW;+ }+ return 0;+}++int el_PROT_graphics(GRAPHICS_FUNC_ARGS) {+ *firea = 7;+ *firer = 250;+ *fireg = 170;+ *fireb = 170;+ *pixel_mode |= FIRE_BLEND;+ return 1;+}++int el_PRTI_graphics(GRAPHICS_FUNC_ARGS) {+ *firea = 8;+ *firer = 255;+ *fireg = 0;+ *fireb = 0;+ *pixel_mode |= EFFECT_DBGLINES;+ *pixel_mode |= EFFECT_GRAVIN;+ *pixel_mode &= ~PMODE;+ *pixel_mode |= PMODE_ADD;+ return 1;+}++int el_PRTO_graphics(GRAPHICS_FUNC_ARGS) {+ *firea = 8;+ *firer = 0;+ *fireg = 0;+ *fireb = 255;+ *pixel_mode |= EFFECT_DBGLINES;+ *pixel_mode |= EFFECT_GRAVOUT;+ *pixel_mode &= ~PMODE;+ *pixel_mode |= PMODE_ADD;+ return 1;+}++int el_PSTN_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->life) {+ *colr -= 60;+ *colg -= 60;+ }+ return 0;+}++int el_PTNM_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->tmp) *pixel_mode |= PMODE_FLARE;+ return 0;+}++int el_PUMP_graphics(GRAPHICS_FUNC_ARGS) {+ int lifemod = ((cpart->life > 10 ? 10 : cpart->life) * 19);+ *colb += lifemod;+ return 0;+}++int el_PVOD_graphics(GRAPHICS_FUNC_ARGS) {+ int lifemod = ((cpart->life > 10 ? 10 : cpart->life) * 16);+ *colr += lifemod;+ return 0;+}++/* QRTZ and PQRT */+int Element_QRTZ_graphics(GRAPHICS_FUNC_ARGS) {+ int z = (cpart->tmp2 - 5) * 16; /* speckles! */+ *colr += z;+ *colg += z;+ *colb += z;+ return 0;+}++int el_ROCK_graphics(GRAPHICS_FUNC_ARGS) {+ int z = (cpart->tmp2 - 7) * 6; /* Randomized color noise based on tmp2 */+ *colr += z;+ *colg += z;+ *colb += z;+ if (p_temp(cpart) >= 810.15f) { /* Glows when hot, right before melting becomes bright */+ *pixel_mode |= FIRE_ADD;+ *firea = (int)((p_temp(cpart) - 810.15f) / 45);+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ }+ return 0;+}++int el_SEED_graphics(GRAPHICS_FUNC_ARGS) {+ int water = (cpart->ctype >> PLNT_LIFE) & 0xFF;+ if (water > 3) { /* Ready for growth */+ *colr -= 50;+ *colg -= 50;+ *colb -= 50;+ } else if (water > 0) { /* Had a sip of water */+ *colr -= 25;+ *colg -= 25;+ *colb -= 25;+ }+ return 0;+}++/* SLCN.cpp's SLCN_COLOUR */+static const uint32_t SLCN_COLOUR[16] = {+ 0x5A6679, 0x6878A1, 0xABBFDD, 0x838490, 0xBCCDDF, 0x82A0D2, 0x5B6680, 0x232C3B,+ 0x485067, 0x8B9AB6, 0xADB1C1, 0xC3C6D1, 0x8594AD, 0x262F47, 0xA9AEBC, 0xC2E1F7,+};+/* (its 32-bit sparkle state, the original's tmp: bits 0 to 15 in tmp, 16 to 31 in tmp2, see el_powders.c) */+#define SLCN_STATE(p) ((uint32_t)(uint16_t)(p)->tmp | (uint32_t)(uint16_t)(p)->tmp2 << 16)+int el_SLCN_graphics(GRAPHICS_FUNC_ARGS) {+ uint32_t st = SLCN_STATE(cpart);+ uint32_t curr = SLCN_COLOUR[(st >> 12) & 15];+ int r = curr >> 16 & 255, g = curr >> 8 & 255, b = curr & 255;+ if (st & 0x800) { /* mix with next colour if phase is at least halfway there */+ uint32_t next = SLCN_COLOUR[(st >> 16) & 15];+ r = (r + (int)(next >> 16 & 255)) / 2;+ g = (g + (int)(next >> 8 & 255)) / 2;+ b = (b + (int)(next & 255)) / 2;+ }+ *colr = r;+ *colg = g;+ *colb = b;+ int rnd = (int)((st & 0xFFFF) * ((st >> 16) & 0xFFFF));+ if (!(rnd % 887)) *pixel_mode |= PMODE_FLARE | PMODE_GLOW;+ if (!(rnd % 593)) *pixel_mode |= PMODE_SPARK;+ return 0;+}++int el_SMKE_graphics(GRAPHICS_FUNC_ARGS) {+ *colr = 55;+ *colg = 55;+ *colb = 55;+ *firea = 75;+ *firer = 55;+ *fireg = 55;+ *fireb = 55;+ *pixel_mode = PMODE_NONE; /* Clear default, don't draw pixel */+ *pixel_mode |= FIRE_BLEND;+ return 1;+}++int el_SOAP_graphics(GRAPHICS_FUNC_ARGS) {+ *pixel_mode |= EFFECT_LINES | PMODE_BLUR;+ return 1;+}++int el_SPNG_graphics(GRAPHICS_FUNC_ARGS) {+ *colr -= cpart->life * 15;+ *colg -= cpart->life * 15;+ *colb -= cpart->life * 15;+ if (*colr <= 50) *colr = 50;+ if (*colg <= 50) *colg = 50;+ if (*colb <= 20) *colb = 20;+ return 0;+}++int el_SPRK_graphics(GRAPHICS_FUNC_ARGS) {+ *firea = 60;+ *firer = *colr / 2;+ *fireg = *colg / 2;+ *fireb = *colb / 2;+ *pixel_mode |= FIRE_SPARK;+ return 1;+}++/* STKM, STK2 and FIGH: drawn with their legs (render.c) */+int Element_STKM_graphics(GRAPHICS_FUNC_ARGS) {+ *colr = *colg = *colb = *cola = 0;+ *pixel_mode = PSPEC_STICKMAN;+ return 1;+}++int el_STOR_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->tmp & 0xFF) { /* (the stored element: tmp's bits 8 to 15 keep part of its tmp4, sim.c) */+ *pixel_mode |= PMODE_GLOW;+ *colr = 0x50;+ *colg = 0xDF;+ *colb = 0xDF;+ } else {+ *colr = 0x20;+ *colg = 0xAF;+ *colb = 0xAF;+ }+ return 0;+}++int el_SWCH_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->life >= 10) {+ *colr = 17;+ *colg = 217;+ *colb = 24;+ *pixel_mode |= PMODE_GLOW;+ }+ return 0;+}++int el_THDR_graphics(GRAPHICS_FUNC_ARGS) {+ *firea = 160;+ *fireg = 192;+ *fireb = 255;+ *firer = 144;+ *pixel_mode |= FIRE_ADD;+ return 1;+}++/* TRON.cpp's tron_colours (MakeTronColors: HSV_to_RGB(i << 4, 255, 255)) */+static const uint32_t tron_colours[32] = {+ 0xFF0000, 0xFF4300, 0xFF8800, 0xFFCC00, 0xEDFF00, 0xA9FF00, 0x65FF00, 0x21FF00, 0x00FF22, 0x00FF66, 0x00FFAA,+ 0x00FFEE, 0x00CBFF, 0x0087FF, 0x0043FF, 0x0000FF, 0x4400FF, 0x8700FF, 0xCC00FF, 0xFF00EE, 0xFF00A9, 0xFF0066,+ 0xFF0021, 0xFF0021, 0xFF0021, 0xFF0021, 0xFF0021, 0xFF0021, 0xFF0021, 0xFF0021, 0xFF0021, 0xFF0021,+};+#define TRON_HEAD 0x00000001+#define TRON_DEATH 0x00000010+int el_TRON_graphics(GRAPHICS_FUNC_ARGS) {+ uint32_t col = tron_colours[(cpart->tmp & 0xF800) >> 11];+ if (cpart->tmp & TRON_HEAD) *pixel_mode |= PMODE_GLOW;+ *colr = (col & 0xFF0000) >> 16;+ *colg = (col & 0x00FF00) >> 8;+ *colb = (col & 0x0000FF);+ if (cpart->tmp & TRON_DEATH) {+ *pixel_mode |= FIRE_ADD | PMODE_FLARE;+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ *firea = 255;+ }+ if (cpart->life < cpart->tmp2 && !(cpart->tmp & TRON_HEAD)) {+ *pixel_mode |= PMODE_BLEND;+ *pixel_mode &= ~PMODE_FLAT;+ *cola = (int)((((float)cpart->life) / ((float)cpart->tmp2)) * 255.0f);+ }+ return 0;+}++int el_TUNG_graphics(GRAPHICS_FUNC_ARGS) {+ const float MELTING_POINT = elements[PT_TUNG].HighTemperature;+ float startTemp = MELTING_POINT - 1500.0f;+ float tempOver = (((p_temp(cpart) - startTemp) / 1500.0f) * 3.14159265f) - (3.14159265f / 2.0f);+ if (tempOver > -(3.14159265f / 2.0f)) {+ if (tempOver > 3.14159265f / 2.0f) tempOver = 3.14159265f / 2.0f;+ float gradv = sinf(tempOver) + 1.0f;+ *firer = (int)(gradv * 258.0f);+ *fireg = (int)(gradv * 156.0f);+ *fireb = (int)(gradv * 112.0f);+ *firea = 30;+ *colr += *firer;+ *colg += *fireg;+ *colb += *fireb;+ *pixel_mode |= FIRE_ADD;+ }+ return 0;+}++/* VIBR and BVBR */+int Element_VIBR_graphics(GRAPHICS_FUNC_ARGS) {+ int gradient = cpart->tmp / 10;+ if (gradient >= 100 || cpart->life) {+ *colr = (int)(fabsf(sinf(expf((750.0f - cpart->life) / 170))) * 200.0f);+ if (cpart->tmp2) {+ *colg = *colr;+ *colb = 255;+ } else {+ *colg = 255;+ *colb = *colr;+ }+ *firea = 90;+ *firer = *colr;+ *fireg = *colg;+ *fireb = *colb;+ *pixel_mode = PMODE_NONE;+ *pixel_mode |= FIRE_BLEND;+ } else if (gradient < 100) {+ *colr += (int)restrict_flt(gradient * 2.0f, 0, 255);+ *colg += (int)restrict_flt(gradient * 2.0f, 0, 175);+ *colb += (int)restrict_flt(gradient * 2.0f, 0, 255);+ *firea = (int)restrict_flt(gradient * .6f, 0, 60);+ *firer = *colr / 2;+ *fireg = *colg / 2;+ *fireb = *colb / 2;+ *pixel_mode |= FIRE_BLEND;+ }+ return 0;+}++int el_VINE_graphics(GRAPHICS_FUNC_ARGS) {+ float maxtemp = (float)cpart->tmp2 > p_temp(cpart) ? (float)cpart->tmp2 : p_temp(cpart);+ if (maxtemp > 300) {+ *colr += (int)restrict_flt((maxtemp - 300) / 5, 0, 58);+ *colg -= (int)restrict_flt((maxtemp - 300) / 2, 0, 102);+ *colb += (int)restrict_flt((maxtemp - 300) / 5, 0, 70);+ }+ if (maxtemp < 273) {+ *colg += (int)restrict_flt((273 - maxtemp) / 4, 0, 255);+ *colb += (int)restrict_flt((273 - maxtemp) / 1.5f, 0, 255);+ }+ return 0;+}++int el_VIRS_graphics(GRAPHICS_FUNC_ARGS) {+ *pixel_mode |= PMODE_BLUR;+ *pixel_mode |= NO_DECO;+ return 1;+}++int el_VRSG_graphics(GRAPHICS_FUNC_ARGS) {+ *pixel_mode &= ~PMODE;+ *pixel_mode |= FIRE_BLEND;+ *firer = *colr / 2;+ *fireg = *colg / 2;+ *fireb = *colb / 2;+ *firea = 125;+ *pixel_mode |= NO_DECO;+ return 1;+}++int el_VRSS_graphics(GRAPHICS_FUNC_ARGS) {+ *pixel_mode |= NO_DECO;+ return 1;+}++int el_WARP_graphics(GRAPHICS_FUNC_ARGS) {+ *colr = *colg = *colb = *cola = 0;+ *pixel_mode |= NO_DECO;+ return 0;+}++#define WIFI_FREQUENCY 0.0628f+int el_WIFI_graphics(GRAPHICS_FUNC_ARGS) {+ int q = (int)((p_temp(cpart) - 73.15f) / 100 + 1);+ *colr = (int)(sinf(WIFI_FREQUENCY * q + 0) * 127 + 128);+ *colg = (int)(sinf(WIFI_FREQUENCY * q + 2) * 127 + 128);+ *colb = (int)(sinf(WIFI_FREQUENCY * q + 4) * 127 + 128);+ *pixel_mode |= EFFECT_DBGLINES;+ return 0;+}++int el_WIRE_graphics(GRAPHICS_FUNC_ARGS) {+ if (cpart->ctype == 0) {+ *colr = 255;+ *colg = 204;+ *colb = 0;+ return 0;+ }+ if (cpart->ctype == 1) {+ *colr = 50;+ *colg = 100;+ *colb = 255;+ return 0;+ }+ if (cpart->ctype == 2) {+ *colr = 255;+ *colg = 100;+ *colb = 50;+ return 0;+ }+ return 0;+}++int el_WOOD_graphics(GRAPHICS_FUNC_ARGS) {+ float maxtemp = (float)cpart->tmp > p_temp(cpart) ? (float)cpart->tmp : p_temp(cpart);+ if (maxtemp > 400) {+ *colr -= (int)restrict_flt((maxtemp - 400) / 3, 0, 172);+ *colg -= (int)restrict_flt((maxtemp - 400) / 4, 0, 140);+ *colb -= (int)restrict_flt((maxtemp - 400) / 20, 0, 44);+ }+ if (maxtemp < 273) {+ *colr -= (int)restrict_flt((273 - maxtemp) / 5, 0, 40);+ *colg += (int)restrict_flt((273 - maxtemp) / 4, 0, 40);+ *colb += (int)restrict_flt((273 - maxtemp) / 1.5f, 0, 150);+ }+ return 0;+}diff --git a/games/numpowder/src/render_ovl.c b/games/numpowder/src/render_ovl.cnew file mode 100644index 00000000..d3d5a9ec--- /dev/null+++ b/games/numpowder/src/render_ovl.c@@ -0,0 +1,157 @@+/* NumPowder: the overlay, the interface drawn over the sim and around it (the original's Graphics calls in+ * GameView::OnDraw and its components' Draw): a list made once a frame, drawn into every band it crosses. */+#include "render.h"+#include <string.h>++void ov_reset(Overlay *o) { o->n = o->ntext = o->ncalls = 0, o->full = false; }++bool ov_overflowed; /* (tests: a frame had more to draw than the list holds) */+static OvOp *ov_add(Overlay *o, int kind, int x, int y, int w, int h, uint32_t rgb, int alpha) {+ if (o->n >= OV_MAX) {+ o->full = ov_overflowed = true;+ return NULL;+ }+ OvOp *op = &o->op[o->n++];+ op->kind = (uint8_t)kind, op->alpha = (uint8_t)(alpha < 0 ? 0 : alpha > 255 ? 255 : alpha);+ op->x = (int16_t)x, op->y = (int16_t)y, op->w = (int16_t)w, op->h = (int16_t)h, op->rgb = rgb, op->text = 0;+ return op;+}++void ov_fill(Overlay *o, int x, int y, int w, int h, uint32_t rgb, int alpha) {+ if (w > 0 && h > 0) ov_add(o, OV_FILL, x, y, w, h, rgb, alpha);+}+void ov_rect(Overlay *o, int x, int y, int w, int h, uint32_t rgb, int alpha) {+ if (w > 0 && h > 0) ov_add(o, OV_RECT, x, y, w, h, rgb, alpha);+}+void ov_frame(Overlay *o, int x, int y, int w, int h, int thick, uint32_t rgb) {+ for (int k = 1; k <= thick; k++) ov_rect(o, x - k, y - k, w + 2 * k, h + 2 * k, rgb, 255);+}+static void ov_text_kind(Overlay *o, int kind, int x, int y, const char *s, uint32_t rgb, int alpha) {+ int n = (int)strlen(s) + 1;+ if (o->ntext + n > OV_POOL) {+ o->full = ov_overflowed = true;+ return;+ }+ OvOp *op = ov_add(o, kind, x, y, 0, 0, rgb, alpha);+ if (!op) return;+ memcpy(o->pool + o->ntext, s, (size_t)n);+ op->text = (uint16_t)o->ntext;+ /* (its size, to skip the bands it misses) */+ op->w = (int16_t)(font_text_width(s) + 2);+ op->h = (int16_t)(font_text_lines(s) * FONT_H);+ o->ntext += n;+}+void ov_text(Overlay *o, int x, int y, const char *s, uint32_t rgb, int alpha) { ov_text_kind(o, OV_TEXT, x, y, s, rgb, alpha); }+void ov_text_outline(Overlay *o, int x, int y, const char *s, uint32_t rgb, int alpha) {+ ov_text_kind(o, OV_TEXT_OUTLINE, x, y, s, rgb, alpha);+}+void ov_text_add(Overlay *o, int x, int y, const char *s, uint32_t rgb, int alpha) { ov_text_kind(o, OV_TEXT_ADD, x, y, s, rgb, alpha); }+void ov_text_big(Overlay *o, int x, int y, const char *s, uint32_t rgb) {+ int n = o->n;+ ov_text_kind(o, OV_TEXT_BIG, x, y - 2, s, rgb, 255);+ if (o->n > n) o->op[n].y = (int16_t)y, o->op[n].w *= 2, o->op[n].h *= 2;+}+void ov_line(Overlay *o, int x1, int y1, int x2, int y2, uint32_t rgb, int alpha) { ov_add(o, OV_LINE, x1, y1, x2, y2, rgb, alpha); }+void ov_xor_line(Overlay *o, int x1, int y1, int x2, int y2) { ov_add(o, OV_XOR_LINE, x1, y1, x2, y2, 0, 255); }+void ov_xor_rect(Overlay *o, int x, int y, int w, int h) { ov_add(o, OV_XOR_RECT, x, y, w, h, 0, 255); }+void ov_call(Overlay *o, OvFn fn, const void *ctx) {+ if (o->ncalls >= OV_CALLS) {+ o->full = true;+ return;+ }+ OvOp *op = ov_add(o, OV_CALL, 0, 0, 0, 0, (uint32_t)o->ncalls, 255);+ if (!op) return;+ o->fn[o->ncalls] = fn, o->ctx[o->ncalls] = ctx;+ o->ncalls++;+}++/* ---------------------------------------------------------------- drawing into a band */+void band_fill(Band *b, int x, int y, int w, int h, uint32_t rgb, int alpha) {+ int x0 = x < b->x0 ? b->x0 : x, y0 = y < b->y0 ? b->y0 : y;+ int x1 = x + w > b->x0 + b->w ? b->x0 + b->w : x + w, y1 = y + h > b->y0 + b->h ? b->y0 + b->h : y + h;+ if (x0 >= x1 || y0 >= y1) return;+ uint16_t c = rgb565(rgb);+ /* black over at half or a quarter of what's there (px_blend's 32 levels: 16 or 24 of black): each channel shifted,+ * two pixels a word */+ int keep = 32 - ((alpha + 4) >> 3);+ if (!(rgb & 0xFFFFFF) && alpha > 0 && alpha < 255 && (keep == 16 || keep == 8)) {+ int sh = keep == 16 ? 1 : 2;+ uint32_t mask = sh == 1 ? 0x7BEF7BEFu : 0x39E739E7u;+ for (int yy = y0; yy < y1; yy++) {+ uint16_t *d = b->px + (yy - b->y0) * b->w + (x0 - b->x0), *e = d + (x1 - x0);+ if (((uintptr_t)d & 2) && d < e) *d = (uint16_t)((*d >> sh) & mask), d++;+ for (; e - d >= 2; d += 2) *(uint32_t *)(void *)d = (*(uint32_t *)(void *)d >> sh) & mask;+ if (d < e) *d = (uint16_t)((*d >> sh) & mask);+ }+ return;+ }+ for (int yy = y0; yy < y1; yy++) {+ uint16_t *d = b->px + (yy - b->y0) * b->w + (x0 - b->x0);+ if (alpha >= 255)+ for (int xx = x0; xx < x1; xx++) *d++ = c;+ else+ for (int xx = x0; xx < x1; xx++, d++) *d = px_blend(*d, rgb, alpha);+ }+}++static inline void band_px(Band *b, int x, int y, uint32_t rgb, int alpha, bool xor) {+ int sx = x - b->x0, sy = y - b->y0;+ if ((unsigned)sx >= (unsigned)b->w || (unsigned)sy >= (unsigned)b->h) return;+ uint16_t *d = &b->px[sy * b->w + sx];+ *d = xor ? px_xor(*d) : px_blend(*d, rgb, alpha);+}++void band_line(Band *b, int x1, int y1, int x2, int y2, uint32_t rgb, int alpha, bool xor) {+ if ((y1 < b->y0 && y2 < b->y0) || (y1 >= b->y0 + b->h && y2 >= b->y0 + b->h)) return;+ int dx = abs(x2 - x1), dy = abs(y2 - y1), sx = x1 < x2 ? 1 : -1, sy = y1 < y2 ? 1 : -1, err = dx - dy;+ for (;;) {+ band_px(b, x1, y1, rgb, alpha, xor);+ if (x1 == x2 && y1 == y2) break;+ int e2 = 2 * err;+ if (e2 > -dy) err -= dy, x1 += sx;+ if (e2 < dx) err += dx, y1 += sy;+ }+}++void ov_draw(const Overlay *o, Band *b) {+ for (int k = 0; k < o->n; k++) {+ const OvOp *op = &o->op[k];+ if (op->kind == OV_CALL) {+ o->fn[op->rgb](b, o->ctx[op->rgb]);+ continue;+ }+ if (op->kind == OV_LINE || op->kind == OV_XOR_LINE) {+ band_line(b, op->x, op->y, op->w, op->h, op->rgb, op->alpha, op->kind == OV_XOR_LINE);+ continue;+ }+ /* (boxes and texts that miss the band) */+ int top = op->kind == OV_TEXT_BIG ? op->y - 5 : op->kind >= OV_TEXT && op->kind <= OV_TEXT_ADD ? op->y - 3 : op->y;+ if (top >= b->y0 + b->h || op->y + op->h + 1 <= b->y0) continue;+ switch (op->kind) {+ case OV_FILL: band_fill(b, op->x, op->y, op->w, op->h, op->rgb, op->alpha); break;+ case OV_RECT:+ band_fill(b, op->x, op->y, op->w, 1, op->rgb, op->alpha);+ if (op->h > 1) band_fill(b, op->x, op->y + op->h - 1, op->w, 1, op->rgb, op->alpha);+ if (op->h > 2) {+ band_fill(b, op->x, op->y + 1, 1, op->h - 2, op->rgb, op->alpha);+ if (op->w > 1) band_fill(b, op->x + op->w - 1, op->y + 1, 1, op->h - 2, op->rgb, op->alpha);+ }+ break;+ case OV_XOR_RECT:+ /* RasterizeDottedRect: every other pixel of the edges */+ for (int x = op->x; x < op->x + op->w; x += 2) {+ band_px(b, x, op->y, 0, 255, true);+ band_px(b, x, op->y + op->h - 1, 0, 255, true);+ }+ for (int y = op->y + 2; y < op->y + op->h - 1; y += 2) {+ band_px(b, op->x, y, 0, 255, true);+ band_px(b, op->x + op->w - 1, y, 0, 255, true);+ }+ break;+ case OV_TEXT: font_draw(b, op->x, op->y, o->pool + op->text, op->rgb, op->alpha, FONT_BLEND); break;+ case OV_TEXT_ADD: font_draw(b, op->x, op->y, o->pool + op->text, op->rgb, op->alpha, FONT_ADD); break;+ case OV_TEXT_OUTLINE: font_draw_outline(b, op->x, op->y, o->pool + op->text, op->rgb, op->alpha); break;+ case OV_TEXT_BIG: font_draw_big(b, op->x, op->y, o->pool + op->text, op->rgb); break;+ }+ }+}diff --git a/games/numpowder/src/sim.c b/games/numpowder/src/sim.cnew file mode 100644index 00000000..d2c72e64--- /dev/null+++ b/games/numpowder/src/sim.c@@ -0,0 +1,1284 @@+/* NumPowder: The Powder Toy's Simulation (Simulation.cpp): the particles' store, creating and killing them,+ * the frame's steps around the particles' update (BeforeSim, AfterSim, RecalcFreeParticles, CheckStacking),+ * the flood fills, the random numbers (common/tpt-rand.cpp) and the settings. The particles' update and+ * movement are in sim_move.c. */+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("O3") /* (a hot path: a few KB of flash for speed) */+#endif+#include "simpriv.h"++/* ---------------------------------------------------------------- the state */+Particle *parts;+int npart_max;+int parts_active, parts_lastActiveIndex = -1;+int pfree = -1;+int NUM_PARTS;+int elementCount[PT_NUM];+uint16_t (*pmap_id)[XRES];+uint16_t (*photons_id)[XRES];+uint8_t *sim_scratch;+uint32_t temp_dither = 0x2545F491;++unsigned char bmap[YWCELLS][XWCELLS], emap[YWCELLS][XWCELLS];+float fvx[YACELLS][XACELLS], fvy[YACELLS][XACELLS];++SimSettings settings;+int legacy_enable, aheat_enable, water_equal_test, edgeMode = EDGE_VOID, gravityMode;+float customGravityX, customGravityY;+bool ngrav_enable;+int currentTick;+uint32_t frameCount;+bool sys_pause;+int emp_decor;++int ISWIRE;+bool emap_any12;+bool force_stacking_check;+int emp_trigger_count;+bool etrd_count_valid;+int etrd_life0_count;+int lightningRecreate;+bool gravWallChanged;+bool elementRecount;+uint8_t wireless[CHANNELS][2];+int CGOL, GSPEED = 1;+int Element_PPIP_ppip_changed;+int16_t Element_PSTN_tempParts[XRES > YRES ? XRES : YRES];+uint8_t Element_LOLZ_lolz[XRES / 9][YRES / 9];+uint8_t Element_LOVE_love[XRES / 9][YRES / 9];+playerst player, player2, fighters[MAX_FIGHTERS];+unsigned char fighcount;+PortalSlot portalp[PORTAL_SLOTS];+int portal_count;++static inline void set_active(int n) {+ parts_active = n;+ parts_lastActiveIndex = n - 1;+}++/* ---------------------------------------------------------------- random numbers: xoroshiro128+ (tpt-rand.cpp) */+uint64_t rng_state[2] = {0, 614};+static inline uint64_t rotl(uint64_t x, int k) { return (x << k) | (x >> (64 - k)); }+static inline uint64_t rng_next(void) {+ uint64_t s0 = rng_state[0], s1 = rng_state[1], result = s0 + s1;+ s1 ^= s0;+ rng_state[0] = rotl(s0, 55) ^ s1 ^ (s1 << 14);+ rng_state[1] = rotl(s1, 36);+ return result;+}+unsigned int rng_gen(void) { return (unsigned int)(rng_next() & 0x7FFFFFFF); }+unsigned int rng_u32(void) { return (unsigned int)rng_next(); }+int rng_between(int lower, int upper) {+ unsigned int r = (unsigned int)rng_next();+ return (int)(r % ((unsigned int)upper - (unsigned int)lower + 1u)) + lower;+}+/* the original takes the 64-bit number modulo the denominator; below 2^16 that's done with 32-bit divisions */+bool rng_chance(int numerator, unsigned int denominator) {+ if (numerator < 0) return false;+ uint64_t n = rng_next();+ uint32_t m;+ if (denominator <= 0x10000u) {+ uint32_t hi = (uint32_t)(n >> 32), lo = (uint32_t)n, k = (0u - denominator) % denominator; /* 2^32 mod d */+ m = ((hi % denominator) * k + lo % denominator) % denominator;+ } else {+ m = (uint32_t)(n % denominator);+ }+ return m < (unsigned int)numerator;+}+float rng_uniform01(void) { return (float)(uint32_t)rng_next() / (float)0xFFFFFFFFu; }+void rng_seed(unsigned int sd) { rng_state[0] = sd, rng_state[1] = sd; }++/* ---------------------------------------------------------------- the particles' store (Parts) */+static void parts_reset(void) {+ memset(parts, 0, sizeof(Particle) * (size_t)npart_max);+ set_active(0);+ pfree = -1;+}+int parts_alloc(void) {+ if (pfree != -1) {+ int i = pfree;+ pfree = parts[i].life;+ return i;+ }+ if (parts_active < NPART) {+ int i = parts_active;+ set_active(parts_active + 1);+ return i;+ }+ return -1;+}+static void parts_free(int i) {+ parts[i].type = PT_NONE;+ parts[i].life = (int16_t)pfree;+ pfree = i;+}+static bool max_parts_reached(void) { return pfree == -1 && parts_active >= NPART; }+/* Parts::Flatten: the free list in order, the active ids up to the last particle */+void sim_flatten_parts(void) {+ int newActive = 0, prev = -1;+ pfree = -1;+ for (int i = 0; i < parts_active; i++) {+ if (parts[i].type) {+ for (int j = newActive; j < i; ++j) {+ if (prev < 0) pfree = j;+ else parts[prev].life = (int16_t)j;+ prev = j;+ }+ newActive = i + 1;+ }+ }+ if (prev < 0) pfree = -1;+ else parts[prev].life = -1;+ set_active(newActive);+}++/* ---------------------------------------------------------------- tmp4, which the particle doesn't keep+ * VIRS, VRSS, VRSG: tmp3 holds the cure countdown when it's above 0 (as the original's tmp3), or minus tmp4 (the+ * countdown to dying) otherwise: the original only uses tmp4 while tmp3 is 0, and clears it when cured.+ * PLNT, SEED: the 15 bits of genes in ctype's bits 20 to 31 (the original's ctype uses 20) and flags' bits 5 to 7.+ * STOR: the stored particle's ctype in ctype's bits 8 to 31 (the original's ctype there is an element) and+ * tmp's bits 8 to 15 (its tmp is the stored element).+ * PIPE, PPIP: the stored ctype in ctype's bits 8 to 31 (bits 0 to 7 are the stored element), sign-extended;+ * one that doesn't fit 24 bits (photons' wavelengths) keeps its top bits in a small table by particle id. */+#define PIPE_OVF 64+static uint16_t pipe_ovf_id[PIPE_OVF]; /* id + 1, 0 free */+static int8_t pipe_ovf_hi[PIPE_OVF];+static int pipe_ovf_find(int i) {+ for (int k = 0; k < PIPE_OVF; k++)+ if (pipe_ovf_id[k] == i + 1) return k;+ return -1;+}+void pipe_ovf_clear(int i) {+ int k = pipe_ovf_find(i);+ if (k >= 0) pipe_ovf_id[k] = 0;+}+void pipe_ovf_move(int from, int to) {+ pipe_ovf_clear(to);+ int k = pipe_ovf_find(from);+ if (k >= 0) pipe_ovf_id[k] = (uint16_t)(to + 1);+}+int tmp4_get(int i) {+ const Particle *p = &parts[i];+ switch (p->type) {+ case PT_VIRS: case PT_VRSS: case PT_VRSG:+ return p->tmp3 < 0 ? -p->tmp3 : 0;+ case PT_PLNT: case PT_SEED:+ return (int)(((uint32_t)p->ctype >> 20) | (uint32_t)((p->flags >> 5) & 7) << 12);+ case PT_STOR:+ return (int)(((uint32_t)p->ctype >> 8) | ((uint32_t)(uint16_t)p->tmp >> 8) << 24);+ case PT_PIPE: case PT_PPIP: {+ int v = p->ctype >> 8; /* (arithmetic) */+ int k = pipe_ovf_find(i);+ if (k >= 0) v = (int)(((uint32_t)v & 0xFFFFFF) | (uint32_t)(uint8_t)pipe_ovf_hi[k] << 24);+ return v;+ }+ default:+ return 0;+ }+}+void tmp4_set(int i, int v) {+ Particle *p = &parts[i];+ switch (p->type) {+ case PT_VIRS: case PT_VRSS: case PT_VRSG:+ if (p->tmp3 <= 0) p->tmp3 = (int16_t)-iclamp(v, 0, 32767);+ break;+ case PT_PLNT: case PT_SEED:+ p->ctype = (int32_t)(((uint32_t)p->ctype & 0xFFFFF) | ((uint32_t)v & 0xFFF) << 20);+ p->flags = (uint8_t)((p->flags & 0x1F) | (((uint32_t)v >> 12) & 7) << 5);+ break;+ case PT_STOR:+ p->ctype = (int32_t)(((uint32_t)p->ctype & 0xFF) | ((uint32_t)v & 0xFFFFFF) << 8);+ p->tmp = (int16_t)(((uint16_t)p->tmp & 0xFF) | (((uint32_t)v >> 24) & 0xFF) << 8);+ break;+ case PT_PIPE: case PT_PPIP: {+ int k = pipe_ovf_find(i);+ if (v >= -0x800000 && v < 0x800000) {+ if (k >= 0) pipe_ovf_id[k] = 0;+ } else {+ if (k < 0)+ for (k = 0; k < PIPE_OVF && pipe_ovf_id[k]; k++) {}+ if (k < PIPE_OVF) pipe_ovf_id[k] = (uint16_t)(i + 1), pipe_ovf_hi[k] = (int8_t)(v >> 24);+ /* (the table full: what fits, the low 23 bits, positive, rather than a value read back sign-extended from+ * bit 23. A photon keeps its blue and green wavelengths) */+ else v &= 0x7FFFFF;+ }+ p->ctype = (int32_t)(((uint32_t)p->ctype & 0xFF) | ((uint32_t)v & 0xFFFFFF) << 8);+ break;+ }+ default:+ break;+ }+}+void tmp4_clear(int i) { tmp4_set(i, 0); }++/* ---------------------------------------------------------------- the portals' particles (portalp) */+const int portal_rx[8] = {-1, 0, 1, 1, 1, 0, -1, -1};+const int portal_ry[8] = {-1, -1, -1, 0, 1, 1, 1, 0};+static uint64_t portal_used(int channel, int dir, uint32_t *hi) {+ uint64_t lo = 0;+ *hi = 0;+ for (int k = 0; k < portal_count; k++)+ if (portalp[k].channel == channel && portalp[k].dir == dir) {+ int s = portalp[k].slot;+ if (s < 64) lo |= (uint64_t)1 << s;+ else *hi |= 1u << (s - 64);+ }+ return lo;+}+static int portal_first_free(int channel, int dir) {+ uint32_t hi;+ uint64_t lo = portal_used(channel, dir, &hi);+ if (~lo) return __builtin_ctzll(~lo);+ if ((~hi) & 0xFFFF) return 64 + __builtin_ctz(~hi);+ return -1; /* the 80 places taken */+}+bool portal_free(int channel, int dir) { return portal_count < PORTAL_SLOTS && portal_first_free(channel, dir) >= 0; }+bool portal_put(int channel, int dir, const Particle *p) {+ if (portal_count >= PORTAL_SLOTS) return false;+ int s = portal_first_free(channel, dir);+ if (s < 0) return false;+ portalp[portal_count].channel = (uint8_t)channel;+ portalp[portal_count].dir = (uint8_t)dir;+ portalp[portal_count].slot = (uint8_t)s;+ portalp[portal_count].p = *p;+ portal_count++;+ return true;+}+int portal_find(int channel, int dir, int slot) {+ for (int k = 0; k < portal_count; k++)+ if (portalp[k].slot == slot && portalp[k].channel == channel && portalp[k].dir == dir) return k;+ return -1;+}+void portal_take(int entry) { portalp[entry] = portalp[--portal_count]; }+bool portal_any(int channel) {+ for (int k = 0; k < portal_count; k++)+ if (portalp[k].channel == channel) return true;+ return false;+}++/* ---------------------------------------------------------------- SimulationData's */+float HeatCapacityOf(const Particle *p) {+ if ((p->type == PT_PIPE || p->type == PT_PPIP) && IsElement(TYP(p->ctype)))+ return elements[p->type].HeatCapacity + elements[TYP(p->ctype)].HeatCapacity;+ return elements[p->type].HeatCapacity;+}++/* ---------------------------------------------------------------- killing, changing and creating particles */+void kill_part(int i) {+ if (i < 0 || i >= NPART) return;+ Particle *p = &parts[i];+ int x = (p->x + 32) / 64, y = (p->y + 32) / 64; /* (int)(x + 0.5f) */+ int t = p->type;+ if (t && elements[t].ChangeType) elements[t].ChangeType(i, x, y, t, PT_NONE);+ if (x >= 0 && y >= 0 && x < XRES && y < YRES) {+ if (pmap_id[y][x] == i + 1) pmap_id[y][x] = 0;+ else if (photons_id[y][x] == i + 1) photons_id[y][x] = 0;+ }+ if (t == PT_NONE) return;+ if (t == PT_PIPE || t == PT_PPIP) pipe_ovf_clear(i);+ elementCount[t]--;+ parts_free(i);+ NUM_PARTS -= 1;+}++bool part_change_type(int i, int x, int y, int t) {+ if (x < 0 || y < 0 || x >= XRES || y >= YRES || i >= NPART || t < 0 || t >= PT_NUM || !parts[i].type) return false;+ if (!elements[t].Enabled || t == PT_NONE) {+ kill_part(i);+ return true;+ }+ if (elements[t].CreateAllowed && !elements[t].CreateAllowed(i, x, y, t)) return false;+ int from = parts[i].type;+ if (elements[from].ChangeType) elements[from].ChangeType(i, x, y, from, t);+ if (elements[t].ChangeType) elements[t].ChangeType(i, x, y, parts[i].type, t);+ from = parts[i].type;+ if (from > 0 && from < PT_NUM && elementCount[from]) elementCount[from]--;+ elementCount[t]++;+ if ((from == PT_PIPE || from == PT_PPIP) && t != PT_PIPE && t != PT_PPIP) pipe_ovf_clear(i);+ parts[i].type = (uint8_t)t;+ if (elements[t].Properties & TYPE_ENERGY) {+ photons_id[y][x] = (uint16_t)(i + 1);+ if (pmap_id[y][x] == i + 1) pmap_id[y][x] = 0;+ } else {+ pmap_id[y][x] = (uint16_t)(i + 1);+ if (photons_id[y][x] == i + 1) photons_id[y][x] = 0;+ }+ return false;+}++/* p: -1 a new particle, -2 from the brush, -3 without the map's checks, or the particle to replace */+int create_part(int p, int x, int y, int t, int v) {+ if (x < 0 || y < 0 || x >= XRES || y >= YRES || t <= 0 || t >= PT_NUM || !elements[t].Enabled) return -1;++ if (t == PT_SPRK && p != -3 && !(p == -2 && elements[TYP(PMAPAT(x, y))].CtypeDraw)) {+ int r = PMAPAT(x, y), type = TYP(r), index = ID(r);+ if (type == PT_WIRE) {+ parts[index].ctype = PT_DUST;+ return index;+ }+ if (!(type == PT_INST || (elements[type].Properties & PROP_CONDUCTS)) || parts[index].life != 0) return -1;+ if (p == -2 && type == PT_INST) {+ FloodINST(x, y);+ return index;+ }+ parts[index].type = PT_SPRK;+ parts[index].life = 4;+ parts[index].ctype = type;+ if (p_temp(&parts[index]) + 10.0f < 673.0f && !legacy_enable &&+ (type == PT_METL || type == PT_BMTL || type == PT_BRMT || type == PT_PSCN || type == PT_NSCN ||+ type == PT_ETRD || type == PT_NBLE || type == PT_IRON))+ p_set_temp(&parts[index], p_temp(&parts[index]) + 10.0f);+ return index;+ }++ if (p == -2) {+ int r = PMAPAT(x, y);+ if (r) {+ int drawOn = TYP(r);+ if (elements[drawOn].CtypeDraw) elements[drawOn].CtypeDraw(ID(r), t, v);+ return -1;+ } else if (IsWallBlocking(x, y, t)) {+ return -1;+ } else if (photons_id[y][x] && (elements[t].Properties & TYPE_ENERGY)) {+ return -1;+ }+ }++ if (elements[t].CreateAllowed && !elements[t].CreateAllowed(p, x, y, t)) return -1;++ int i, oldType = PT_NONE;+ if (p == -1 || p == -2 || p == -3) {+ if (p == -1) {+ /* a particle there: only one that can be in the same place; none but a wall: only one the wall allows */+ if (pmap_id[y][x] ? (eval_move(t, x, y, NULL) != 2) : (bmap[y / WCELL][x / WCELL] && eval_move(t, x, y, NULL) == 0))+ return -1;+ }+ i = parts_alloc();+ if (i == -1) return -1;+ NUM_PARTS += 1;+ } else {+ int oldX = (parts[p].x + 32) / 64, oldY = (parts[p].y + 32) / 64;+ if (InBounds(oldX, oldY)) {+ if (pmap_id[oldY][oldX] == p + 1) pmap_id[oldY][oldX] = 0;+ if (photons_id[oldY][oldX] == p + 1) photons_id[oldY][oldX] = 0;+ }+ oldType = parts[p].type;+ if (elements[oldType].ChangeType) elements[oldType].ChangeType(p, oldX, oldY, oldType, t);+ if (oldType) elementCount[oldType]--;+ if (oldType == PT_PIPE || oldType == PT_PPIP) pipe_ovf_clear(p);+ i = p;+ }++ /* parts[i] = elements[t].DefaultProperties */+ const Element *e = &elements[t];+ Particle *q = &parts[i];+ q->type = (uint8_t)t;+ q->flags = 0;+ q->life = (int16_t)e->DefaultProperties.life;+ q->ctype = e->DefaultProperties.ctype;+ q->tmp = (int16_t)e->DefaultProperties.tmp;+ q->tmp2 = (int16_t)e->DefaultProperties.tmp2;+ q->tmp3 = (int16_t)e->DefaultProperties.tmp3;+ p_set_temp(q, e->DefaultProperties.temp);+ q->vx = q->vy = 0;+ if (t == PT_MORT) q->vx = (int16_t)(2 * P_VEL); /* (its DefaultProperties.vx, the only element with one: CHOO CHOO) */+ q->x = (int16_t)(x * 64);+ q->y = (int16_t)(y * 64);+ if (e->DefaultProperties.tmp4) tmp4_set(i, e->DefaultProperties.tmp4);++ if (e->Properties & TYPE_ENERGY) photons_id[y][x] = (uint16_t)(i + 1);+ else if (t != PT_STKM && t != PT_STKM2 && t != PT_FIGH) pmap_id[y][x] = (uint16_t)(i + 1);++ /* (pretty powders' colours are decoration, which isn't kept) */+ if (e->Create) e->Create(i, x, y, t, v);+ if (e->ChangeType) e->ChangeType(i, x, y, oldType, t);+ elementCount[t]++;+ return i;+}++/* changes a particle's type, keeping its temperature and velocity */+int createPartTempVel(int i, int x, int y, int t) {+ uint16_t temp = parts[i].temp;+ int16_t pvx = parts[i].vx, pvy = parts[i].vy;+ int np = create_part(i, x, y, t, -1);+ if (np >= 0) {+ parts[np].temp = temp;+ parts[np].vx = pvx;+ parts[np].vy = pvy;+ }+ return np;+}++void delete_part(int x, int y) {+ if (x < 0 || y < 0 || x >= XRES || y >= YRES) return;+ int i = photons_id[y][x] ? photons_id[y][x] : pmap_id[y][x];+ if (!i) return;+ kill_part(i - 1);+}++int parts_avg(int ci, int ni, int t) {+ if (t == PT_INSL) { /* to keep electronics working */+ int pmr = PMAPAT(((int)(p_x(&parts[ci]) + 0.5f) + (int)(p_x(&parts[ni]) + 0.5f)) / 2,+ ((int)(p_y(&parts[ci]) + 0.5f) + (int)(p_y(&parts[ni]) + 0.5f)) / 2);+ return pmr ? parts[ID(pmr)].type : PT_NONE;+ }+ int pmr2 = PMAPAT((int)((p_x(&parts[ci]) + p_x(&parts[ni])) / 2 + 0.5f),+ (int)((p_y(&parts[ci]) + p_y(&parts[ni])) / 2 + 0.5f));+ if (pmr2) {+ if (parts[ID(pmr2)].type == t) return t;+ } else {+ return PT_NONE;+ }+ return PT_NONE;+}++/* photons from PHOT going through GLOW */+void create_gain_photon(int pp) {+ if (max_parts_reached()) return;+ int lr = 2 * rng_between(0, 1) - 1;+ float xx = q64(p_x(&parts[pp]) - lr * 0.3f * p_vy(&parts[pp]));+ float yy = q64(p_y(&parts[pp]) + lr * 0.3f * p_vx(&parts[pp]));+ int nx = (int)(xx + 0.5f), ny = (int)(yy + 0.5f);+ if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) return;+ int g = PMAPAT(nx, ny);+ if (TYP(g) != PT_GLOW) return;+ uint16_t oldTemp = parts[ID(g)].temp;+ int i = create_part(-3, nx, ny, PT_PHOT, -1);+ if (i == -1) return;+ p_set_x(&parts[i], xx);+ p_set_y(&parts[i], yy);+ parts[i].vx = parts[pp].vx;+ parts[i].vy = parts[pp].vy;+ parts[i].temp = oldTemp;+ int temp_bin = (int)((p_temp(&parts[i]) - 273.0f) * 0.25f);+ if (temp_bin < 0) temp_bin = 0;+ if (temp_bin > 25) temp_bin = 25;+ parts[i].ctype = 0x1F << temp_bin;+}++/* photons from NEUT going through GLAS */+void create_cherenkov_photon(int pp) {+ if (max_parts_reached()) return;+ int nx = (int)(p_x(&parts[pp]) + 0.5f), ny = (int)(p_y(&parts[pp]) + 0.5f);+ int g = PMAPAT(nx, ny);+ if (TYP(g) != PT_GLAS && TYP(g) != PT_BGLA) return;+ if (hypotf(p_vx(&parts[pp]), p_vy(&parts[pp])) < 1.44f) return;+ uint16_t oldTemp = parts[ID(g)].temp;+ int i = create_part(-3, nx, ny, PT_PHOT, -1);+ if (i == -1) return;+ int lr = 2 * rng_between(0, 1) - 1;+ parts[i].ctype = 0x00000F80;+ parts[i].x = parts[pp].x;+ parts[i].y = parts[pp].y;+ parts[i].temp = oldTemp;+ float nvx = p_vx(&parts[pp]) - lr * 2.5f * p_vy(&parts[pp]);+ float nvy = p_vy(&parts[pp]) + lr * 2.5f * p_vx(&parts[pp]);+ float r = 1.269f / hypotf(nvx, nvy); /* photons have speed of light. no discussion. */+ p_set_vx(&parts[i], nvx * r);+ p_set_vy(&parts[i], nvy * r);+}++/* ---------------------------------------------------------------- gravity's field at a particle */+void GetGravityField(int x, int y, float particleGrav, float newtonGrav, float *pGravX, float *pGravY) {+ switch (gravityMode) {+ default:+ case GRAV_VERTICAL:+ *pGravX = 0;+ *pGravY = particleGrav;+ break;+ case GRAV_OFF:+ *pGravX = 0;+ *pGravY = 0;+ break;+ case GRAV_RADIAL: {+ *pGravX = 0;+ *pGravY = 0;+ float dx = (float)(x - XCNTR), dy = (float)(y - YCNTR);+ if (dx || dy) {+ float pGravD = 0.01f - hypotf(dx, dy);+ *pGravX = particleGrav * (dx / pGravD);+ *pGravY = particleGrav * (dy / pGravD);+ }+ break;+ }+ case GRAV_CUSTOM:+ *pGravX = particleGrav * customGravityX;+ *pGravY = particleGrav * customGravityY;+ break;+ }+ if (newtonGrav) {+ *pGravX += newtonGrav * gravx[y / ACELL][x / ACELL];+ *pGravY += newtonGrav * gravy[y / ACELL][x / ACELL];+ }+}++/* ---------------------------------------------------------------- walls */+bool IsWallBlocking(int x, int y, int type) {+ int wall = bmap[y / WCELL][x / WCELL];+ if (wall) {+ uint32_t props = elements[type].Properties;+ if (wall == WL_ALLOWGAS && !(props & TYPE_GAS)) return true;+ else if (wall == WL_ALLOWENERGY && !(props & TYPE_ENERGY)) return true;+ else if (wall == WL_ALLOWLIQUID && !(props & TYPE_LIQUID)) return true;+ else if (wall == WL_ALLOWPOWDER && !(props & TYPE_PART)) return true;+ else if (wall == WL_ALLOWAIR || wall == WL_WALL || wall == WL_WALLELEC) return true;+ else if (wall == WL_EWALL && !emap[y / WCELL][x / WCELL]) return true;+ else if (wall == WL_DETECT && (props & TYPE_SOLID)) return true;+ }+ return false;+}++static inline bool is_wire(int x, int y) {+ if ((unsigned)x >= XWCELLS || (unsigned)y >= YWCELLS) return false; /* (off the grid: no wall) */+ int b = bmap[y][x];+ return b == WL_DETECT || b == WL_EWALL || b == WL_ALLOWLIQUID || b == WL_WALLELEC || b == WL_ALLOWALLELEC ||+ b == WL_EHOLE || b == WL_STASIS;+}+static inline bool is_wire_off(int x, int y) { return is_wire(x, y) && emap[y][x] < 8; }++/* powers the connected wall cells (in wall cells) */+void set_emap(int x, int y) {+ if (!is_wire_off(x, y)) return;+ int x1 = x, x2 = x;+ while (x1 > 0 && is_wire_off(x1 - 1, y)) x1--;+ while (x2 < XWCELLS - 1 && is_wire_off(x2 + 1, y)) x2++;+ for (x = x1; x <= x2; x++) emap[y][x] = 16;++ if (y > 1 && x1 == x2 && is_wire(x1 - 1, y - 1) && is_wire(x1, y - 1) && is_wire(x1 + 1, y - 1) &&+ !is_wire(x1 - 1, y - 2) && is_wire(x1, y - 2) && !is_wire(x1 + 1, y - 2))+ set_emap(x1, y - 2);+ else if (y > 0)+ for (x = x1; x <= x2; x++)+ if (is_wire_off(x, y - 1)) {+ if (x == x1 || x == x2 || y >= YWCELLS - 1 || is_wire(x - 1, y - 1) || is_wire(x + 1, y - 1) ||+ is_wire(x - 1, y + 1) || !is_wire(x, y + 1) || is_wire(x + 1, y + 1))+ set_emap(x, y - 1);+ }++ if (y < YWCELLS - 2 && x1 == x2 && is_wire(x1 - 1, y + 1) && is_wire(x1, y + 1) && is_wire(x1 + 1, y + 1) &&+ !is_wire(x1 - 1, y + 2) && is_wire(x1, y + 2) && !is_wire(x1 + 1, y + 2))+ set_emap(x1, y + 2);+ else if (y < YWCELLS - 1)+ for (x = x1; x <= x2; x++)+ if (is_wire_off(x, y + 1)) {+ if (x == x1 || x == x2 || y < 0 || is_wire(x - 1, y + 1) || is_wire(x + 1, y + 1) ||+ is_wire(x - 1, y - 1) || !is_wire(x, y - 1) || is_wire(x + 1, y - 1))+ set_emap(x, y + 1);+ }+}++void SetEdgeMode(int newEdgeMode) {+ edgeMode = newEdgeMode;+ int b = BORDER / WCELL; /* the edge's wall cells */+ switch (edgeMode) {+ case EDGE_VOID:+ case EDGE_LOOP:+ case EDGE_SOLID:+ for (int y = 0; y < YWCELLS; y++)+ for (int x = 0; x < XWCELLS; x++)+ if (y < b || x < b || y >= YWCELLS - b || x >= XWCELLS - b) bmap[y][x] = edgeMode == EDGE_SOLID ? WL_WALL : 0;+ break;+ default:+ SetEdgeMode(EDGE_VOID);+ }+}++/* the wavelengths a photon keeps going through glass, and the bin of its refraction index */+int get_wavelength_bin(int *wm) {+ if (!(*wm & 0x3FFFFFFF)) return -1;+ int w0 = __builtin_ctz((unsigned)*wm | 0xC0000000u);+ int wM = 31 - __builtin_clz((unsigned)*wm & 0x3FFFFFFFu);+ if (wM - w0 < 5) return wM + w0;+ int r = (int)rng_gen();+ int i = (r >> 1) % (wM - w0 - 4);+ i += w0;+ if (r & 1) {+ *wm &= 0x1F << i;+ return (i + 2) * 2;+ } else {+ *wm &= 0xF << i;+ return (i + 2) * 2 - 1;+ }+}++/* a line of particles, 0 particles thick (SPRK's) */+void CreateLine(int x1, int y1, int x2, int y2, int c) {+ bool reverseXY = abs(y2 - y1) > abs(x2 - x1);+ int x, y, dx, dy, sy, v = ID(c);+ float e, de;+ c = TYP(c);+ if (reverseXY) {+ y = x1, x1 = y1, y1 = y;+ y = x2, x2 = y2, y2 = y;+ }+ if (x1 > x2) {+ y = x1, x1 = x2, x2 = y;+ y = y1, y1 = y2, y2 = y;+ }+ dx = x2 - x1;+ dy = abs(y2 - y1);+ e = 0.0f;+ de = dx ? dy / (float)dx : 0.0f;+ y = y1;+ sy = (y1 < y2) ? 1 : -1;+ for (x = x1; x <= x2; x++) {+ if (reverseXY) create_part(-1, y, x, c, v);+ else create_part(-1, x, y, c, v);+ e += de;+ if (e >= 0.5f) {+ y += sy;+ if ((y1 < y2) ? (y <= y2) : (y >= y2)) {+ if (reverseXY) create_part(-1, y, x, c, v);+ else create_part(-1, x, y, c, v);+ }+ e -= 1.0f;+ }+ }+}++/* ---------------------------------------------------------------- flood fills' stack (CoordStack): the cells+ * pushed, as runs along a row (pushing the next x of the top run extends it), so the order is the original's+ * and a row pushed whole is one entry; in sim_scratch after `from` bytes */+static uint32_t *cs_runs;+static int cs_n, cs_cap;+void flood_stack_init(int from) {+ cs_runs = (uint32_t *)(void *)(sim_scratch + from);+ cs_cap = (SCRATCH - from) / 4;+ cs_n = 0;+}+bool flood_stack_push(int x, int y) {+ if (cs_n) {+ uint32_t t = cs_runs[cs_n - 1];+ if ((int)(t >> 16) == y && (int)(t & 0xFF) + 1 == x) {+ cs_runs[cs_n - 1] = t + 1;+ return true;+ }+ }+ if (cs_n >= cs_cap) return false; /* (the original's CoordStackOverflowException) */+ cs_runs[cs_n++] = (uint32_t)y << 16 | (uint32_t)x << 8 | (uint32_t)x;+ return true;+}+void flood_stack_pop(int *x, int *y) {+ uint32_t t = cs_runs[cs_n - 1];+ *y = (int)(t >> 16);+ *x = (int)(t & 0xFF);+ if ((int)(t & 0xFF) == (int)((t >> 8) & 0xFF)) cs_n--;+ else cs_runs[cs_n - 1] = t - 1;+}+int flood_stack_size(void) { return cs_n; }+/* a bitmap of the cells looked at, in sim_scratch's first FLOOD_BITMAP bytes */+#define FLOOD_BITMAP ((XRES * YRES + 7) / 8)+static inline bool bm_get(int x, int y) {+ int k = y * XRES + x;+ return sim_scratch[k >> 3] >> (k & 7) & 1;+}+static inline void bm_set(int x, int y) {+ int k = y * XRES + x;+ sim_scratch[k >> 3] |= (uint8_t)(1 << (k & 7));+}++bool FloodFillPmapCheck(int x, int y, int type) {+ if (type == 0) return !pmap_id[y][x] && !photons_id[y][x];+ if (elements[type].Properties & TYPE_ENERGY) return TYP(PHOTAT(x, y)) == type;+ return TYP(PMAPAT(x, y)) == type;+}++/* the original's flood_prop, setting an int property (FIELD_LIFE, FIELD_CTYPE, FIELD_TMP...) */+static void set_field(int i, int field, int value) {+ switch (field) {+ case FIELD_LIFE: parts[i].life = (int16_t)value; break;+ case FIELD_CTYPE: parts[i].ctype = value; break;+ case FIELD_TMP: parts[i].tmp = (int16_t)value; break;+ case FIELD_TMP2: parts[i].tmp2 = (int16_t)value; break;+ case FIELD_TMP3: parts[i].tmp3 = (int16_t)value; break;+ case FIELD_TMP4: tmp4_set(i, value); break;+ default: break;+ }+}+int flood_prop_int(int x, int y, int field, int value) {+ int i, x1, x2, dy = 1, did_something = 0;+ int r = PMAPAT(x, y);+ if (!r) r = PHOTAT(x, y);+ if (!r) return 0;+ int parttype = TYP(r);+ memset(sim_scratch, 0, FLOOD_BITMAP);+ flood_stack_init(FLOOD_BITMAP);+ flood_stack_push(x, y);+ do {+ flood_stack_pop(&x, &y);+ x1 = x2 = x;+ while (x1 >= BORDER) {+ if (!FloodFillPmapCheck(x1 - 1, y, parttype) || bm_get(x1 - 1, y)) break;+ x1--;+ }+ while (x2 < XRES - BORDER) {+ if (!FloodFillPmapCheck(x2 + 1, y, parttype) || bm_get(x2 + 1, y)) break;+ x2++;+ }+ for (x = x1; x <= x2; x++) {+ i = pmap_id[y][x];+ if (!i) i = photons_id[y][x];+ if (!i) continue;+ set_field(i - 1, field, value);+ bm_set(x, y);+ did_something = 1;+ }+ if (y >= BORDER + dy)+ for (x = x1; x <= x2; x++)+ if (FloodFillPmapCheck(x, y - dy, parttype) && !bm_get(x, y - dy))+ if (!flood_stack_push(x, y - dy)) return -1;+ if (y < YRES - BORDER - dy)+ for (x = x1; x <= x2; x++)+ if (FloodFillPmapCheck(x, y + dy, parttype) && !bm_get(x, y + dy))+ if (!flood_stack_push(x, y + dy)) return -1;+ } while (cs_n > 0);+ return did_something;+}++static inline bool isSparkableInst(int x, int y) {+ int r = PMAPAT(x, y);+ return TYP(r) == PT_INST && parts[ID(r)].life == 0;+}+static inline bool isInst(int x, int y) {+ int r = PMAPAT(x, y);+ return TYP(r) == PT_INST || (TYP(r) == PT_SPRK && parts[ID(r)].ctype == PT_INST);+}+/* sparks a whole piece of INST at once */+int FloodINST(int x, int y) {+ int x1, x2, created_something = 0;+ if (!isSparkableInst(x, y)) return 1;+ flood_stack_init(0);+ flood_stack_push(x, y);+ do {+ flood_stack_pop(&x, &y);+ x1 = x2 = x;+ while (x1 >= BORDER && isSparkableInst(x1 - 1, y)) x1--;+ while (x2 < XRES - BORDER && isSparkableInst(x2 + 1, y)) x2++;+ for (x = x1; x <= x2; x++)+ if (create_part(-1, x, y, PT_SPRK, -1) >= 0) created_something = 1;++ /* add vertically adjacent pixels to stack (wire crossing for INST) */+ if (y >= BORDER + 1 && x1 == x2 && isInst(x1 - 1, y - 1) && isInst(x1, y - 1) && isInst(x1 + 1, y - 1) &&+ !isInst(x1 - 1, y - 2) && isInst(x1, y - 2) && !isInst(x1 + 1, y - 2)) {+ /* travelling vertically up, skipping a horizontal line */+ if (isSparkableInst(x1, y - 2) && !flood_stack_push(x1, y - 2)) return -1;+ } else if (y >= BORDER + 1) {+ for (x = x1; x <= x2; x++)+ if (isSparkableInst(x, y - 1)) {+ /* at the end of a horizontal section, or a T junction or not a 1px wire crossing */+ if (x == x1 || x == x2 || y >= YRES - BORDER - 1 || !isInst(x, y + 1) || isInst(x + 1, y + 1) || isInst(x - 1, y + 1))+ if (!flood_stack_push(x, y - 1)) return -1;+ }+ }+ if (y < YRES - BORDER - 1 && x1 == x2 && isInst(x1 - 1, y + 1) && isInst(x1, y + 1) && isInst(x1 + 1, y + 1) &&+ !isInst(x1 - 1, y + 2) && isInst(x1, y + 2) && !isInst(x1 + 1, y + 2)) {+ /* travelling vertically down, skipping a horizontal line */+ if (isSparkableInst(x1, y + 2) && !flood_stack_push(x1, y + 2)) return -1;+ } else if (y < YRES - BORDER - 1) {+ for (x = x1; x <= x2; x++)+ if (isSparkableInst(x, y + 1)) {+ if (x == x1 || x == x2 || y < 0 || !isInst(x, y - 1) || isInst(x + 1, y - 1) || isInst(x - 1, y - 1))+ if (!flood_stack_push(x, y + 1)) return -1;+ }+ }+ } while (cs_n > 0);+ return created_something;+}++/* water equalization: moves water to a free place at the top of the body of water it's in */+bool flood_water(int x, int y, int i) {+ int x1, x2, originalX = x, originalY = y;+ if (!pmap_id[y][x]) return false;+ memset(sim_scratch, 0, FLOOD_BITMAP);+ flood_stack_init(FLOOD_BITMAP);+ flood_stack_push(x, y);+ do {+ flood_stack_pop(&x, &y);+ x1 = x2 = x;+ while (x1 >= BORDER) {+ if (elements[TYP(PMAPAT(x1 - 1, y))].Falldown != 2 || bm_get(x1 - 1, y)) break;+ x1--;+ }+ while (x2 < XRES - BORDER) {+ if (elements[TYP(PMAPAT(x2 + 1, y))].Falldown != 2 || bm_get(x2 + 1, y)) break;+ x2++;+ }+ for (x = x1; x <= x2; x++) {+ if ((y - 1) > originalY && !pmap_id[y - 1][x]) {+ /* try a random place on this line, there's probably a free one somewhere */+ int randPos = rng_between(x, x2);+ if (!pmap_id[y - 1][randPos] && eval_move(parts[i].type, randPos, y - 1, NULL)) x = randPos;+ /* or the original place on the left */+ else if (!eval_move(parts[i].type, x, y - 1, NULL)) continue;+ sim_move(i, originalX, originalY, (float)x, (float)(y - 1));+ return true;+ }+ bm_set(x, y);+ }+ if (y >= BORDER + 1)+ for (x = x1; x <= x2; x++)+ if (elements[TYP(PMAPAT(x, y - 1))].Falldown == 2 && !bm_get(x, y - 1))+ if (!flood_stack_push(x, y - 1)) return false;+ if (y < YRES - BORDER - 1)+ for (x = x1; x <= x2; x++)+ if (elements[TYP(PMAPAT(x, y + 1))].Falldown == 2 && !bm_get(x, y + 1))+ if (!flood_stack_push(x, y + 1)) return false;+ } while (cs_n > 0);+ return false;+}++/* ---------------------------------------------------------------- the pmap, the free list and life (RecalcFreeParticles),+ * counting the particles stacked in a cell (the original's pmap_count) on the way: a bit for the cells with one+ * counted, and the cells with more in a small table (in sim_scratch, until CheckStacking reads it) */+#define STACK_BITMAP ((XRES * YRES + 7) / 8)+#define STACK_SLOTS 256+typedef struct { uint16_t cell, count; } StackCount;+static StackCount *stack_tab;+static int stack_n;+static bool stack_valid;+static void stack_count(int cell) {+ uint8_t *bm = sim_scratch;+ if (!(bm[cell >> 3] >> (cell & 7) & 1)) {+ bm[cell >> 3] |= (uint8_t)(1 << (cell & 7));+ return;+ }+ for (int k = 0; k < stack_n; k++)+ if (stack_tab[k].cell == cell) {+ if (stack_tab[k].count < 0xFFFF) stack_tab[k].count++;+ return;+ }+ if (stack_n < STACK_SLOTS) stack_tab[stack_n++] = (StackCount){(uint16_t)cell, 2};+}++void RecalcFreeParticles(bool do_life_dec) {+ clear_words(pmap_id, sizeof(uint16_t) * XRES * YRES);+ clear_words(photons_id, sizeof(uint16_t) * XRES * YRES);+ clear_words(sim_scratch, (STACK_BITMAP + 3) & ~3);+ stack_tab = (StackCount *)(void *)(sim_scratch + ((STACK_BITMAP + 3) & ~3));+ stack_n = 0;+ stack_valid = true;+ NUM_PARTS = 0;+ for (int i = 0; i < parts_active; i++) {+ Particle *p = &parts[i];+ int t = p->type;+ if (!t) continue;+ int x = (p->x + 32) / 64, y = (p->y + 32) / 64;+ bool inBounds = false;+ if ((unsigned)x < XRES && (unsigned)y < YRES) {+ if (elements[t].Properties & TYPE_ENERGY) {+ photons_id[y][x] = (uint16_t)(i + 1);+ } else {+ /* particles can be inside INVS and FILT: those don't take the place of one already there */+ if (!pmap_id[y][x] || (t != PT_INVIS && t != PT_FILT)) pmap_id[y][x] = (uint16_t)(i + 1);+ if (t != PT_THDR && t != PT_EMBR && t != PT_FIGH && t != PT_PLSM) stack_count(y * XRES + x);+ }+ inBounds = true;+ }+ NUM_PARTS++;+ if (elementRecount && t >= 0 && t < PT_NUM && elements[t].Enabled) elementCount[t]++;++ if (do_life_dec) {+ if (t < 0 || t >= PT_NUM || !elements[t].Enabled) {+ kill_part(i);+ continue;+ }+ uint32_t props = elements[t].Properties;+ /* (stasis looked at only when it matters) */+#define stasis (inBounds && bmap[y / WCELL][x / WCELL] == WL_STASIS && emap[y / WCELL][x / WCELL] < 8)+ if (p->life > 0 && (props & PROP_LIFE_DEC) && !stasis) {+ p->life--;+ if (p->life <= 0 && (props & (PROP_LIFE_KILL_DEC | PROP_LIFE_KILL))) {+ kill_part(i);+ continue;+ }+ } else if (p->life <= 0 && (props & PROP_LIFE_KILL) && !stasis) {+ kill_part(i);+ continue;+ }+#undef stasis+ }+ }+ sim_flatten_parts();+ if (elementRecount) elementRecount = false;+}++static int stack_cmp(const void *a, const void *b) {+ return (int)((const StackCount *)a)->cell - (int)((const StackCount *)b)->cell;+}+static StackCount *stack_at(int cell) {+ for (int k = 0; k < stack_n; k++)+ if (stack_tab[k].cell == cell) return &stack_tab[k];+ return NULL;+}+/* too many particles in one place make a black hole (CheckStacking); the counts can't reach NPART here, so a+ * count over 5 marked is kept with its top bit */+#define MARKED 0x8000+void CheckStacking(void) {+ bool excessive_stacking_found = false;+ force_stacking_check = false;+ if (!stack_valid) return;+ stack_valid = false;+ qsort(stack_tab, (size_t)stack_n, sizeof(StackCount), stack_cmp); /* the cells in the original's order */+ for (int k = 0; k < stack_n; k++) {+ int count = stack_tab[k].count, cell = stack_tab[k].cell, x = cell % XRES, y = cell / XRES;+ if (count > 5) {+ if (bmap[y / WCELL][x / WCELL] == WL_EHOLE) {+ if (count > 1500) { /* more stacking allowed in an E-hole */+ stack_tab[k].count |= MARKED;+ excessive_stacking_found = true;+ }+ } else if (count > 1500 || (unsigned int)rng_between(0, 1599) <= (unsigned int)(count + 100)) {+ stack_tab[k].count |= MARKED;+ excessive_stacking_found = true;+ }+ }+ }+ if (excessive_stacking_found) {+ for (int i = 0; i < parts_active; i++) {+ if (!parts[i].type) continue;+ int t = parts[i].type, x = (parts[i].x + 32) / 64, y = (parts[i].y + 32) / 64;+ if (x >= 0 && y >= 0 && x < XRES && y < YRES && !(elements[t].Properties & TYPE_ENERGY)) {+ StackCount *s = stack_at(y * XRES + x);+ if (s && (s->count & MARKED)) {+ if ((s->count & ~MARKED) != 0) {+ /* stacking -> NBHL */+ int strength = s->count & ~MARKED;+ create_part(i, x, y, PT_NBHL, -1);+ p_set_temp(&parts[i], MAX_TEMP);+ parts[i].tmp = (int16_t)imin(strength, 51200); /* strength of the gravity field */+ s->count = MARKED; /* (the original's pmap_count = NPART: the rest are killed) */+ } else {+ kill_part(i);+ }+ }+ }+ }+ }+}++/* ---------------------------------------------------------------- the area cleared (clear_area) */+void clear_area(int area_x, int area_y, int area_w, int area_h) {+ int x0 = imax(area_x, 0), y0 = imax(area_y, 0);+ int x1 = imin(area_x + area_w, XRES), y1 = imin(area_y + area_h, YRES);+ if (x1 <= x0 || y1 <= y0) return;+ area_x = x0, area_y = y0, area_w = x1 - x0, area_h = y1 - y0;+ float fx = area_x - .5f, fy = area_y - .5f;+ for (int i = 0; i < parts_active; i++)+ if (parts[i].type) {+ float px = p_x(&parts[i]), py = p_y(&parts[i]);+ if (px >= fx && px <= fx + area_w + 1 && py >= fy && py <= fy + area_h + 1) kill_part(i);+ }+ int cx1 = area_x / WCELL, cy1 = area_y / WCELL, cx2 = (area_x + area_w) / WCELL, cy2 = (area_y + area_h) / WCELL;+ for (int y = cy1; y <= cy2 && y < YWCELLS; y++)+ for (int x = cx1; x <= cx2 && x < XWCELLS; x++) {+ if (bmap[y][x] == WL_GRAV) gravWallChanged = true;+ bmap[y][x] = 0;+ emap[y][x] = 0;+ }+}++/* ---------------------------------------------------------------- the settings */+void sim_default_settings(void) {+ settings = (SimSettings){+ .heat = true, .ambient_heat = false, .newtonian_gravity = false, .water_equalization = false,+ .air_mode = AIR_ON, .gravity_mode = GRAV_VERTICAL, .edge_mode = EDGE_VOID,+ .custom_gravity_x = 0, .custom_gravity_y = 0, .ambient_air_temp = R_TEMP + 273.15f,+ .edge_pressure = 0, .edge_velocity_x = 0, .edge_velocity_y = 0, .vorticity = 0.1f,+ .convection_mode = AIRC_BOUSSINESQ,+ };+}+void sim_settings_changed(void) {+ legacy_enable = !settings.heat;+ aheat_enable = settings.ambient_heat;+ water_equal_test = settings.water_equalization;+ gravityMode = settings.gravity_mode < NUM_GRAVMODES ? settings.gravity_mode : GRAV_VERTICAL;+ customGravityX = settings.custom_gravity_x;+ customGravityY = settings.custom_gravity_y;+ airMode = settings.air_mode < NUM_AIRMODES ? settings.air_mode : AIR_ON;+ ambientAirTemp = restrict_flt(settings.ambient_air_temp, MIN_TEMP, MAX_TEMP);+ edgePressure = settings.edge_pressure;+ edgeVelocityX = settings.edge_velocity_x;+ edgeVelocityY = settings.edge_velocity_y;+ vorticityCoeff = settings.vorticity;+ convectionMode = settings.convection_mode < NUM_CONVMODES ? settings.convection_mode : AIRC_BOUSSINESQ;+ if (settings.edge_mode != edgeMode) SetEdgeMode(settings.edge_mode < NUM_EDGEMODES ? settings.edge_mode : EDGE_VOID);+ if (settings.newtonian_gravity != ngrav_enable) grav_enable(settings.newtonian_gravity);+}++/* ---------------------------------------------------------------- starting and clearing */+#ifdef HOST+__attribute__((weak)) int host_npart = 0; /* tests: the particles to make room for (0: as many as the calculator) */+#endif+#if defined(SIM_SCENE) || defined(HOST)+/* speed tests of the simulation (make EXTRA=-DSIM_SCENE=n, with tools/emu.py): a scene from the start.+ * 1: the lower half full (water, sand, oil, a stone floor); 2: wood burning, with gas; 3: as many particles as+ * fit, powders and liquids; 4: the lower half with pressure, Newtonian gravity and ambient heat; 5: the Game of+ * Life over half the grid; 6: electronics (metal, PSCN/NSCN, batteries, sparks) */+static void scene_fill(int x0, int y0, int x1, int y1, int t) {+ for (int y = y0; y <= y1; y++)+ for (int x = x0; x <= x1; x++) create_part(-1, x, y, t, -1);+}+void sim_scene(int n) {+ int x0 = BORDER, x1 = XRES - BORDER - 1, y1 = YRES - BORDER - 1;+ CreateWallBox(x0, y1 - 1, x1, y1, WL_WALL);+ CreateWallBox(x0, BORDER, x0 + 1, y1, WL_WALL), CreateWallBox(x1 - 1, BORDER, x1, y1, WL_WALL);+ int top = (YRES - 2 * BORDER) / 2 + BORDER, lo = y1 - 2;+ switch (n) {+ case 1: case 4:+ scene_fill(x0 + 2, top, 40, lo, PT_WATR);+ scene_fill(41, top, 70, lo, PT_SAND);+ scene_fill(71, top, x1 - 2, lo, PT_OIL);+ if (n == 4) {+ settings.newtonian_gravity = true, settings.ambient_heat = true;+ sim_settings_changed();+ scene_fill(45, 20, 47, 22, PT_SING);+ scene_fill(20, 15, 23, 18, PT_PLEX);+ scene_fill(20, 19, 23, 19, PT_FIRE);+ }+ break;+ case 2:+ scene_fill(10, 25, 85, lo, PT_WOOD);+ scene_fill(10, 15, 85, 24, PT_GAS);+ scene_fill(10, lo - 1, 85, lo, PT_FIRE);+ break;+ case 3:+ for (int y = BORDER; y <= lo; y++)+ for (int x = x0 + 2; x <= x1 - 2; x++) {+ static const uint8_t mix[] = {PT_SAND, PT_WATR, PT_DUST, PT_OIL, PT_SALT, PT_STNE};+ create_part(-1, x, y, mix[(x / 8 + y / 8) % 6], -1);+ }+ break;+ case 5:+ for (int y = top; y <= lo; y++)+ for (int x = x0 + 2; x <= x1 - 2; x++)+ if (rng_chance(1, 3)) create_part(-1, x, y, PT_LIFE, 0);+ break;+ case 6:+ for (int y = 12; y <= lo; y += 4) {+ scene_fill(10, y, 85, y, (y / 4) % 3 == 0 ? PT_METL : (y / 4) % 3 == 1 ? PT_PSCN : PT_NSCN);+ create_part(-1, 9, y, PT_BTRY, -1);+ scene_fill(10, y + 1, 85, y + 1, PT_WATR);+ }+ break;+ default:+ break;+ }+}+#endif+void sim_init(void) {+ /* the particles take the RAM left after the game's own: on the calculator from _heap_start to _heap_end */+ static bool done;+ if (done) return;+ done = true;+ size_t maps = sizeof(uint16_t) * XRES * YRES;+#ifdef HOST+ size_t room = maps * 2 + SCRATCH + sizeof(Particle) * (size_t)(host_npart ? host_npart : 4000);+ uint8_t *from = (uint8_t *)malloc(room), *to = from + room;+#else+ extern char _heap_start[], _heap_end[];+ uint8_t *from = (uint8_t *)(((uintptr_t)_heap_start + 3) & ~(uintptr_t)3), *to = (uint8_t *)_heap_end;+#endif+ photons_id = (uint16_t (*)[XRES])(void *)from;+ from += maps;+ sim_scratch = from;+ from += SCRATCH;+ if (!pmap_id) {+ pmap_id = (uint16_t (*)[XRES])(void *)from;+ from += maps;+ }+ parts = (Particle *)(void *)from;+ long n = (long)(to - from) / (long)sizeof(Particle);+ npart_max = n > 32767 ? 32767 : n < 0 ? 0 : (int)n; /* (life holds the free list: 16 bits) */+ sim_default_settings();+ air_make_kernel();+ rng_state[0] = 0x9E3779B97F4A7C15ull, rng_state[1] = 614;+ sim_clear();+ sim_settings_changed();+ UpdateGravityMask();+#ifdef SIM_SCENE+ sim_scene(SIM_SCENE);+#endif+}++void sim_clear(void) {+ for (int i = 0; i < parts_active; i++)+ if (parts[i].type) kill_part(i);+ frameCount = 0;+ emp_decor = 0;+ emp_trigger_count = 0;+ memset(bmap, 0, sizeof bmap);+ memset(emap, 0, sizeof emap);+ parts_reset();+ NUM_PARTS = 0;+ memset(pmap_id, 0, sizeof(uint16_t) * XRES * YRES);+ memset(photons_id, 0, sizeof(uint16_t) * XRES * YRES);+ memset(fvx, 0, sizeof fvx);+ memset(fvy, 0, sizeof fvy);+ memset(wireless, 0, sizeof wireless);+ portal_count = 0;+ memset(pipe_ovf_id, 0, sizeof pipe_ovf_id);+ memset(fighters, 0, sizeof fighters);+ memset(&player, 0, sizeof player);+ memset(&player2, 0, sizeof player2);+ memset(Element_LOLZ_lolz, 0, sizeof Element_LOLZ_lolz);+ memset(Element_LOVE_love, 0, sizeof Element_LOVE_love);+ memset(Element_PSTN_tempParts, 0, sizeof Element_PSTN_tempParts);+ Element_PPIP_ppip_changed = 0;+ memset(elementCount, 0, sizeof elementCount);+ elementRecount = true;+ fighcount = 0;+ player.spwn = 0;+ player.spawnID = -1;+ player.rocketBoots = false;+ player.fan = false;+ player2.spwn = 0;+ player2.spawnID = -1;+ player2.rocketBoots = false;+ player2.fan = false;+ stack_valid = false;+ grav_reset();+ air_clear();+ air_clear_heat();+ SetEdgeMode(edgeMode);+}++/* ---------------------------------------------------------------- the frame around the particles' update */+static const char love_table[9][9] = {+ {0, 0, 1, 1, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 1, 1, 0, 0, 0}, {1, 0, 0, 0, 0, 0, 1, 0, 0},+ {1, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1, 0},+ {1, 0, 0, 0, 0, 0, 1, 0, 0}, {0, 1, 0, 0, 1, 1, 0, 0, 0}, {0, 0, 1, 1, 0, 0, 0, 0, 0},+};+static const char lolz_table[9][9] = {+ {0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 0, 0, 1, 0, 0}, {1, 0, 0, 0, 0, 0, 1, 0, 0},+ {1, 0, 0, 1, 1, 0, 0, 1, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0}, {1, 0, 1, 0, 0, 1, 0, 1, 0},+ {0, 1, 0, 1, 1, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 1, 0},+};+static void love_lolz(void) {+ int nx, nnx, ny, nny, r, rt;+ for (ny = 0; ny < YRES - 4; ny++)+ for (nx = 0; nx < XRES - 4; nx++) {+ r = PMAPAT(nx, ny);+ if (!r) continue;+ else if ((ny < 9 || nx < 9 || ny > YRES - 7 || nx > XRES - 10) && (parts[ID(r)].type == PT_LOVE || parts[ID(r)].type == PT_LOLZ))+ kill_part(ID(r));+ else if (parts[ID(r)].type == PT_LOVE)+ Element_LOVE_love[nx / 9][ny / 9] = 1;+ else if (parts[ID(r)].type == PT_LOLZ)+ Element_LOLZ_lolz[nx / 9][ny / 9] = 1;+ }+ for (nx = 9; nx <= XRES - 18; nx++)+ for (ny = 9; ny <= YRES - 7; ny++) {+ if (Element_LOVE_love[nx / 9][ny / 9] == 1) {+ for (nnx = 0; nnx < 9; nnx++)+ for (nny = 0; nny < 9; nny++)+ if (ny + nny > 0 && ny + nny < YRES && nx + nnx >= 0 && nx + nnx < XRES) {+ rt = PMAPAT(nx + nnx, ny + nny);+ if (!rt && love_table[nnx][nny] == 1) create_part(-1, nx + nnx, ny + nny, PT_LOVE, -1);+ else if (!rt) continue;+ else if (parts[ID(rt)].type == PT_LOVE && love_table[nnx][nny] == 0) kill_part(ID(rt));+ }+ }+ Element_LOVE_love[nx / 9][ny / 9] = 0;+ if (Element_LOLZ_lolz[nx / 9][ny / 9] == 1) {+ for (nnx = 0; nnx < 9; nnx++)+ for (nny = 0; nny < 9; nny++)+ if (ny + nny > 0 && ny + nny < YRES && nx + nnx >= 0 && nx + nnx < XRES) {+ rt = PMAPAT(nx + nnx, ny + nny);+ if (!rt && lolz_table[nny][nnx] == 1) create_part(-1, nx + nnx, ny + nny, PT_LOLZ, -1);+ else if (!rt) continue;+ else if (parts[ID(rt)].type == PT_LOLZ && lolz_table[nny][nnx] == 0) kill_part(ID(rt));+ }+ }+ Element_LOLZ_lolz[nx / 9][ny / 9] = 0;+ }+}++/* updates the pmap, the Game of Life and the rest that isn't particles, before they're updated */+void BeforeSim(bool willUpdate) {+ if (willUpdate) {+ air_update();+ if (aheat_enable) air_update_heat();+ grav_exchange();+ memset(gravmass, 0, sizeof(float) * XACELLS * YACELLS); /* (cleared for the frame) */+ if (emp_decor > 0) emp_decor -= emp_decor / 25 + 2;+ if (emp_decor < 0) emp_decor = 0;+ etrd_count_valid = false;+ etrd_life0_count = 0;+ currentTick++;+ elementRecount |= !(currentTick % 180);+ if (elementRecount) memset(elementCount, 0, sizeof elementCount);+ }+ if (gravWallChanged) {+ UpdateGravityMask();+ gravWallChanged = false;+ }+ RecalcFreeParticles(willUpdate);+ if (willUpdate) {+ /* walls' electricity fades; walls block air and ambient heat. (Whether a wall cell is at 12 now, when it+ * sparks conductors touching it: it can't come back to 12 before the next frame's fading) */+ bool at12 = false;+ for (int y = 0; y < YWCELLS; y++)+ for (int x = 0; x < XWCELLS; x++)+ if (emap[y][x]) at12 |= --emap[y][x] == 12;+ emap_any12 = at12;+ air_walls_block();+ /* stacking makes black holes */+ if (force_stacking_check || rng_chance(1, 10)) CheckStacking();+ if (elementCount[PT_LOVE] > 0 || elementCount[PT_LOLZ] > 0) love_lolz();+ /* make WIRE work */+ if (elementCount[PT_WIRE] > 0)+ for (int nx = 0; nx < XRES; nx++)+ for (int ny = 0; ny < YRES; ny++) {+ int r = PMAPAT(nx, ny);+ if (r && parts[ID(r)].type == PT_WIRE) parts[ID(r)].tmp = (int16_t)parts[ID(r)].ctype;+ }+ /* PPIP's triggers from the last frame (kept in flags) become this frame's */+ if (Element_PPIP_ppip_changed) {+ for (int i = 0; i < parts_active; i++)+ if (parts[i].type == PT_PPIP) {+ parts[i].flags |= (uint8_t)((parts[i].flags >> PPIP_LATE_SHIFT) & PPIP_TMPFLAG_TRIGGERS);+ parts[i].flags &= (uint8_t)~(PPIP_TMPFLAG_TRIGGERS << PPIP_LATE_SHIFT);+ }+ Element_PPIP_ppip_changed = 0;+ }+ /* the Game of Life; GSPEED is frames per generation */+ if (elementCount[PT_LIFE] > 0 && ++CGOL >= GSPEED) SimulateGoL();+ /* wifi channels */+ if (ISWIRE > 0) {+ for (int q = 0; q < (int)(MAX_TEMP - 73.15f) / 100 + 2; q++) {+ wireless[q][0] = wireless[q][1];+ wireless[q][1] = 0;+ }+ ISWIRE--;+ }+ /* spawn STKM and STK2 */+ if (!player.spwn && player.spawnID >= 0)+ create_part(-1, (int)p_x(&parts[player.spawnID]), (int)p_y(&parts[player.spawnID]), PT_STKM, -1);+ if (!player2.spwn && player2.spawnID >= 0)+ create_part(-1, (int)p_x(&parts[player2.spawnID]), (int)p_y(&parts[player2.spawnID]), PT_STKM2, -1);+ }+}++void AfterSim(void) {+ if (emp_trigger_count) {+ Element_EMP_Trigger(emp_trigger_count);+ emp_trigger_count = 0;+ }+ frameCount += 1;+}++void sim_step(void) {+ sim_settings_changed();+ BeforeSim(true);+ UpdateParticles(0, NPART);+ AfterSim();+}++void sim_frame(bool update) {+ if (update) {+ sim_step();+ } else {+ sim_settings_changed();+ BeforeSim(false);+ }+}diff --git a/games/numpowder/src/sim.h b/games/numpowder/src/sim.hnew file mode 100644index 00000000..4f1ad4aa--- /dev/null+++ b/games/numpowder/src/sim.h@@ -0,0 +1,204 @@+/* NumPowder: the simulation (The Powder Toy's Simulation, Air and gravity), in C.+ *+ * Ported element code reads like the original's with these changes:+ * - `sim->` goes: the simulation's state and functions are globals (create_part, kill_part, pv, bmap...);+ * - `pmap[y][x]` and `photons[y][x]` are read with PMAPAT(x, y) and PHOTAT(x, y), which give the original's+ * values (PMAP(id, type), 0 for none), and written with PMAPSET(x, y, r) and PHOTSET(x, y, r) (the+ * simulation's code only: the interface reads them);+ * - `parts[i].x`, `.y`, `.vx`, `.vy` and `.temp` are fixed point: read them with p_x(&parts[i])...,+ * write them with p_set_x(&parts[i], v)... (simdefs.h); the other fields are plain ints;+ * - air, gravity and fan cells are ACELL wide, wall cells WCELL: `sim->pv[y/CELL][x/CELL]` becomes+ * pv[y/ACELL][x/ACELL], `sim->bmap[y/CELL][x/CELL]` becomes bmap[y/WCELL][x/WCELL]; the edge where+ * particles die (the original's `x < CELL`...) is BORDER wide;+ * - `sim->rng.between(a, b)` is rng_between(a, b), `.chance(n, d)` rng_chance(n, d), `.gen()` rng_gen(),+ * `()` rng_u32(), `.uniform01()` rng_uniform01();+ * - the element table is `elements[t]` (elements.h), its fields named as the original's;+ * - NPART is npart_max, `parts.active` parts_active. */+#ifndef NP_SIM_H+#define NP_SIM_H+#include "simdefs.h"+#include "elements.h"++/* ---------------------------------------------------------------- the particles */+extern Particle *parts; /* npart_max of them (the RAM the calculator gives decides how many) */+extern int npart_max;+extern int parts_active; /* the original's parts.active: ids from 0 to parts_active - 1 are in use */+extern int parts_lastActiveIndex; /* the highest id in use (parts_active - 1) */+extern int pfree; /* the free list (as the original's) */+extern int NUM_PARTS;+extern int elementCount[PT_NUM];+/* the maps: an id + 1 per particle cell (0: none); pmap for everything but energy, photons for energy.+ * main() may point pmap_id at a YRES x XRES array on its stack before sim_init (or sim_init takes it from+ * the heap) */+extern uint16_t (*pmap_id)[XRES];+extern uint16_t (*photons_id)[XRES];+static inline int PMAPAT(int x, int y) {+ unsigned id = pmap_id[y][x];+ return id ? PMAP((int)id - 1, parts[id - 1].type) : 0;+}+static inline int PHOTAT(int x, int y) {+ unsigned id = photons_id[y][x];+ return id ? PMAP((int)id - 1, parts[id - 1].type) : 0;+}+/* the original's `pmap[y][x] = r` (r a PMAP value, or 0) */+static inline void PMAPSET(int x, int y, int r) { pmap_id[y][x] = r ? (uint16_t)(ID(r) + 1) : 0; }+static inline void PHOTSET(int x, int y, int r) { photons_id[y][x] = r ? (uint16_t)(ID(r) + 1) : 0; }++/* ---------------------------------------------------------------- air, heat, walls, gravity */+extern float pv[YACELLS][XACELLS], vx[YACELLS][XACELLS], vy[YACELLS][XACELLS]; /* pressure and air velocity */+extern float hv[YACELLS][XACELLS]; /* ambient heat */+extern float fvx[YACELLS][XACELLS], fvy[YACELLS][XACELLS]; /* fans */+extern unsigned char bmap[YWCELLS][XWCELLS]; /* walls (WL_*) */+extern unsigned char emap[YWCELLS][XWCELLS]; /* walls' electricity */+extern float gravx[YACELLS][XACELLS], gravy[YACELLS][XACELLS]; /* Newtonian gravity's field (gravOut) */+extern float gravmass[YACELLS][XACELLS]; /* its masses, this frame (gravIn.mass) */+extern uint8_t gravmask[YACELLS][XACELLS]; /* 0 inside a box of gravity walls (gravIn.mask) */+extern uint8_t bmap_blockair[YACELLS][XACELLS], bmap_blockairh[YACELLS][XACELLS]; /* Air's */++/* ---------------------------------------------------------------- the simulation's settings */+enum { EDGE_VOID, EDGE_SOLID, EDGE_LOOP, NUM_EDGEMODES };+enum { GRAV_VERTICAL, GRAV_OFF, GRAV_RADIAL, GRAV_CUSTOM, NUM_GRAVMODES };+enum { AIR_ON, AIR_PRESSUREOFF, AIR_VELOCITYOFF, AIR_OFF, AIR_NOUPDATE, NUM_AIRMODES };+enum { AIRC_NONE, AIRC_LEGACY, AIRC_BOUSSINESQ, NUM_CONVMODES };+typedef struct {+ bool heat; /* legacy_enable is !heat */+ bool ambient_heat; /* aheat_enable */+ bool newtonian_gravity;+ bool water_equalization;+ uint8_t air_mode, gravity_mode, edge_mode;+ float custom_gravity_x, custom_gravity_y;+ float ambient_air_temp; /* Kelvin */+ /* the original's newer air options (its defaults: 0, 0, 0, 0.1, AIRC_BOUSSINESQ) */+ float edge_pressure, edge_velocity_x, edge_velocity_y, vorticity;+ uint8_t convection_mode;+} SimSettings;+/* the interface changes `settings`, then calls sim_settings_changed() (sim_step also applies them) */+extern SimSettings settings;+void sim_settings_changed(void);+void sim_default_settings(void);+/* the original's variables, kept from `settings` */+extern int legacy_enable, aheat_enable, water_equal_test, edgeMode, gravityMode;+extern float customGravityX, customGravityY;+extern bool ngrav_enable; /* Newtonian gravity on (the original's bool(grav)) */+extern int currentTick;+extern uint32_t frameCount;+extern bool sys_pause;+extern int emp_decor; /* EMP's flash, for the renderer */++/* ---------------------------------------------------------------- random numbers (the original's RNG) */+unsigned int rng_gen(void); /* .gen(): 31 bits */+unsigned int rng_u32(void); /* (): 32 bits */+int rng_between(int lower, int upper);+bool rng_chance(int numerator, unsigned int denominator);+float rng_uniform01(void);+void rng_seed(unsigned int seed);+extern uint64_t rng_state[2];++/* ---------------------------------------------------------------- the original's functions */+int create_part(int p, int x, int y, int t, int v); /* v: -1 when the original's caller gives none */+int createPartTempVel(int i, int x, int y, int t);+void kill_part(int i);+bool part_change_type(int i, int x, int y, int t);+void delete_part(int x, int y);+int eval_move(int pt, int nx, int ny, unsigned *rr);+int try_move(int i, int x, int y, int nx, int ny);+int do_move(int i, int x, int y, float nxf, float nyf);+bool sim_move(int i, int x, int y, float nxf, float nyf);+int parts_avg(int ci, int ni, int t);+void create_gain_photon(int pp);+void create_cherenkov_photon(int pp);+void GetGravityField(int x, int y, float particleGrav, float newtonGrav, float *pGravX, float *pGravY);+bool IsWallBlocking(int x, int y, int type);+void set_emap(int x, int y);+int flood_prop_int(int x, int y, int field, int value); /* flood_prop with an int field (FIELD_*) */+int FloodINST(int x, int y);+bool flood_water(int x, int y, int i);+void CreateLine(int x1, int y1, int x2, int y2, int c);+int get_wavelength_bin(int *wm);+void photoelectric_effect(int nx, int ny);+void SetEdgeMode(int newEdgeMode);+void RecalcFreeParticles(bool do_life_dec);+void clear_area(int area_x, int area_y, int area_w, int area_h);+static inline bool IsElement(int type) { return type > 0 && type < PT_NUM && elements[type].Enabled; }+static inline bool IsElementOrNone(int type) { return type >= 0 && type < PT_NUM && elements[type].Enabled; }++/* ---------------------------------------------------------------- running it */+void sim_init(void); /* the particles' room: before anything else */+void sim_clear(void); /* clear_sim */+void sim_step(void); /* a frame: BeforeSim, UpdateParticles, AfterSim */+void sim_frame(bool update); /* a frame shown: sim_step, or (paused) only BeforeSim(false) */++/* ---------------------------------------------------------------- walls (WallType.h, SimulationData.cpp) */+enum { WL_ERASE, WL_WALLELEC, WL_EWALL, WL_DETECT, WL_STREAM, WL_FAN, WL_ALLOWLIQUID, WL_DESTROYALL, WL_WALL,+ WL_ALLOWAIR, WL_ALLOWPOWDER, WL_ALLOWALLELEC, WL_EHOLE, WL_ALLOWGAS, WL_GRAV, WL_ALLOWENERGY, WL_BLOCKAIR,+ WL_ERASEALL, WL_STASIS, UI_WALLCOUNT, WL_FLOODHELPER = 255 };+typedef struct {+ uint32_t colour, eglow; /* 0xRRGGBB; eglow is added to the fire glow when the wall is powered */+ uint8_t drawstyle;+ const char *name, *identifier, *descs;+} WallType;+extern const WallType walltypes[UI_WALLCOUNT];++/* ---------------------------------------------------------------- tools (simtools/), in the original's order */+enum { TOOL_HEAT, TOOL_COOL, TOOL_AIR, TOOL_VAC, TOOL_PGRV, TOOL_NGRV, TOOL_MIX, TOOL_CYCL, TOOL_AMBM, TOOL_AMBP,+ TOOL_WIND, TOOL_COUNT };+typedef struct { const char *identifier, *name; uint32_t colour; const char *description; } SimToolInfo;+extern const SimToolInfo simtools[TOOL_COUNT];++/* ---------------------------------------------------------------- Game of Life (BuiltinGOL.h, GOLString.cpp) */+#define NGOL 24+typedef struct { const char *name; int oldtype, ruleset; uint32_t colour, colour2; const char *description; } BuiltinGOL;+extern const BuiltinGOL builtinGol[NGOL];+int ParseGOLString(const char *value); /* "B3/S23" (or "B3/S23/2"): a rule, -1 if invalid */+void SerialiseGOLRule(int rule, char *out); /* (out: 24 chars) */++/* ---------------------------------------------------------------- drawing with the brush (Editing.cpp, the tools)+ * A tool is an element (the original's ToolID: PMAP(v, type), so PMAP(n, PT_LIFE) is the nth Game of Life+ * type and PT_NONE erases), TOOL_WALLS + WL_* or TOOL_SIMTOOLS + TOOL_*. */+#define TOOL_WALLS 0x40000000+#define TOOL_SIMTOOLS 0x20000000+enum { BRUSH_CIRCLE, BRUSH_SQUARE, BRUSH_TRIANGLE, NUM_BRUSHES };+typedef struct { int rx, ry; uint8_t shape; } Brush;+extern Brush brush; /* radii 0 to 200, as the original's */+bool brush_has(int dx, int dy); /* is (dx, dy) in the brush (-rx..rx, -ry..ry) */+extern float tool_strength; /* the original's: 1, shift 10, ctrl 0.1 */+/* replace mode (REPLACE_MODE) and specific delete (SPECIFIC_DELETE) of replaceModeSelected */+enum { REPLACE_MODE = 1, SPECIFIC_DELETE = 2 };+extern int replaceModeSelected, replaceModeFlags;+/* GameController::DrawPoints: a press (held false: Tool::Draw) or the cursor held (Tool::DrawLine dragging),+ * every frame while the button is down */+void sim_tool_points(int tool, int x1, int y1, int x2, int y2, bool held);+void sim_tool_line(int tool, int x1, int y1, int x2, int y2); /* a line drawn (shift-drag) */+void sim_tool_box(int tool, int x1, int y1, int x2, int y2); /* a box drawn (ctrl-drag) */+void sim_tool_fill(int tool, int x, int y); /* flood fill */+/* the element tools themselves (the original's CreateParts, CreateLine, CreateBox, FloodParts) */+int CreateParts(int p, int x, int y, int c, int flags); /* with the brush; flags -1: replaceModeFlags */+int CreatePartsR(int p, int x, int y, int rx, int ry, int c, int flags);+void CreateLineBrush(int x1, int y1, int x2, int y2, int c, int flags);+void CreateBox(int p, int x1, int y1, int x2, int y2, int c, int flags);+int FloodParts(int x, int y, int c, int cm, int flags);+int CreateWalls(int x, int y, int rx, int ry, int wall, bool withBrush);+void CreateWallLine(int x1, int y1, int x2, int y2, int rx, int ry, int wall, bool withBrush);+void CreateWallBox(int x1, int y1, int x2, int y2, int wall);+int FloodWalls(int x, int y, int wall, int bm);++/* ---------------------------------------------------------------- stickmen (Stickman.h) */+#define MAX_FIGHTERS 16 /* (the original's is 100) */+typedef struct {+ char comm, pcomm; /* commands: 1 left, 2 right, 4 up (jump), 8 down (use the element) */+ int elem; /* the element it uses */+ float legs[16]; /* the legs' positions */+ float accs[8];+ char spwn; /* spawned */+ unsigned int frames; /* since the last LIGH it made */+ bool rocketBoots, fan;+ int spawnID; /* its SPWN */+} playerst;+extern playerst player, player2, fighters[MAX_FIGHTERS];+extern unsigned char fighcount;+/* the arrow keys for STKM (who 0) or STK2 (who 1): GameController::KeyPress and KeyRelease */+enum { STKM_LEFT = 1, STKM_RIGHT = 2, STKM_UP = 4, STKM_DOWN = 8 };+void stkm_key(int who, int key, bool down);+/* every frame (GameController::Update): a stickman not out uses the right tool's element when it comes */+void stkm_frame(int rightElement);+#endifdiff --git a/games/numpowder/src/sim_move.c b/games/numpowder/src/sim_move.cnew file mode 100644index 00000000..7c533ee1--- /dev/null+++ b/games/numpowder/src/sim_move.c@@ -0,0 +1,1524 @@+/* NumPowder: The Powder Toy's particle update and movement (Simulation.cpp): eval_move, try_move, do_move,+ * move, the surfaces' normals for reflection and refraction, PlanMove, and UpdateParticles with its phases+ * (GetNeighbourhood, TransitionPhase, MovementPhase). */+#if defined(__GNUC__) && !defined(__clang__)+#pragma GCC optimize("O3") /* (a hot path: a few KB of flash for speed) */+#endif+#include "simpriv.h"++static inline float remainder_p(float x, float y) { return fmodf(x, y) + (x >= 0 ? 0 : y); }+/* (int)(v + 0.5f) of a particle's x or y (truncated, as the original's) */+static inline int ipos(int16_t v) { return (v + 32) / 64; }+/* the type of the particle with this pmap id + 1 (0: none) */+static inline int type_of_id(unsigned id) { return id ? parts[id - 1].type : 0; }++/* ---------------------------------------------------------------- moving into a place+ * eval_move: 0 can't (bounce), 1 swaps, 2 both occupy the same place */+/* eval_move's less common parts: can_move's 3 (it depends on the particle there), and walls */+static __attribute__((noinline)) int eval_move_3(int pt, int nx, int ny, unsigned r) {+ int result = 3;+ const Particle *q = &parts[ID(r)];+ switch (TYP(r)) {+ case PT_LCRY:+ if (pt == PT_PHOT) result = (q->life > 5) ? 2 : 0;+ break;+ case PT_GPMP:+ if (pt == PT_PHOT) result = (q->life < 10) ? 2 : 0;+ break;+ case PT_INVIS: {+ float pressureResistance = q->tmp > 0 ? (float)q->tmp : 4.0f;+ float pres = pv[ny / ACELL][nx / ACELL];+ result = (pres < -pressureResistance || pres > pressureResistance) ? 2 : 0;+ break;+ }+ case PT_PVOD:+ if (q->life == 10) result = (!q->ctype || (q->ctype == pt) != (q->tmp & 1)) ? 1 : 0;+ else result = 0;+ break;+ case PT_VOID:+ result = (!q->ctype || (q->ctype == pt) != (q->tmp & 1)) ? 1 : 0;+ break;+ case PT_SWCH:+ if (pt == PT_TRON) return q->life >= 10 ? -2 : -1; /* (the answer, walls or not: -2 for 2, -1 for 0) */+ break;+ default:+ result = 1; /* "this should never happen" */+ }+ return result;+}+static __attribute__((noinline)) int eval_move_wall(int pt, int nx, int ny, unsigned r, int result) {+ int wall = bmap[ny / WCELL][nx / WCELL];+ if (IsWallBlocking(nx, ny, pt)) return 0;+ if (wall == WL_EHOLE && !emap[ny / WCELL][nx / WCELL] && !(elements[pt].Properties & TYPE_SOLID) &&+ !(elements[TYP(r)].Properties & TYPE_SOLID))+ return 2;+ return result;+}+static inline __attribute__((always_inline)) int eval_move_i(int pt, int nx, int ny, unsigned *rr) {+ if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) return 0;+ unsigned r = (unsigned)PMAPAT(nx, ny);+ if (rr) *rr = r;+ if (pt >= PT_COUNT || TYP(r) >= PT_COUNT) return 0;+ int result = can_move(pt, TYP(r));+ if (result == 3) {+ result = eval_move_3(pt, nx, ny, r);+ if (result < 0) return result == -2 ? 2 : 0;+ }+ if (bmap[ny / WCELL][nx / WCELL]) return eval_move_wall(pt, nx, ny, r, result);+ return result;+}++int eval_move(int pt, int nx, int ny, unsigned *rr) { return eval_move_i(pt, nx, ny, rr); }++/* try_move's less common parts, apart so that its usual way stays short: */+/* a move refused (r is there): WOOD hit hard, and the energy particles' */+static __attribute__((noinline)) int try_move_refused(int i, int x, int y, int nx, int ny, unsigned r) {+ Particle *p = &parts[i];+ int rt = TYP(r);+ if (rt == PT_WOOD) {+ /* WOOD -> SAWD */+ float vel = sqrtf(p_vx(p) * p_vx(p) + p_vy(p) * p_vy(p));+ if (vel > 5) part_change_type(ID(r), nx, ny, PT_SAWD);+ }+ if (!(elements[p->type].Properties & TYPE_ENERGY)) return 0;+ Particle *q = &parts[ID(r)];+ if (!legacy_enable && p->type == PT_PHOT && r) { /* PHOT heat conduction */+ if (rt == PT_COAL || rt == PT_BCOL) q->temp = p->temp;+ if (rt < PT_NUM && !IsHeatInsulator(q) && rt != PT_FILT) {+ p_set_temp(p, restrict_flt((p_temp(q) + p_temp(p)) / 2, MIN_TEMP, MAX_TEMP));+ q->temp = p->temp;+ }+ } else if ((p->type == PT_NEUT || p->type == PT_ELEC) && (rt == PT_CLNE || rt == PT_PCLN || rt == PT_BCLN || rt == PT_PBCN)) {+ if (!q->ctype) q->ctype = p->type;+ }+ if (rt == PT_PRTI && (elements[p->type].Properties & TYPE_ENERGY)) {+ int count;+ for (count = 0; count < 8; count++)+ if (isign(x - nx) == isign(portal_rx[count]) && isign(y - ny) == isign(portal_ry[count])) break;+ count = count % 8;+ q->tmp = (int16_t)(int)((p_temp(q) - 73.15f) / 100 + 1);+ if (q->tmp >= CHANNELS) q->tmp = CHANNELS - 1;+ else if (q->tmp < 0) q->tmp = 0;+ if (portal_put(q->tmp, count, p)) kill_part(i);+ }+ return 0;+}+/* both in the same place (r is there): what photons, neutrons, electrons, protons and BIZR do */+static __attribute__((noinline)) int try_move_overlap(int i, int x, int y, int nx, int ny, unsigned r) {+ Particle *p = &parts[i];+ Particle *q = &parts[ID(r)];+ switch (p->type) {+ case PT_PHOT:+ switch (TYP(r)) {+ case PT_GLOW:+ if (!q->life && rng_chance(1, 30)) {+ q->life = 120;+ create_gain_photon(i);+ }+ break;+ case PT_FILT:+ p->ctype = Element_FILT_interactWavelengths(q, p->ctype);+ break;+ case PT_C5:+ /* C5's tmp and tmp3 keep the photon's velocity (the original's tmp, 16 bits each), tmp2 its place */+ if (q->life > 0 && (q->ctype & p->ctype & 0xFFFFFFC0)) {+ float cvx = q->tmp / 255.0f, cvy = q->tmp3 / 255.0f;+ float pvx = p_vx(p), pvy = p_vy(p);+ float vn = pvx * pvx + pvy * pvy;+ /* a velocity of 0 would divide by 0: shoot the photon off at 90 degrees instead */+ if (pvx + cvx == 0 && pvy + cvy == 0) {+ p_set_vx(p, cvy);+ p_set_vy(p, -cvx);+ } else {+ p->ctype = (q->ctype & p->ctype) >> 6;+ pvx += cvx; /* add momentum of photons to each other */+ pvy += cvy;+ vn /= pvx * pvx + pvy * pvy; /* normalize velocity to original value */+ vn = sqrtf(vn);+ p_set_vx(p, pvx * vn);+ p_set_vy(p, pvy * vn);+ }+ q->life = 0;+ q->ctype = 0;+ } else if (!q->ctype && (p->ctype & 0xFFFFFFC0)) {+ q->life = 1;+ q->ctype = p->ctype;+ q->tmp = (int16_t)(int)(p_vx(p) * 255.0f);+ q->tmp3 = (int16_t)((int)(p_vy(p) * 16711680.0f) >> 16);+ int dx = (int)((p_x(p) - x) * 255.0f), dy = (int)((p_y(p) - y) * 16711680.0f) >> 16;+ q->tmp2 = (int16_t)((dx & 0xFF) | (dy << 8));+ kill_part(i);+ }+ break;+ case PT_INVIS: {+ float pressureResistance = (q->tmp > 0) ? (float)q->tmp : 4.0f;+ float pres = pv[ny / ACELL][nx / ACELL];+ if (pres >= -pressureResistance && pres <= pressureResistance) {+ /* PHOT + INVIS -> NEUT + INVIS */+ part_change_type(i, x, y, PT_NEUT);+ p->ctype = 0;+ }+ break;+ }+ case PT_BIZR:+ case PT_BIZRG:+ case PT_BIZRS:+ /* PHOT + BIZR -> ELEC + BIZR */+ part_change_type(i, x, y, PT_ELEC);+ p->ctype = 0;+ break;+ case PT_H2:+ if (!(p->tmp & 0x1)) {+ /* PHOT + H2 -> PROT + ELEC */+ part_change_type(i, x, y, PT_PROT);+ p->ctype = 0;+ p->tmp2 = 0x1;+ create_part(ID(r), x, y, PT_ELEC, -1);+ return 1;+ }+ break;+ case PT_GPMP:+ if (q->life == 0) {+ /* PHOT + GPMP -> GRVT + GPMP */+ part_change_type(i, x, y, PT_GRVT);+ p->tmp = (int16_t)(int)(p_temp(q) - 273.15f);+ }+ break;+ }+ break;+ case PT_NEUT:+ /* NEUT + GLAS/BGLA -> NEUT + GLAS/BGLA + PHOT */+ if (TYP(r) == PT_GLAS || TYP(r) == PT_BGLA)+ if (rng_chance(1, 10)) create_cherenkov_photon(i);+ break;+ case PT_ELEC:+ if (TYP(r) == PT_GLOW) {+ /* ELEC + GLOW -> PHOT + GLOW */+ part_change_type(i, x, y, PT_PHOT);+ p->ctype = 0x3FFFFFFF;+ }+ break;+ case PT_PROT:+ /* PROT + INVIS -> NEUT + INVIS */+ if (TYP(r) == PT_INVIS) part_change_type(i, x, y, PT_NEUT);+ break;+ case PT_BIZR:+ case PT_BIZRG:+ if (TYP(r) == PT_FILT) p->ctype = Element_FILT_interactWavelengths(q, p->ctype);+ break;+ }+ return 1;+}+/* a swap with r, which eats some particles or is held back by some: 0 no move, 1 on to the swap, -1 eaten */+static __attribute__((noinline)) int try_move_swap_special(int i, int x, int y, int nx, int ny, unsigned r) {+ Particle *p = &parts[i];+ switch (TYP(r)) {+ case PT_VOID:+ case PT_PVOD:+ /* void eats particles (its ctype was checked in eval_move) */+ kill_part(i);+ return -1;+ case PT_BHOL:+ case PT_NBHL:+ /* black holes eat particles */+ if (!legacy_enable) p_set_temp(&parts[ID(r)], restrict_flt(p_temp(&parts[ID(r)]) + p_temp(p) / 2, MIN_TEMP, MAX_TEMP));+ kill_part(i);+ return -1;+ case PT_WHOL:+ case PT_NWHL:+ /* white holes eat ANAR */+ if (p->type == PT_ANAR) {+ if (!legacy_enable)+ p_set_temp(&parts[ID(r)], restrict_flt(p_temp(&parts[ID(r)]) - (MAX_TEMP - p_temp(p)) / 2, MIN_TEMP, MAX_TEMP));+ kill_part(i);+ return -1;+ }+ break;+ case PT_DEUT:+ if (p->type == PT_ELEC) {+ if (parts[ID(r)].life < 6000) parts[ID(r)].life += 1;+ p_set_temp(&parts[ID(r)], 0);+ kill_part(i);+ return -1;+ }+ break;+ case PT_VIBR:+ case PT_BVBR:+ if (elements[p->type].Properties & TYPE_ENERGY) {+ parts[ID(r)].tmp += 20;+ kill_part(i);+ return -1;+ }+ break;+ }++ switch (p->type) {+ case PT_NEUT:+ if (elements[TYP(r)].Properties & PROP_NEUTABSORB) {+ kill_part(i);+ return -1;+ }+ break;+ case PT_CNCT: {+ float cnctGravX, cnctGravY; /* offset from gravity */+ GetGravityField(x, y, elements[PT_CNCT].Gravity, elements[PT_CNCT].Gravity, &cnctGravX, &cnctGravY);+ int offsetX = 0, offsetY = 0;+ if (cnctGravX > 0.0f) offsetX++;+ else if (cnctGravX < 0.0f) offsetX--;+ if (cnctGravY > 0.0f) offsetY++;+ else if (cnctGravY < 0.0f) offsetY--;+ if ((offsetX != 0) != (offsetY != 0) && /* not a diagonal */+ ((nx - x) * offsetX > 0 || (ny - y) * offsetY > 0) && /* the destination is below */+ (TYP(PMAPAT(x + offsetX, y + offsetY)) == PT_CNCT || TYP(PMAPAT(x + offsetX, y + offsetY)) == PT_ROCK))+ return 0;+ break;+ }+ case PT_GBMB:+ if (p->life > 0) return 0;+ break;+ }++ return 1;+}+/* the elements try_move_overlap and try_move_swap_special have something to do for */+static const uint8_t move_special[PT_NUM] = {+ /* (bit 0: as the one moving into the same place; 1: as the one moving to a swap; 2: as the one swapped with) */+ [PT_PHOT] = 1, [PT_NEUT] = 3, [PT_ELEC] = 1, [PT_PROT] = 1, [PT_BIZR] = 1, [PT_BIZRG] = 1,+ [PT_CNCT] = 2, [PT_GBMB] = 2,+ [PT_VOID] = 4, [PT_PVOD] = 4, [PT_BHOL] = 4, [PT_NBHL] = 4, [PT_WHOL] = 4, [PT_NWHL] = 4, [PT_DEUT] = 4,+ [PT_VIBR] = 4, [PT_BVBR] = 4,+};++/* try_move when it's a swap: 0 no swap or move, 1 still overlapping or moving (the swap happens later) */+static __attribute__((noinline)) int try_move_swap(int i, int x, int y, int nx, int ny, unsigned r) {+ Particle *p = &parts[i];+ int pt = p->type;+ if ((move_special[pt] & 2) || (move_special[TYP(r)] & 4)) {+ int k = try_move_swap_special(i, x, y, nx, ny, r);+ if (k <= 0) return 0;+ }++ if ((bmap[y / WCELL][x / WCELL] == WL_EHOLE && !emap[y / WCELL][x / WCELL]) &&+ !(bmap[ny / WCELL][nx / WCELL] == WL_EHOLE && !emap[ny / WCELL][nx / WCELL]))+ return 0;++ int ri = ID(r);+ if (r) { /* the swap */+ if (p->type == PT_NEUT) {+ /* the target is NEUTPENETRATE: it's moved around when a neutron passes */+ int s = PMAPAT(x, y);+ if (s && !(elements[TYP(s)].Properties & PROP_NEUTPENETRATE)) return 1; /* only the neutron moves */+ if (bmap[y / WCELL][x / WCELL] == WL_ALLOWENERGY) return 1; /* not into an energy-only wall */+ if (s) {+ PMAPSET(nx, ny, s);+ parts[ID(s)].x = (int16_t)(nx * 64);+ parts[ID(s)].y = (int16_t)(ny * 64);+ } else {+ PMAPSET(nx, ny, 0);+ }+ parts[ri].x = (int16_t)(x * 64);+ parts[ri].y = (int16_t)(y * 64);+ PMAPSET(x, y, PMAP(ri, parts[ri].type));+ return 1;+ }+ if (pmap_id[ny][nx] == ri + 1) pmap_id[ny][nx] = 0;+ parts[ri].x = p->x;+ parts[ri].y = p->y;+ int rx = ipos(parts[ri].x), ry = ipos(parts[ri].y);+ pmap_id[ry][rx] = (uint16_t)(ri + 1);+ }+ return 1;+}++/* try_move_i's 0 when nothing was done but look (no WOOD hit, not an energy particle): the same move tried again+ * before anything changes gets the same answer */+#define MOVE_REFUSED (-2)+static inline __attribute__((always_inline)) int try_move_i(int i, int x, int y, int nx, int ny) {+ unsigned r = 0;+ if (x == nx && y == ny) return 1;+ if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) return 1;+ Particle *p = &parts[i];+ int pt = p->type;+ int e = eval_move_i(pt, nx, ny, &r);++ /* half-silvered mirror */+ if (!e && pt == PT_PHOT && ((TYP(r) == PT_BMTL && rng_chance(1, 2)) || TYP(PMAPAT(x, y)) == PT_BMTL)) e = 2;++ if (!e) { /* no movement */+ if (TYP(r) != PT_WOOD && !(elements[pt].Properties & TYPE_ENERGY)) return MOVE_REFUSED;+ return try_move_refused(i, x, y, nx, ny, r);+ }++ if (e == 2) { /* both occupy the same place */+ if (move_special[pt] & 1) return try_move_overlap(i, x, y, nx, ny, r);+ return 1;+ }++ /* else e == 1: swapping */+ return try_move_swap(i, x, y, nx, ny, r);+}++int try_move(int i, int x, int y, int nx, int ny) {+ int r = try_move_i(i, x, y, nx, ny);+ return r == MOVE_REFUSED ? 0 : r;+}++/* the original's move, the place given as a particle keeps it (1/64 particle) */+static inline __attribute__((always_inline)) bool sim_move_q(int i, int x, int y, int16_t qx, int16_t qy) {+ Particle *p = &parts[i];+ int t = p->type;+ p->x = qx;+ p->y = qy;+ int nx = ipos(qx), ny = ipos(qy); /* (the place the stored position rounds to) */+ if (ny != y || nx != x) {+ if (pmap_id[y][x] == i + 1) pmap_id[y][x] = 0;+ if (photons_id[y][x] == i + 1) photons_id[y][x] = 0;+ /* out of bounds: killed */+ if (nx < BORDER || nx >= XRES - BORDER || ny < BORDER || ny >= YRES - BORDER) {+ kill_part(i);+ return false;+ }+ if (elements[t].Properties & TYPE_ENERGY) photons_id[ny][nx] = (uint16_t)(i + 1);+ else if (t) pmap_id[ny][nx] = (uint16_t)(i + 1);+ }+ return true;+}++/* tries to move a particle, and if it can, moves it: updates pmap and its position. The place is rounded to the+ * particle's 1/64 once: the cell it's in is worked out from that, so it's the one checked (q64) */+static inline void edge_wrap(float *nxf, float *nyf) {+ if (edgeMode == EDGE_LOOP) {+ int nx = (int)(*nxf + 0.5f), ny = (int)(*nyf + 0.5f);+ bool x_ok = (nx >= BORDER && nx < XRES - BORDER);+ bool y_ok = (ny >= BORDER && ny < YRES - BORDER);+ if (!x_ok) *nxf = remainder_p(*nxf - BORDER + .5f, XRES - BORDER * 2.0f) + BORDER - .5f;+ if (!y_ok) *nyf = remainder_p(*nyf - BORDER + .5f, YRES - BORDER * 2.0f) + BORDER - .5f;+ }+}+/* (MOVE_REFUSED for try_move's plain refusal) */+static int do_move_q(int i, int x, int y, int16_t qx, int16_t qy, int nx, int ny) {+ if (parts[i].type == PT_NONE) return 0;+ int result = try_move_i(i, x, y, nx, ny);+ if (result > 0) {+ if (!sim_move_q(i, x, y, qx, qy)) return -1;+ }+ return result;+}+/* the usual refusal, seen without going through try_move: a particle there it can't move into (can_move 0, or+ * either type out of the table), no wall, not WOOD, not an energy particle. Then try_move would only have looked+ * and said MOVE_REFUSED; false when it's anything else (try_move tells) */+static inline __attribute__((always_inline)) bool plainly_refused(int i, int x, int y, int nx, int ny) {+ if ((x == nx && y == ny) || (unsigned)nx >= XRES || (unsigned)ny >= YRES) return false;+ int pt = parts[i].type;+ if (!pt || (elements[pt].Properties & TYPE_ENERGY)) return false;+ unsigned id = pmap_id[ny][nx];+ if (!id || bmap[ny / WCELL][nx / WCELL]) return false;+ int tr = parts[id - 1].type;+ return tr != PT_WOOD && (pt >= PT_COUNT || tr >= PT_COUNT || can_move(pt, tr) == 0);+}+int do_move(int i, int x, int y, float nxf, float nyf) {+ edge_wrap(&nxf, &nyf);+ int16_t qx = np_q16(nxf, P_POS), qy = np_q16(nyf, P_POS);+ int nx = ipos(qx), ny = ipos(qy);+ if (plainly_refused(i, x, y, nx, ny)) return 0;+ int result = do_move_q(i, x, y, qx, qy, nx, ny);+ return result == MOVE_REFUSED ? 0 : result;+}+/* do_move for MovementPhase's tries one after the other, where nothing changes between them but the moves: a+ * place refused (MOVE_REFUSED) is refused again without looking. The memo is the refused move's cells, packed (0:+ * none); `loop` is edgeMode == EDGE_LOOP */+typedef uint32_t MoveMemo;+static inline uint32_t memo_key(int x, int y, int nx, int ny) {+ return 1u | (uint32_t)nx << 1 | (uint32_t)ny << 8 | (uint32_t)x << 16 | (uint32_t)y << 24;+}+static inline int do_move_m(MoveMemo *m, bool loop, int i, int x, int y, float nxf, float nyf) {+ if (loop) edge_wrap(&nxf, &nyf);+ int16_t qx = np_q16(nxf, P_POS), qy = np_q16(nyf, P_POS);+ int nx = ipos(qx), ny = ipos(qy);+ /* (a refused place is on the grid, the particle too: their cells fit the key) */+ if ((unsigned)nx < XRES && (unsigned)ny < YRES) {+ uint32_t key = memo_key(x, y, nx, ny);+ if (*m == key) return 0;+ if (plainly_refused(i, x, y, nx, ny)) {+ *m = key;+ return 0;+ }+ }+ int result = do_move_q(i, x, y, qx, qy, nx, ny);+ if (result == MOVE_REFUSED) {+ *m = memo_key(x, y, nx, ny);+ return 0;+ }+ *m = 0;+ return result;+}+/* plainly_refused for a particle of type pt and a cell holding a particle of type tr, on the grid, without a+ * wall, not the particle's own */+static inline bool refused_by(int pt, int tr) {+ return pt && !(elements[pt].Properties & TYPE_ENERGY) && tr != PT_WOOD && (pt >= PT_COUNT || tr >= PT_COUNT || can_move(pt, tr) == 0);+}++/* the original's move */+bool sim_move(int i, int x, int y, float nxf, float nyf) { return sim_move_q(i, x, y, np_q16(nxf, P_POS), np_q16(nyf, P_POS)); }++/* sparks from PHOT hitting PSCN next to NSCN */+void photoelectric_effect(int nx, int ny) {+ int r = PMAPAT(nx, ny);+ if (TYP(r) == PT_PSCN && !parts[ID(r)].life) {+ if (TYP(PMAPAT(nx - 1, ny)) == PT_NSCN || TYP(PMAPAT(nx + 1, ny)) == PT_NSCN ||+ TYP(PMAPAT(nx, ny - 1)) == PT_NSCN || TYP(PMAPAT(nx, ny + 1)) == PT_NSCN) {+ parts[ID(r)].ctype = PT_PSCN;+ part_change_type(ID(r), nx, ny, PT_SPRK);+ parts[ID(r)].life = 4;+ }+ }+}++/* ---------------------------------------------------------------- surfaces' normals (reflection, refraction) */+static unsigned direction_to_map(float dx, float dy) {+ return (unsigned)(dx >= 0) | (unsigned)((dx + dy) >= 0) << 1 | (unsigned)(dy >= 0) << 2 |+ (unsigned)((dy - dx) >= 0) << 3 | (unsigned)(dx <= 0) << 4 | (unsigned)((dx + dy) <= 0) << 5 |+ (unsigned)(dy <= 0) << 6 | (unsigned)((dy - dx) <= 0) << 7;+}+static int is_blocking(unsigned t, int x, int y) {+ if (t & REFRACT) {+ if (x < 0 || y < 0 || x >= XRES || y >= YRES) return 0;+ int rt = TYP(PMAPAT(x, y));+ return rt == PT_GLAS || rt == PT_BGLA;+ }+ return !eval_move((int)t, x, y, NULL);+}+static int is_boundary(unsigned pt, int x, int y) {+ if (!is_blocking(pt, x, y)) return 0;+ if (is_blocking(pt, x, y - 1) && is_blocking(pt, x, y + 1) && is_blocking(pt, x - 1, y) && is_blocking(pt, x + 1, y)) return 0;+ return 1;+}+static int find_next_boundary(unsigned pt, int *x, int *y, int dm, int *em, bool reverse) {+ static const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};+ static const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};+ static const int de[8] = {0x83, 0x07, 0x0E, 0x1C, 0x38, 0x70, 0xE0, 0xC1};+ if (*x <= 0 || *x >= XRES - 1 || *y <= 0 || *y >= YRES - 1) return 0;+ if (*em != -1) dm &= de[*em];+ unsigned mask = 0;+ for (int i = 0; i < 8; ++i)+ if ((dm & (1 << i)) && is_blocking(pt, *x + dx[i], *y + dy[i])) mask |= 1u << i;+ for (int i = 0; i < 8; ++i) {+ int n = (i + (reverse ? 1 : -1)) & 7;+ if ((mask & (1u << i)) && !(mask & (1u << n))) {+ *x += dx[i];+ *y += dy[i];+ *em = i;+ return 1;+ }+ }+ return 0;+}+static bool get_normal(unsigned pt, int x, int y, float dx, float dy, float *pnx, float *pny) {+ int ldm, rdm, lm, rm, lx, ly, lv, rx, ry, rv, i, j;+ if (!dx && !dy) return false;+ if (!is_boundary(pt, x, y)) return false;+ ldm = (pt & REFRACT) ? 0xFF : (int)direction_to_map(-dy, dx);+ rdm = (pt & REFRACT) ? 0xFF : (int)direction_to_map(dy, -dx);+ lx = rx = x;+ ly = ry = y;+ lv = rv = 1;+ lm = rm = -1;+ j = 0;+ for (i = 0; i < SURF_RANGE; i++) {+ if (lv) lv = find_next_boundary(pt, &lx, &ly, ldm, &lm, true);+ if (rv) rv = find_next_boundary(pt, &rx, &ry, rdm, &rm, false);+ j += lv + rv;+ if (!lv && !rv) break;+ }+ if (j < NORMAL_MIN_EST) return false;+ if ((lx == rx) && (ly == ry)) return false;+ float ex = (float)(rx - lx), ey = (float)(ry - ly);+ float r = 1.0f / hypotf(ex, ey);+ *pnx = ey * r;+ *pny = -ex * r;+ return true;+}+/* get_normal_interp<true>: finds the boundary along the way (sparking PSCN under PHOT), then its normal */+static bool get_normal_interp(unsigned pt, float x0, float y0, float dx, float dy, float *nx, float *ny) {+ int x, y, i;+ dx /= NORMAL_FRAC;+ dy /= NORMAL_FRAC;+ for (i = 0; i < NORMAL_INTERP; i++) {+ x = (int)(x0 + 0.5f);+ y = (int)(y0 + 0.5f);+ if (x < 0 || y < 0 || x >= XRES || y >= YRES) return false;+ if (is_boundary(pt, x, y)) break;+ x0 += dx;+ y0 += dy;+ }+ if (i >= NORMAL_INTERP) return false;+ if (pt == PT_PHOT) photoelectric_effect(x, y);+ return get_normal(pt, x, y, dx, dy, nx, ny);+}+int get_normal_interp_ok(int pt, float x0, float y0, float dx, float dy, float *nx, float *ny) {+ return get_normal_interp((unsigned)pt, x0, y0, dx, dy, nx, ny);+}++/* ---------------------------------------------------------------- planning a move (PlanMove<true>) */+typedef struct {+ int fin_x, fin_y, clear_x, clear_y;+ float fin_xf, fin_yf, clear_xf, clear_yf;+ float vx, vy;+ bool cut; /* the velocity was cut to MAX_VELOCITY (else it's the particle's) */+} PlanMoveResult;++static PlanMoveResult PlanMove(int i, int x, int y) {+ const Particle *p = &parts[i];+ int t = p->type;+ int fin_x, fin_y, clear_x, clear_y;+ float fin_xf, fin_yf, clear_xf, clear_yf;+ float pvx = p_vx(p), pvy = p_vy(p), px = p_x(p), py = p_y(p);+ float mv = fmaxf(fabsf(pvx), fabsf(pvy));+ bool cut = false;+ if (mv < ISTP || isnan(mv)) {+ clear_x = x;+ clear_y = y;+ clear_xf = px;+ clear_yf = py;+ fin_xf = clear_xf + pvx;+ fin_yf = clear_yf + pvy;+ fin_x = (int)(fin_xf + 0.5f);+ fin_y = (int)(fin_yf + 0.5f);+ } else {+ if (mv > MAX_VELOCITY) {+ pvx *= MAX_VELOCITY / mv;+ pvy *= MAX_VELOCITY / mv;+ mv = MAX_VELOCITY;+ cut = true;+ }+ /* interpolate to see if there is anything in the way */+ float dx = pvx * ISTP / mv, dy = pvy * ISTP / mv;+ fin_xf = px;+ fin_yf = py;+ fin_x = (int)(fin_xf + 0.5f);+ fin_y = (int)(fin_yf + 0.5f);+ bool closedEholeStart = InBounds(fin_x, fin_y) && (bmap[fin_y / WCELL][fin_x / WCELL] == WL_EHOLE && !emap[fin_y / WCELL][fin_x / WCELL]);+ while (1) {+ mv -= ISTP;+ fin_xf += dx;+ fin_yf += dy;+ fin_x = (int)(fin_xf + 0.5f);+ fin_y = (int)(fin_yf + 0.5f);+ if (edgeMode == EDGE_LOOP) {+ bool x_ok = (fin_xf >= BORDER - .5f && fin_xf < XRES - BORDER - .5f);+ bool y_ok = (fin_yf >= BORDER - .5f && fin_yf < YRES - BORDER - .5f);+ if (!x_ok) fin_xf = remainder_p(fin_xf - BORDER + .5f, XRES - BORDER * 2.0f) + BORDER - .5f;+ if (!y_ok) fin_yf = remainder_p(fin_yf - BORDER + .5f, YRES - BORDER * 2.0f) + BORDER - .5f;+ fin_x = (int)(fin_xf + 0.5f);+ fin_y = (int)(fin_yf + 0.5f);+ }+ if (mv <= 0.0f) {+ /* nothing found */+ fin_xf = px + pvx;+ fin_yf = py + pvy;+ if (edgeMode == EDGE_LOOP) {+ bool x_ok = (fin_xf >= BORDER - .5f && fin_xf < XRES - BORDER - .5f);+ bool y_ok = (fin_yf >= BORDER - .5f && fin_yf < YRES - BORDER - .5f);+ if (!x_ok) fin_xf = remainder_p(fin_xf - BORDER + .5f, XRES - BORDER * 2.0f) + BORDER - .5f;+ if (!y_ok) fin_yf = remainder_p(fin_yf - BORDER + .5f, YRES - BORDER * 2.0f) + BORDER - .5f;+ }+ fin_x = (int)(fin_xf + 0.5f);+ fin_y = (int)(fin_yf + 0.5f);+ clear_xf = fin_xf - dx;+ clear_yf = fin_yf - dy;+ clear_x = (int)(clear_xf + 0.5f);+ clear_y = (int)(clear_yf + 0.5f);+ break;+ }+ /* blocked if it can't move (0), or it would be eaten (can_move 3, eval_move 1); photons are slowed by+ * any particle, and the absorb wall blocks particles */+ int eval = eval_move(t, fin_x, fin_y, NULL);+ bool inside = InBounds(fin_x, fin_y);+ if (!eval || (inside && can_move(t, TYP(PMAPAT(fin_x, fin_y))) == 3 && eval == 1) ||+ (t == PT_PHOT && inside && pmap_id[fin_y][fin_x]) ||+ (inside && bmap[fin_y / WCELL][fin_x / WCELL] == WL_DESTROYALL) ||+ (inside && closedEholeStart != (bmap[fin_y / WCELL][fin_x / WCELL] == WL_EHOLE && !emap[fin_y / WCELL][fin_x / WCELL]))) {+ /* found an obstacle */+ clear_xf = fin_xf - dx;+ clear_yf = fin_yf - dy;+ clear_x = (int)(clear_xf + 0.5f);+ clear_y = (int)(clear_yf + 0.5f);+ break;+ }+ if (bmap[fin_y / WCELL][fin_x / WCELL] == WL_DETECT && emap[fin_y / WCELL][fin_x / WCELL] < 8)+ set_emap(fin_x / WCELL, fin_y / WCELL);+ }+ }+ return (PlanMoveResult){fin_x, fin_y, clear_x, clear_y, fin_xf, fin_yf, clear_xf, clear_yf, pvx, pvy, cut};+}++/* ---------------------------------------------------------------- the particles' update */+typedef struct {+ uint16_t id[8]; /* the pmap ids (id + 1, 0: none) around, in the original's order (its surround[]) */+ int surround_space;+ int nt; /* over 1: something around that isn't the particle's type (for water's movement) */+ float pGravX, pGravY;+} Neighbourhood;++/* GetGravityField where it's only the vertical gravity: without Newtonian gravity its field is 0 everywhere, so it+ * adds nothing (a particle's gravity of -0 is left to it, as adding 0 would make it +0) */+static inline void gravity_field(int x, int y, float particleGrav, float newtonGrav, float *pGravX, float *pGravY) {+ if (gravityMode == GRAV_VERTICAL && !ngrav_enable && !(particleGrav == 0 && signbit(particleGrav))) {+ *pGravX = 0;+ *pGravY = particleGrav;+ return;+ }+ GetGravityField(x, y, particleGrav, newtonGrav, pGravX, pGravY);+}++/* the bytes of w that are 0 (UQSUB8 makes them 1, the others 0; USAD8 adds them up) */+static inline int zero_bytes(uint32_t w) {+#if defined(__ARM_FEATURE_SIMD32) && __ARM_FEATURE_SIMD32+ uint32_t m, r;+ __asm__("uqsub8 %0, %1, %2" : "=r"(m) : "r"(0x01010101u), "r"(w));+ __asm__("usad8 %0, %1, %2" : "=r"(r) : "r"(m), "r"(0u));+ return (int)r;+#else+ return !(w & 0xFFu) + !(w & 0xFF00u) + !(w & 0xFF0000u) + !(w & 0xFF000000u);+#endif+}++static inline void GetNeighbourhood(int t, int x, int y, Neighbourhood *n) {+ const Particle *P = parts;+ const uint16_t *row = &pmap_id[y][x]; /* (x and y are inside the border) */+ /* (the original's order: x - 1, then x, then x + 1, each from y - 1 down) */+ static const int16_t at[8] = {-XRES - 1, -1, XRES - 1, -XRES, XRES, -XRES + 1, 1, XRES + 1};+ /* (their types a byte each in two words: empty space is the bytes at 0, the other types the bytes not at t) */+ uint32_t w[2] = {0, 0};+ n->pGravX = n->pGravY = 0;+ for (int j = 0; j < 8; j++) {+ unsigned id = row[at[j]];+ uint32_t rt = id ? P[id - 1].type : 0;+ n->id[j] = (uint16_t)id;+ w[j >> 2] |= rt << ((j & 3) * 8);+ }+ uint32_t tt = (uint32_t)t * 0x01010101u;+ n->surround_space = zero_bytes(w[0]) + zero_bytes(w[1]); /* empty space */+ n->nt = 8 - zero_bytes(w[0] ^ tt) - zero_bytes(w[1] ^ tt); /* empty space and particles of another type */+ if (!(elements[t].Properties & TYPE_SOLID) && (elements[t].Gravity || elements[t].NewtonianGravity))+ gravity_field(x, y, elements[t].Gravity, elements[t].NewtonianGravity, &n->pGravX, &n->pGravY);+}++/* the wall cells a conductor at x, y touches, for sparks from walls: the original checks one, the cell next to+ * it when it's at the edge of its 4-particle cell, its own when in the middle; with 2-particle cells every+ * particle is at an edge, so its own cell and the ones next to it it touches */+static int touched_cells(int x, int y, int *cx, int *cy) {+ int ox = x / WCELL, oy = y / WCELL;+ int dx = x % WCELL == 0 ? -1 : x % WCELL == WCELL - 1 ? 1 : 0;+ int dy = y % WCELL == 0 ? -1 : y % WCELL == WCELL - 1 ? 1 : 0;+ int n = 0;+ const int cand[4][2] = {{ox, oy}, {ox + dx, oy}, {ox, oy + dy}, {ox + dx, oy + dy}};+ for (int k = 0; k < 4; k++) {+ if (k && ((k == 1 && !dx) || (k == 2 && !dy) || (k == 3 && (!dx || !dy)))) continue;+ if (cand[k][0] >= 0 && cand[k][1] >= 0 && cand[k][0] < XWCELLS && cand[k][1] < YWCELLS)+ cx[n] = cand[k][0], cy[n] = cand[k][1], n++;+ }+ return n;+}++/* the elements the heat transfer's exceptions name (IsHeatInsulator's and TransitionPhase's): the others conduct+ * when their HeatConduct isn't 0, with their element's HeatCapacity */+static const uint8_t heat_special[PT_NUM] = {+ [PT_FILT] = 1, [PT_BRAY] = 1, [PT_BIZR] = 1, [PT_BIZRG] = 1, [PT_PHOT] = 1, [PT_ELEC] = 1, [PT_DEUT] = 1,+ [PT_HSWC] = 1, [PT_PIPE] = 1, [PT_PPIP] = 1,+};++/* (x, y: the particle's place, as UpdateParticles worked it out) */+static __attribute__((noinline)) bool TransitionPhase(int i, int x, int y, const Neighbourhood *nb) {+ Particle *p = &parts[i];+ int t = p->type;+ int ax = x / ACELL, ay = y / ACELL;+ bool transitionOccurred = false;+ if (!legacy_enable) {+ float gel_scale = 1.0f;+ if (t == PT_GEL) gel_scale = p->tmp * 2.55f;++ if ((elements[t].Properties & TYPE_LIQUID) && (t != PT_GEL || gel_scale > (1 + rng_between(0, 254)))) {+ float convGravX, convGravY;+ GetGravityField(x, y, -2.0f, -2.0f, &convGravX, &convGravY);+ int offsetX = iclamp((int)roundf(convGravX + x), x - 1, x + 1);+ int offsetY = iclamp((int)roundf(convGravY + y), y - 1, y + 1);+ /* some heat convection for liquids */+ if (offsetX != x || offsetY != y) {+ int r = PMAPAT(offsetX, offsetY);+ if (r && p->type == TYP(r)) {+ if (p->temp > parts[ID(r)].temp) {+ uint16_t swappage = p->temp;+ p->temp = parts[ID(r)].temp;+ parts[ID(r)].temp = swappage;+ }+ }+ }+ }++ /* heat transfer */+ if (t && !IsHeatInsulator(p) && rng_chance((int)(elements[t].HeatConduct * gel_scale), 250)) {+ /* with the air */+ if (aheat_enable && !(elements[t].Properties & PROP_NOAMBHEAT)) {+ float dtemp = hv[ay][ax] - p_temp(p);+ float hc = HeatCapacityOf(p);+ float alpha = fminf(0.04f, 0.4f * hc); /* alpha / heat_capacity must be < 1 */+ p_set_temp_d(p, restrict_flt(p_temp(p) + alpha * dtemp / hc, MIN_TEMP, MAX_TEMP));+ hv[ay][ax] = restrict_flt(hv[ay][ax] - alpha * dtemp, MIN_TEMP, MAX_TEMP);+ }+ /* with other particles (the original writes the result to all 8, the particle itself for the ones that+ * don't conduct: here only to the ones that do) */+ float hc_total = 0.0f, c_heat = 0.0f;+ uint16_t conduct[8];+ int nc = 0;+ bool tspecial = heat_special[t];+ for (int j = 0; j < 8; j++) {+ unsigned id = nb->id[j];+ if (!id) continue;+ const Particle *q = &parts[id - 1];+ int rt = q->type;+ if (!rt || !elements[rt].HeatConduct) continue;+ if ((tspecial || heat_special[rt]) &&+ (IsHeatInsulator(q) || (t == PT_FILT && (rt == PT_BRAY || rt == PT_BIZR || rt == PT_BIZRG)) ||+ (rt == PT_FILT && (t == PT_BRAY || t == PT_PHOT || t == PT_BIZR || t == PT_BIZRG)) ||+ (t == PT_ELEC && rt == PT_DEUT) || (t == PT_DEUT && rt == PT_ELEC) ||+ (t == PT_HSWC && rt == PT_FILT && p->tmp == 1) || (t == PT_FILT && rt == PT_HSWC && q->tmp == 1)))+ continue;+ conduct[nc++] = (uint16_t)(id - 1);+ float hc = heat_special[rt] ? HeatCapacityOf(q) : elements[rt].HeatCapacity;+ c_heat += p_temp(q) * hc;+ hc_total += hc;+ }+ float hc = HeatCapacityOf(p);+ c_heat += p_temp(p) * hc;+ hc_total += hc;+ /* equilibrium temperature */+ float pt = restrict_flt(c_heat / hc_total, MIN_TEMP, MAX_TEMP);+ p_set_temp_d(p, pt); /* (one dithered value for all of them, as the original's one) */+ for (int k = 0; k < nc; k++) parts[conduct[k]].temp = p->temp;++ float ctemph = pt, ctempl = pt;+ /* change boiling point with pressure */+ if (((elements[t].Properties & TYPE_LIQUID) && IsElementOrNone(elements[t].HighTemperatureTransition) &&+ (elements[elements[t].HighTemperatureTransition].Properties & TYPE_GAS)) || t == PT_LNTG || t == PT_SLTW)+ ctemph -= 2.0f * pv[ay][ax];+ else if (((elements[t].Properties & TYPE_GAS) && IsElementOrNone(elements[t].LowTemperatureTransition) &&+ (elements[elements[t].LowTemperatureTransition].Properties & TYPE_LIQUID)) || t == PT_WTRV)+ ctempl -= 2.0f * pv[ay][ax];+ int s = 1;++ /* a fix for ice with ctype = 0 */+ if ((t == PT_ICEI || t == PT_SNOW) && (!IsElement(p->ctype) || p->ctype == PT_ICEI || p->ctype == PT_SNOW))+ p->ctype = PT_WATR;++ if (elements[t].HighTemperatureTransition != NT && ctemph >= elements[t].HighTemperature) {+ /* particle type change due to high temperature */+ if (elements[t].HighTemperatureTransition != ST) {+ if (t == PT_FOG) p->ctype = 0; /* clear unnecessary ctype */+ t = elements[t].HighTemperatureTransition;+ } else if (t == PT_ICEI || t == PT_SNOW) {+ if (p->ctype > 0 && p->ctype < PT_NUM && p->ctype != t) {+ if (elements[p->ctype].LowTemperatureTransition == PT_ICEI || elements[p->ctype].LowTemperatureTransition == PT_SNOW) {+ if (pt < elements[p->ctype].LowTemperature) s = 0;+ } else if (pt < 273.15f) {+ s = 0;+ }+ if (s) {+ t = p->ctype;+ p->ctype = PT_NONE;+ p->life = 0;+ }+ } else {+ s = 0;+ }+ } else if (t == PT_SLTW) {+ /* SLTW -> SALT/WTRV */+ t = rng_chance(1, 4) ? PT_SALT : PT_WTRV;+ } else if (t == PT_BRMT) {+ /* BRMT(TUNG) -> LAVA(TUNG) */+ if (p->ctype == PT_TUNG) {+ if (ctemph < elements[p->ctype].HighTemperature) {+ s = 0;+ } else {+ t = PT_LAVA;+ p->type = PT_TUNG;+ }+ } else if (ctemph >= elements[t].HighTemperature) {+ t = PT_LAVA;+ } else {+ s = 0;+ }+ } else if (t == PT_CRMC) {+ float pres = fmaxf((pv[ay][ax] + pv[(y - 2) / ACELL][ax] + pv[(y + 2) / ACELL][ax] + pv[ay][(x - 2) / ACELL] ++ pv[ay][(x + 2) / ACELL]) * 2.0f, 0.0f);+ if (ctemph < pres + elements[PT_CRMC].HighTemperature) s = 0;+ else t = PT_LAVA;+ } else if (t == PT_RIME) {+ if (p->tmp > 5) {+ /* RIME -> ACID */+ t = PT_ACID;+ p->life = (int16_t)(25 + 5 * p->tmp);+ p->tmp = 0;+ } else {+ /* RIME -> WATR */+ t = p->ctype == PT_DSTW ? PT_DSTW : PT_WATR;+ p->ctype = 0;+ }+ } else {+ s = 0;+ }+ } else if (elements[t].LowTemperatureTransition != NT && ctempl < elements[t].LowTemperature) {+ /* particle type change due to low temperature */+ if (elements[t].LowTemperatureTransition != ST) {+ t = elements[t].LowTemperatureTransition;+ } else if (t == PT_WTRV) {+ /* WTRV -> RIME/DSTW */+ t = (pt < 273.0f) ? PT_RIME : PT_DSTW;+ } else if (t == PT_LAVA) {+ if (p->ctype > 0 && p->ctype < PT_NUM && p->ctype != PT_LAVA && elements[p->ctype].Enabled) {+ if (p->ctype == PT_THRM && pt >= elements[PT_BMTL].HighTemperature) {+ s = 0;+ } else if ((p->ctype == PT_VIBR || p->ctype == PT_BVBR) && pt >= 273.15f) {+ s = 0;+ } else if (p->ctype == PT_TUNG) {+ /* TUNG melts in its own update; the threshold is its HighTemperature */+ if (pt >= elements[p->ctype].HighTemperature) s = 0;+ } else if (p->ctype == PT_CRMC) {+ float pres = fmaxf((pv[ay][ax] + pv[(y - 2) / ACELL][ax] + pv[(y + 2) / ACELL][ax] + pv[ay][(x - 2) / ACELL] ++ pv[ay][(x + 2) / ACELL]) * 2.0f, 0.0f);+ if (ctemph >= pres + elements[PT_CRMC].HighTemperature) s = 0;+ } else if (elements[p->ctype].HighTemperatureTransition == PT_LAVA || p->ctype == PT_HEAC) {+ if (pt >= elements[p->ctype].HighTemperature) s = 0;+ } else if (pt >= 973.0f) {+ s = 0; /* freezing point for lava with any other ctype */+ }+ if (s) {+ t = p->ctype;+ p->ctype = PT_NONE;+ if (t == PT_THRM) {+ /* LAVA(THRM) -> BMTL */+ p->tmp = 0;+ t = PT_BMTL;+ }+ if (t == PT_PLUT) {+ /* LAVA(PLUT) -> LAVA */+ p->tmp = 0;+ t = PT_LAVA;+ }+ }+ } else if (pt < 973.0f) {+ t = PT_STNE; /* LAVA -> STNE */+ } else {+ s = 0;+ }+ } else {+ s = 0;+ }+ } else {+ s = 0;+ }++ if (s) { /* a type change */+ if (t == PT_ICEI || t == PT_LAVA || t == PT_SNOW) p->ctype = p->type;+ if (t == PT_RIME) p->ctype = PT_DSTW;+ if (!(t == PT_ICEI && p->ctype == PT_FRZW) && t != PT_ACID) p->life = 0;+ if (t == PT_FIRE) {+ /* if tmp isn't 0 the FIRE might turn into DSTW later */+ p->tmp = 0;+ if (p->type == PT_SEED) {+ p->ctype = 0;+ p->tmp2 = 0;+ p->tmp3 = 0;+ tmp4_set(i, 0);+ }+ }+ if ((elements[t].Properties & TYPE_GAS) && !(elements[p->type].Properties & TYPE_GAS)) pv[ay][ax] += 0.50f;+ if (t == PT_NONE) {+ kill_part(i);+ return true;+ }+ /* part_change_type can refuse and kill the particle (STKM when one exists...) */+ if (part_change_type(i, x, y, t)) return true;+ if (t == PT_FIRE || t == PT_PLSM || t == PT_CFLM) p->life = (int16_t)rng_between(120, 169);+ if (t == PT_LAVA) {+ if (p->ctype == PT_BRMT) p->ctype = PT_BMTL;+ else if (p->ctype == PT_SAND) p->ctype = PT_GLAS;+ else if (p->ctype == PT_BGLA) p->ctype = PT_GLAS;+ else if (p->ctype == PT_PQRT) p->ctype = PT_QRTZ;+ else if (p->ctype == PT_LITH && p->tmp2 > 3) p->ctype = PT_GLAS;+ p->life = (int16_t)rng_between(240, 359);+ }+ transitionOccurred = true;+ }++ /* (temperatures are kept within MIN_TEMP and MAX_TEMP) */+ if (t == PT_LAVA) {+ p->life = (int16_t)(int)restrict_flt((p_temp(p) - 700) / 7, 0, 400);+ if (p->ctype == PT_THRM && p->tmp > 0) {+ p->tmp--;+ p_set_temp(p, 3500);+ }+ if (p->ctype == PT_PLUT && p->tmp > 0) {+ p->tmp--;+ p_set_temp(p, MAX_TEMP);+ }+ }+ } else {+ if (!(bmap_blockairh[ay][ax] & 0x8)) bmap_blockairh[ay][ax]++;+ }+ }++ if (t == PT_LIFE) p_set_temp(p, restrict_flt(p_temp(p) - 50.0f, MIN_TEMP, MAX_TEMP));++ /* sparks from walls (conductors only from a wall cell at 12) */+ if (((elements[t].Properties & PROP_CONDUCTS) && emap_any12) || t == PT_SPRK) {+ int cx[4], cy[4], n = touched_cells(x, y, cx, cy);+ for (int k = 0; k < n; k++) {+ int nx = cx[k], ny = cy[k];+ if (t != PT_SPRK) {+ if (emap[ny][nx] == 12 && !p->life && bmap[ny][nx] != WL_STASIS) {+ part_change_type(i, x, y, PT_SPRK);+ p->life = 4;+ p->ctype = t;+ t = PT_SPRK;+ }+ } else {+ int b = bmap[ny][nx];+ if (b == WL_DETECT || b == WL_EWALL || b == WL_ALLOWLIQUID || b == WL_WALLELEC || b == WL_ALLOWALLELEC || b == WL_EHOLE)+ set_emap(nx, ny);+ }+ }+ }++ /* the basic explosion, from Explosive */+ if ((elements[t].Explosive & 2) && pv[ay][ax] > 2.5f) {+ p->life = (int16_t)rng_between(180, 259);+ p_set_temp(p, restrict_flt(elements[PT_FIRE].DefaultProperties.temp + (elements[t].Flammable / 2), MIN_TEMP, MAX_TEMP));+ t = PT_FIRE;+ part_change_type(i, x, y, t);+ pv[ay][ax] += 0.25f * CFDS;+ }++ {+ int s = 1;+ /* (gravtot, worked out only where it's needed) */+#define gravtot (fabsf(gravx[ay][ax]) + fabsf(gravy[ay][ax]))+ if (elements[t].HighPressureTransition != NT && pv[ay][ax] > elements[t].HighPressure) {+ /* particle type change due to high pressure */+ if (elements[t].HighPressureTransition != ST) {+ t = elements[t].HighPressureTransition;+ } else if (t == PT_BMTL) {+ if (pv[ay][ax] > 2.5f) t = PT_BRMT;+ else if (pv[ay][ax] > 1.0f && p->tmp == 1) t = PT_BRMT;+ else s = 0;+ } else {+ s = 0;+ }+ } else if (elements[t].LowPressureTransition != NT && pv[ay][ax] < elements[t].LowPressure && gravtot <= (elements[t].LowPressure / 4.0f)) {+ /* particle type change due to low pressure */+ if (elements[t].LowPressureTransition != ST) t = elements[t].LowPressureTransition;+ else s = 0;+ } else if (elements[t].HighPressureTransition != NT && gravtot > (elements[t].HighPressure / 4.0f)) {+ /* particle type change due to high gravity */+ if (elements[t].HighPressureTransition != ST) {+ t = elements[t].HighPressureTransition;+ } else if (t == PT_BMTL) {+ if (gravtot > 0.625f) t = PT_BRMT;+ else if (gravtot > 0.25f && p->tmp == 1) t = PT_BRMT;+ else s = 0;+ } else {+ s = 0;+ }+ } else {+ s = 0;+ }+#undef gravtot+ if (s) {+ if (t == PT_NONE) {+ kill_part(i);+ return true;+ }+ p->life = 0;+ /* so that PIPE -> BRMT doesn't set BRMT's ctype */+ if (t == PT_BRMT) {+ tmp4_set(i, 0);+ p->ctype = 0;+ p->tmp = 0;+ p->tmp2 = 0;+ p->tmp3 = 0;+ }+ if (part_change_type(i, x, y, t)) return true;+ if (t == PT_FIRE) p->life = (int16_t)rng_between(120, 169);+ transitionOccurred = true;+ }+ }+ return transitionOccurred;+}++/* the velocity times the element's Collision: at 0 (most liquids), 0 at once */+static inline void vel_scale(Particle *p, float coll) {+ if (coll == 0) {+ p->vx = p->vy = 0;+ return;+ }+ p_set_vx(p, p_vx(p) * coll);+ p_set_vy(p, p_vy(p) * coll);+}++static void MovementPhase(int i, const Neighbourhood *nb) {+ Particle *p = &parts[i];+ int t = p->type;+ int x = ipos(p->x), y = ipos(p->y);+ PlanMoveResult mr = PlanMove(i, x, y);+ int fin_x = mr.fin_x, fin_y = mr.fin_y, clear_x = mr.clear_x, clear_y = mr.clear_y;+ float fin_xf = mr.fin_xf, fin_yf = mr.fin_yf, clear_xf = mr.clear_xf, clear_yf = mr.clear_yf;+ /* (PlanMove's velocity is the particle's unless it cut it to MAX_VELOCITY: then it's kept) */+ if (mr.cut) {+ p_set_vx(p, mr.vx);+ p_set_vy(p, mr.vy);+ }++ int stagnant = p->flags & FLAG_STAGNANT;+ p->flags &= (uint8_t)~FLAG_STAGNANT;++ if (t == PT_STKM || t == PT_STKM2 || t == PT_FIGH) {+ /* head movement: the head passes through anything */+ p_set_x(p, p_x(p) + p_vx(p));+ p_set_y(p, p_y(p) + p_vy(p));+ int nx = ipos(p->x), ny = ipos(p->y);+ if (edgeMode == EDGE_LOOP) {+ bool x_ok = (nx >= BORDER && nx < XRES - BORDER);+ bool y_ok = (ny >= BORDER && ny < YRES - BORDER);+ int oldnx = nx, oldny = ny;+ if (!x_ok) {+ p_set_x(p, remainder_p(p_x(p) - BORDER + .5f, XRES - BORDER * 2.0f) + BORDER - .5f);+ nx = ipos(p->x);+ }+ if (!y_ok) {+ p_set_y(p, remainder_p(p_y(p) - BORDER + .5f, YRES - BORDER * 2.0f) + BORDER - .5f);+ ny = ipos(p->y);+ }+ if (!x_ok || !y_ok) { /* adjust the stickman's legs */+ playerst *stickman = NULL;+ if (t == PT_STKM) stickman = &player;+ else if (t == PT_STKM2) stickman = &player2;+ else if (t == PT_FIGH && p->tmp >= 0 && p->tmp < MAX_FIGHTERS) stickman = &fighters[p->tmp];+ if (stickman)+ for (int k = 0; k < 16; k += 2) {+ stickman->legs[k] += (float)(nx - oldnx);+ stickman->legs[k + 1] += (float)(ny - oldny);+ stickman->accs[k / 2] *= .95f;+ }+ p_set_vy(p, p_vy(p) * .95f);+ p_set_vx(p, p_vx(p) * .95f);+ }+ }+ if (ny != y || nx != x) {+ if (pmap_id[y][x] == i + 1) pmap_id[y][x] = 0;+ else if (photons_id[y][x] == i + 1) photons_id[y][x] = 0;+ if (nx < BORDER || nx >= XRES - BORDER || ny < BORDER || ny >= YRES - BORDER) {+ kill_part(i);+ return;+ }+ if (elements[t].Properties & TYPE_ENERGY) photons_id[ny][nx] = (uint16_t)(i + 1);+ else if (t) pmap_id[ny][nx] = (uint16_t)(i + 1);+ }+ } else if (elements[t].Properties & TYPE_ENERGY) {+ if (t == PT_PHOT) {+ if (p->flags & FLAG_SKIPMOVE) {+ p->flags &= (uint8_t)~FLAG_SKIPMOVE;+ return;+ }+ if (eval_move(PT_PHOT, fin_x, fin_y, NULL)) {+ int rt = TYP(PMAPAT(fin_x, fin_y)), lt = TYP(PMAPAT(x, y));+ int rt_glas = (rt == PT_GLAS) || (rt == PT_BGLA), lt_glas = (lt == PT_GLAS) || (lt == PT_BGLA);+ if ((rt_glas && !lt_glas) || (lt_glas && !rt_glas)) {+ float nrx, nry;+ if (!get_normal_interp(REFRACT | (unsigned)t, p_x(p), p_y(p), p_vx(p), p_vy(p), &nrx, &nry)) {+ kill_part(i);+ return;+ }+ int ctype = p->ctype;+ int r = get_wavelength_bin(&ctype);+ p->ctype = ctype;+ if (r == -1 || !(p->ctype & 0x3FFFFFFF)) {+ kill_part(i);+ return;+ }+ float nn = GLASS_IOR - GLASS_DISP * (r - 30) / 30.0f;+ nn *= nn;+ bool enter = rt_glas && !lt_glas;+ nrx = enter ? -nrx : nrx;+ nry = enter ? -nry : nry;+ nn = enter ? 1.0f / nn : nn;+ float pvx = p_vx(p), pvy = p_vy(p);+ float ct1 = pvx * nrx + pvy * nry;+ float ct2 = 1.0f - (nn * nn) * (1.0f - (ct1 * ct1));+ if (ct2 < 0.0f) {+ /* total internal reflection */+ p_set_vx(p, pvx - 2.0f * ct1 * nrx);+ p_set_vy(p, pvy - 2.0f * ct1 * nry);+ fin_xf = p_x(p);+ fin_yf = p_y(p);+ fin_x = x;+ fin_y = y;+ } else {+ /* refraction */+ ct2 = sqrtf(ct2);+ ct2 = ct2 - nn * ct1;+ p_set_vx(p, nn * pvx + ct2 * nrx);+ p_set_vy(p, nn * pvy + ct2 * nry);+ }+ }+ }+ }+ if (stagnant) { /* reflected on the previous frame */+ /* whole coordinates, for compatibility with existing saves */+ if (!do_move(i, x, y, (float)fin_x, (float)fin_y) && p->type) {+ kill_part(i);+ return;+ }+ } else if (!do_move(i, x, y, fin_xf, fin_yf)) {+ if (p->type == PT_NONE) return;+ /* reflection */+ p->flags |= FLAG_STAGNANT;+ if (t == PT_NEUT && rng_chance(1, 10)) {+ kill_part(i);+ return;+ }+ int r = PMAPAT(fin_x, fin_y);+ if ((TYP(r) == PT_PIPE || TYP(r) == PT_PPIP) && !TYP(parts[ID(r)].ctype)) {+ Element_PIPE_transfer_part_to_pipe(p, &parts[ID(r)]); /* (the original doesn't kill it) */+ return;+ }+ if (t == PT_PHOT) {+ int mask = (int)elements[TYP(r)].PhotonReflectWavelengths;+ if (TYP(r) == PT_LITH) {+ int wl_bin = parts[ID(r)].ctype / 4;+ if (wl_bin < 0) wl_bin = 0;+ if (wl_bin > 25) wl_bin = 25;+ mask = (0x1F << wl_bin);+ } else if (TYP(r) == PT_SEED) {+ /* SEED's colour genes reflect different wavelengths */+ int colour = (parts[ID(r)].ctype >> 6) & 0x3f; /* PLNT_COLOUR */+ mask |= ((colour & 0x30) != 0) ? 0 : (1 << 25); /* red */+ mask |= ((colour & 0x0C) != 0) ? 0 : (1 << 15); /* green */+ mask |= ((colour & 0x03) != 0) ? 0 : (1 << 5); /* blue */+ }+ p->ctype &= mask;+ }+ float nrx, nry;+ if (get_normal_interp((unsigned)t, p_x(p), p_y(p), p_vx(p), p_vy(p), &nrx, &nry)) {+ float pvx = p_vx(p), pvy = p_vy(p);+ if (TYP(r) == PT_CRMC) {+ float rr = rng_between(-50, 50) * 0.01f;+ rr = rr * rr * rr;+ float rx = cosf(rr), ry = sinf(rr);+ float anrx = rx * nrx + ry * nry, anry = rx * nry - ry * nrx;+ float dp = anrx * pvx + anry * pvy;+ p_set_vx(p, pvx - 2.0f * dp * anrx);+ p_set_vy(p, pvy - 2.0f * dp * anry);+ } else {+ float dp = nrx * pvx + nry * pvy;+ p_set_vx(p, pvx - 2.0f * dp * nrx);+ p_set_vy(p, pvy - 2.0f * dp * nry);+ }+ /* the actual movement waits for the next frame, so that fast particles reflect and refract right */+ } else {+ if (t != PT_NEUT) kill_part(i);+ return;+ }+ if (!(p->ctype & 0x3FFFFFFF) && t == PT_PHOT) {+ kill_part(i);+ return;+ }+ }+ } else if (elements[t].Falldown == 0) {+ /* gases and solids (not powders) */+ if (!do_move(i, x, y, fin_xf, fin_yf)) {+ if (p->type == PT_NONE) return;+ /* can't move there: bounce off */+ if (fin_x > x + ISTP) fin_x = x + ISTP;+ if (fin_x < x - ISTP) fin_x = x - ISTP;+ if (fin_y > y + ISTP) fin_y = y + ISTP;+ if (fin_y < y - ISTP) fin_y = y - ISTP;+ float coll = elements[t].Collision;+ if (do_move(i, x, y, (float)(2 * x - fin_x), (float)fin_y)) {+ p_set_vx(p, p_vx(p) * coll);+ } else if (do_move(i, x, y, (float)fin_x, (float)(2 * y - fin_y))) {+ p_set_vy(p, p_vy(p) * coll);+ } else {+ vel_scale(p, coll);+ }+ }+ } else {+ float coll = elements[t].Collision;+ MoveMemo memo = 0;+ const bool loop = edgeMode == EDGE_LOOP;+ /* water equalization (it doesn't update when changed later, if checking stagnant) */+ if (water_equal_test && elements[t].Falldown == 2 && rng_chance(1, 200))+ if (flood_water(x, y, i)) return;+ /* liquids and powders */+ if (!do_move_m(&memo, loop, i, x, y, fin_xf, fin_yf)) {+ if (p->type == PT_NONE) return;+ if (fin_x != x && do_move_m(&memo, loop, i, x, y, fin_xf, clear_yf)) {+ vel_scale(p, coll);+ } else if (fin_y != y && do_move_m(&memo, loop, i, x, y, clear_xf, fin_yf)) {+ vel_scale(p, coll);+ } else {+ float pGravX = nb->pGravX, pGravY = nb->pGravY;+ int r = (int)(rng_u32() & 1) * 2 - 1; /* the side searched first (rng_between(0, 1): the low bit) */+ if ((clear_x != x || clear_y != y || nb->nt || nb->surround_space) && (fabsf(p_vx(p)) > 0.01f || fabsf(p_vy(p)) > 0.01f)) {+ /* diagonal movement if the target is blocked, unless stuck among identical particles */+ float dx = p_vx(p) - p_vy(p) * r, dy = p_vy(p) + p_vx(p) * r;+ float mv = fmaxf(fabsf(dx), fabsf(dy));+ dx /= mv;+ dy /= mv;+ if (do_move_m(&memo, loop, i, x, y, clear_xf + dx, clear_yf + dy)) {+ vel_scale(p, coll);+ return;+ }+ {+ float swappage = dx;+ dx = dy * r;+ dy = -swappage * r;+ }+ if (do_move_m(&memo, loop, i, x, y, clear_xf + dx, clear_yf + dy)) {+ vel_scale(p, coll);+ return;+ }+ }+ if (elements[t].Falldown > 1 && !ngrav_enable && gravityMode == GRAV_VERTICAL && p_vy(p) > fabsf(p_vx(p))) {+ int s = 0, rt;+ /* stagnant: FLAG_STAGNANT was set on the previous frame */+ if (!stagnant || nb->nt) rt = 30; /* slightly less water lag, though it changes how it moves a lot */+ else rt = 10;+ if (t == PT_GEL) rt = (int)(p->tmp * 0.20f + 5.0f);+ int nx = -1, ny = -1;+ /* (the rows read once: fin and clear are on the grid here, as do_move didn't take the particle off it;+ * a type is read again after a do_move that didn't move it, as the original reads pmap each time) */+ const uint16_t *rowF = pmap_id[fin_y], *rowC = pmap_id[clear_y];+ const uint8_t *wallF = bmap[fin_y / WCELL], *wallC = bmap[clear_y / WCELL];+ /* (j from clear_x + r while 0 <= j < XRES and clear_x - rt <= j < clear_x + rt) */+ int lo = imax(clear_x - rt, 0), hi = imin(clear_x + rt, XRES) - 1;+ /* a move to (j, fin_yf) or (j, clear_yf) is to that row when it rounds to it (without the loop edges'+ * wrapping): then one plainly refused is seen from the row already read (do_move would say 0) */+ bool rowF_exact = !loop && ipos(np_q16(fin_yf, P_POS)) == fin_y;+ bool rowC_exact = !loop && ipos(np_q16(clear_yf, P_POS)) == clear_y;+ for (int j = clear_x + r; j >= lo && j <= hi; j += r) {+ /* (where this row holds this element, and the row it falls to holds it too or something it's plainly+ * refused by, without walls, nothing happens but going on: the cells passed over the way the code below+ * would) */+ int pt = p->type, ok = -1;+ while (j >= lo && j <= hi) {+ unsigned a = rowF[j], b = rowC[j];+ if (!a || !b || parts[b - 1].type != t || (wallF[(unsigned)j / WCELL] | wallC[(unsigned)j / WCELL])) break;+ int tf = parts[a - 1].type;+ if (tf != t) {+ if (!rowF_exact || (j == x && fin_y == y)) break;+ if (tf != ok) {+ if (!refused_by(pt, tf)) break;+ ok = tf;+ }+ }+ j += r;+ }+ if (j < lo || j > hi) break;+ unsigned idF = rowF[j];+ int tf = type_of_id(idF), wF = wallF[(unsigned)j / WCELL];+ if (tf != t || wF) {+ if (rowF_exact && idF && !wF && !(j == x && fin_y == y) && refused_by(p->type, tf)) {+ s = 0;+ } else if ((s = do_move_m(&memo, loop, i, x, y, (float)j, fin_yf))) {+ nx = ipos(p->x);+ ny = ipos(p->y);+ break;+ }+ }+ unsigned idC = rowC[j];+ int tc = type_of_id(idC), wC = wallC[(unsigned)j / WCELL];+ if (fin_y != clear_y && (tc != t || wC)) {+ if (rowC_exact && idC && !wC && !(j == x && clear_y == y) && refused_by(p->type, tc)) {+ s = 0;+ } else {+ if ((s = do_move_m(&memo, loop, i, x, y, (float)j, clear_yf))) {+ nx = ipos(p->x);+ ny = ipos(p->y);+ break;+ }+ tc = type_of_id(rowC[j]);+ }+ }+ if (tc != t || (wC && wC != WL_STREAM)) break;+ }+ r = (p_vy(p) > 0) ? 1 : -1;+ if (s == 1) {+ for (int j = ny + r; j >= 0 && j < YRES && j >= ny - rt && j < ny + rt; j += r) {+ if ((TYP(PMAPAT(nx, j)) != t || bmap[j / WCELL][nx / WCELL]) && do_move_m(&memo, loop, i, nx, ny, (float)nx, (float)j)) break;+ if (TYP(PMAPAT(nx, j)) != t || (bmap[j / WCELL][nx / WCELL] && bmap[j / WCELL][nx / WCELL] != WL_STREAM)) break;+ }+ } else if (s == -1) {+ /* out of bounds */+ } else if ((clear_x != x || clear_y != y) && do_move_m(&memo, loop, i, x, y, clear_xf, clear_yf)) {+ } else {+ p->flags |= FLAG_STAGNANT;+ }+ vel_scale(p, coll);+ } else if (elements[t].Falldown > 1 && fabsf(pGravX * p_vx(p) + pGravY * p_vy(p)) > fabsf(pGravY * p_vx(p) - pGravX * p_vy(p))) {+ float nxf, nyf, prev_pGravX = 0, prev_pGravY = 0, ptGrav = elements[t].Gravity;+ int s = 0;+ int rt = (!stagnant || nb->nt) ? 30 : 10;+ /* clear_xf, clear_yf: the last place it can almost certainly move to */+ nxf = clear_xf;+ nyf = clear_yf;+ int nx = clear_x, ny = clear_y;+ /* look for places to move to perpendicular to gravity, up to rt of them */+ for (int j = 0; j < rt; j++) {+ GetGravityField(nx, ny, ptGrav, 1.0f, &pGravX, &pGravY);+ float mv = fmaxf(fabsf(pGravX), fabsf(pGravY)); /* the largest component made 1 particle */+ if (mv < 0.0001f) break;+ pGravX /= mv;+ pGravY /= mv;+ /* 1 particle perpendicular to gravity, r is +1/-1 at random */+ if (j) {+ /* gravity's direction plus its last change: less frothy, following radial gravity's curve */+ nxf += r * (pGravY * 2.0f - prev_pGravY);+ nyf += -r * (pGravX * 2.0f - prev_pGravX);+ } else {+ nxf += r * pGravY;+ nyf += -r * pGravX;+ }+ prev_pGravX = pGravX;+ prev_pGravY = pGravY;+ nx = (int)(nxf + 0.5f);+ ny = (int)(nyf + 0.5f);+ if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) break;+ if (TYP(PMAPAT(nx, ny)) != t || bmap[ny / WCELL][nx / WCELL]) {+ s = do_move_m(&memo, loop, i, x, y, nxf, nyf);+ if (s) {+ nx = ipos(p->x);+ ny = ipos(p->y);+ break;+ }+ /* something else, or a wall: stop unless the wall is invisible to particles */+ if (TYP(PMAPAT(nx, ny)) != t || bmap[ny / WCELL][nx / WCELL] != WL_STREAM) break;+ }+ }+ if (s == 1) {+ /* moved perpendicular to gravity: now along it, until blocked by something else, up to rt */+ clear_x = nx;+ clear_y = ny;+ for (int j = 0; j < rt; j++) {+ GetGravityField(nx, ny, ptGrav, 1.0f, &pGravX, &pGravY);+ float mv = fmaxf(fabsf(pGravX), fabsf(pGravY));+ if (mv < 0.0001f) break;+ pGravX /= mv;+ pGravY /= mv;+ nxf += pGravX;+ nyf += pGravY;+ nx = (int)(nxf + 0.5f);+ ny = (int)(nyf + 0.5f);+ if (nx < 0 || ny < 0 || nx >= XRES || ny >= YRES) break;+ if (TYP(PMAPAT(nx, ny)) != t || bmap[ny / WCELL][nx / WCELL]) {+ s = do_move_m(&memo, loop, i, clear_x, clear_y, nxf, nyf);+ if (s || TYP(PMAPAT(nx, ny)) != t || bmap[ny / WCELL][nx / WCELL] != WL_STREAM) break;+ }+ }+ } else if (s == -1) {+ /* out of bounds */+ } else if ((clear_x != x || clear_y != y) && do_move_m(&memo, loop, i, x, y, clear_xf, clear_yf)) {+ } else {+ p->flags |= FLAG_STAGNANT;+ }+ vel_scale(p, coll);+ } else {+ /* after interpolation, the last clear place */+ if ((clear_x != x || clear_y != y) && do_move_m(&memo, loop, i, x, y, clear_xf, clear_yf)) {+ } else {+ p->flags |= FLAG_STAGNANT;+ }+ vel_scale(p, coll);+ }+ }+ }+ }+}++/* the main particle loop: every particle, once a frame (parts_active can grow on the way: new particles past+ * the current one are updated in the same frame, as in the original) */+void UpdateParticles(int start, int end) {+ for (int i = start; i < end && i < parts_active; i++) {+ Particle *p = &parts[i];+ int t = p->type;+ if (!t) continue;+ int x = ipos(p->x), y = ipos(p->y);++ /* off the screen: killed */+ if (x < BORDER || y < BORDER || x >= XRES - BORDER || y >= YRES - BORDER) {+ kill_part(i);+ continue;+ }+ const Element *e = &elements[t];+ /* in a wall it isn't allowed in: killed */+ int wall = bmap[y / WCELL][x / WCELL];+ if (wall &&+ (wall == WL_WALL || wall == WL_WALLELEC || wall == WL_ALLOWAIR || wall == WL_DESTROYALL ||+ (wall == WL_ALLOWLIQUID && !(e->Properties & TYPE_LIQUID)) || (wall == WL_ALLOWPOWDER && !(e->Properties & TYPE_PART)) ||+ (wall == WL_ALLOWGAS && !(e->Properties & TYPE_GAS)) || (wall == WL_ALLOWENERGY && !(e->Properties & TYPE_ENERGY)) ||+ (wall == WL_EWALL && !emap[y / WCELL][x / WCELL])) &&+ t != PT_STKM && t != PT_STKM2 && t != PT_FIGH) {+ kill_part(i);+ continue;+ }+ /* stasis: no update */+ if (wall == WL_STASIS && emap[y / WCELL][x / WCELL] < 8) continue;+ if (wall == WL_DETECT && emap[y / WCELL][x / WCELL] < 8) set_emap(x / WCELL, y / WCELL);++ /* the air gets the particle's velocity */+ int ax = x / ACELL, ay = y / ACELL;+ vx[ay][ax] = vx[ay][ax] * e->AirLoss + e->AirDrag * p_vx(p);+ vy[ay][ax] = vy[ay][ax] * e->AirLoss + e->AirDrag * p_vy(p);+ if (e->HotAir) {+ if (t == PT_GAS || t == PT_NBLE) {+ if (pv[ay][ax] < 3.5f) pv[ay][ax] += 4.0f * e->HotAir * (3.5f - pv[ay][ax]);+ } else {+ /* the hot air into the pressure (black hole, white hole) */+ pv[ay][ax] += 4.0f * e->HotAir;+ }+ }++ Neighbourhood nb;+ GetNeighbourhood(t, x, y, &nb);++ /* the particle's velocity: loss, air, gravity, diffusion (one rounding at the end) */+ float pvx = p_vx(p), pvy = p_vy(p);+ if (t != PT_SPNG || !(p->flags & FLAG_MOVABLE)) {+ pvx *= e->Loss;+ pvy *= e->Loss;+ }+ pvx += e->Advection * vx[ay][ax] + nb.pGravX;+ pvy += e->Advection * vy[ay][ax] + nb.pGravY;+ if (e->Diffusion) { /* gases' random diffusion */+ pvx += e->Diffusion * (2.0f * rng_uniform01() - 1.0f);+ pvy += e->Diffusion * (2.0f * rng_uniform01() - 1.0f);+ }+ p_set_vx(p, pvx);+ p_set_vy(p, pvy);++ bool transitionOccurred = TransitionPhase(i, x, y, &nb);+ if (!p->type) continue;+ if (transitionOccurred) t = p->type;++ /* the element's own update */+ if (elements[t].Update) {+ if (elements[t].Update(i, x, y, nb.surround_space, nb.nt)) continue;+ x = ipos(p->x);+ y = ipos(p->y);+ }+ if (legacy_enable) Element_legacyUpdate(i, x, y, nb.surround_space, nb.nt); /* heat simulation off */+ if (p->type == PT_NONE) continue;+ if (transitionOccurred) continue;+ if (!p->vx && !p->vy) continue; /* not moving */+ MovementPhase(i, &nb);+ }+}diff --git a/games/numpowder/src/simdefs.h b/games/numpowder/src/simdefs.hnew file mode 100644index 00000000..8a9cd3d1--- /dev/null+++ b/games/numpowder/src/simdefs.h@@ -0,0 +1,180 @@+/* NumPowder: The Powder Toy's simulation definitions, for the calculator.+ *+ * The original's grid is CELLS x CELL = 153 x 96 cells of 4 x 4 particles (612 x 384); its code is written+ * against those constants. Here the particle grid is 100 x 64, each drawn 3 x 3 pixels (300 x 192, the original's+ * layout at half its size). Walls (bmap, emap) have cells of 2 x 2 particles (WCELL) for finer building; air,+ * gravity and fans keep the original's cells of 4 x 4 particles (ACELL).+ *+ * A particle keeps every field the original's has, packed into 24 bytes (56 there): positions, velocities and+ * temperatures are fixed point, read and written through the accessors below (p_x, p_set_vx, p_temp...). */+#ifndef NP_SIMDEFS_H+#define NP_SIMDEFS_H+#include <math.h>+#include <stdbool.h>+#include <stdint.h>++/* ---------------------------------------------------------------- the grid */+#define XRES 100+#define YRES 64+#define NCELLS_P (XRES * YRES) /* particle cells */+#define WCELL 2 /* walls: bmap, emap (the original's CELL) */+#define XWCELLS (XRES / WCELL)+#define YWCELLS (YRES / WCELL)+#define ACELL 4 /* air (pv, vx, vy, hv), gravity, fans (the original's CELL) */+#define XACELLS (XRES / ACELL)+#define YACELLS (YRES / ACELL)+#define CFDS (4.0f / ACELL)+#define ISTP (ACELL / 2)+#define BORDER ACELL /* the edge where particles die: the original's one CELL (4 particles) */+#define XCNTR (XRES / 2)+#define YCNTR (YRES / 2)+#define MAX_VELOCITY 1e4f+#define PX_SCALE 3 /* screen pixels per particle */++/* ---------------------------------------------------------------- the original's constants */+#define MAX_TEMP 9999.0f+#define MIN_TEMP 0.0f+#define O_MAX_TEMP 3500.0f+#define O_MIN_TEMP (-273.0f)+#define MAX_PRESSURE 256.0f+#define MIN_PRESSURE (-256.0f)+#define R_TEMP 22.0f+#define IPL (MIN_PRESSURE - 1)+#define IPH (MAX_PRESSURE + 1)+#define ITL (MIN_TEMP - 1)+#define ITH (MAX_TEMP + 1)+#define NT (-1) /* no transition (PT_NONE kills) */+#define ST PT_NUM /* special transition */+#define M_GRAV 6.67300e-1f++#define TYPE_PART 0x00000001u+#define TYPE_LIQUID 0x00000002u+#define TYPE_SOLID 0x00000004u+#define TYPE_GAS 0x00000008u+#define TYPE_ENERGY 0x00000010u+#define STATE_FLAGS 0x0000001Fu+#define PROP_CONDUCTS 0x00000020u+#define PROP_PHOTPASS 0x00000040u+#define PROP_NEUTPENETRATE 0x00000080u+#define PROP_NEUTABSORB 0x00000100u+#define PROP_NEUTPASS 0x00000200u+#define PROP_DEADLY 0x00000400u+#define PROP_HOT_GLOW 0x00000800u+#define PROP_LIFE 0x00001000u+#define PROP_RADIOACTIVE 0x00002000u+#define PROP_LIFE_DEC 0x00004000u+#define PROP_LIFE_KILL 0x00008000u+#define PROP_LIFE_KILL_DEC 0x00010000u+#define PROP_SPARKSETTLE 0x00020000u+#define PROP_NOAMBHEAT 0x00040000u+#define PROP_NOCTYPEDRAW 0x00100000u++#define FLAG_STAGNANT 0x1+#define FLAG_SKIPMOVE 0x2+#define FLAG_MOVABLE 0x8+#define FLAG_PHOTDECO 0x8++/* the fields of a particle, as the original numbers them (CarriesTypeIn, the property tool) */+enum { FIELD_TYPE = 0, FIELD_LIFE = 1, FIELD_CTYPE = 2, FIELD_TMP = 9, FIELD_TMP2 = 10, FIELD_TMP3 = 11, FIELD_TMP4 = 12 };++/* the menu sections (MenuSection.h) */+enum { SC_WALL, SC_ELEC, SC_POWERED, SC_SENSOR, SC_FORCE, SC_EXPLOSIVE, SC_GAS, SC_LIQUID, SC_POWDERS, SC_SOLIDS,+ SC_NUCLEAR, SC_SPECIAL, SC_LIFE, SC_TOOL, SC_FAVORITES, SC_DECO, SC_TOTAL };++/* pmap values: an id and a type, as the original packs them (its PMAPBITS is 9; the types here fit 8 bits) */+#define PMAPBITS 8+#define PMAPMASK ((1 << PMAPBITS) - 1)+#define PT_NUM (1 << PMAPBITS)+static inline int ID(int r) { return r >> PMAPBITS; }+static inline int TYP(int r) { return r & PMAPMASK; }+static inline int PMAP(int id, int typ) { return (id << PMAPBITS) | (typ & PMAPMASK); }+static inline int PMAPID(int id) { return id << PMAPBITS; }+static inline bool InBounds(int x, int y) { return x >= 0 && y >= 0 && x < XRES && y < YRES; }++/* ---------------------------------------------------------------- a particle */+typedef struct {+ int32_t ctype; /* 32 bits: photons' wavelengths */+ int16_t life, tmp, tmp2, tmp3; /* (the original's are int; tmp4 is not kept: see p_tmp4) */+ int16_t x, y; /* position, 1/64 particle */+ int16_t vx, vy; /* velocity, 1/256 particle a frame */+ uint16_t temp; /* Kelvin, 1/4 */+ uint8_t type, flags;+} Particle;+_Static_assert(sizeof(Particle) == 24, "a particle is 24 bytes");++#define P_POS 64.0f+#define P_VEL 256.0f+#define P_TEMP 4.0f+static inline float p_x(const Particle *p) { return p->x * (1 / P_POS); }+static inline float p_y(const Particle *p) { return p->y * (1 / P_POS); }+static inline float p_vx(const Particle *p) { return p->vx * (1 / P_VEL); }+static inline float p_vy(const Particle *p) { return p->vy * (1 / P_VEL); }+/* temperatures are kept as (T + 0.1 K) * 4, so that the whole degrees Celsius (n + 273.15 K) the original starts+ * elements at are exact; 0 is 0 K, and T_MAXQ is MAX_TEMP exactly (WARP's 10000 K is MAX_TEMP here: a code above+ * it would cost every temperature read a test) */+#define T_OFFSET 0.1f+#define T_MAXQ 39997+static inline float p_temp(const Particle *p) {+ return fminf(fmaxf(p->temp * (1 / P_TEMP) - T_OFFSET, MIN_TEMP), MAX_TEMP);+}+/* to the nearest (ties to even), within int16_t, NaN as 0: on the calculator two instructions do it all */+static inline int16_t np_q16(float v, float scale) {+ float s = v * scale;+#if defined(__ARM_FP) && defined(__thumb2__)+ int32_t r;+ __asm__("vcvtr.s32.f32 %0, %0" : "+t"(s)); /* (saturating; NaN gives 0) */+ __asm__("vmov %0, %1" : "=r"(r) : "t"(s));+ __asm__("ssat %0, #16, %0" : "+r"(r));+ return (int16_t)r;+#else+ if (!(s == s)) return 0; /* NaN */+ s = s < -32768 ? -32768 : s > 32767 ? 32767 : s;+ return (int16_t)rintf(s);+#endif+}+/* velocities: to their 1/256 with dithering. Rounded to the nearest, a slow particle's v *= Loss would stop under+ * 10/256 (half a step off rounds back up) and it would drift for ever; dithered, the fraction is kept on average.+ * Stochastic rounding: the value in 1/256 of a step (towards 0), a random byte added, then the step it's in (so a+ * value already on a step stays on it). The dither has its own generator (temp_dither, the temperatures' too, here+ * a step of an LCG: its top byte), so the original's random numbers stay the same. NaN is 0, as np_q16 */+extern uint32_t temp_dither;+static inline int16_t np_q16_d(float v, float scale) {+ float s = v * (scale * 256.0f);+ if (s > 8388352.0f) s = 8388352.0f; /* (32767 steps at most, the byte added or not; NaN stays NaN) */+ int32_t t;+#if defined(__ARM_FP) && defined(__thumb2__)+ __asm__("vcvt.s32.f32 %0, %0" : "+t"(s)); /* (towards 0, saturating; NaN gives 0) */+ __asm__("vmov %0, %1" : "=r"(t) : "t"(s));+ __asm__("ssat %0, #24, %0" : "+r"(t));+#else+ if (!(s == s)) s = 0;+ t = s < -8388608.0f ? -8388608 : (int32_t)s;+#endif+ temp_dither = temp_dither * 1664525u + 1013904223u;+ return (int16_t)((t + (int32_t)(temp_dither >> 24)) >> 8);+}+static inline void p_set_x(Particle *p, float v) { p->x = np_q16(v, P_POS); }+static inline void p_set_y(Particle *p, float v) { p->y = np_q16(v, P_POS); }+static inline void p_set_vx(Particle *p, float v) { p->vx = np_q16_d(v, P_VEL); }+static inline void p_set_vy(Particle *p, float v) { p->vy = np_q16_d(v, P_VEL); }+/* a temperature kept to the nearest (within MIN_TEMP and MAX_TEMP; NaN: MIN_TEMP, as restrict_flt) */+static inline uint16_t temp_q(float t) {+ t = !(t >= MIN_TEMP) ? MIN_TEMP : t > MAX_TEMP ? MAX_TEMP : t;+ return t >= MAX_TEMP ? T_MAXQ : (uint16_t)((t + T_OFFSET) * P_TEMP + 0.5f);+}+static inline void p_set_temp(Particle *p, float t) { p->temp = temp_q(t); }+/* the cell a particle is in (the original's (int)(x + 0.5f)) */+static inline int p_cx(const Particle *p) { return (p->x + 32) >> 6; }+static inline int p_cy(const Particle *p) { return (p->y + 32) >> 6; }++/* the functions' arguments, as the original's (the simulation, parts and pmap are globals here: sim.h) */+#define UPDATE_FUNC_ARGS int i, int x, int y, int surround_space, int nt+#define UPDATE_FUNC_SUBCALL_ARGS i, x, y, surround_space, nt+#define GRAPHICS_FUNC_ARGS const Particle *cpart, int nx, int ny, int *pixel_mode, int *cola, int *colr, int *colg, int *colb, int *firea, int *firer, int *fireg, int *fireb+#define GRAPHICS_FUNC_SUBCALL_ARGS cpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb+#define ELEMENT_CREATE_FUNC_ARGS int i, int x, int y, int t, int v+#define ELEMENT_CREATE_ALLOWED_FUNC_ARGS int i, int x, int y, int t+#define ELEMENT_CHANGETYPE_FUNC_ARGS int i, int x, int y, int from, int to+#define CTYPEDRAW_FUNC_ARGS int i, int t, int v+#define CTYPEDRAW_FUNC_SUBCALL_ARGS i, t, v+#endifdiff --git a/games/numpowder/src/simpriv.h b/games/numpowder/src/simpriv.hnew file mode 100644index 00000000..518d9942--- /dev/null+++ b/games/numpowder/src/simpriv.h@@ -0,0 +1,245 @@+/* NumPowder: what the simulation's files share and the interface doesn't need: the original's helpers (Misc.h),+ * the can_move table, the elements' shared state and the functions elements call in each other. */+#ifndef NP_SIMPRIV_H+#define NP_SIMPRIV_H+#include <stdlib.h>+#include <string.h>+#include "sim.h"++/* ---------------------------------------------------------------- Misc.h */+static inline float restrict_flt(float f, float min, float max) {+ if (!isfinite(f)) return min;+ if (f < min) return min;+ if (f > max) return max;+ return f;+}+static inline int isign_i(int i) { return i < 0 ? -1 : i > 0 ? 1 : 0; }+static inline int isign_f(float i) { return i < 0 ? -1 : i > 0 ? 1 : 0; }+#define isign(v) _Generic((v), float: isign_f, double: isign_f, default: isign_i)(v)+static inline int imin(int a, int b) { return a < b ? a : b; }+static inline int imax(int a, int b) { return a > b ? a : b; }+static inline int iclamp(int v, int lo, int hi) { return v < lo ? lo : v > hi ? hi : v; }+static inline unsigned clamp_flt(float f, float min, float max) {+ if (f < min) return 0;+ if (f > max) return 255;+ return (unsigned)(int)(255.0f * (f - min) / (max - min));+}+#define NP_PI 3.14159265358979323846f+/* a position as a particle keeps it (1/64 particle): the cell a moved particle ends up in is worked out from+ * this, so it's the one that was checked */+static inline float q64(float v) { return np_q16(v, P_POS) * (1 / P_POS); }++/* a temperature kept to its 1/4 K with dithering, where the original adds small amounts every frame (heat+ * conduction, ambient heat, URAN, POLO...): rounded to the nearest, a change under 1/8 K would be lost; dithered,+ * it's kept on average. The dither has its own generator, so the original's random numbers stay the same. */+extern uint32_t temp_dither;+static inline void p_set_temp_d(Particle *p, float t) {+ t = !(t >= MIN_TEMP) ? MIN_TEMP : t > MAX_TEMP ? MAX_TEMP : t;+ if (t >= MAX_TEMP) {+ p->temp = T_MAXQ;+ return;+ }+ float s = (t + T_OFFSET) * P_TEMP;+ uint32_t q = (uint32_t)s;+ temp_dither ^= temp_dither << 13;+ temp_dither ^= temp_dither >> 17;+ temp_dither ^= temp_dither << 5;+ if ((float)(temp_dither >> 8) * (1.0f / 16777216.0f) < s - (float)q) q++;+ p->temp = (uint16_t)q;+}++/* clears n bytes (a multiple of 4, word aligned) a word at a time: the library's memset goes a byte at a time */+static inline void clear_words(void *p, size_t n) {+ uint32_t *d = (uint32_t *)p, *e = d + n / 4;+ while (e - d >= 4) d[0] = d[1] = d[2] = d[3] = 0, d += 4;+ while (d < e) *d++ = 0;+}++/* ---------------------------------------------------------------- SimulationConfig.h */+#define NPART npart_max+#define MAXSIGNS 16+#define AIR_TSTEPP 0.3f+#define AIR_TSTEPV 0.4f+#define AIR_VADV 0.3f+#define AIR_VLOSS 0.999f+#define AIR_PLOSS 0.9999f+#define SURF_RANGE 10+#define NORMAL_MIN_EST 3+#define NORMAL_INTERP 20+#define NORMAL_FRAC 16+#define REFRACT 0x80000000u+#define GLASS_IOR 1.9f+#define GLASS_DISP 0.07f+#define CHANNELS 101 /* the original's int(MAX_TEMP - 73) / 100 + 2 */+#define OLD_SPC_AIR 236+#define SPC_AIR 256++/* the original's GT_* (old ids of the Game of Life types) */+enum { GT_GOL = 78, GT_HLIF, GT_ASIM, GT_2x2, GT_DANI, GT_AMOE, GT_MOVE, GT_PGOL, GT_DMOE, GT_34, GT_LLIF, GT_STAN,+ GT_SEED = 134, GT_MAZE, GT_COAG, GT_WALL, GT_GNAR, GT_REPL, GT_MYST, GT_LOTE = 142, GT_FRG2, GT_STAR, GT_FROG,+ GT_BRAN };++/* ---------------------------------------------------------------- can_move (SimulationData::init_can_move),+ * 2 bits a pair in flash (canmove_data.c, made by tools/gen_elements.py) */+#define CANMOVE_STRIDE ((PT_COUNT + 3) / 4)+extern const uint8_t can_move_table[PT_COUNT][CANMOVE_STRIDE];+static inline int can_move(int moving, int dest) {+ return (can_move_table[moving][dest >> 2] >> ((dest & 3) * 2)) & 3;+}++/* ---------------------------------------------------------------- SimulationData's */+static inline bool IsHeatInsulator(const Particle *p);+float HeatCapacityOf(const Particle *p);++/* ---------------------------------------------------------------- the simulation's own state */+extern int ISWIRE;+extern bool emap_any12; /* a wall cell's electricity is at 12 this frame (BeforeSim): it sparks conductors */+extern bool force_stacking_check;+extern int emp_trigger_count;+extern bool etrd_count_valid;+extern int etrd_life0_count;+extern int lightningRecreate;+extern bool gravWallChanged;+extern bool elementRecount;+extern uint8_t wireless[CHANNELS][2];+extern int CGOL, GSPEED;+extern int Element_PPIP_ppip_changed;+extern int16_t Element_PSTN_tempParts[XRES > YRES ? XRES : YRES];+extern uint8_t Element_LOLZ_lolz[XRES / 9][YRES / 9];+extern uint8_t Element_LOVE_love[XRES / 9][YRES / 9];+/* scratch RAM shared by the passes that need some for a moment (flood fills, the air's next state, the stacking+ * check's counts, the Game of Life): SCRATCH bytes, word aligned */+#define SCRATCH (2 * XACELLS * YACELLS * 4 + 2 * XACELLS * 4)+extern uint8_t *sim_scratch;++/* the flood fills' stack (CoordStack), in sim_scratch after its first `from` bytes */+void flood_stack_init(int from);+bool flood_stack_push(int x, int y); /* false when full */+void flood_stack_pop(int *x, int *y);+int flood_stack_size(void);++/* the portals' particles (the original's portalp[CHANNELS][8][80]: 80 places for each channel and direction): a pool of+ * PORTAL_SLOTS shared by all, each knowing its channel, direction and place */+#define PORTAL_SLOTS 64+typedef struct { uint8_t channel, dir, slot; Particle p; } PortalSlot;+extern PortalSlot portalp[PORTAL_SLOTS];+extern int portal_count;+extern const int portal_rx[8], portal_ry[8];+bool portal_free(int channel, int dir); /* is there a free place */+bool portal_put(int channel, int dir, const Particle *p); /* in the first free place (PRTI); false if none */+int portal_find(int channel, int dir, int slot); /* the pool's entry at that place, -1 none */+void portal_take(int entry);+bool portal_any(int channel);++/* tmp4, which the 24-byte particle doesn't keep, for the few elements that use it: a small table by particle id */+int tmp4_get(int i);+void tmp4_set(int i, int v);+void tmp4_clear(int i);++/* ---------------------------------------------------------------- core functions elements use */+int get_normal_interp_ok(int pt, float x0, float y0, float dx, float dy, float *nx, float *ny);+void detach(int i);+bool FloodFillPmapCheck(int x, int y, int type);+void UpdateParticles(int start, int end);+void BeforeSim(bool willUpdate);+void AfterSim(void);+void CheckStacking(void);+void SimulateGoL(void);+void sim_flatten_parts(void);+int parts_alloc(void);+static inline bool parts_full(void) { return pfree == -1 && parts_active >= NPART; } /* Parts::MaxPartsReached */+void UpdateGravityMask(void);+#if defined(SIM_SCENE) || defined(HOST)+void sim_scene(int n); /* the speed tests' scenes (sim.c), also the tests' */+#endif+extern float grav_work_mass[YACELLS][XACELLS]; /* the masses handed to the gravity's worker, and its state */+extern uint8_t grav_work_mask[YACELLS][XACELLS];+extern bool grav_work_pending, grav_force_recalc;+void grav_exchange(void);+void grav_reset(void);+void grav_enable(bool enable);+void air_update(void);+void air_update_heat(void);+void air_clear(void);+void air_clear_heat(void);+void air_make_kernel(void);+void air_invert(void);+void air_approximate_block_maps(void);+void air_walls_block(void);+extern float ambientAirTemp, edgePressure, edgeVelocityX, edgeVelocityY, vorticityCoeff;+extern int airMode, convectionMode;++/* ---------------------------------------------------------------- elements' functions other elements call */+int Element_FILT_interactWavelengths(Particle *cpart, int origWl);+int Element_FILT_getWavelengths(const Particle *cpart);+void Element_PIPE_transfer_part_to_pipe(Particle *part, Particle *pipe);+void Element_PIPE_transfer_pipe_to_part(Particle *pipe, Particle *part, bool STOR);+void Element_PIPE_transformPatchOffsets(Particle *part, const int offsets[8]);+void Element_PPIP_flood_trigger(int x, int y, int sparkedBy);+void Element_EMP_Trigger(int triggerCount);+void Element_STKM_init_legs(playerst *playerp, int i);+void Element_STKM_set_element(playerst *playerp, int element);+int Element_STKM_run_stickman(playerst *playerp, UPDATE_FUNC_ARGS);+void Element_STKM_interact(playerst *playerp, int i, int x, int y);+bool Element_FIGH_CanAlloc(void);+int Element_FIGH_Alloc(void);+void Element_FIGH_NewFighter(int fighterID, int i, int elem);+void Element_SOAP_detach(int i);+void SOAP_neighbourLoop(float *dx, float *dy); /* Element_SOAP_neighourLoop (the renderer's too) */+int Element_LIFE_createAllowed_ok(void);+bool Element_PCLN_ctypeDraw(CTYPEDRAW_FUNC_ARGS);+int Element_COAL_update(UPDATE_FUNC_ARGS);+int Element_NTCT_update(UPDATE_FUNC_ARGS);+int Element_ETRD_nearestSparkablePart(int targetId);+int Element_FIRE_update(UPDATE_FUNC_ARGS);+int Element_PIPE_update(UPDATE_FUNC_ARGS);+int Element_VIRS_update(UPDATE_FUNC_ARGS);+bool basicCtypeDraw(CTYPEDRAW_FUNC_ARGS);+bool ctypeDrawVInTmp(CTYPEDRAW_FUNC_ARGS);+bool ctypeDrawVInCtype(CTYPEDRAW_FUNC_ARGS);+int Element_legacyUpdate(UPDATE_FUNC_ARGS);++/* PLNT's and SEED's genes (PLNT.h): ctype's bits 0 to 19 (bits 20 to 31 keep part of tmp4: see tmp4_get) */+#define PLNT_PHASE 1+#define PLNT_DIR 3+#define PLNT_COLOUR 6+#define PLNT_LIFE 12+#define PLNT_TOTAL_CTP 20+#define PLNT_TOTAL_TMP 15+#define PLNT_CTYPE 0xFFFFF+/* directions counter-clockwise from the top: 107 / 2.6 / 345 */+static const struct { int8_t X, Y; } dir3x3[8] = {{0, -1}, {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}};+int Element_PLNT_detectDown(int x, int y);++/* PIPE's and PPIP's flags (PIPE.h), moved to fit 16 bits of tmp, and 8 of flags */+#define PFLAG_CAN_CONDUCT 0x0001 /* (the original's 0x00000001) */+#define PIPE_SINGLE 0x0002 /* a single pixel pipe (0x00000100) */+#define PIPE_FWD_SINGLE 0x0004 /* transfers like a single pixel pipe going forward (0x00000200) */+#define PIPE_FWD_SHIFT 3 /* and its direction (0x00001C00) */+#define PIPE_REV_SINGLE 0x0040 /* the same in reverse (0x00002000, 0x0001C000) */+#define PIPE_REV_SHIFT 7+#define PIPE_FWD_GROUP 0x003C /* the forward and reverse groups, swapped when a PPIP reverses */+#define PIPE_REV_GROUP 0x03C0+#define PFLAG_INITIALIZING 0x0400 /* colours not set yet (0x00020000) */+#define PFLAG_COLOR_RED 0x0800 /* (0x00040000...) */+#define PFLAG_COLOR_GREEN 0x1000+#define PFLAG_COLOR_BLUE 0x1800+#define PFLAG_COLORS 0x1800+#define PPIP_TMPFLAG_REVERSED 0x2000 /* (0x01000000) */+#define PPIP_TMPFLAG_PAUSED 0x4000 /* (0x02000000) */+/* in flags (bit 0 is FLAG_STAGNANT): this frame's triggers, the next frame's (the original's tmp << 3), and+ * PFLAG_NORMALSPEED (the original's flags 0x00010000) */+#define PPIP_TMPFLAG_TRIGGER_REVERSE 0x02+#define PPIP_TMPFLAG_TRIGGER_OFF 0x04+#define PPIP_TMPFLAG_TRIGGER_ON 0x08+#define PPIP_TMPFLAG_TRIGGERS 0x0E+#define PPIP_LATE_SHIFT 3+#define PFLAG_NORMALSPEED 0x80+void pipe_ovf_clear(int i);+void pipe_ovf_move(int from, int to);++static inline bool IsHeatInsulator(const Particle *p) {+ return elements[p->type].HeatConduct == 0 || (p->type == PT_HSWC && p->life != 10) ||+ ((p->type == PT_PIPE || p->type == PT_PPIP) && (p->tmp & PFLAG_CAN_CONDUCT) == 0);+}+#endifdiff --git a/games/numpowder/src/simsave.c b/games/numpowder/src/simsave.cnew file mode 100644index 00000000..7c2feffc--- /dev/null+++ b/games/numpowder/src/simsave.c@@ -0,0 +1,634 @@+/* NumPowder: saving the simulation to a compact byte stream and loading it, as the original's Simulation::Save,+ * GameSave's OPS format and Simulation::Load (with GameModel::SaveToSimParameters) do.+ *+ * As in OPS, the particles go by place, row by row and in id order within a place, and come back with new ids in+ * that order in the middle of their cells; velocities are kept to 1/16 (a byte each, 127 for none), the air's+ * pressure and velocity to 1/128, the ambient heat to a kelvin, the fans to 1/64; flags aren't kept (but for+ * PIPE's and PLNT's, which hold the original's tmp and tmp4 here); SOAP keeps its forward links and gets its+ * back links from them; stickmen keep their rocket boots and fans and get new legs. Unlike OPS, temperatures keep+ * their 1/4 K (OPS rounds them to a kelvin), and the frame count, the random numbers and the temperature dither+ * are always kept and put back after loading, so a save loaded twice goes on the same way.+ *+ * The stream, little-endian:+ * "NPWD", version, the particles' count (varint), the settings, the frame count, random numbers and dither;+ * the walls (bmap, emap: run-length); the fans (a bitmap of the cells that have one, then a byte each way); the+ * air's pressure, velocities and ambient heat (a bitmap of the cells not at rest, then 16 bits each); the air+ * blocking maps (run-length); the stickmen's rocket boots and fans; Newtonian gravity's maps when it's on;+ * the particles, each a byte saying what's as the last one (the next cell or the same one, the element, the+ * temperature, the velocity) or the element's defaults, then only the rest. Sand, drawn or settled, is about a+ * byte a grain. */+#include "simpriv.h"+#include "simsave.h"++#define MAGIC "NPWD"+#define VERSION 3 /* (2: temperatures kept as T * 4, read and converted) */++/* what a particle's first byte says */+#define H_NEXTCELL 0x01 /* it's in the cell after the last particle's */+#define H_SAMECELL 0x02 /* it's in the last particle's cell (neither: a varint of the cells skipped, less 2) */+#define H_TYPE 0x04 /* the last particle's element (else a byte) */+#define H_TEMP 0x08 /* the last particle's temperature if the same element, else its default (else the difference) */+#define H_VEL 0x10 /* the last particle's velocity if the same element, else none (else two bytes) */+#define H_FIELDS 0x20 /* life, ctype, tmp, tmp2, tmp3 are the defaults (else a byte saying which aren't, then those) */+#define H_FLAGS 0x40 /* a byte of flags follows */+#define H_EXTRA 0x80 /* a byte of extras follows, then theirs: */+#define X_PIPEHI 0x01 /* PIPE's tmp4's top byte */+#define X_SOAPLINK 0x02 /* a SOAP's forward link: the place in the stream of the one it's linked to, less its own */+#define X_BOOTS 0x08 /* a fighter's rocket boots */+#define X_FAN 0x10 /* a fighter's fan */++/* ---------------------------------------------------------------- the particles' order */+/* the cell a particle is saved in (Save's int(x + 0.5f)), -1 if outside */+static inline int cell_of(int i) {+ int x = (parts[i].x + 32) / 64, y = (parts[i].y + 32) / 64;+ return InBounds(x, y) ? y * XRES + x : -1;+}+/* its place in the stream: its cell, then its id (plus 1; 0: not saved) */+static inline uint32_t key_of(int i) {+ if (!parts[i].type) return 0;+ int c = cell_of(i);+ return c < 0 ? 0 : ((uint32_t)c << 16 | (uint32_t)i) + 1;+}++/* the scratch RAM while saving: a bit for each cell with a particle that isn't on pmap or photons there, then the+ * keys of the next particles to write, as a heap */+#define EXTRA_BYTES ((XRES * YRES + 7) / 8)+#define HEAP_AT ((EXTRA_BYTES + 3) & ~3)+#define HEAP_CAP ((SCRATCH - HEAP_AT) / 4)+_Static_assert(HEAP_CAP >= 256, "the scratch RAM holds a good part of the particles' keys");+static inline uint32_t *heap(void) { return (uint32_t *)(void *)(sim_scratch + HEAP_AT); }+static inline bool has_extras(int c) { return sim_scratch[c >> 3] >> (c & 7) & 1; }++static void mark_extras(void) {+ const uint16_t *pm = &pmap_id[0][0], *ph = &photons_id[0][0];+ memset(sim_scratch, 0, EXTRA_BYTES);+ for (int i = 0; i < parts_active; i++) {+ if (!parts[i].type) continue;+ int c = cell_of(i);+ if (c >= 0 && pm[c] != i + 1 && ph[c] != i + 1) sim_scratch[c >> 3] |= (uint8_t)(1 << (c & 7));+ }+}++static void sift_down(uint32_t *h, int n, uint32_t k) {+ int j = 0;+ for (;;) {+ int c = 2 * j + 1;+ if (c >= n) break;+ if (c + 1 < n && h[c + 1] > h[c]) c++;+ if (h[c] <= k) break;+ h[j] = h[c], j = c;+ }+ h[j] = k;+}+/* the next keys after `after`, as many as the heap holds, in order; how many */+static int next_keys(uint32_t after) {+ uint32_t *h = heap();+ int n = 0;+ for (int i = 0; i < parts_active; i++) {+ uint32_t k = key_of(i);+ if (k <= after) continue;+ if (n < HEAP_CAP) {+ int j = n++;+ while (j > 0 && h[(j - 1) / 2] < k) h[j] = h[(j - 1) / 2], j = (j - 1) / 2;+ h[j] = k;+ } else if (k < h[0]) {+ sift_down(h, n, k);+ }+ }+ for (int end = n - 1; end > 0; end--) {+ uint32_t top = h[0];+ sift_down(h, end, h[end]);+ h[end] = top;+ }+ return n;+}++/* the particles with keys from ka up to (not with) kb: from the maps when every one there is on them */+static int count_keys(uint32_t ka, uint32_t kb) {+ int ca = (int)((ka - 1) >> 16), cb = (int)((kb - 1) >> 16), n = 0;+ bool scan = cb - ca > 2 * XRES;+ for (int c = ca; c <= cb && !scan; c++) scan = has_extras(c);+ if (scan) {+ for (int i = 0; i < parts_active; i++) {+ uint32_t k = key_of(i);+ n += k >= ka && k < kb;+ }+ return n;+ }+ const uint16_t *pm = &pmap_id[0][0], *ph = &photons_id[0][0];+ for (int c = ca; c <= cb; c++) {+ int a = pm[c] - 1, b = ph[c] - 1;+ if (a >= 0 && cell_of(a) == c) {+ uint32_t k = key_of(a);+ n += k >= ka && k < kb;+ }+ if (b >= 0 && b != a && cell_of(b) == c) {+ uint32_t k = key_of(b);+ n += k >= ka && k < kb;+ }+ }+ return n;+}++/* ---------------------------------------------------------------- the values as saved */+static uint32_t air16(float v) { /* pressure and air velocity: [-255, 255] + 256, times 128 */+ v = fmaxf(-255.0f, fminf(255.0f, v)) + 256.0f;+ return (uint32_t)(int)(v * 128);+}+static float unair16(uint32_t v) { return (float)v / 128.0f - 256; }+static uint32_t heat16(float v) { /* ambient heat: to a kelvin */+ return !(v >= 0) ? 0 : v >= 65535 ? 65535 : (uint32_t)(int)(v + 0.5f);+}+static float unheat16(uint32_t v) { return (float)v; }+static uint32_t fan8(float v) { /* fans: 1/64 */+ int t = (int)(v * 64.0f + 127.5f);+ return (uint32_t)(t < 0 ? 0 : t > 255 ? 255 : t);+}+static float unfan8(uint32_t v) { return ((float)v - 127.0f) / 64.0f; }+static uint32_t vel8(int16_t v) { /* a particle's velocity: 1/16, none if under 0.001 */+ float f = v * (1 / P_VEL);+ if (!(fabsf(f) > 0.001f)) return 127;+ int t = (int)(f * 16.0f + 127.5f);+ return (uint32_t)(t < 0 ? 0 : t > 255 ? 255 : t);+}+static int16_t unvel8(uint32_t v) { return (int16_t)(((int)v - 127) * (int)(P_VEL / 16)); }+static uint16_t default_temp(int t, int version) {+ float d = elements[t].DefaultProperties.temp;+ if (version == 2) return (uint16_t)(restrict_flt(d, MIN_TEMP, MAX_TEMP) * P_TEMP + 0.5f);+ return temp_q(d);+}+/* the flags kept: PIPE's and PPIP's hold the original's tmp bits, PLNT's and SEED's the top of tmp4 */+static uint32_t kept_flags(int t, uint32_t f) {+ if (t == PT_PIPE || t == PT_PPIP) return f & 0xFE;+ if (t == PT_PLNT || t == PT_SEED) return f & 0xE0;+ return 0;+}++/* ---------------------------------------------------------------- writing (out NULL: counting) */+typedef struct {+ uint8_t *out;+ uint32_t n, room;+ bool over;+ int index, lastCell, lastType, lastTemp, lastVx, lastVy; /* (the particles') */+} W;+static void w8(W *w, uint32_t v) {+ if (w->out) {+ if (w->n < w->room) w->out[w->n] = (uint8_t)v;+ else w->over = true;+ }+ w->n++;+}+static void w32(W *w, uint32_t v) { w8(w, v), w8(w, v >> 8), w8(w, v >> 16), w8(w, v >> 24); }+static void wf(W *w, float f) {+ union { float f; uint32_t u; } c = {f};+ w32(w, c.u);+}+static void wvar(W *w, uint32_t v) {+ while (v >= 0x80) w8(w, (v & 0x7F) | 0x80), v >>= 7;+ w8(w, v);+}+static void wzig(W *w, int32_t v) { wvar(w, ((uint32_t)v << 1) ^ (uint32_t)(v >> 31)); }+static void wrle(W *w, const uint8_t *a, int n) {+ for (int k = 0; k < n;) {+ int run = 1;+ while (k + run < n && run < 255 && a[k + run] == a[k]) run++;+ w8(w, (uint32_t)run), w8(w, a[k]);+ k += run;+ }+}+/* a map's values as q makes them: a bitmap of those not rest, then those, `bytes` each */+static void wmap(W *w, const float *a, int n, uint32_t (*q)(float), uint32_t rest, int bytes) {+ for (int k = 0; k < n; k += 8) {+ uint32_t b = 0;+ for (int j = 0; j < 8 && k + j < n; j++) b |= (uint32_t)(q(a[k + j]) != rest) << j;+ w8(w, b);+ }+ for (int k = 0; k < n; k++) {+ uint32_t v = q(a[k]);+ if (v == rest) continue;+ w8(w, v);+ if (bytes == 2) w8(w, v >> 8);+ }+}+static void wfloats(W *w, const float *a, int n) { /* floats as they are, the zero ones left out */+ for (int k = 0; k < n; k += 8) {+ uint32_t b = 0;+ for (int j = 0; j < 8 && k + j < n; j++) b |= (uint32_t)(a[k + j] != 0) << j;+ w8(w, b);+ }+ for (int k = 0; k < n; k++)+ if (a[k] != 0) wf(w, a[k]);+}++static void wpart(W *w, int i) {+ const Particle *p = &parts[i];+ int t = p->type, cell = cell_of(i);+ const Element *e = &elements[t];+ int life = p->life, ctype = p->ctype, tmp = p->tmp, tmp2 = p->tmp2, tmp3 = p->tmp3, extra = 0, link = 0;+ uint32_t flags = kept_flags(t, p->flags);+ if ((t == PT_PIPE || t == PT_PPIP) && tmp4_get(i) >> 23 != 0 && tmp4_get(i) >> 23 != -1) extra |= X_PIPEHI;+ if (t == PT_SOAP) {+ /* only the forward link, to a SOAP that's saved, as the place in the stream (as OPS: the back links come+ * from the forward ones) */+ int j = tmp;+ if ((ctype & 2) && j >= 0 && j < parts_active && parts[j].type == PT_SOAP && key_of(j)) {+ uint32_t k = key_of(i), kj = key_of(j);+ link = kj > k ? count_keys(k, kj) : -count_keys(kj, k);+ extra |= X_SOAPLINK;+ }+ if (ctype & 2) tmp = 0;+ if (ctype & 4) tmp2 = 0;+ ctype &= ~6;+ }+ if (t == PT_FIGH) {+ if (tmp >= 0 && tmp < MAX_FIGHTERS) extra |= (fighters[tmp].rocketBoots ? X_BOOTS : 0) | (fighters[tmp].fan ? X_FAN : 0);+ tmp = 0; /* (its fighter: a new one when loaded) */+ }+ bool same = t == w->lastType;+ int refTemp = same ? w->lastTemp : default_temp(t, VERSION);+ uint32_t qx = vel8(p->vx), qy = vel8(p->vy), refx = same ? (uint32_t)w->lastVx : 127, refy = same ? (uint32_t)w->lastVy : 127;+ uint32_t m = (uint32_t)(life != e->DefaultProperties.life) | (uint32_t)(ctype != e->DefaultProperties.ctype) << 1 |+ (uint32_t)(tmp != (int16_t)e->DefaultProperties.tmp) << 2 | (uint32_t)(tmp2 != (int16_t)e->DefaultProperties.tmp2) << 3 |+ (uint32_t)(tmp3 != (int16_t)e->DefaultProperties.tmp3) << 4;+ uint32_t h = (cell == w->lastCell + 1 ? H_NEXTCELL : cell == w->lastCell ? H_SAMECELL : 0) | (same ? H_TYPE : 0) |+ (p->temp == refTemp ? H_TEMP : 0) | (qx == refx && qy == refy ? H_VEL : 0) | (m ? 0 : H_FIELDS) |+ (flags ? H_FLAGS : 0) | (extra ? H_EXTRA : 0);+ w8(w, h);+ if (!(h & (H_NEXTCELL | H_SAMECELL))) wvar(w, (uint32_t)(cell - w->lastCell - 2));+ if (!(h & H_TYPE)) w8(w, (uint32_t)t);+ if (!(h & H_TEMP)) wzig(w, (int)p->temp - refTemp);+ if (!(h & H_VEL)) w8(w, qx), w8(w, qy);+ if (m) {+ w8(w, m);+ if (m & 1) wzig(w, life);+ if (m & 2) wzig(w, ctype);+ if (m & 4) wzig(w, tmp);+ if (m & 8) wzig(w, tmp2);+ if (m & 16) wzig(w, tmp3);+ }+ if (flags) w8(w, flags);+ if (extra) {+ w8(w, (uint32_t)extra);+ if (extra & X_PIPEHI) w8(w, (uint32_t)(tmp4_get(i) >> 24));+ if (extra & X_SOAPLINK) wzig(w, link);+ }+ w->index++, w->lastCell = cell, w->lastType = t, w->lastTemp = p->temp, w->lastVx = (int)qx, w->lastVy = (int)qy;+}++static void write_all(W *w) {+ int count = 0;+ for (int i = 0; i < parts_active; i++) count += key_of(i) != 0;+ for (int k = 0; k < 4; k++) w8(w, (uint8_t)MAGIC[k]);+ w8(w, VERSION);+ wvar(w, (uint32_t)count);+ /* the settings (SaveToSimParameters's) */+ w8(w, settings.heat), w8(w, settings.ambient_heat), w8(w, settings.newtonian_gravity), w8(w, settings.water_equalization);+ w8(w, settings.air_mode), w8(w, settings.gravity_mode), w8(w, settings.edge_mode), w8(w, settings.convection_mode);+ wf(w, settings.custom_gravity_x), wf(w, settings.custom_gravity_y), wf(w, settings.ambient_air_temp);+ wf(w, settings.edge_pressure), wf(w, settings.edge_velocity_x), wf(w, settings.edge_velocity_y), wf(w, settings.vorticity);+ w32(w, frameCount);+ w32(w, (uint32_t)rng_state[0]), w32(w, (uint32_t)(rng_state[0] >> 32));+ w32(w, (uint32_t)rng_state[1]), w32(w, (uint32_t)(rng_state[1] >> 32));+ w32(w, temp_dither);+ /* walls, fans, air */+ wrle(w, &bmap[0][0], XWCELLS * YWCELLS);+ wrle(w, &emap[0][0], XWCELLS * YWCELLS);+ wmap(w, &fvx[0][0], XACELLS * YACELLS, fan8, 127, 1), wmap(w, &fvy[0][0], XACELLS * YACELLS, fan8, 127, 1);+ wmap(w, &pv[0][0], XACELLS * YACELLS, air16, air16(0), 2), wmap(w, &vx[0][0], XACELLS * YACELLS, air16, air16(0), 2);+ wmap(w, &vy[0][0], XACELLS * YACELLS, air16, air16(0), 2);+ wmap(w, &hv[0][0], XACELLS * YACELLS, heat16, heat16(ambientAirTemp), 2);+ wrle(w, &bmap_blockair[0][0], XACELLS * YACELLS);+ wrle(w, &bmap_blockairh[0][0], XACELLS * YACELLS);+ w8(w, (uint32_t)player.rocketBoots | (uint32_t)player.fan << 1 | (uint32_t)player2.rocketBoots << 2 | (uint32_t)player2.fan << 3);+ /* Newtonian gravity's maps (gravIn's and gravOut's) */+ w8(w, ngrav_enable);+ if (ngrav_enable) {+ wfloats(w, &gravmass[0][0], XACELLS * YACELLS);+ wrle(w, &gravmask[0][0], XACELLS * YACELLS);+ wfloats(w, &gravx[0][0], XACELLS * YACELLS), wfloats(w, &gravy[0][0], XACELLS * YACELLS);+ }+ /* the particles, by place */+ mark_extras();+ w->index = 0, w->lastCell = -1, w->lastType = 0;+ uint32_t after = 0;+ for (;;) {+ int n = next_keys(after);+ if (!n) break;+ const uint32_t *h = heap();+ for (int k = 0; k < n; k++) wpart(w, (int)((h[k] - 1) & 0xFFFF));+ after = heap()[n - 1];+ }+}++uint32_t simsave_size(void) {+ W w = {0};+ write_all(&w);+ return w.n;+}++uint32_t simsave_write(uint8_t *out, uint32_t room) {+ W w = {0};+ w.out = out, w.room = room;+ write_all(&w);+ return w.over ? 0 : w.n;+}++/* ---------------------------------------------------------------- reading */+typedef struct { const uint8_t *d; uint32_t n, len; bool bad; } R;+static uint32_t r8(R *r) {+ if (r->n >= r->len) {+ r->bad = true;+ return 0;+ }+ return r->d[r->n++];+}+static uint32_t r32(R *r) {+ uint32_t v = r8(r);+ v |= r8(r) << 8;+ v |= r8(r) << 16;+ return v | r8(r) << 24;+}+static float rf(R *r) {+ union { uint32_t u; float f; } c;+ c.u = r32(r);+ return c.f;+}+static uint32_t rvar(R *r) {+ uint32_t v = 0;+ for (int s = 0; s < 35; s += 7) {+ uint32_t b = r8(r);+ v |= (b & 0x7F) << s;+ if (!(b & 0x80)) return v;+ }+ r->bad = true;+ return v;+}+static int32_t rzig(R *r) {+ uint32_t v = rvar(r);+ return (int32_t)(v >> 1) ^ -(int32_t)(v & 1);+}+/* into a (NULL: only read) */+static void rrle(R *r, uint8_t *a, int n) {+ for (int k = 0; k < n;) {+ int run = (int)r8(r);+ uint8_t v = (uint8_t)r8(r);+ if (!run || r->bad) {+ r->bad = true;+ return;+ }+ for (int j = 0; j < run && k < n; j++, k++)+ if (a) a[k] = v;+ }+}+static void rmap(R *r, float *a, int n, float (*f)(uint32_t), float rest, int bytes) {+ uint32_t bits = r->n;+ r->n += (uint32_t)(n + 7) / 8;+ if (r->n > r->len) {+ r->bad = true;+ return;+ }+ for (int k = 0; k < n; k++) {+ float v = rest;+ if (r->d[bits + k / 8] >> (k & 7) & 1) {+ uint32_t q = r8(r);+ if (bytes == 2) q |= r8(r) << 8;+ v = f(q);+ }+ if (a) a[k] = v;+ }+}+static void rfloats(R *r, float *a, int n) {+ uint32_t bits = r->n;+ r->n += (uint32_t)(n + 7) / 8;+ if (r->n > r->len) {+ r->bad = true;+ return;+ }+ for (int k = 0; k < n; k++) {+ float v = (r->d[bits + k / 8] >> (k & 7) & 1) ? rf(r) : 0;+ if (a) a[k] = v;+ }+}++int simsave_count(const uint8_t *data, uint32_t len) {+ R r = {data, 0, len, false};+ bool magic = true;+ for (int k = 0; k < 4; k++) magic &= r8(&r) == (uint8_t)MAGIC[k];+ int version = r8(&r);+ if (r.bad || !magic || (version != VERSION && version != 2)) return -1;+ uint32_t n = rvar(&r);+ return r.bad || n > 0xFFFF ? -1 : (int)n;+}++/* the new ids of the particles in the stream: as their places, but from where one wasn't made (or another was+ * made with it, STKM's SPAWN) the difference changes; those changes are kept, a few */+#define ID_CHANGES 64+typedef struct {+ struct { uint16_t from; int16_t delta; } at[ID_CHANGES];+ int n, delta;+ bool lost;+ uint16_t lostFrom;+} IdMap;+#define NOT_MADE INT16_MIN+static void idmap_note(IdMap *m, int index, int id) {+ int delta = id < 0 ? NOT_MADE : id - index;+ if (delta == m->delta || m->lost) return;+ if (m->n == ID_CHANGES) {+ m->lost = true, m->lostFrom = (uint16_t)index;+ return;+ }+ m->at[m->n].from = (uint16_t)index, m->at[m->n].delta = (int16_t)delta;+ m->n++, m->delta = delta;+}+static int idmap_get(const IdMap *m, int index) {+ if (m->lost && index >= m->lostFrom) return -1;+ int delta = 0;+ for (int k = 0; k < m->n && m->at[k].from <= index; k++) delta = m->at[k].delta;+ return delta == NOT_MADE ? -1 : index + delta;+}++/* a particle from the stream, made as Simulation::Load makes it; its id or -1 */+static int load_particle(const Particle *p, int extra, int pipeHi, uint32_t boots) {+ int t = p->type, x = p->x / 64, y = p->y / 64;+ if ((player.spwn == 1 && t == PT_STKM) || (player2.spwn == 1 && t == PT_STKM2)) return -1;+ if ((t == PT_SPAWN || t == PT_SPAWN2) && elementCount[t]) return -1;+ if (t == PT_FIGH && !Element_FIGH_CanAlloc()) return -1;+ if (elements[t].CreateAllowed && !elements[t].CreateAllowed(-3, x, y, t)) return -1;+ int i = create_part(-3, x, y, t, -1);+ if (i < 0) return -1;+ int fighter = parts[i].tmp; /* (FIGH: the fighter its ChangeType just took) */+ parts[i] = *p;+ if (t == PT_PIPE || t == PT_PPIP) {+ int v = p->ctype >> 8; /* (24 bits, signed) */+ if (extra & X_PIPEHI) v = (int)(((uint32_t)v & 0xFFFFFF) | (uint32_t)(uint8_t)pipeHi << 24);+ tmp4_set(i, v);+ }+ switch (t) {+ case PT_STKM:+ Element_STKM_init_legs(&player, i);+ player.spwn = 1;+ player.elem = PT_DUST;+ if (boots & 1) player.rocketBoots = true;+ if (boots & 2) player.fan = true;+ break;+ case PT_STKM2:+ Element_STKM_init_legs(&player2, i);+ player2.spwn = 1;+ player2.elem = PT_DUST;+ if (boots & 4) player2.rocketBoots = true;+ if (boots & 8) player2.fan = true;+ break;+ case PT_SPAWN: player.spawnID = i; break;+ case PT_SPAWN2: player2.spawnID = i; break;+ case PT_FIGH:+ /* (the original takes another fighter here and leaves the first one taken; this one keeps it) */+ parts[i].tmp = (int16_t)fighter;+ if (fighter >= 0 && fighter < MAX_FIGHTERS) {+ fighters[fighter].elem = PT_DUST;+ Element_FIGH_NewFighter(fighter, i, parts[i].ctype);+ if (extra & X_BOOTS) fighters[fighter].rocketBoots = true;+ if (extra & X_FAN) fighters[fighter].fan = true;+ } else {+ kill_part(i);+ return -1;+ }+ break;+ default:+ break;+ }+ return i;+}++/* reads it all; real false: only checks it */+static bool read_all(R *r, bool real, int version) {+ int count = (int)rvar(r);+ SimSettings s;+ s.heat = r8(r), s.ambient_heat = r8(r), s.newtonian_gravity = r8(r), s.water_equalization = r8(r);+ s.air_mode = (uint8_t)r8(r), s.gravity_mode = (uint8_t)r8(r), s.edge_mode = (uint8_t)r8(r), s.convection_mode = (uint8_t)r8(r);+ s.custom_gravity_x = rf(r), s.custom_gravity_y = rf(r), s.ambient_air_temp = rf(r);+ s.edge_pressure = rf(r), s.edge_velocity_x = rf(r), s.edge_velocity_y = rf(r), s.vorticity = rf(r);+ uint32_t fc = r32(r);+ uint64_t s0 = r32(r);+ s0 |= (uint64_t)r32(r) << 32;+ uint64_t s1 = r32(r);+ s1 |= (uint64_t)r32(r) << 32;+ uint32_t dither = r32(r);+ if (r->bad) return false;+ if (real) {+ /* SaveToSimParameters, then clear_sim */+ settings = s;+ sim_settings_changed();+ sim_clear();+ }+ rrle(r, real ? &bmap[0][0] : NULL, XWCELLS * YWCELLS);+ rrle(r, real ? &emap[0][0] : NULL, XWCELLS * YWCELLS);+ rmap(r, real ? &fvx[0][0] : NULL, XACELLS * YACELLS, unfan8, 0, 1);+ rmap(r, real ? &fvy[0][0] : NULL, XACELLS * YACELLS, unfan8, 0, 1);+ rmap(r, real ? &pv[0][0] : NULL, XACELLS * YACELLS, unair16, 0, 2);+ rmap(r, real ? &vx[0][0] : NULL, XACELLS * YACELLS, unair16, 0, 2);+ rmap(r, real ? &vy[0][0] : NULL, XACELLS * YACELLS, unair16, 0, 2);+ rmap(r, real ? &hv[0][0] : NULL, XACELLS * YACELLS, unheat16, real ? unheat16(heat16(ambientAirTemp)) : 0, 2);+ rrle(r, real ? &bmap_blockair[0][0] : NULL, XACELLS * YACELLS);+ rrle(r, real ? &bmap_blockairh[0][0] : NULL, XACELLS * YACELLS);+ uint32_t boots = r8(r);+ bool gravMaps = r8(r) != 0;+ if (gravMaps) {+ bool use = real && ngrav_enable; /* (useGravityMaps) */+ rfloats(r, use ? &gravmass[0][0] : NULL, XACELLS * YACELLS);+ rrle(r, use ? &gravmask[0][0] : NULL, XACELLS * YACELLS);+ if (use) grav_exchange(); /* ResetNewtonianGravity: the worker takes these masses */+ rfloats(r, use ? &gravx[0][0] : NULL, XACELLS * YACELLS);+ rfloats(r, use ? &gravy[0][0] : NULL, XACELLS * YACELLS);+ if (use) grav_force_recalc = true;+ }+ if (r->bad) return false;++ /* the particles */+ IdMap ids;+ ids.n = 0, ids.delta = 0, ids.lost = false, ids.lostFrom = 0;+ int cell = -1, type = 0, temp = 0, qx = 127, qy = 127;+ for (int k = 0; k < count; k++) {+ uint32_t h = r8(r);+ if ((h & H_NEXTCELL) && (h & H_SAMECELL)) return false;+ cell += (h & H_NEXTCELL) ? 1 : (h & H_SAMECELL) ? 0 : (int)rvar(r) + 2;+ bool same = (h & H_TYPE) != 0;+ if (!same) type = (int)r8(r);+ if (r->bad || cell < 0 || cell >= XRES * YRES || type <= 0 || type >= PT_NUM || !elements[type].Enabled) return false;+ const Element *e = &elements[type];+ int refTemp = same ? temp : default_temp(type, version);+ temp = (h & H_TEMP) ? refTemp : refTemp + rzig(r);+ if (!same) qx = qy = 127;+ if (!(h & H_VEL)) qx = (int)r8(r), qy = (int)r8(r);+ Particle p;+ memset(&p, 0, sizeof p);+ p.type = (uint8_t)type;+ p.x = (int16_t)(cell % XRES * 64), p.y = (int16_t)(cell / XRES * 64);+ p.vx = unvel8((uint32_t)qx), p.vy = unvel8((uint32_t)qy);+ p.life = (int16_t)e->DefaultProperties.life, p.ctype = e->DefaultProperties.ctype;+ p.tmp = (int16_t)e->DefaultProperties.tmp, p.tmp2 = (int16_t)e->DefaultProperties.tmp2, p.tmp3 = (int16_t)e->DefaultProperties.tmp3;+ if (!(h & H_FIELDS)) {+ uint32_t m = r8(r);+ if (!m || m > 31) return false;+ if (m & 1) p.life = (int16_t)rzig(r);+ if (m & 2) p.ctype = rzig(r);+ if (m & 4) p.tmp = (int16_t)rzig(r);+ if (m & 8) p.tmp2 = (int16_t)rzig(r);+ if (m & 16) p.tmp3 = (int16_t)rzig(r);+ }+ if (h & H_FLAGS) p.flags = (uint8_t)kept_flags(type, r8(r));+ int extra = 0, pipeHi = 0, link = -1;+ if (h & H_EXTRA) {+ extra = (int)r8(r);+ if (extra & X_PIPEHI) pipeHi = (int)r8(r);+ if (extra & X_SOAPLINK) link = k + rzig(r);+ }+ if (r->bad || temp < 0 || temp > (version == 2 ? (int)(MAX_TEMP * P_TEMP + 0.5f) : T_MAXQ) ||+ (extra & X_SOAPLINK && (link < 0 || link >= count)))+ return false;+ /* (a version 2 save's temperatures, as T * 4: the nearest now, whole degrees Celsius exact) */+ p.temp = version == 2 ? temp_q(temp * (1 / P_TEMP)) : (uint16_t)temp;+ if (!real) continue;+ if (type == PT_SOAP) {+ p.ctype &= ~6;+ if (link >= 0) p.ctype |= 2, p.tmp = (int16_t)(uint16_t)link; /* (the place in the stream, for now) */+ }+ idmap_note(&ids, k, load_particle(&p, extra, pipeHi, boots));+ }+ if (r->bad) return false;+ if (!real) return true;++ /* as Simulation::Load ends */+ force_stacking_check = true;+ Element_PPIP_ppip_changed = 1;+ /* (clear_sim asked for a recount: the original's RecalcFreeParticles then counts the particles create_part+ * already counted, twice until the next recount; here they're counted once) */+ if (elementRecount) memset(elementCount, 0, sizeof elementCount);+ RecalcFreeParticles(false);+ /* SOAP's links: the forward ones to the new ids, and the back ones from them */+ for (int i = 0; i < parts_active; i++)+ if (parts[i].type == PT_SOAP && (parts[i].ctype & 2)) {+ int j = idmap_get(&ids, (uint16_t)parts[i].tmp);+ if (j >= 0 && j < parts_active && parts[j].type == PT_SOAP) {+ parts[i].tmp = (int16_t)j;+ parts[j].ctype |= 4;+ parts[j].tmp2 = (int16_t)i;+ } else {+ parts[i].ctype &= ~2;+ parts[i].tmp = 0;+ }+ }+ gravWallChanged = true;+ /* the frame count and random numbers as saved (the original sets them before clear_sim, which zeroes the+ * frame count, and the elements' Create functions use the random numbers while loading) */+ frameCount = fc, rng_state[0] = s0, rng_state[1] = s1, temp_dither = dither;+ return true;+}++bool simsave_read(const uint8_t *data, uint32_t len) {+ if (simsave_count(data, len) < 0) return false;+ int version = data[4];+ R check = {data, 5, len, false};+ if (!read_all(&check, false, version)) return false; /* (all of it checked before anything changes) */+ R r = {data, 5, len, false};+ return read_all(&r, true, version);+}diff --git a/games/numpowder/src/simsave.h b/games/numpowder/src/simsave.hnew file mode 100644index 00000000..e7878f7e--- /dev/null+++ b/games/numpowder/src/simsave.h@@ -0,0 +1,15 @@+/* NumPowder: the simulation as a compact byte stream (the original's Simulation::Save and Load with GameSave's+ * OPS format, for the slots and Home's autosave): the particles by place, the walls, fans and air, Newtonian+ * gravity, the stickmen's boots, the settings, the frame count and the random numbers. As in OPS, particles come+ * back in the middle of their cells with new ids and velocities to 1/16; temperatures are kept to their 1/4 K.+ * Saving changes nothing, and a save of a loaded save is the same bytes. */+#ifndef NP_SIMSAVE_H+#define NP_SIMSAVE_H+#include <stdbool.h>+#include <stdint.h>++uint32_t simsave_size(void); /* the bytes simsave_write writes now */+uint32_t simsave_write(uint8_t *out, uint32_t room); /* 0 if room is too small */+bool simsave_read(const uint8_t *data, uint32_t len); /* false (and the simulation unchanged) if not a save */+int simsave_count(const uint8_t *data, uint32_t len); /* a save's particles, -1 if not a save */+#endifdiff --git a/games/numpowder/src/tools.c b/games/numpowder/src/tools.cnew file mode 100644index 00000000..82d7050c--- /dev/null+++ b/games/numpowder/src/tools.c@@ -0,0 +1,499 @@+/* NumPowder: drawing on the simulation with the brush (Editing.cpp's CreateParts and the rest, the tools of+ * gui/game/tool and simulation/simtools), and the stickmen's keys (GameController). */+#include "simpriv.h"++const SimToolInfo simtools[TOOL_COUNT] = {+ {"DEFAULT_TOOL_HEAT", "HEAT", 0xFFDD00, "Heats the targeted element."},+ {"DEFAULT_TOOL_COOL", "COOL", 0x00DDFF, "Cools the targeted element."},+ {"DEFAULT_TOOL_AIR", "AIR", 0xFFFFFF, "Air, creates airflow and pressure."},+ {"DEFAULT_TOOL_VAC", "VAC", 0x303030, "Vacuum, reduces air pressure."},+ {"DEFAULT_TOOL_PGRV", "PGRV", 0xCCCCFF, "Creates a short-lasting gravity well."},+ {"DEFAULT_TOOL_NGRV", "NGRV", 0xAACCFF, "Creates a short-lasting negative gravity well."},+ {"DEFAULT_TOOL_MIX", "MIX", 0xFFD090, "Mixes particles."},+ {"DEFAULT_TOOL_CYCL", "CYCL", 0x132f5b, "Cyclone, produces swirling air currents"},+ {"DEFAULT_TOOL_AMBM", "AMBM", 0x00DDFF, "Decreases ambient air temperature."},+ {"DEFAULT_TOOL_AMBP", "AMBP", 0xFFDD00, "Increases ambient air temperature."},+ {"DEFAULT_TOOL_WIND", "WIND", 0x404040, "Creates air movement."},+};++Brush brush = {4, 4, BRUSH_CIRCLE};+float tool_strength = 1.0f;+int replaceModeSelected, replaceModeFlags;++/* ---------------------------------------------------------------- the brushes (EllipseBrush with a perfect+ * circle, RectangleBrush, TriangleBrush) */+static int clampr(int r) { return r < 0 ? 0 : r > 200 ? 200 : r; }+/* the ellipse's column i (0..2rx): its rows j (0..2ry) with bottom < j < top */+static int ellipse_top(int i, int rx, int ry) {+ /* the original's test in doubles, times 16 in integers (exact) */+ if (i > rx) i = 2 * rx - i;+ int yTop = ry + 1;+ int64_t a = 4 * (int64_t)(i - rx) * (i - rx) * (2 * ry - 1) * (2 * ry - 1), b = 4 * (int64_t)(2 * rx - 1) * (2 * rx - 1);+ int64_t r2 = 16 * (int64_t)rx * rx * ry * ry;+ while (a + (int64_t)(yTop - ry) * (yTop - ry) * b <= r2) yTop++;+ return yTop;+}+bool brush_has(int dx, int dy) {+ int rx = clampr(brush.rx), ry = clampr(brush.ry);+ if (dx < -rx || dx > rx || dy < -ry || dy > ry) return false;+ switch (brush.shape) {+ case BRUSH_SQUARE:+ return true;+ case BRUSH_TRIANGLE:+ return (abs((rx + 2 * dx) * ry + rx * dy) + abs(2 * rx * (dy - ry)) + abs((rx - 2 * dx) * ry + rx * dy)) <= (4 * rx * ry);+ default: {+ if (!rx) return true; /* a vertical line */+ int i = dx + rx, j = dy + ry;+ if (i == rx && (j == 0 || j == 2 * ry)) return true; /* the top and bottom middle are always in */+ int top = ellipse_top(i, rx, ry), bottom = 2 * ry - top;+ return j > bottom && j < top;+ }+ }+}+/* the brush's points around x, y, in the original's order (bottom row first, left to right) */+typedef void (*BrushFn)(int x, int y, void *u);+static void brush_each(int x, int y, BrushFn fn, void *u) {+ int rx = clampr(brush.rx), ry = clampr(brush.ry);+ if (brush.shape == BRUSH_CIRCLE && rx) {+ int16_t top[201]; /* each column's top (by symmetry, columns 0..rx) */+ for (int i = 0; i <= rx; i++) top[i] = (int16_t)ellipse_top(i, rx, ry);+ for (int dy = ry; dy >= -ry; dy--)+ for (int dx = -rx; dx <= rx; dx++) {+ int i = dx + rx, j = dy + ry, t = top[i > rx ? 2 * rx - i : i];+ if ((j > 2 * ry - t && j < t) || (i == rx && (j == 0 || j == 2 * ry))) fn(x + dx, y + dy, u);+ }+ } else {+ for (int dy = ry; dy >= -ry; dy--)+ for (int dx = -rx; dx <= rx; dx++)+ if (brush_has(dx, dy)) fn(x + dx, y + dy, u);+ }+}++/* ---------------------------------------------------------------- the element tools (Editing.cpp) */+static int CreatePartFlags(int p, int x, int y, int c, int flags) {+ if (x < 0 || y < 0 || x >= XRES || y >= YRES) return 0;+ int pm = PMAPAT(x, y), ph = PHOTAT(x, y);+ if (flags & REPLACE_MODE) {+ /* replace anything there, or a particle of the type on top */+ if ((!replaceModeSelected && (ph || pm)) || (!ph && pm && TYP(pm) == replaceModeSelected) || (ph && TYP(ph) == replaceModeSelected)) {+ if (c) create_part(ph ? ID(ph) : ID(pm), x, y, TYP(c), ID(c));+ else delete_part(x, y);+ }+ return 0;+ } else if (!c) {+ delete_part(x, y);+ return 0;+ } else if (flags & SPECIFIC_DELETE) {+ if ((!replaceModeSelected && (ph || pm)) || (!ph && pm && TYP(pm) == replaceModeSelected) || (ph && TYP(ph) == replaceModeSelected))+ delete_part(x, y);+ return 0;+ }+ return create_part(p, x, y, TYP(c), ID(c)) == -1;+}++typedef struct { int p, c, flags; } PartsCtx;+static void create_at(int x, int y, void *u) {+ PartsCtx *k = u;+ if (x >= 0 && y >= 0 && x < XRES && y < YRES) CreatePartFlags(k->p, x, y, k->c, k->flags);+}+/* CreateParts with the brush */+int CreateParts(int p, int x, int y, int c, int flags) {+ if (flags == -1) flags = replaceModeFlags;+ int rx = brush.rx, ry = brush.ry;+ if (c == PT_LIGH) { /* special case for LIGH */+ if (currentTick < lightningRecreate) return 1;+ int newlife = rx + ry;+ if (newlife > 55) newlife = 55;+ c = PMAP(newlife, c);+ lightningRecreate = currentTick + imax(newlife / 4, 1);+ return CreatePartFlags(p, x, y, c, flags);+ } else if (c == PT_TESC) {+ int newtmp = rx * 4 + ry * 4 + 7;+ if (newtmp > 300) newtmp = 300;+ c = PMAP(newtmp, c);+ }+ PartsCtx k = {p, c, flags};+ brush_each(x, y, create_at, &k);+ return 0;+}+/* CreateParts in a rectangle of radii rx, ry */+int CreatePartsR(int p, int x, int y, int rx, int ry, int c, int flags) {+ bool created = false;+ if (flags == -1) flags = replaceModeFlags;+ if (c == PT_LIGH) {+ if (currentTick < lightningRecreate) return 1;+ int newlife = rx + ry;+ if (newlife > 55) newlife = 55;+ c = PMAP(newlife, c);+ lightningRecreate = currentTick + imax(newlife / 4, 1);+ rx = ry = 0;+ } else if (c == PT_TESC) {+ int newtmp = rx * 4 + ry * 4 + 7;+ if (newtmp > 300) newtmp = 300;+ c = PMAP(newtmp, c);+ }+ for (int j = -ry; j <= ry; j++)+ for (int i = -rx; i <= rx; i++)+ if (CreatePartFlags(p, x + i, y + j, c, flags)) created = true;+ return !created;+}++void CreateLineBrush(int x1, int y1, int x2, int y2, int c, int flags) {+ int x, y, dx, dy, sy, rx = brush.rx, ry = brush.ry;+ bool reverseXY = abs(y2 - y1) > abs(x2 - x1);+ float e = 0.0f, de;+ if (reverseXY) {+ y = x1, x1 = y1, y1 = y;+ y = x2, x2 = y2, y2 = y;+ }+ if (x1 > x2) {+ y = x1, x1 = x2, x2 = y;+ y = y1, y1 = y2, y2 = y;+ }+ dx = x2 - x1;+ dy = abs(y2 - y1);+ de = dx ? dy / (float)dx : 0.0f;+ y = y1;+ sy = (y1 < y2) ? 1 : -1;+ for (x = x1; x <= x2; x++) {+ if (reverseXY) CreateParts(-2, y, x, c, flags);+ else CreateParts(-2, x, y, c, flags);+ e += de;+ if (e >= 0.5f) {+ y += sy;+ if (!(rx + ry) && ((y1 < y2) ? (y <= y2) : (y >= y2))) {+ if (reverseXY) CreateParts(-2, y, x, c, flags);+ else CreateParts(-2, x, y, c, flags);+ }+ e -= 1.0f;+ }+ }+}++void CreateBox(int p, int x1, int y1, int x2, int y2, int c, int flags) {+ int i, j;+ if (x1 > x2) i = x2, x2 = x1, x1 = i;+ if (y1 > y2) j = y2, y2 = y1, y1 = j;+ for (j = y2; j >= y1; j--)+ for (i = x1; i <= x2; i++) CreatePartsR(p, i, j, 0, 0, c, flags);+}++/* the flood fill's bitmap and stack in the scratch RAM (as sim.c's) */+#define FLOOD_BITMAP ((XRES * YRES + 7) / 8)+static inline bool fb_get(int x, int y) {+ int k = y * XRES + x;+ return sim_scratch[k >> 3] >> (k & 7) & 1;+}+static inline void fb_set(int x, int y) {+ int k = y * XRES + x;+ sim_scratch[k >> 3] |= (uint8_t)(1 << (k & 7));+}++int FloodParts(int x, int y, int fullc, int cm, int flags) {+ int c = TYP(fullc);+ int x1, x2, dy = 1, created_something = 0;+ if (cm == -1) {+ /* outside: nothing */+ if (c != 0 && (x < BORDER || x >= XRES - BORDER || y < BORDER || y >= YRES - BORDER || c == PT_SPRK)) return 1;+ else if (x < 0 || x >= XRES || y < 0 || y >= YRES) return 1;+ if (c == 0) {+ cm = TYP(PMAPAT(x, y));+ if (!cm) {+ cm = TYP(PHOTAT(x, y));+ if (!cm) {+ if (bmap[y / WCELL][x / WCELL]) return FloodWalls(x, y, WL_ERASE, -1);+ return -1;+ }+ }+ } else {+ cm = 0;+ }+ }+ if (c != 0 && IsWallBlocking(x, y, c)) return 1;+ if (!FloodFillPmapCheck(x, y, cm)) return 1;+ memset(sim_scratch, 0, FLOOD_BITMAP);+ flood_stack_init(FLOOD_BITMAP);+ flood_stack_push(x, y);+ do {+ flood_stack_pop(&x, &y);+ x1 = x2 = x;+ /* go left as far as possible */+ while (c ? x1 > BORDER : x1 > 0) {+ if (fb_get(x1 - 1, y) || !FloodFillPmapCheck(x1 - 1, y, cm) || (c != 0 && IsWallBlocking(x1 - 1, y, c))) break;+ x1--;+ }+ while (c ? x2 < XRES - BORDER - 1 : x2 < XRES - 1) {+ if (fb_get(x2 + 1, y) || !FloodFillPmapCheck(x2 + 1, y, cm) || (c != 0 && IsWallBlocking(x2 + 1, y, c))) break;+ x2++;+ }+ /* fill span */+ for (x = x1; x <= x2; x++) {+ if (!fullc) {+ if (elements[cm].Properties & TYPE_ENERGY) {+ if (photons_id[y][x]) {+ kill_part(photons_id[y][x] - 1);+ created_something = 1;+ }+ } else if (pmap_id[y][x]) {+ kill_part(pmap_id[y][x] - 1);+ created_something = 1;+ }+ } else if (CreatePartsR(-2, x, y, 0, 0, fullc, flags)) {+ created_something = 1;+ }+ fb_set(x, y);+ }+ if (c ? y >= BORDER + dy : y >= dy)+ for (x = x1; x <= x2; x++)+ if (!fb_get(x, y - dy) && FloodFillPmapCheck(x, y - dy, cm) && (c == 0 || !IsWallBlocking(x, y - dy, c)))+ if (!flood_stack_push(x, y - dy)) return -1;+ if (c ? y < YRES - BORDER - dy : y < YRES - dy)+ for (x = x1; x <= x2; x++)+ if (!fb_get(x, y + dy) && FloodFillPmapCheck(x, y + dy, cm) && (c == 0 || !IsWallBlocking(x, y + dy, c)))+ if (!flood_stack_push(x, y + dy)) return -1;+ } while (flood_stack_size() > 0);+ return created_something;+}++/* ---------------------------------------------------------------- the simulation tools (simtools/) */+static int tool_perform(int tool, Particle *cpart, int x, int y, int brushX, int brushY, float strength) {+ int ax = x / ACELL, ay = y / ACELL;+ switch (tool) {+ case TOOL_HEAT:+ case TOOL_COOL: {+ if (!cpart) return 0;+ float d = (cpart->type == PT_PUMP || cpart->type == PT_GPMP) ? strength * .1f : strength * 2.0f;+ /* (kept within 0 and MAX_TEMP; dithered: PUMP's and GPMP's 0.1 K a time is under a step of 1/4 K) */+ p_set_temp_d(cpart, p_temp(cpart) + (tool == TOOL_HEAT ? d : -d));+ return 1;+ }+ case TOOL_AIR:+ case TOOL_VAC:+ pv[ay][ax] += (tool == TOOL_AIR ? strength : -strength) * 0.05f;+ if (pv[ay][ax] > MAX_PRESSURE) pv[ay][ax] = MAX_PRESSURE;+ else if (pv[ay][ax] < MIN_PRESSURE) pv[ay][ax] = MIN_PRESSURE;+ return 1;+ case TOOL_PGRV:+ gravmass[ay][ax] = strength * 5.0f;+ return 1;+ case TOOL_NGRV:+ gravmass[ay][ax] = strength * -5.0f;+ return 1;+ case TOOL_MIX: {+ int thisPart = PMAPAT(x, y);+ if (!thisPart) return 0;+ if (rng_u32() % 100 != 0) return 0;+ int distance = (int)(powf(strength, .5f) * 10);+ if (distance <= 0) return 0;+ if (!(elements[TYP(thisPart)].Properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS))) return 0;+ int newX = x + (int)(rng_u32() % (unsigned)distance) - (distance / 2);+ int newY = y + (int)(rng_u32() % (unsigned)distance) - (distance / 2);+ if (newX < 0 || newY < 0 || newX >= XRES || newY >= YRES) return 0;+ int thatPart = PMAPAT(newX, newY);+ if (!thatPart) return 0;+ if ((elements[TYP(thisPart)].Properties & STATE_FLAGS) != (elements[TYP(thatPart)].Properties & STATE_FLAGS)) return 0;+ PMAPSET(x, y, thatPart);+ parts[ID(thatPart)].x = (int16_t)(x * 64);+ parts[ID(thatPart)].y = (int16_t)(y * 64);+ PMAPSET(newX, newY, thisPart);+ parts[ID(thisPart)].x = (int16_t)(newX * 64);+ parts[ID(thisPart)].y = (int16_t)(newY * 64);+ return 1;+ }+ case TOOL_CYCL:+ /* once per air cell (less laggy): the air turns around the brush's middle */+ if ((x % ACELL) == 0 && (y % ACELL) == 0) {+ if (brushX == x && brushY == y) return 1;+ float dvx = (float)(brushX - x), dvy = (float)(brushY - y);+ float invsqr = 1 / sqrtf(dvx * dvx + dvy * dvy);+ vx[ay][ax] -= (strength / 16) * (-dvy) * invsqr;+ vy[ay][ax] -= (strength / 16) * dvx * invsqr;+ if (vx[ay][ax] > MAX_PRESSURE) vx[ay][ax] = MAX_PRESSURE;+ else if (vx[ay][ax] < MIN_PRESSURE) vx[ay][ax] = MIN_PRESSURE;+ if (vy[ay][ax] > MAX_PRESSURE) vy[ay][ax] = MAX_PRESSURE;+ else if (vy[ay][ax] < MIN_PRESSURE) vy[ay][ax] = MIN_PRESSURE;+ }+ return 1;+ case TOOL_AMBM:+ case TOOL_AMBP:+ if (!aheat_enable) return 0;+ hv[ay][ax] += (tool == TOOL_AMBP ? strength : -strength) * 2.0f;+ if (hv[ay][ax] > MAX_TEMP) hv[ay][ax] = MAX_TEMP;+ if (hv[ay][ax] < MIN_TEMP) hv[ay][ax] = MIN_TEMP;+ return 1;+ default: /* (WIND has no Perform) */+ return 0;+ }+}+/* SimTool::CallPerform */+static void call_perform(int tool, int x, int y, int brushX, int brushY, float strength) {+ Particle *cpart = NULL;+ if (pmap_id[y][x]) cpart = &parts[pmap_id[y][x] - 1];+ else if (photons_id[y][x]) cpart = &parts[photons_id[y][x] - 1];+ tool_perform(tool, cpart, x, y, brushX, brushY, strength);+}+typedef struct { int tool, bx, by; float strength; } PerformCtx;+static void perform_at(int x, int y, void *u) {+ PerformCtx *k = u;+ if (x >= 0 && y >= 0 && x < XRES && y < YRES) call_perform(k->tool, x, y, k->bx, k->by, k->strength);+}+static void tool_draw(int tool, int x, int y, float strength) { /* defaultPerformDraw */+ PerformCtx k = {tool, x, y, strength};+ brush_each(x, y, perform_at, &k);+}+typedef struct { float dx, dy; } WindCtx;+static void wind_at(int x, int y, void *u) {+ WindCtx *k = u;+ if (x >= 0 && y >= 0 && x < XRES && y < YRES) {+ vx[y / ACELL][x / ACELL] += k->dx;+ vy[y / ACELL][x / ACELL] += k->dy;+ }+}+static void tool_draw_line(int tool, int x1, int y1, int x2, int y2, bool dragging, float strength) {+ if (tool == TOOL_WIND) { /* WIND's performDrawLine */+ float s = (dragging ? 0.01f : 0.002f) * strength;+ WindCtx k = {(x2 - x1) * s, (y2 - y1) * s};+ brush_each(x1, y1, wind_at, &k);+ return;+ }+ /* defaultPerformDrawLine */+ int x, y, dx, dy, sy, rx = brush.rx, ry = brush.ry;+ bool reverseXY = abs(y2 - y1) > abs(x2 - x1);+ float e = 0.0f, de;+ if (reverseXY) {+ y = x1, x1 = y1, y1 = y;+ y = x2, x2 = y2, y2 = y;+ }+ if (x1 > x2) {+ y = x1, x1 = x2, x2 = y;+ y = y1, y1 = y2, y2 = y;+ }+ dx = x2 - x1;+ dy = abs(y2 - y1);+ de = dx ? dy / (float)dx : 0.0f;+ y = y1;+ sy = (y1 < y2) ? 1 : -1;+ for (x = x1; x <= x2; x++) {+ if (reverseXY) tool_draw(tool, y, x, strength);+ else tool_draw(tool, x, y, strength);+ e += de;+ if (e >= 0.5f) {+ y += sy;+ if (!(rx + ry) && ((y1 < y2) ? (y <= y2) : (y >= y2))) {+ if (reverseXY) tool_draw(tool, y, x, strength);+ else tool_draw(tool, x, y, strength);+ }+ e -= 1.0f;+ }+ }+}+static void tool_draw_rect(int tool, int x1, int y1, int x2, int y2, float strength) { /* defaultPerformDrawRect */+ int brushX = (x1 + x2) / 2, brushY = (y1 + y2) / 2;+ int tlx = imin(x1, x2), tly = imin(y1, y2), brx = imax(x1, x2), bry = imax(y1, y2);+ for (int y = tly; y <= bry; y++)+ for (int x = tlx; x <= brx; x++)+ if (x >= 0 && y >= 0 && x < XRES && y < YRES) call_perform(tool, x, y, brushX, brushY, strength);+}++/* ---------------------------------------------------------------- the tools as the interface uses them */+static bool plop_tool(int c) { return c == PT_STKM || c == PT_STKM2 || c == PT_FIGH; }++void sim_tool_points(int tool, int x1, int y1, int x2, int y2, bool held) {+ if (tool & TOOL_WALLS) {+ int wall = tool & 0xFF;+ if (!held) CreateWalls(x2, y2, 1, 1, wall, true);+ else CreateWallLine(x1, y1, x2, y2, 1, 1, wall, true);+ } else if (tool & TOOL_SIMTOOLS) {+ int t = tool & 0xFF;+ if (!held) tool_draw(t, x2, y2, tool_strength);+ else tool_draw_line(t, x1, y1, x2, y2, true, tool_strength);+ } else if (plop_tool(tool)) {+ /* PlopTool: one, where clicked */+ if (!held) create_part(-2, x2, y2, TYP(tool), ID(tool));+ } else if (tool == PT_LIGH) {+ /* Element_LIGH_Tool: drawn while dragging, in the brush's rectangle */+ if (!held) CreateParts(-2, x2, y2, tool, -1);+ else CreatePartsR(-2, x1, y1, brush.rx, brush.ry, PT_LIGH, -1);+ } else {+ if (!held) CreateParts(-2, x2, y2, tool, -1);+ else CreateLineBrush(x1, y1, x2, y2, tool, -1);+ }+}++void sim_tool_line(int tool, int x1, int y1, int x2, int y2) {+ if (tool & TOOL_WALLS) {+ int wall = tool & 0xFF;+ int wallX = x1 / WCELL, wallY = y1 / WCELL;+ if (wall == WL_FAN && bmap[wallY][wallX] == WL_FAN) {+ /* the fans connected to the start get the line's direction and strength */+ float newFanVelX = (x2 - x1) * 0.005f, newFanVelY = (y2 - y1) * 0.005f;+ FloodWalls(x1, y1, WL_FLOODHELPER, WL_FAN);+ for (int j = 0; j < YWCELLS; j++)+ for (int i = 0; i < XWCELLS; i++)+ if (bmap[j][i] == WL_FLOODHELPER) {+ fvx[j * WCELL / ACELL][i * WCELL / ACELL] = newFanVelX;+ fvy[j * WCELL / ACELL][i * WCELL / ACELL] = newFanVelY;+ bmap[j][i] = WL_FAN;+ }+ } else {+ CreateWallLine(x1, y1, x2, y2, 1, 1, wall, true);+ }+ } else if (tool & TOOL_SIMTOOLS) {+ tool_draw_line(tool & 0xFF, x1, y1, x2, y2, false, 1.0f);+ } else if (plop_tool(tool)) {+ } else if (tool == PT_LIGH) {+ /* (not dragging: nothing) */+ } else {+ CreateLineBrush(x1, y1, x2, y2, tool, -1);+ }+}++void sim_tool_box(int tool, int x1, int y1, int x2, int y2) {+ if (tool & TOOL_WALLS) CreateWallBox(x1, y1, x2, y2, tool & 0xFF);+ else if (tool & TOOL_SIMTOOLS) tool_draw_rect(tool & 0xFF, x1, y1, x2, y2, 1.0f);+ else if (plop_tool(tool)) return;+ else if (tool == PT_TESC) CreateBox(-2, x1, y1, x2, y2, tool | PMAPID(brush.rx * 4 + brush.ry * 4 + 7), -1);+ else CreateBox(-2, x1, y1, x2, y2, tool, -1);+}++void sim_tool_fill(int tool, int x, int y) {+ if (tool & TOOL_WALLS) {+ if ((tool & 0xFF) != WL_STREAM) FloodWalls(x, y, tool & 0xFF, -1);+ } else if (tool & TOOL_SIMTOOLS) {+ /* (no fill) */+ } else if (plop_tool(tool)) {+ } else if (tool == PT_TESC) {+ FloodParts(x, y, tool | PMAPID(brush.rx * 4 + brush.ry * 4 + 7), -1, -1);+ } else {+ FloodParts(x, y, tool, -1, -1);+ }+}++/* ---------------------------------------------------------------- the stickmen's keys (GameController) */+void stkm_key(int who, int key, bool down) {+ playerst *pl = who ? &player2 : &player;+ if (down) {+ if (key == STKM_RIGHT) pl->comm = (char)(pl->comm | 0x02);+ else if (key == STKM_LEFT) pl->comm = (char)(pl->comm | 0x01);+ else if (key == STKM_DOWN && (pl->comm & 0x08) != 0x08) pl->comm = (char)(pl->comm | 0x08);+ else if (key == STKM_UP && (pl->comm & 0x04) != 0x04) pl->comm = (char)(pl->comm | 0x04);+ } else {+ if (key == STKM_RIGHT || key == STKM_LEFT) {+ pl->pcomm = pl->comm; /* the last movement */+ pl->comm = (char)(pl->comm & 12);+ } else if (key == STKM_UP) {+ pl->comm = (char)(pl->comm & 11);+ } else if (key == STKM_DOWN) {+ pl->comm = (char)(pl->comm & 7);+ }+ }+}++void stkm_frame(int rightElement) {+ if (!player.spwn || !player2.spwn) {+ int rightSelected = PT_DUST;+ if (rightElement && IsElementOrNone(rightElement)) rightSelected = rightElement;+ if (!player.spwn) Element_STKM_set_element(&player, rightSelected);+ if (!player2.spwn) Element_STKM_set_element(&player2, rightSelected);+ }+}diff --git a/games/numpowder/src/ui.c b/games/numpowder/src/ui.cnew file mode 100644index 00000000..596acbfd--- /dev/null+++ b/games/numpowder/src/ui.c@@ -0,0 +1,277 @@+/* NumPowder: the interface's modes and keys (the original's GameView and GameController on a keypad): the cursor+ * and the brush, drawing (DrawPoints), lines, boxes and fills (shift-drag, ctrl-drag, flood fill), sampling,+ * pausing, the stickmen, the welcome card, and the menus and windows (ui_menu.c, ui_opts.c, ui_save.c). */+#include "ui.h"+#include <string.h>++Ui ui;+/* the welcome card's clock: when it began to fade (by 60 a second, as the original's introText) */+static uint32_t intro_t0;++void ui_message(const char *text) {+ ui.tip_text = text;+ ui.tip = 120; /* (the original's infoTipPresence) */+}++void ui_init(void) {+ memset(&ui, 0, sizeof ui);+ ui.cx = XRES / 2, ui.cy = YRES / 2;+ ui.tool[0] = PT_DUST, ui.tool[1] = PT_NONE; /* (the original's: DUST and NONE) */+ ui.section = SC_POWDERS;+ ui.held = -1;+ ui.intro = 2048;+ brush.rx = brush.ry = 2, brush.shape = BRUSH_CIRCLE;+ /* things stop at the screen's edges (the original's default lets them fall out of it: a bottomless pit on so small+ * a screen); a configuration or an autosave keeps its own */+ settings.edge_mode = EDGE_SOLID;+ sim_settings_changed();+ saves_restore();+ config_load();+ /* the last session's simulation, from the autosave */+ if (slot_used(0, NULL)) load_slot(0);+ ui.tip = 0;+}++bool ui_home(void) {+ static uint32_t failed_at;+ bool ok = save_slot(0) != SAVE_NOROOM;+ if (!ok && (!failed_at || plat_millis() - failed_at > 4000)) {+ /* (the save failed: Home again within a few seconds quits all the same) */+ failed_at = plat_millis();+ ui_message("Not saved: Home again quits anyway");+ return false;+ }+ return true;+}++/* ---------------------------------------------------------------- the cursor */+/* the arrows: a step when pressed, then held a step every frame (shift: 4) */+static void cursor_keys(void) {+ int step = key_held(K_SHIFT) ? 4 : 1;+ static const uint32_t keys[4] = {K_LEFT, K_RIGHT, K_UP, K_DOWN};+ static const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};+ for (int k = 0; k < 4; k++) {+ int bit = __builtin_ctz(keys[k]);+ int held = input.held_ticks[bit];+ if (key_pressed(keys[k]) || (held > 6)) ui.cx += dx[k] * step, ui.cy += dy[k] * step;+ }+ ui.cx = ui.cx < 0 ? 0 : ui.cx >= XRES ? XRES - 1 : ui.cx;+ ui.cy = ui.cy < 0 ? 0 : ui.cy >= YRES ? YRES - 1 : ui.cy;+}++/* Brush::AdjustSize(delta, logarithmic) */+static void brush_size(int d) {+ int r = brush.rx;+ r += d * (r / 5 > 1 ? r / 5 : 1);+ r = r < 0 ? 0 : r > 40 ? 40 : r;+ brush.rx = brush.ry = r;+}++static bool is_plop(int tool) {+ int t = TYP(tool);+ return tool_is_element(tool) && (t == PT_STKM || t == PT_STKM2 || t == PT_FIGH);+}++/* a tool pressed (GameView's mouse down) */+static void tool_press(int side) {+ int tool = ui.tool[side];+ if (tool == TOOL_SAMPLE) {+ sample_at(ui.cx, ui.cy);+ return;+ }+ if (is_plop(tool)) {+ /* PlopTool: one, where clicked; then the arrows move it */+ sim_tool_points(tool, ui.cx, ui.cy, ui.cx, ui.cy, false);+ if (TYP(tool) != PT_FIGH && (elementCount[PT_STKM] || elementCount[PT_STKM2] || TYP(tool) == PT_STKM || TYP(tool) == PT_STKM2)) {+ ui.mode = MODE_STKM;+ ui_message("Arrows: the stickman. Back: the brush");+ }+ return;+ }+ ui.held = (int8_t)side;+ ui.lx = ui.cx, ui.ly = ui.cy;+ tool_strength = 1.0f;+ sim_tool_points(tool, ui.cx, ui.cy, ui.cx, ui.cy, false);+}++static void sim_keys(void) {+ bool shift = key_held(K_SHIFT);+ if (key_pressed(K_TOOLBOX)) {+ ui.held = -1;+ menu_open();+ return;+ }+ if (key_pressed(K_VAR)) {+ ui.held = -1;+ options_open();+ return;+ }+ cursor_keys();+ /* drawing: OK the left tool, Back the right one; with shift, a line from here */+ bool pressed = false;+ for (int side = 0; side < 2; side++) {+ uint32_t k = side ? K_BACK : K_OK;+ if (key_pressed(k) && ui.held < 0) {+ if (shift && !is_plop(ui.tool[side]) && ui.tool[side] != TOOL_SAMPLE) {+ ui.mode = MODE_SHAPE;+ ui.shape = SHAPE_LINE;+ ui.shape_side = (uint8_t)side;+ ui.sx = ui.cx, ui.sy = ui.cy;+ return;+ }+ tool_press(side);+ pressed = true;+ }+ }+ if (ui.held >= 0 && !pressed) {+ uint32_t k = ui.held ? K_BACK : K_OK;+ if (!key_held(k)) {+ ui.held = -1;+ } else {+ /* held: every frame, from where it drew last (DrawPoints held) */+ sim_tool_points(ui.tool[(int)ui.held], ui.lx, ui.ly, ui.cx, ui.cy, true);+ ui.lx = ui.cx, ui.ly = ui.cy;+ }+ }+ if (key_pressed(K_ALPHA)) {+ if (shift) {+ sys_pause = true;+ ui.step = true;+ } else {+ sys_pause = !sys_pause;+ ui_message(sys_pause ? "Paused" : "Resumed");+ }+ }+ if (key_repeat(K_PLUS)) {+ if (shift) brush.shape = (uint8_t)((brush.shape + 1) % NUM_BRUSHES);+ else brush_size(1);+ }+ if (key_repeat(K_MINUS)) {+ if (shift) brush.shape = (uint8_t)((brush.shape + NUM_BRUSHES - 1) % NUM_BRUSHES);+ else brush_size(-1);+ }+ if (key_pressed(K_BACKSPACE)) sample_at(ui.cx, ui.cy);+}++static void shape_keys(void) {+ cursor_keys();+ /* (backspace cycles the shapes: shift is the cursor's speed, as everywhere) */+ if (key_pressed(K_BACKSPACE)) ui.shape = (uint8_t)((ui.shape + 1) % NUM_SHAPES);+ if (key_pressed(K_BACK) || key_pressed(K_TOOLBOX) || key_pressed(K_VAR)) {+ /* (the shape cancelled; toolbox and var still open their menus) */+ ui.mode = MODE_SIM;+ if (key_pressed(K_TOOLBOX)) menu_open();+ else if (key_pressed(K_VAR)) options_open();+ return;+ }+ if (key_pressed(K_OK)) {+ int tool = ui.tool[ui.shape_side];+ tool_strength = 1.0f;+ if (ui.shape == SHAPE_LINE) sim_tool_line(tool, ui.sx, ui.sy, ui.cx, ui.cy);+ else if (ui.shape == SHAPE_BOX) sim_tool_box(tool, ui.sx, ui.sy, ui.cx, ui.cy);+ else sim_tool_fill(tool, ui.cx, ui.cy);+ ui.mode = MODE_SIM;+ }+}++/* the stickmen (GameController::KeyPress/KeyRelease's arrows): shift held for the second one */+static uint8_t stkm_down[2];+static void stkm_keys(void) {+ static const uint32_t keys[4] = {K_LEFT, K_RIGHT, K_UP, K_DOWN};+ static const int cmds[4] = {STKM_LEFT, STKM_RIGHT, STKM_UP, STKM_DOWN};+ /* (kept while a stickman or a spawn point exists: dying, it comes back at its SPWN the next frame) */+ bool leave = key_pressed(K_BACK) || key_pressed(K_TOOLBOX) || key_pressed(K_VAR) ||+ !(elementCount[PT_STKM] || elementCount[PT_STKM2] || elementCount[PT_SPAWN] || elementCount[PT_SPAWN2]);+ int who = key_held(K_SHIFT) ? 1 : 0;+ for (int k = 0; k < 4; k++) {+ for (int w = 0; w < 2; w++) {+ bool want = !leave && w == who && key_held(keys[k]);+ bool was = stkm_down[w] & (1 << k);+ if (want != was) {+ stkm_key(w, cmds[k], want);+ stkm_down[w] = (uint8_t)(want ? stkm_down[w] | (1 << k) : stkm_down[w] & ~(1 << k));+ }+ }+ }+ if (key_pressed(K_ALPHA)) sys_pause = !sys_pause;+ if (leave) {+ ui.mode = MODE_SIM;+ if (key_pressed(K_TOOLBOX)) menu_open();+ if (key_pressed(K_VAR)) options_open();+ }+}++bool ui_tick(void) {+ if (key_pressed(K_HOME)) return !ui_home();+ if (ui.intro > 0) {+ /* the welcome card stays until a key (but Home), which does nothing else; then it fades out in under a second */+ uint32_t now = plat_millis();+ if (ui.intro > 50) {+ if (!input.pressed) return true;+ intro_t0 = now;+ ui.intro = 50;+ return true;+ }+ int32_t left = 50 - (int32_t)((now - intro_t0) * 60 / 1000);+ ui.intro = (int16_t)(left > 0 ? left : 0);+ }+ switch (ui.mode) {+ case MODE_SIM: sim_keys(); break;+ case MODE_SHAPE: shape_keys(); break;+ case MODE_STKM: stkm_keys(); break;+ case MODE_MENU: menu_keys(); break;+ case MODE_OPTIONS: options_keys(); break;+ case MODE_SETTINGS: settings_keys(); break;+ case MODE_CONFIRM: confirm_keys(); break;+ case MODE_SAVES: saves_keys(); break;+ case MODE_TEXT: text_keys(); break;+ }+ if (ui.mode != MODE_SIM) ui.held = -1;+ if (ui.tip > 0) ui.tip--;+ return true;+}++/* ---------------------------------------------------------------- drawing */+/* what the panel below the sim shows: drawn again only when it changes */+static uint32_t panel_sig(void) {+ uint32_t h = 2166136261u;+#define MIX(v) (h = (h ^ (uint32_t)(v)) * 16777619u)+ MIX(ui.mode), MIX(ui.section), MIX(ui.sel), MIX(ui.scroll), MIX(ui.text), MIX(ui.shape);+ MIX(ui.tool[0]), MIX(ui.tool[1]), MIX(sys_pause), MIX(brush.rx), MIX(brush.ry), MIX(brush.shape);+ MIX(ui.nfav), MIX(ui.intro > 0 ? ui.intro : 0);+ for (int k = 0; k < ui.nfav; k++) MIX(ui.fav[k]);+#undef MIX+ return h;+}++int ui_draw(Overlay *o, bool *panel) {+ static uint32_t last_sig;+ uint32_t sig = panel_sig();+ if (sig != last_sig || ui.intro > 0) *panel = true;+ last_sig = sig;+ bool sim_view = (ui.mode == MODE_SIM || ui.mode == MODE_SHAPE || ui.mode == MODE_MENU) && ui.intro <= 0;+ if (sim_view) brush_draw(o);+ if ((sim_view || ui.mode == MODE_STKM) && ui.intro <= 0) stickman_hp(o);+ if (ui.intro < 51) hud_draw(o);+ switch (ui.mode) {+ case MODE_MENU: menu_draw(o, *panel); break;+ case MODE_OPTIONS: options_draw(o); break;+ case MODE_SETTINGS: settings_draw(o); break;+ case MODE_CONFIRM: confirm_draw(o); break;+ case MODE_SAVES: saves_draw(o); break;+ case MODE_TEXT: text_draw(o); break;+ }+ /* the info tip (GameView's infoTip): in the middle, fading; not over a window's text (the settings show it on+ * their details' line, the others just below the sim) */+ if (ui.tip > 0 && ui.tip_text && ui.mode != MODE_SETTINGS) {+ int a = (ui.tip > 50 ? 50 : ui.tip) * 5;+ bool window = ui.mode == MODE_SAVES || ui.mode == MODE_CONFIRM || ui.mode == MODE_TEXT || ui.mode == MODE_OPTIONS;+ int tw = font_text_width(ui.tip_text) - 1;+ if (window) ov_text_outline(o, SIM_X + (SIM_W - tw) / 2, SIM_H - 14, ui.tip_text, 0xFFFFFF, a);+ else ov_text_outline(o, SIM_X + (SIM_W - tw) / 2, SIM_H / 2 - 2, ui.tip_text, 0xFFFFFF, a);+ }+ if (*panel) panel_draw(o);+ if (ui.intro > 0) intro_draw(o);+ /* (the material menu's list of sections stays on the screen as it is until the panel changes) */+ return ui.mode == MODE_MENU ? MENU_LIST_X : SCREEN_W;+}diff --git a/games/numpowder/src/ui.h b/games/numpowder/src/ui.hnew file mode 100644index 00000000..b43f84cc--- /dev/null+++ b/games/numpowder/src/ui.h@@ -0,0 +1,131 @@+/* NumPowder: the interface on the keypad: the original's simulation, element buttons, font and windows, without+ * its desktop chrome. The sim's area at the top; below it, a panel saying what OK and Back draw with, the brush, and+ * a line of the keys that do something now. toolbox opens the materials (the original's menu sections, by name, and+ * their buttons), var a short menu (how to play, keys, saves, the display, the settings).+ *+ * ui.c: the modes and the keys; ui_menu.c: the material menu; ui_draw.c: the panel, the brush, the hover info and+ * the debug HUD, the welcome card; ui_opts.c: the menu, the settings, the windows (confirm, text pages); ui_save.c:+ * the save slots and their copy in a Python script. */+#ifndef NP_UI_H+#define NP_UI_H+#include "input.h"+#include "render.h"++/* the interface's own tools, besides the core's (elements, TOOL_WALLS + WL_*, TOOL_SIMTOOLS + TOOL_*) */+#define TOOL_UI 0x10000000+#define TOOL_SAMPLE (TOOL_UI + 0) /* SMPL: picks the element under the cursor */+static inline bool tool_is_element(int tool) { return !(tool & (TOOL_WALLS | TOOL_SIMTOOLS | TOOL_UI)); }++enum {+ MODE_SIM, /* drawing on the sim */+ MODE_SHAPE, /* a line, box or fill being placed (shift + OK) */+ MODE_STKM, /* the arrows move the stickmen */+ MODE_MENU, /* the material menu (toolbox) */+ MODE_OPTIONS, /* the menu (var) */+ MODE_SETTINGS, /* its settings */+ MODE_CONFIRM, /* a question: OK yes, Back no */+ MODE_SAVES, /* the save slots */+ MODE_TEXT, /* how to play, keys, credits */+};+enum { SHAPE_LINE, SHAPE_BOX, SHAPE_FILL, NUM_SHAPES };+enum { CONFIRM_CLEAR, CONFIRM_LOAD, CONFIRM_OVERWRITE };+enum { TEXT_HELP, TEXT_KEYS, TEXT_CREDITS };++#define NFAV 12+typedef struct {+ uint8_t mode, prev_mode;+ int cx, cy; /* the cursor, in particles */+ int lx, ly; /* where the held tool drew last */+ int8_t held; /* the tool held down: 0 (OK) or 1 (Back), -1 none */+ int tool[2]; /* the left (OK) and right (Back) tools */+ uint8_t section; /* the element menu's section */+ int sel; /* its selected tool */+ int16_t scroll; /* the element buttons' scroll, pixels */+ uint8_t shape, shape_side; /* MODE_SHAPE: what, and with which tool */+ int sx, sy; /* its start */+ uint8_t opt; /* MODE_OPTIONS: the selected row */+ uint8_t set; /* MODE_SETTINGS: the selected row */+ uint8_t confirm; /* MODE_CONFIRM: the question */+ uint8_t slot, saving; /* MODE_SAVES: the selected slot; saving or loading */+ uint8_t text; /* MODE_TEXT: which */+ int16_t text_top; /* its scroll, or how to play's page */+ bool debug; /* the original's HUD: FPS, the particles' count, all of what's under the brush */+ bool step; /* a frame to step, paused */+ int16_t intro; /* the intro text's time left (the original's introText) */+ int16_t tip; /* a message's time left */+ const char *tip_text;+ int fav[NFAV]; /* the favourites (SC_FAVORITES) */+ uint8_t nfav;+ uint32_t fps100; /* frames a second, x100 */+} Ui;+extern Ui ui;++void ui_init(void);+bool ui_tick(void); /* the keys, a frame: false to quit */+int ui_draw(Overlay *o, bool *panel); /* the width of the sim's rows to show again (panel: all of them, and the panel) */+void ui_message(const char *text);+bool ui_home(void); /* Home: autosaves; true to quit */++/* ui_menu.c */+int menu_count(int section);+int menu_tool(int section, int k);+int menu_find(int section, int tool); /* the tool's index in a section, -1 */+int tool_section(int tool); /* the section a tool is in */+const char *tool_name(int tool); /* its button's text */+const char *tool_description(int tool);+uint32_t tool_colour(int tool);+void menu_open(void);+void menu_show_tool(int tool);+void menu_keys(void);+void menu_draw(Overlay *o, bool full); /* over the sim: the sections (when full: they don't change), the description */+#define MENU_LIST_X (SCREEN_W - 112) /* the sections' list */+void menu_row(Overlay *o); /* below it: the section's buttons */+extern const char *const section_names[SC_TOTAL];+extern const uint8_t section_icons[SC_TOTAL];++/* ui_draw.c */+#define PANEL_Y SIM_H /* the panel below the sim */+#define KEYS_Y (SCREEN_H - 14) /* its line of keys (the text's y) */+void hud_draw(Overlay *o);+void brush_draw(Overlay *o);+void panel_draw(Overlay *o); /* what OK and Back hold, or the material menu's buttons; the keys */+void keys_line(Overlay *o, const char *text);+void intro_draw(Overlay *o);+char *text_cat(char *p, const char *end, const char *s); /* (ends it with a 0) */+char *text_cat_fixed(char *p, const char *end, float v); /* (2 decimals) */+void stickman_hp(Overlay *o);+void particle_info(char *out, int n, int x, int y, bool line2);+int fmt_fixed(char *out, float v, int decimals);+int fmt_int(char *out, int v);+void text_wrap(char *out, int n, const char *s, int width);+void sample_at(int x, int y); /* the original's sample: the left tool from what's there */++/* ui_opts.c */+void options_open(void);+void options_keys(void);+void options_draw(Overlay *o);+void settings_keys(void);+void settings_draw(Overlay *o);+void confirm_open(int what);+void confirm_keys(void);+void confirm_draw(Overlay *o);+void text_open(int what);+void text_keys(void);+void text_draw(Overlay *o);+/* the TPT window look: a dark box with a border, its title */+void window_draw(Overlay *o, int x, int y, int w, int h, const char *title);+const char *mode_keys(void); /* the keys line for the mode */++/* ui_save.c */+#define NSLOTS 4+void saves_open(bool saving);+void saves_keys(void);+void saves_draw(Overlay *o);+enum { SAVE_OK, SAVE_NOROOM, SAVE_UNAVAILABLE };+int save_slot(int slot); /* 0 the autosave, 1..NSLOTS: SAVE_* */+bool load_slot(int slot);+bool slot_used(int slot, int *nparts);+void saves_restore(void); /* the slots from their copy, after the app was installed again */+void config_save(void); /* the settings and the interface's choices */+void config_load(void);+#endifdiff --git a/games/numpowder/src/ui_draw.c b/games/numpowder/src/ui_draw.cnew file mode 100644index 00000000..a31f3de4--- /dev/null+++ b/games/numpowder/src/ui_draw.c@@ -0,0 +1,425 @@+/* NumPowder: what's drawn over the sim and below it: what's under the brush (small, or the original's debug HUD:+ * GameView::OnDraw's FPS box and sample), the brush's outline (Brush::RenderPoint, RenderLine, RenderRect), the panel+ * below the sim (what OK and Back hold, the brush, the keys) and the welcome card. */+#include "ui.h"+#include <string.h>++/* ---------------------------------------------------------------- numbers as text (no printf on the calculator) */+#define cat text_cat+#define cat_fixed text_cat_fixed+int fmt_int(char *out, int v) {+ char tmp[12];+ int n = 0, k = 0;+ unsigned u = v < 0 ? (unsigned)-(long)v : (unsigned)v;+ do tmp[n++] = (char)('0' + u % 10), u /= 10;+ while (u);+ if (v < 0) out[k++] = '-';+ while (n) out[k++] = tmp[--n];+ out[k] = 0;+ return k;+}+/* Format::Precision: a fixed number of decimals */+int fmt_fixed(char *out, float v, int decimals) {+ if (!isfinite(v)) return (int)(strcpy(out, "nan"), 3);+ int k = 0;+ if (v < 0) out[k++] = '-', v = -v;+ long scale = 1;+ for (int i = 0; i < decimals; i++) scale *= 10;+ long q = (long)(v * scale + 0.5f);+ k += fmt_int(out + k, (int)(q / scale));+ if (decimals) {+ out[k++] = '.';+ long f = q % scale;+ for (long d = scale / 10; d; d /= 10) out[k++] = (char)('0' + (f / d) % 10);+ }+ out[k] = 0;+ return k;+}+char *text_cat(char *p, const char *end, const char *s) {+ while (*s && p < end - 1) *p++ = *s++;+ *p = 0;+ return p;+}+static char *cat_int(char *p, const char *end, int v) {+ char b[12];+ fmt_int(b, v);+ return cat(p, end, b);+}+char *text_cat_fixed(char *p, const char *end, float v) {+ char b[24];+ fmt_fixed(b, v, 2);+ return cat(p, end, b);+}++/* breaks a text into lines no wider than `width` at its spaces */+void text_wrap(char *out, int n, const char *s, int width) {+ int len = 0, line_start = 0, last_space = -1;+ for (; *s && len < n - 1; s++) {+ out[len] = *s;+ if (*s == '\n') line_start = len + 1, last_space = -1;+ else if (*s == ' ') last_space = len;+ len++;+ out[len] = 0;+ if (font_text_width(out + line_start) > width && last_space > line_start) {+ out[last_space] = '\n';+ line_start = last_space + 1;+ last_space = -1;+ }+ }+ out[len] = 0;+}++/* ---------------------------------------------------------------- what's under the cursor */+/* SimulationData::ElementResolve */+static const char *element_resolve(int type, int ctype) {+ if (type == PT_LIFE) return ctype >= 0 && ctype < NGOL ? builtinGol[ctype].name : "LIFE";+ if (type >= 0 && type < PT_NUM) return elements[type].Name;+ return "Empty";+}++static const Particle *particle_at(int x, int y, int *id) {+ int r = PHOTAT(x, y);+ if (!r) r = PMAPAT(x, y);+ if (!r) return NULL;+ *id = ID(r);+ return &parts[ID(r)];+}++/* GameView::OnDraw's sample: the particle (with the debug HUD's details), the wall, the air */+void particle_info(char *out, int n, int x, int y, bool line2) {+ char *p = out, *end = out + n;+ *p = 0;+ int id = -1;+ const Particle *s = particle_at(x, y, &id);+ if (!line2) {+ if (s) {+ /* (BasicParticleInfo; with the debug HUD, GameView's details) */+ int type = s->type, ctype = s->ctype;+ int pipeType = TYP(ctype), stored = (type == PT_PIPE || type == PT_PPIP) ? tmp4_get(id) : 0; /* (PIPE: its tmp4) */+ if (type == PT_LAVA && IsElement(ctype)) {+ p = cat(p, end, "Molten "), p = cat(p, end, element_resolve(ctype, -1));+ } else if ((type == PT_PIPE || type == PT_PPIP) && IsElement(pipeType)) {+ p = cat(p, end, element_resolve(type, -1));+ if (pipeType == PT_LAVA && IsElement(stored)) p = cat(p, end, " with molten "), p = cat(p, end, element_resolve(stored, -1));+ else p = cat(p, end, " with "), p = cat(p, end, element_resolve(pipeType, stored));+ } else if (ui.debug && type == PT_FILT) {+ static const char *const filtModes[] = {"set colour", "AND", "OR", "AND-NOT", "red shift", "blue shift", "no effect",+ "XOR", "NOT", "old QRTZ scattering", "variable red shift", "variable blue shift"};+ p = cat(p, end, element_resolve(type, ctype)), p = cat(p, end, " (");+ p = cat(p, end, s->tmp >= 0 && s->tmp <= 11 ? filtModes[s->tmp] : "unknown mode"), p = cat(p, end, ")");+ } else if (ui.debug && (type == PT_SEED || (type == PT_PLNT && (ctype & PLNT_CTYPE)))) {+ /* the genes: water, colour (cyan, magenta, yellow), the direction, active */+ static const char *const directions[8] = {"N", "NW", "W", "SW", "S", "SE", "E", "NE"};+ static const char *const colours[3][4] = {{"cc", "cC", "Cc", "CC"}, {"mm", "mM", "Mm", "MM"}, {"yy", "yY", "Yy", "YY"}};+ int colour = (ctype >> PLNT_COLOUR) & 0x3F;+ p = cat(p, end, element_resolve(type, ctype)), p = cat(p, end, " (");+ p = cat_int(p, end, (ctype >> PLNT_LIFE) & 0xFF), p = cat(p, end, " ");+ p = cat(p, end, colours[0][(colour >> 4) & 3]), p = cat(p, end, colours[1][(colour >> 2) & 3]);+ p = cat(p, end, colours[2][colour & 3]), p = cat(p, end, " "), p = cat(p, end, directions[(ctype >> PLNT_DIR) & 7]);+ p = cat(p, end, " "), p = cat_int(p, end, ctype & 1), p = cat(p, end, ")");+ } else {+ p = cat(p, end, element_resolve(type, ctype));+ bool wavelength = type == PT_PHOT || type == PT_BIZR || type == PT_BIZRG || type == PT_BIZRS || type == PT_FILT ||+ type == PT_BRAY || type == PT_C5;+ if (ui.debug && !wavelength && type != PT_EMBR && type != PT_PRTI && type != PT_PRTO && type != PT_LIFE) {+ if (type == PT_CRAY || type == PT_DRAY || type == PT_CONV || type == PT_LDTC)+ p = cat(p, end, " ("), p = cat(p, end, element_resolve(TYP(ctype), ID(ctype))), p = cat(p, end, ")");+ else if (type == PT_CLNE || type == PT_BCLN || type == PT_PCLN || type == PT_PBCN || type == PT_DTEC)+ p = cat(p, end, " ("), p = cat(p, end, element_resolve(ctype, s->tmp)), p = cat(p, end, ")");+ else if (IsElement(ctype) && type != PT_GLOW && type != PT_WIRE && type != PT_SOAP && type != PT_LITH)+ p = cat(p, end, " ("), p = cat(p, end, element_resolve(ctype, 0)), p = cat(p, end, ")");+ else if (ctype)+ p = cat(p, end, " ("), p = cat_int(p, end, ctype), p = cat(p, end, ")");+ }+ }+ p = cat(p, end, ", Temp: "), p = cat_fixed(p, end, p_temp(s) - 273.15f), p = cat(p, end, "C");+ } else if (bmap[y / WCELL][x / WCELL] && bmap[y / WCELL][x / WCELL] < UI_WALLCOUNT) {+ p = cat(p, end, walltypes[bmap[y / WCELL][x / WCELL]].name);+ } else {+ p = cat(p, end, "Empty");+ }+ p = cat(p, end, ", Pressure: "), p = cat_fixed(p, end, pv[y / ACELL][x / ACELL]);+ } else {+ /* the debug HUD's: life, tmp (tmp2 where it means something), the particle's number and place */+ if (s) {+ int type = s->type;+ p = cat(p, end, "Life: "), p = cat_int(p, end, s->life);+ if (type == PT_CONV && IsElementOrNone(TYP(s->tmp)) && TYP(s->tmp))+ p = cat(p, end, ", Tmp: "), p = cat(p, end, element_resolve(TYP(s->tmp), ID(s->tmp)));+ else if (type != PT_RFRG && type != PT_RFGL && type != PT_LIFE) p = cat(p, end, ", Tmp: "), p = cat_int(p, end, s->tmp);+ if (type == PT_CRAY || type == PT_DRAY || type == PT_EXOT || type == PT_LIGH || type == PT_SOAP || type == PT_TRON ||+ type == PT_VIBR || type == PT_VIRS || type == PT_WARP || type == PT_LCRY || type == PT_CBNW || type == PT_TSNS ||+ type == PT_DTEC || type == PT_LSNS || type == PT_PSTN || type == PT_LDTC || type == PT_VSNS || type == PT_LITH ||+ type == PT_CONV || type == PT_ETRD)+ p = cat(p, end, ", Tmp2: "), p = cat_int(p, end, s->tmp2);+ p = cat(p, end, ", #"), p = cat_int(p, end, id), p = cat(p, end, ", ");+ }+ p = cat(p, end, "X:"), p = cat_int(p, end, x), p = cat(p, end, " Y:"), p = cat_int(p, end, y);+ if (aheat_enable) p = cat(p, end, ", AHeat: "), p = cat_fixed(p, end, hv[y / ACELL][x / ACELL] - 273.15f), p = cat(p, end, "C");+ }+}++/* sampling (GameView's middle click): the left tool becomes what's under the cursor */+void sample_at(int x, int y) {+ int id;+ const Particle *s = particle_at(x, y, &id);+ int tool = -1;+ if (s) {+ if (s->type == PT_LIFE) tool = PMAP(s->ctype >= 0 && s->ctype < NGOL ? s->ctype : 0, PT_LIFE);+ else if (elements[s->type].MenuVisible) tool = s->type;+ } else if (bmap[y / WCELL][x / WCELL] && bmap[y / WCELL][x / WCELL] < UI_WALLCOUNT) {+ tool = TOOL_WALLS + bmap[y / WCELL][x / WCELL];+ }+ if (tool >= 0) {+ ui.tool[0] = tool;+ ui.section = (uint8_t)tool_section(tool);+ menu_show_tool(tool);+ }+}++/* ---------------------------------------------------------------- the HUD */+/* what's under the brush, small: its name and temperature, the pressure when there is some (in the corner the+ * original's HUD has it); with "Details in the HUD", the original's: its FPS and particles' count, all the sample */+void hud_draw(Overlay *o) {+ char buf[96];+ char *p = buf, *end = buf + sizeof buf;+ int alpha = 255 - ui.intro * 5;+ if (ui.debug) {+ /* FPS and the particles' count (top left) */+ char f[16];+ fmt_fixed(f, ui.fps100 / 100.0f, 2);+ p = cat(p, end, "FPS: "), p = cat(p, end, f);+ p = cat(p, end, " Parts: "), p = cat_int(p, end, NUM_PARTS);+ if (replaceModeFlags & REPLACE_MODE) p = cat(p, end, " [REPLACE MODE]");+ if (replaceModeFlags & SPECIFIC_DELETE) p = cat(p, end, " [SPECIFIC DELETE]");+ int tw = font_text_width(buf) - 1, fps_right = SIM_X + 8 + tw + 4;+ ov_fill(o, SIM_X + 4, 4, tw + 8, FONT_H - 2 + 5, 0x000000, 127);+ ov_text(o, SIM_X + 8, 8, buf, 0x20D8FF, 191);+ if (alpha <= 0 || ui.mode == MODE_STKM || ui.mode == MODE_MENU) return;+ particle_info(buf, sizeof buf, ui.cx, ui.cy, false);+ tw = font_text_width(buf) - 1;+ int x = SIM_X + SIM_W - 8 - tw, y = 8;+ if (x - 4 < fps_right + 2) y += 15;+ if (x < SIM_X + 4) x = SIM_X + 4;+ ov_fill(o, x - 4, y - 4, tw + 8, 15, 0x000000, alpha / 2);+ ov_text(o, x, y, buf, 0xFFFFFF, alpha * 3 / 4);+ particle_info(buf, sizeof buf, ui.cx, ui.cy, true);+ tw = font_text_width(buf) - 1;+ x = SIM_X + SIM_W - 8 - tw;+ if (x < SIM_X + 4) x = SIM_X + 4;+ ov_fill(o, x - 4, y + 11, tw + 8, 14, 0x000000, alpha / 2);+ ov_text(o, x, y + 14, buf, 0xFFFFFF, alpha * 3 / 4);+ return;+ }+ /* (only while the brush is in use: not over the windows and menus) */+ if (alpha <= 0 || (ui.mode != MODE_SIM && ui.mode != MODE_SHAPE)) return;+ int id;+ const Particle *s = particle_at(ui.cx, ui.cy, &id);+ int wall = bmap[ui.cy / WCELL][ui.cx / WCELL];+ if (s) {+ if (s->type == PT_LAVA && IsElement(s->ctype)) p = cat(p, end, "molten "), p = cat(p, end, element_resolve(s->ctype, -1));+ else p = cat(p, end, element_resolve(s->type, s->ctype));+ char t[16];+ fmt_fixed(t, p_temp(s) - 273.15f, 0);+ p = cat(p, end, " "), p = cat(p, end, t), p = cat(p, end, FONT_DEG "C");+ } else if (wall && wall < UI_WALLCOUNT) {+ p = cat(p, end, walltypes[wall].name);+ } else {+ return; /* (nothing there) */+ }+ float pres = pv[ui.cy / ACELL][ui.cx / ACELL];+ if (fabsf(pres) >= 0.5f) {+ char t[16];+ fmt_fixed(t, pres, 1);+ p = cat(p, end, " pressure "), p = cat(p, end, t);+ }+ int tw = font_text_width(buf) - 1, x = SIM_X + SIM_W - 6 - tw;+ ov_fill(o, x - 3, 3, tw + 6, 14, 0x000000, alpha / 2);+ ov_text(o, x, 7, buf, 0xFFFFFF, alpha * 7 / 8);+}++/* ---------------------------------------------------------------- a stickman's life */+/* with the cursor on a stickman's head, its life by the cursor (the original's renderer, under the mouse) */+void stickman_hp(Overlay *o) {+ if (!elementCount[PT_STKM] && !elementCount[PT_STKM2] && !elementCount[PT_FIGH]) return;+ for (int i = 0; i < parts_active; i++) {+ int t = parts[i].type;+ if (t != PT_STKM && t != PT_STKM2 && t != PT_FIGH) continue;+ int nx = p_cx(&parts[i]), ny = p_cy(&parts[i]), life = parts[i].life;+ if (!(ui.cx > nx - 3 && ui.cx < nx + 3 && ui.cy < ny + 3 && ui.cy > ny - 3)) continue;+ char hp[12], txt[16];+ fmt_int(hp, life);+ int pad = 3 - (int)strlen(hp), k = 0; /* (Format::Width(life, 3)) */+ while (pad-- > 0) txt[k++] = ' ';+ strcpy(txt + k, hp);+ int mx = SIM_X + ui.cx * PX_SCALE + 1, my = ui.cy * PX_SCALE + 1;+ ov_text(o, mx - 8 - 2 * (life < 100) - 2 * (life < 10), my - 12, txt, 0xFFFFFF, 255);+ return;+ }+}++/* ---------------------------------------------------------------- the brush's outline */+typedef struct { int cx, cy; } BrushCtx;+static BrushCtx brush_ctx;+static inline void xor_px(Band *b, int x, int y) {+ if (x < SIM_X || y < 0 || x >= SIM_X + SIM_W || y >= SIM_H) return;+ int sx = x - b->x0, sy = y - b->y0;+ if ((unsigned)sx < (unsigned)b->w && (unsigned)sy < (unsigned)b->h) b->px[sy * b->w + sx] = px_xor(b->px[sy * b->w + sx]);+}+/* Brush::RenderPoint: the brush's edge, drawn on the outer pixels of its edge particles (not their middles) */+static void brush_outline_fn(Band *band, const void *ctx) {+ const BrushCtx *c = ctx;+ int rx = brush.rx, ry = brush.ry;+ int py0 = band->y0 / PX_SCALE - 1, py1 = (band->y0 + band->h) / PX_SCALE + 1;+ for (int dy = -ry; dy <= ry; dy++) {+ int y = c->cy + dy;+ if (y < py0 || y > py1) continue;+ for (int dx = -rx; dx <= rx; dx++) {+ if (!brush_has(dx, dy)) continue;+ bool top = dy > -ry && brush_has(dx, dy - 1), bottom = dy < ry && brush_has(dx, dy + 1);+ bool left = dx > -rx && brush_has(dx - 1, dy), right = dx < rx && brush_has(dx + 1, dy);+ if (top && bottom && left && right) continue;+ int bx = SIM_X + (c->cx + dx) * PX_SCALE, by = y * PX_SCALE;+ for (int j = 0; j < PX_SCALE; j++)+ for (int i = 0; i < PX_SCALE; i++) {+ bool on = (j == 0 && !top) || (j == PX_SCALE - 1 && !bottom) || (i == 0 && !left) || (i == PX_SCALE - 1 && !right);+ if (on && !(i == 1 && j == 1)) xor_px(band, bx + i, by + j);+ }+ }+ }+}+/* a particle's middle on the screen */+static int screen_x(int v) { return SIM_X + v * PX_SCALE + 1; }+static int screen_y(int v) { return v * PX_SCALE + 1; }+static void xor_box(Overlay *o, int X0, int Y0, int X1, int Y1) {+ ov_xor_line(o, X0, Y0, X1, Y0);+ ov_xor_line(o, X0, Y1, X1, Y1);+ ov_xor_line(o, X0, Y0 + 1, X0, Y1 - 1);+ ov_xor_line(o, X1, Y0 + 1, X1, Y1 - 1);+}+void brush_draw(Overlay *o) {+ int tool = ui.tool[ui.mode == MODE_SHAPE ? ui.shape_side : 0];+ if (ui.mode == MODE_SHAPE) {+ if (ui.shape == SHAPE_LINE) {+ ov_xor_line(o, screen_x(ui.sx), screen_y(ui.sy), screen_x(ui.cx), screen_y(ui.cy));+ } else if (ui.shape == SHAPE_BOX) {+ int x0 = ui.sx < ui.cx ? ui.sx : ui.cx, x1 = ui.sx < ui.cx ? ui.cx : ui.sx;+ int y0 = ui.sy < ui.cy ? ui.sy : ui.cy, y1 = ui.sy < ui.cy ? ui.cy : ui.sy;+ if (tool & TOOL_WALLS) x0 -= x0 % WCELL, y0 -= y0 % WCELL, x1 += WCELL - 1 - x1 % WCELL, y1 += WCELL - 1 - y1 % WCELL;+ xor_box(o, SIM_X + x0 * PX_SCALE, y0 * PX_SCALE, SIM_X + x1 * PX_SCALE + PX_SCALE - 1, y1 * PX_SCALE + PX_SCALE - 1);+ return;+ } else {+ /* Brush::RenderFill: a small cross */+ int x = screen_x(ui.cx), y = screen_y(ui.cy);+ ov_xor_line(o, x - 7, y, x - 2, y);+ ov_xor_line(o, x + 7, y, x + 2, y);+ ov_xor_line(o, x, y - 7, x, y - 2);+ ov_xor_line(o, x, y + 7, x, y + 2);+ return;+ }+ }+ if (tool & TOOL_WALLS) {+ /* a wall brush covers whole wall cells (GameView: NormaliseBlockCoord) */+ int wx = ui.cx / WCELL, wy = ui.cy / WCELL, rx = brush.rx / WCELL, ry = brush.ry / WCELL;+ xor_box(o, SIM_X + (wx - rx) * WCELL * PX_SCALE, (wy - ry) * WCELL * PX_SCALE,+ SIM_X + (wx + rx + 1) * WCELL * PX_SCALE - 1, (wy + ry + 1) * WCELL * PX_SCALE - 1);+ return;+ }+ brush_ctx = (BrushCtx){ui.cx, ui.cy};+ ov_call(o, brush_outline_fn, &brush_ctx);+}++/* ---------------------------------------------------------------- the panel below the sim */+/* a small brush: its shape at one pixel a particle (radius up to 6) */+typedef struct { int x, y; } BrushIconCtx;+static BrushIconCtx brush_icon;+static void brush_icon_fn(Band *b, const void *ctx) {+ const BrushIconCtx *c = ctx;+ int rx = brush.rx < 6 ? brush.rx : 6, ry = brush.ry < 6 ? brush.ry : 6;+ for (int dy = -ry; dy <= ry; dy++)+ for (int dx = -rx; dx <= rx; dx++) {+ /* (a bigger brush is shown by its shape at radius 6) */+ int sx = brush.rx > 6 ? dx * brush.rx / 6 : dx, sy = brush.ry > 6 ? dy * brush.ry / 6 : dy;+ if (brush_has(sx, sy)) band_fill(b, c->x + dx, c->y + dy, 1, 1, 0xFFFFFF, 255);+ }+}++/* a tool as the original's ToolButton (its colour, its name in black or white as it's light or dark), here as wide+ * as its name needs; NONE is "ERASE" (the walls' eraser "WALL ERASE"). Returns its width */+static int held_button(Overlay *o, int x, int y, int tool, uint32_t border) {+ uint32_t c = tool_colour(tool);+ const char *name = tool == PT_NONE ? "ERASE" : tool == (TOOL_WALLS | WL_ERASE) ? "WALL ERASE" : tool_name(tool);+ /* (a wall's name without its " WALL": LIQUID, GAS...) */+ char t[16];+ int n = (int)strlen(name), k = 0;+ if ((tool & TOOL_WALLS) && n > 5 && !strcmp(name + n - 5, " WALL")) n -= 5;+ while (k < n && k < 12) t[k] = name[k], k++;+ t[k] = 0;+ int tw = font_text_width(t) - 1, w = tw + 10 > 30 ? tw + 10 : 30, h = 18;+ ov_fill(o, x + 2, y + 2, w - 4, h - 4, c, 255);+ ov_rect(o, x, y, w, h, border, 255);+ ov_rect(o, x + 1, y + 1, w - 2, h - 2, 0x000000, 255);+ int total = (c & 255) + 3 * (c >> 8 & 255) + 2 * (c >> 16 & 255);+ ov_text(o, x + (w - tw) / 2, y + 5, t, total < 544 ? 0xFFFFFF : 0x000000, 255);+ return w;+}++/* the line of keys at the bottom: centred, the keys' names in the original's orange (\bo), the rest grey */+void keys_line(Overlay *o, const char *text) {+ ov_fill(o, 0, KEYS_Y - 4, SCREEN_W, 1, 0x404040, 255);+ ov_text(o, (SCREEN_W - font_text_width(text)) / 2, KEYS_Y, text, 0xC0C0C0, 255);+}++void panel_draw(Overlay *o) {+ if (ui.mode == MODE_MENU) {+ menu_row(o);+ } else {+ /* what OK and Back draw with */+ int y = PANEL_Y + 3, x = 6;+ ov_text(o, x, y + 5, "OK", 0xFFD820, 255);+ x += font_text_width("OK") + 3;+ x += held_button(o, x, y, ui.tool[0], 0xFF0000) + 10;+ ov_text(o, x, y + 5, "Back", 0xFFD820, 255);+ x += font_text_width("Back") + 3;+ x += held_button(o, x, y, ui.tool[1], 0x0000FF) + 12;+ /* the brush: its shape and size; while a shape is placed, which */+ if (ui.mode == MODE_SHAPE) {+ static const char *const names[NUM_SHAPES] = {"line", "box", "fill"};+ ov_text(o, x, y + 5, names[ui.shape], 0xFFFFFF, 255);+ } else {+ brush_icon = (BrushIconCtx){x + 6, y + 9};+ ov_call(o, brush_icon_fn, &brush_icon);+ char r[12] = "size ";+ fmt_int(r + 5, brush.rx);+ ov_text(o, x + 16, y + 5, r, 0xC0C0C0, 255);+ }+ /* paused: the original's pause button, pressed */+ if (sys_pause) {+ int w = font_text_width("paused") + 18, px = SCREEN_W - 4 - w;+ ov_fill(o, px, y + 1, w, 16, 0xFFFFFF, 255);+ ov_text(o, px + 3, y + 4, "\x90", 0x000000, 255);+ ov_text(o, px + 15, y + 5, "paused", 0x000000, 255);+ }+ }+ keys_line(o, mode_keys());+}++/* ---------------------------------------------------------------- the welcome card */+/* on a dark backdrop, a window as the original's: the name, where it comes from, the four keys to start */+void intro_draw(Overlay *o) {+ int a = ui.intro > 50 ? 255 : ui.intro * 5;+ ov_fill(o, 0, 0, SCREEN_W, SCREEN_H, 0x000000, a * 3 / 4);+ if (a < 128) return;+ int w = 236, h = 146, x = (SCREEN_W - w) / 2, y = (SCREEN_H - h) / 2 - 6;+ window_draw(o, x, y, w, h, NULL);+ ov_text_big(o, x + (w - 2 * font_text_width("NumPowder")) / 2, y + 14, "NumPowder", 0xFF4B4B);+ ov_text(o, x + (w - font_text_width("Inspired by The Powder Toy")) / 2, y + 40, "Inspired by The Powder Toy", 0xC0C0C0, 255);+ static const char *const keys[4][2] = {{"OK", "draws"}, {"Back", "erases"}, {"toolbox", "picks a material"},+ {"var", "opens the menu: help, saves"}};+ for (int k = 0; k < 4; k++) {+ int ky = y + 62 + k * 15;+ ov_text(o, x + 70 - font_text_width(keys[k][0]), ky, keys[k][0], 0xFFD820, 255);+ ov_text(o, x + 78, ky, keys[k][1], 0xFFFFFF, 255);+ }+ ov_text(o, x + (w - font_text_width("Press any key")) / 2, y + h - 18, "Press any key", 0x20AAFF, 255);+}diff --git a/games/numpowder/src/ui_menu.c b/games/numpowder/src/ui_menu.cnew file mode 100644index 00000000..35c0108d--- /dev/null+++ b/games/numpowder/src/ui_menu.c@@ -0,0 +1,364 @@+/* NumPowder: the menu sections and their tools (SimulationData's LoadMenus, GameModel::InitTools and BuildMenus)+ * and the material menu (toolbox): the sections by name with their icons, over the sim's right side; the section's+ * tool buttons (ToolButton, GameView::NotifyActiveMenuToolListChanged) and their scroll bar below the sim; the+ * selected one's description (the original's tooltip) over the sim's bottom left. */+#include "ui.h"+#include <string.h>++/* LoadMenus: the sections' icons (glyphs U+E0xx) and names */+const uint8_t section_icons[SC_TOTAL] = {0x41, 0x42, 0x56, 0x19, 0x62, 0x43, 0x45, 0x44,+ 0x50, 0x51, 0x46, 0x4C, 0x52, 0x57, 0x67, 0x64};+const char *const section_names[SC_TOTAL] = {+ "Walls", "Electronics", "Powered Materials", "Sensors", "Force", "Explosives", "Gases", "Liquids",+ "Powders", "Solids", "Radioactive", "Special", "Game Of Life", "Tools", "Favorites", "Decoration tools"};++/* ---------------------------------------------------------------- the tools of a section, in the original's order:+ * the elements by number (NONE first, in Special), the Game of Life types, the walls, the simulation tools, SMPL */+static int menu_walk(int section, int want) {+ int n = 0;+ if (section == SC_FAVORITES) {+ for (int k = 0; k < ui.nfav; k++, n++)+ if (n == want) return ui.fav[k];+ return want < 0 ? n : -1;+ }+ for (int t = 0; t < PT_COUNT; t++)+ if (elements[t].Enabled && elements[t].MenuVisible && elements[t].MenuSection == section) {+ if (n == want) return t;+ n++;+ }+ if (section == SC_LIFE)+ for (int g = 0; g < NGOL; g++, n++)+ if (n == want) return PMAP(g, PT_LIFE);+ if (section == SC_WALL)+ for (int w = 0; w < UI_WALLCOUNT; w++, n++)+ if (n == want) return TOOL_WALLS + w;+ if (section == SC_TOOL) {+ for (int k = 0; k < TOOL_COUNT; k++, n++)+ if (n == want) return TOOL_SIMTOOLS + k;+ if (n == want) return TOOL_SAMPLE;+ n++;+ }+ return want < 0 ? n : -1;+}+int menu_count(int section) { return menu_walk(section, -1); }+int menu_tool(int section, int k) { return k < 0 ? -1 : menu_walk(section, k); }+int menu_find(int section, int tool) {+ int n = menu_count(section);+ for (int k = 0; k < n; k++)+ if (menu_tool(section, k) == tool) return k;+ return -1;+}+int tool_section(int tool) {+ if (tool & TOOL_WALLS) return SC_WALL;+ if (tool & (TOOL_SIMTOOLS | TOOL_UI)) return SC_TOOL;+ if (TYP(tool) == PT_LIFE) return SC_LIFE;+ return elements[TYP(tool)].MenuSection;+}+const char *tool_name(int tool) {+ if (tool & TOOL_WALLS) return walltypes[tool & 0xFF].name;+ if (tool & TOOL_SIMTOOLS) return simtools[tool & 0xFF].name;+ if (tool == TOOL_SAMPLE) return "SMPL";+ if (TYP(tool) == PT_LIFE && ID(tool) < NGOL) return builtinGol[ID(tool)].name;+ return elements[TYP(tool)].Name;+}+const char *tool_description(int tool) {+ if (tool & TOOL_WALLS) return walltypes[tool & 0xFF].descs;+ if (tool & TOOL_SIMTOOLS) return simtools[tool & 0xFF].description;+ if (tool == TOOL_SAMPLE) return "Sample an element on the screen.";+ if (TYP(tool) == PT_LIFE && ID(tool) < NGOL) return builtinGol[ID(tool)].description;+ return elements[TYP(tool)].Description;+}+uint32_t tool_colour(int tool) {+ if (tool & TOOL_WALLS) return walltypes[tool & 0xFF].colour;+ if (tool & TOOL_SIMTOOLS) return simtools[tool & 0xFF].colour;+ if (tool == TOOL_SAMPLE) return 0x000000;+ if (TYP(tool) == PT_LIFE && ID(tool) < NGOL) return builtinGol[ID(tool)].colour;+ return elements[TYP(tool)].Colour;+}++/* ---------------------------------------------------------------- the buttons' look, drawn straight into a band */+static void b_rect(Band *b, int x, int y, int w, int h, uint32_t c) {+ band_fill(b, x, y, w, 1, c, 255);+ band_fill(b, x, y + h - 1, w, 1, c, 255);+ band_fill(b, x, y + 1, 1, h - 2, c, 255);+ band_fill(b, x + w - 1, y + 1, 1, h - 2, c, 255);+}+/* the selection: a thick yellow frame, outlined in black so it shows over anything */+static void b_select(Band *b, int x, int y, int w, int h) {+ b_rect(b, x - 1, y - 1, w + 2, h + 2, 0xFFFF00);+ b_rect(b, x - 2, y - 2, w + 4, h + 4, 0xFFFF00);+ b_rect(b, x - 3, y - 3, w + 6, h + 6, 0x000000);+}+static inline bool b_misses(Band *b, int y, int h) { return y >= b->y0 + b->h || y + h <= b->y0; }++/* Renderer::WallIcon's patterns, 26 x 14 */+static void wall_icon(Band *b, int x0, int y0, int wall) {+ const WallType *wt = &walltypes[wall];+ int w = 26, h = 14;+ if (wall == WL_ERASEALL) {+ /* (stripes of changing colours) */+ int r = 100, g = 150, bl = 50, rd = 1, gd = -1, bd = -1;+ for (int x = 0; x < w; x++) {+ r += 15 * rd, g += 15 * gd, bl += 15 * bd;+ if (r > 200) rd = -1;+ if (g > 200) gd = -1;+ if (bl > 200) bd = -1;+ if (r < 15) rd = 1;+ if (g < 15) gd = 1;+ if (bl < 15) bd = 1;+ int rc = r < 0 ? 0 : r > 150 ? 150 : r, gc = g < 0 ? 0 : g > 200 ? 200 : g, bc = bl < 0 ? 0 : bl > 200 ? 200 : bl;+ band_fill(b, x0 + x, y0, 1, h, (uint32_t)rc << 16 | gc << 8 | bc, 255);+ }+ font_draw_char(b, x0 + w / 2 - 10, y0 + h / 2 - 2, FONT_ICON(0x6C), 0xFF0000, 255, FONT_BLEND);+ font_draw_char(b, x0 + w / 2 + 1, y0 + h / 2 - 2, FONT_ICON(0x6C), 0xFF0000, 255, FONT_BLEND);+ return;+ }+ for (int y = 0; y < h; y++) {+ if (y0 + y < b->y0 || y0 + y >= b->y0 + b->h) continue;+ for (int x = 0; x < w; x++) {+ int32_t c = -1;+ switch (wt->drawstyle) {+ case 1: if (~y & ~(x ^ (y >> 1)) & 1) c = (int32_t)wt->colour; break;+ case 2: if (~y & ~x & 1) c = (int32_t)wt->colour; break;+ case 3: c = (int32_t)wt->colour; break;+ case 4: {+ int d = ((x - y) % 4 + 4) % 4;+ c = d == 0 ? (int32_t)wt->colour : d == 1 ? (int32_t)wt->eglow : 0x202020;+ break;+ }+ }+ switch (wall) {+ case WL_EWALL: if ((x < w / 4 + y) != (x & y & 1)) c = (int32_t)wt->colour; break;+ case WL_WALLELEC: c = (~y & ~x & 1) ? (int32_t)wt->colour : 0x808080; break;+ case WL_EHOLE:+ case WL_STASIS: if ((x < w / 4 + y) == (x & y & 1)) c = (int32_t)wt->colour; break;+ case WL_ERASE: if ((x < w / 2) ? ~y & ~(x ^ (y >> 1)) & 1 : 1) c = (int32_t)wt->colour; break;+ case WL_STREAM: if (x == 0 || y == 0 || x == w - 1 || y == h - 1) c = 0xA0A0A0; break;+ }+ if (c >= 0) band_fill(b, x0 + x, y0 + y, 1, 1, (uint32_t)c, 255);+ }+ }+ if (wall == WL_ERASE) font_draw_char(b, x0 + w / 2 - 4, y0 + h / 2 - 2, FONT_ICON(0x6C), 0xFF0000, 255, FONT_BLEND);+ if (wall == WL_STREAM) {+ font_draw_char(b, x0 + 4, y0 + 2, FONT_ICON(0x0D), 0xFFFFFF, 255, FONT_ADD);+ font_draw_char(b, x0 + 8, y0 + 2, FONT_ICON(0x6D), 0xFFFFFF, 255, FONT_ADD);+ }+}++/* ToolButton::Draw: 30 x 18, the tool's colour (or icon) inside, its name, the border showing which side has it+ * (red the left tool, blue the right one) */+static void tool_button_band(Band *b, int x, int y, int tool, int side) {+ int w = 30, h = 18;+ if (b_misses(b, y - 3, h + 6) || x >= b->x0 + b->w || x + w <= b->x0) return;+ uint32_t colour = tool_colour(tool);+ bool icon = true;+ if (tool & TOOL_WALLS) {+ wall_icon(b, x + 2, y + 2, tool & 0xFF);+ } else if (tool == TOOL_SAMPLE) {+ b_rect(b, x + 2, y + 2, 26, 14, 0xA0A0A0);+ font_draw_char(b, x + 2 + 13 - 5, y + 2 + 7 - 5, FONT_ICON(0x66), 0xFFFFFF, 255, FONT_BLEND);+ font_draw_char(b, x + 2 + 13 - 5, y + 2 + 7 - 5, FONT_ICON(0x6B), 0x64B4FF, 255, FONT_BLEND);+ } else if (tool == PT_NONE) {+ /* NONE's icon: U+E06C in red */+ font_draw_char(b, x + 2 + 13 - 4, y + 2 + 7 - 2, FONT_ICON(0x6C), 0xFF0000, 255, FONT_BLEND);+ } else {+ band_fill(b, x + 2, y + 2, w - 4, h - 4, colour, 255);+ icon = false;+ }+ b_rect(b, x, y, w, h, side == 0 ? 0xFF0000 : side == 1 ? 0x0000FF : 0x000000);+ for (int k = 0; k < ui.nfav; k++)+ if (ui.fav[k] == tool) font_draw_char(b, x, y, FONT_ICON(0x68), 0xFFFF00, 255, FONT_BLEND);+ if (!icon) {+ const char *name = tool_name(tool);+ char txt[8];+ int n = 0;+ while (name[n] && n < 7) txt[n] = name[n], n++; /* (ButtonText.Substr(0, 7)) */+ txt[n] = 0;+ int r = colour >> 16 & 255, g = colour >> 8 & 255, bl = colour & 255;+ int total = bl + 3 * g + 2 * r;+ /* Component::TextPosition, centred within its margins (1 above and below, 4 at the sides) */+ int tw = font_text_width(txt) - 1, tx = 4 + ((w - 8) - tw) / 2, ty = 1 + ((h - 2) - (FONT_H - 2 - 3)) / 2;+ font_draw(b, x + tx, y + ty, txt, total < 544 ? 0xFFFFFF : 0x000000, 255, FONT_BLEND);+ }+}+/* ---------------------------------------------------------------- the material menu */+static uint8_t section_sel[SC_TOTAL]; /* each section's last selected tool */+#define BTN_X0 (SCREEN_W - 6 - 30) /* the first tool's button, at the right as the original's */+#define BTN_Y (PANEL_Y + 2)+#define BTN_STEP 31+#define CAT_X MENU_LIST_X /* the sections' list, over the sim's right side */+#define CAT_W (SCREEN_W - CAT_X)+#define CAT_ROW 12++static void menu_scroll_to(int k) {+ int x = BTN_X0 - BTN_STEP * k + ui.scroll;+ int n = menu_count(ui.section);+ int lo = k + 1 < n ? BTN_STEP / 2 : 1; /* (some of the next one shows) */+ if (x < lo) ui.scroll += lo - x;+ if (x > BTN_X0) ui.scroll -= x - BTN_X0;+ if (ui.scroll < 0) ui.scroll = 0;+}++/* the row scrolled to show a tool of its section (after sampling) */+void menu_show_tool(int tool) {+ int k = menu_find(ui.section, tool);+ ui.scroll = 0;+ if (k >= 0) menu_scroll_to(k);+}++/* (opening: on what OK holds, in its section) */+void menu_open(void) {+ ui.mode = MODE_MENU;+ if (menu_find(ui.section, ui.tool[0]) < 0 && ui.tool[0] != PT_NONE) ui.section = (uint8_t)tool_section(ui.tool[0]);+ int k = menu_find(ui.section, ui.tool[0]);+ if (k < 0) k = section_sel[ui.section];+ int n = menu_count(ui.section);+ ui.sel = n ? (k < n ? k : n - 1) : 0;+ ui.scroll = 0;+ menu_scroll_to(ui.sel);+}++static void menu_section(int d) {+ section_sel[ui.section] = (uint8_t)ui.sel;+ ui.section = (uint8_t)((ui.section + d + SC_TOTAL) % SC_TOTAL);+ int n = menu_count(ui.section), k = menu_find(ui.section, ui.tool[0]);+ if (k < 0) k = section_sel[ui.section];+ ui.sel = n ? (k < n ? k : n - 1) : 0;+ ui.scroll = 0;+ menu_scroll_to(ui.sel);+}++static void fav_toggle(int tool) {+ for (int k = 0; k < ui.nfav; k++)+ if (ui.fav[k] == tool) {+ memmove(&ui.fav[k], &ui.fav[k + 1], sizeof(int) * (size_t)(ui.nfav - k - 1));+ ui.nfav--;+ ui_message("Removed from favorites");+ return;+ }+ if (ui.nfav >= NFAV) {+ ui_message("Favorites are full");+ return;+ }+ ui.fav[ui.nfav++] = tool;+ ui_message("Added to favorites");+}++void menu_keys(void) {+ int n = menu_count(ui.section);+ if (key_pressed(K_BACK) || key_pressed(K_TOOLBOX)) {+ section_sel[ui.section] = (uint8_t)ui.sel;+ ui.mode = MODE_SIM;+ return;+ }+ if (key_pressed(K_VAR)) {+ section_sel[ui.section] = (uint8_t)ui.sel;+ options_open();+ return;+ }+ if (key_repeat(K_UP)) menu_section(-1);+ if (key_repeat(K_DOWN)) menu_section(1);+ n = menu_count(ui.section);+ if (n) {+ /* (the first tool is at the right, as the original's; with shift, a row's worth of buttons at a time, up to+ * the ends) */+ int page = SCREEN_W / BTN_STEP;+ if (key_repeat(K_LEFT)) ui.sel = key_held(K_SHIFT) ? imin(ui.sel + page, n - 1) : (ui.sel + 1) % n;+ if (key_repeat(K_RIGHT)) ui.sel = key_held(K_SHIFT) ? imax(ui.sel - page, 0) : (ui.sel + n - 1) % n;+ menu_scroll_to(ui.sel);+ int tool = menu_tool(ui.section, ui.sel);+ if (key_pressed(K_OK)) {+ /* (OK: for OK; shift+OK: for Back) */+ int side = key_held(K_SHIFT) ? 1 : 0;+ ui.tool[side] = tool;+ section_sel[ui.section] = (uint8_t)ui.sel;+ ui.mode = MODE_SIM;+ }+ if (key_pressed(K_BACKSPACE) && ui.section != SC_FAVORITES) fav_toggle(tool);+ else if (key_pressed(K_BACKSPACE)) {+ fav_toggle(tool);+ n = menu_count(ui.section);+ if (ui.sel >= n) ui.sel = n ? n - 1 : 0;+ }+ }+}++/* the sections, by name with the original's icons, a row each over the sim's right side: the one shown white (the+ * original's pressed MenuButton) in a thick frame */+static void sections_fn(Band *b, const void *ctx) {+ (void)ctx;+ if (b->y0 >= SIM_H) return;+ for (int s = 0; s < SC_TOTAL; s++) {+ int y = s * CAT_ROW;+ if (b_misses(b, y, CAT_ROW)) continue;+ bool on = s == ui.section;+ band_fill(b, CAT_X, y, CAT_W, CAT_ROW, on ? 0xFFFFFF : 0x000000, 255);+ band_fill(b, CAT_X, y, 1, CAT_ROW, 0xC8C8C8, 255);+ uint8_t g = (uint8_t)FONT_ICON(section_icons[s]);+ uint32_t fg = on ? 0x000000 : 0xFFFFFF;+ font_draw_char(b, CAT_X + 4 + (12 - font_char_width(g)) / 2, y + 1, g, fg, 255, FONT_BLEND);+ font_draw(b, CAT_X + 18, y + 2, section_names[s], fg, 255, FONT_BLEND);+ }+ /* (the frame inside the list: its right side is the screen's edge) */+ int y = ui.section * CAT_ROW;+ b_rect(b, CAT_X + 1, y, CAT_W - 1, CAT_ROW, 0xFFFF00);+ b_rect(b, CAT_X + 2, y + 1, CAT_W - 3, CAT_ROW - 2, 0xFFFF00);+ b_rect(b, CAT_X, y - 1, CAT_W, CAT_ROW + 2, 0x000000);+}++/* the section's tool buttons below the sim, the first at the right (GameView::NotifyActiveMenuToolListChanged) */+static void row_fn(Band *b, const void *ctx) {+ (void)ctx;+ if (b->y0 + b->h <= SIM_H || b_misses(b, BTN_Y - 3, 18 + 6 + 6)) return;+ int n = menu_count(ui.section), scroll = ui.scroll;+ for (int k = 0; k < n; k++) {+ int x = BTN_X0 - BTN_STEP * k + scroll;+ if (x + 30 <= 0) break;+ if (x >= SCREEN_W) continue;+ int tool = menu_tool(ui.section, k);+ tool_button_band(b, x, BTN_Y, tool, tool == ui.tool[0] ? 0 : tool == ui.tool[1] ? 1 : -1);+ }+ if (n) {+ /* the selection's frame: thick, yellow, outlined in black (its top on the panel's first rows) */+ int x = BTN_X0 - BTN_STEP * ui.sel + ui.scroll;+ b_select(b, x, BTN_Y + 1, 30, 17);+ band_fill(b, x - 2, BTN_Y - 2, 34, 3, 0xFFFF00, 255);+ }+ /* the scroll bar (GameView::updateToolButtonScroll), when they don't fit */+ int total = (30 + 1) * n;+ if (total > SCREEN_W - 15) {+ int bar = SCREEN_W - 17, size = bar * bar / total;+ int maxscroll = total - BTN_X0 - 30 > 1 ? total - BTN_X0 - 30 : 1;+ int pos = (SCREEN_W - size) - (int)((long)scroll * (SCREEN_W - size) / maxscroll);+ if (pos < 0) pos = 0;+ band_fill(b, pos, BTN_Y + 21, size - 1, 2, 0xC8C8C8, 255);+ }+}++/* below the sim (with the panel): the buttons */+void menu_row(Overlay *o) {+ if (menu_count(ui.section)) ov_call(o, row_fn, NULL);+ else+ ov_text(o, 8, BTN_Y + 5, ui.section == SC_DECO ? "Decorations aren't kept on the calculator"+ : "No favorites yet: " FONT_DEL " in another section adds one", 0xC0C0C0, 255);+}++/* over the sim (every frame): the sections (only when they change: the screen keeps them), the selected tool's name+ * and description */+void menu_draw(Overlay *o, bool full) {+ if (full) ov_call(o, sections_fn, NULL);+ int n = menu_count(ui.section);+ if (!n) return;+ int tool = menu_tool(ui.section, ui.sel);+ char text[300], wrapped[320];+ char *p = text, *end = text + sizeof text;+ p = text_cat(p, end, "\bo"), p = text_cat(p, end, tool == PT_NONE ? "NONE (erases)" : tool_name(tool));+ p = text_cat(p, end, "\bw "), p = text_cat(p, end, tool_description(tool));+ p = text_cat(p, end, "\n\bgshift+OK: for Back");+ int w = CAT_X - SIM_X - 10;+ text_wrap(wrapped, sizeof wrapped, text, w - 8);+ int lines = font_text_lines(wrapped), h = lines * FONT_H + 6, y = SIM_H - 3 - h;+ ov_fill(o, SIM_X + 3, y, w, h, 0x000000, 200);+ ov_rect(o, SIM_X + 3, y, w, h, 0x808080, 255);+ ov_text(o, SIM_X + 7, y + 5, wrapped, 0xFFFFFF, 255);+}diff --git a/games/numpowder/src/ui_opts.c b/games/numpowder/src/ui_opts.cnew file mode 100644index 00000000..5bda145b--- /dev/null+++ b/games/numpowder/src/ui_opts.c@@ -0,0 +1,452 @@+/* NumPowder: the menu (var) and its windows, in the original's window look: the menu itself (resume, how to play,+ * keys, save, load, clear, the display preset, the settings, the credits), the settings (the original's Simulation+ * options and quick options), the confirm prompt (ConfirmPrompt) and the text pages; and the line of keys each mode+ * shows below the sim. */+#include "ui.h"+#include <string.h>++/* ui::Window: black, a grey border, its title in the original's InformationTitle colour over a separator */+void window_draw(Overlay *o, int x, int y, int w, int h, const char *title) {+ ov_fill(o, x - 1, y - 1, w + 2, h + 2, 0x000000, 255);+ ov_rect(o, x, y, w, h, 0xC8C8C8, 255);+ if (title) {+ ov_text(o, x + 4, y + 5, title, 0x8C8CFF, 255);+ ov_fill(o, x + 1, y + 18, w - 2, 1, 0xC8C8C8, 255);+ }+}++/* the keys line below the sim, for each mode: the keys that do something now */+const char *mode_keys(void) {+ switch (ui.mode) {+ case MODE_MENU:+ return "\bo" FONT_LEFT " " FONT_RIGHT "\bg: material " FONT_DOT " \bo" FONT_UP " " FONT_DOWN "\bg: category " FONT_DOT+ " \boOK\bg: choose " FONT_DOT " \boBack\bg: close";+ case MODE_SHAPE:+ return "move the other end " FONT_DOT " \boOK\bg: draw " FONT_DOT " \bo" FONT_DEL "\bg: box/fill " FONT_DOT+ " \boBack\bg: cancel";+ case MODE_STKM: return "\boarrows\bg: move the stickman " FONT_DOT " \boBack\bg: brush";+ case MODE_OPTIONS:+ case MODE_SETTINGS:+ return "\bo" FONT_UP " " FONT_DOWN "\bg: choose " FONT_DOT " \bo" FONT_LEFT " " FONT_RIGHT "\bg: change " FONT_DOT+ " \boOK " FONT_DOT " Back\bg: close";+ case MODE_SAVES: return "\bo" FONT_UP " " FONT_DOWN "\bg: choose a slot " FONT_DOT " \boOK " FONT_DOT " Back\bg: close";+ case MODE_CONFIRM: return "\boOK\bg: yes " FONT_DOT " \boBack\bg: no";+ case MODE_TEXT:+ if (ui.text == TEXT_HELP) return "\bo" FONT_LEFT " " FONT_RIGHT "\bg: page " FONT_DOT " \boBack\bg: close";+ if (ui.text == TEXT_KEYS) return "\bo" FONT_UP " " FONT_DOWN "\bg: scroll " FONT_DOT " \boBack\bg: close";+ return "\boBack\bg: close";+ }+ return "\botoolbox\bg: materials " FONT_DOT " \bovar\bg: menu " FONT_DOT " \bo+/-\bg: brush size " FONT_DOT+ " \boalpha\bg: pause";+}++/* ---------------------------------------------------------------- the menu (var) */+enum { MENU_RESUME, MENU_HELP, MENU_KEYS, MENU_SAVE, MENU_LOAD, MENU_CLEAR, MENU_DISPLAY, MENU_SETTINGS, MENU_CREDITS,+ MENU_COUNT };+static const char *const menu_names[MENU_COUNT] = {"Resume", "How to play", "Keys", "Save", "Load", "Clear",+ "Display", "Settings...", "Credits"};+/* the display presets, in the order of the original's render options (its 0-9 keys: Velocity is 1, Alternative+ * Velocity 0, Life 10), then the ones only its keys give */+static const uint8_t preset_order[PRESET_COUNT] = {+ PRESET_VELOCITY, PRESET_PRESSURE, PRESET_PERSISTENT, PRESET_FIRE, PRESET_BLOB, PRESET_HEAT, PRESET_FANCY,+ PRESET_NOTHING, PRESET_HEATGRAD, PRESET_ALTAIR, PRESET_LIFEGRAD, PRESET_DYNHEAT, PRESET_VORTICITY, PRESET_DEST};++void options_open(void) {+ ui.mode = MODE_OPTIONS;+}++static void preset_step(int d) {+ int now = render_preset_now(), at = 3; /* (fire, the original's default) */+ for (int i = 0; i < PRESET_COUNT; i++)+ if (preset_order[i] == now) at = i;+ at = (at + d + PRESET_COUNT) % PRESET_COUNT;+ render_apply_preset(preset_order[at]);+}++void options_keys(void) {+ if (key_pressed(K_BACK) || key_pressed(K_VAR)) {+ ui.mode = MODE_SIM;+ return;+ }+ if (key_pressed(K_TOOLBOX)) {+ menu_open();+ return;+ }+ if (key_repeat(K_UP)) ui.opt = (uint8_t)((ui.opt + MENU_COUNT - 1) % MENU_COUNT);+ if (key_repeat(K_DOWN)) ui.opt = (uint8_t)((ui.opt + 1) % MENU_COUNT);+ if (ui.opt == MENU_DISPLAY) {+ if (key_repeat(K_LEFT)) preset_step(-1);+ if (key_repeat(K_RIGHT) || key_pressed(K_OK)) preset_step(1);+ return;+ }+ if (!key_pressed(K_OK)) return;+ switch (ui.opt) {+ case MENU_RESUME: ui.mode = MODE_SIM; break;+ case MENU_HELP: text_open(TEXT_HELP); break;+ case MENU_KEYS: text_open(TEXT_KEYS); break;+ case MENU_SAVE: saves_open(true); break;+ case MENU_LOAD: saves_open(false); break;+ case MENU_CLEAR: confirm_open(CONFIRM_CLEAR); break;+ case MENU_SETTINGS: ui.mode = MODE_SETTINGS; break;+ case MENU_CREDITS: text_open(TEXT_CREDITS); break;+ }+}++/* a row's selection: a thick yellow frame */+static void row_frame(Overlay *o, int x, int y, int w, int h) {+ ov_frame(o, x, y, w, h, 2, 0xFFFF00);+}+/* a choice: "< value >", the arrows grey */+static void choice(Overlay *o, int right, int y, const char *v, bool sel) {+ char t[48] = FONT_LEFT " ";+ strcat(t, v);+ strcat(t, " " FONT_RIGHT);+ ov_text(o, right - font_text_width(t), y, t, 0xFFFFFF, sel ? 255 : 200);+}++#define MENU_W 220+#define MENU_ROW 15+#define MENU_H (24 + MENU_COUNT * MENU_ROW + 4)+void options_draw(Overlay *o) {+ int x = SIM_X + (SIM_W - MENU_W) / 2, y = (SIM_H - MENU_H) / 2;+ window_draw(o, x, y, MENU_W, MENU_H, "Menu");+ for (int k = 0; k < MENU_COUNT; k++) {+ int ry = y + 24 + k * MENU_ROW;+ bool sel = k == ui.opt;+ ov_text(o, x + 10, ry + 3, menu_names[k], k == MENU_CLEAR ? 0xFFD820 : 0xFFFFFF, sel ? 255 : 200);+ if (k == MENU_DISPLAY) {+ /* the preset's name, without " Display" */+ int p = render_preset_now();+ char name[40] = "custom";+ if (p >= 0) {+ strcpy(name, render_presets[p].name);+ char *d = strstr(name, " Display");+ if (d) *d = 0;+ }+ choice(o, x + MENU_W - 10, ry + 3, name, sel);+ }+ if (sel) row_frame(o, x + 4, ry, MENU_W - 8, MENU_ROW - 1);+ }+}++/* ---------------------------------------------------------------- the settings */+enum { SET_HEAT, SET_AHEAT, SET_NGRAV, SET_WATER, SET_AIR, SET_GRAVITY, SET_EDGE, SET_GRAVFIELD, SET_STKM, SET_DEBUG,+ SET_COUNT };+static const char *const set_names[SET_COUNT] = {+ "Heat simulation", "Ambient heat", "Newtonian gravity", "Water equalisation", "Air", "Gravity", "Edges",+ "Gravity field lines", "Control the stickman", "Details in the HUD"};+static const char *const set_info[SET_COUNT] = {+ "Can cause odd behaviour when disabled",+ "The air keeps heat: hot things warm it",+ "Heavy particles pull others towards them",+ "Water levels itself out",+ "The air and its pressure, or not",+ "Which way things fall",+ "Solid: things stop at the edges; Void: they fall out",+ "Draws Newtonian gravity's field",+ "The arrows move STKM (shift: STK2)",+ "FPS, particles and all about what's under the brush"};+static const char *const air_names[] = {"On", "Pressure off", "Velocity off", "Off", "No update"};+static const char *const grav_names[] = {"Vertical", "Off", "Radial", "Custom"};+static const char *const edge_names[] = {"Void", "Solid", "Loop"};++static bool set_check(int k) {+ return k == SET_HEAT || k == SET_AHEAT || k == SET_NGRAV || k == SET_WATER || k == SET_GRAVFIELD || k == SET_DEBUG;+}+static bool set_value(int k) {+ switch (k) {+ case SET_HEAT: return settings.heat;+ case SET_AHEAT: return settings.ambient_heat;+ case SET_NGRAV: return settings.newtonian_gravity;+ case SET_WATER: return settings.water_equalization;+ case SET_GRAVFIELD: return ren.grav_field;+ case SET_DEBUG: return ui.debug;+ }+ return false;+}+static void set_change(int k, int d) {+ switch (k) {+ case SET_HEAT: settings.heat = !settings.heat; break;+ case SET_AHEAT: settings.ambient_heat = !settings.ambient_heat; break;+ case SET_NGRAV: settings.newtonian_gravity = !settings.newtonian_gravity; break;+ case SET_WATER: settings.water_equalization = !settings.water_equalization; break;+ case SET_GRAVFIELD: ren.grav_field = !ren.grav_field; break;+ case SET_DEBUG: ui.debug = !ui.debug; break;+ case SET_AIR: settings.air_mode = (uint8_t)((settings.air_mode + d + NUM_AIRMODES) % NUM_AIRMODES); break;+ case SET_GRAVITY: settings.gravity_mode = (uint8_t)((settings.gravity_mode + d + NUM_GRAVMODES) % NUM_GRAVMODES); break;+ case SET_EDGE: settings.edge_mode = (uint8_t)((settings.edge_mode + d + NUM_EDGEMODES) % NUM_EDGEMODES); break;+ }+ sim_settings_changed();+}++void settings_keys(void) {+ if (key_pressed(K_BACK) || key_pressed(K_VAR)) {+ ui.mode = MODE_OPTIONS;+ return;+ }+ if (key_repeat(K_UP)) ui.set = (uint8_t)((ui.set + SET_COUNT - 1) % SET_COUNT);+ if (key_repeat(K_DOWN)) ui.set = (uint8_t)((ui.set + 1) % SET_COUNT);+ int k = ui.set;+ if (k == SET_STKM) {+ if (key_pressed(K_OK)) {+ if (elementCount[PT_STKM] || elementCount[PT_STKM2] || elementCount[PT_SPAWN] || elementCount[PT_SPAWN2]) ui.mode = MODE_STKM;+ else ui_message("Draw STKM first (in Special)");+ }+ return;+ }+ if (key_repeat(K_LEFT)) set_change(k, set_check(k) ? 0 : -1);+ if (key_repeat(K_RIGHT) || key_pressed(K_OK)) set_change(k, 1);+}++#define SET_W 268+#define SET_ROW 14+#define SET_H (24 + SET_COUNT * SET_ROW + 22)+void settings_draw(Overlay *o) {+ int x = SIM_X + (SIM_W - SET_W) / 2, y = (SIM_H - SET_H) / 2;+ window_draw(o, x, y, SET_W, SET_H, "Settings");+ for (int k = 0; k < SET_COUNT; k++) {+ int ry = y + 23 + k * SET_ROW;+ bool sel = k == ui.set;+ if (set_check(k)) {+ /* ui::Checkbox: a 12 x 12 box, filled in the middle when checked */+ ov_rect(o, x + 10, ry + 1, 12, 12, 0xFFFFFF, sel ? 255 : 200);+ if (set_value(k)) ov_fill(o, x + 13, ry + 4, 6, 6, 0xFFFFFF, 255);+ ov_text(o, x + 28, ry + 3, set_names[k], 0xFFFFFF, sel ? 255 : 200);+ } else {+ ov_text(o, x + 10, ry + 3, set_names[k], 0xFFFFFF, sel ? 255 : 200);+ const char *v = k == SET_AIR ? air_names[settings.air_mode % NUM_AIRMODES]+ : k == SET_GRAVITY ? grav_names[settings.gravity_mode % NUM_GRAVMODES]+ : k == SET_EDGE ? edge_names[settings.edge_mode % NUM_EDGEMODES] : NULL;+ if (v) choice(o, x + SET_W - 10, ry + 3, v, sel);+ else ov_text(o, x + SET_W - 20, ry + 3, "\x95", 0xC0C0C0, sel ? 255 : 120); /* (U+E015, an arrow) */+ }+ if (sel) row_frame(o, x + 4, ry, SET_W - 8, SET_ROW - 1);+ }+ /* the selected one's details (the original writes them under each), or the last message */+ ov_fill(o, x + 1, y + SET_H - 18, SET_W - 2, 1, 0xC8C8C8, 255);+ char custom[64];+ const char *info = set_info[ui.set];+ if (ui.set == SET_GRAVITY && settings.gravity_mode == GRAV_CUSTOM) {+ /* (the custom gravity's, as a save gives it: x and y) */+ char *p = custom, *e = custom + sizeof custom;+ p = text_cat(p, e, "Custom gravity: x "), p = text_cat_fixed(p, e, settings.custom_gravity_x);+ p = text_cat(p, e, ", y "), p = text_cat_fixed(p, e, settings.custom_gravity_y);+ info = custom;+ }+ if (ui.tip > 0 && ui.tip_text) ov_text(o, x + 6, y + SET_H - 13, ui.tip_text, 0xFFFFFF, 255);+ else ov_text(o, x + 6, y + SET_H - 13, info, 0xC0C0C0, 255);+}++/* ---------------------------------------------------------------- the confirm prompt */+static const char *const confirm_title[] = {"Clear the simulation", "Load a simulation", "Overwrite a save"};+static const char *const confirm_text[] = {+ "This removes every particle, wall and the air. The autosave and the slots stay.",+ "The simulation on the screen is replaced by the one saved.",+ "The slot already holds a simulation: it's replaced by this one."};+void confirm_open(int what) {+ if (ui.mode != MODE_CONFIRM) ui.prev_mode = ui.mode;+ ui.confirm = (uint8_t)what;+ ui.mode = MODE_CONFIRM;+}+void confirm_keys(void) {+ if (key_pressed(K_BACK)) {+ /* (back to where it was asked from: the saves, or the menu for Clear) */+ ui.mode = ui.prev_mode == MODE_SAVES || ui.prev_mode == MODE_OPTIONS ? ui.prev_mode : MODE_SIM;+ return;+ }+ if (key_pressed(K_OK)) {+ ui.mode = MODE_SIM;+ if (ui.confirm == CONFIRM_CLEAR) {+ sim_clear();+ render_clear_accumulation();+ ui_message("Cleared");+ } else if (ui.confirm == CONFIRM_LOAD) {+ load_slot(ui.slot);+ } else if (ui.confirm == CONFIRM_OVERWRITE) {+ save_slot(ui.slot);+ }+ }+}+void confirm_draw(Overlay *o) {+ char msg[160];+ text_wrap(msg, sizeof msg, confirm_text[ui.confirm], 250 - 16);+ int lines = font_text_lines(msg), w = 250, h = 24 + lines * FONT_H + 6 + 16;+ int x = SIM_X + (SIM_W - w) / 2, y = (SIM_H - h) / 2;+ ov_fill(o, x - 1, y - 1, w + 2, h + 2, 0x000000, 255);+ ov_rect(o, x, y, w, h, 0xC8C8C8, 255);+ ov_text(o, x + 4, y + 8, confirm_title[ui.confirm], 0xFFD820, 255); /* WarningTitle */+ ov_text(o, x + 8, y + 26, msg, 0xFFFFFF, 255);+ /* Cancel and Continue buttons, their keys */+ int by = y + h - 16;+ ov_rect(o, x, by, w - 75, 16, 0xC8C8C8, 255);+ ov_text(o, x + 4, by + 4, "Cancel \bg(Back)", 0xFFFFFF, 255);+ ov_rect(o, x + w - 76, by, 76, 16, 0xC8C8C8, 255);+ ov_text(o, x + w - 72, by + 4, "Continue \bg(OK)", 0xFFD820, 255);+ ov_frame(o, x + w - 76, by, 76, 16, 2, 0xFFFF00);+}++/* ---------------------------------------------------------------- how to play, keys, credits */+/* how to play: a few pages, the original's element names in its teal (\bt), keys in its orange (\bo) */+static const char *const help_pages[][2] = {+ {"Draw",+ "\botoolbox\bw opens the materials: \bo" FONT_LEFT " " FONT_RIGHT "\bw pick one,\n"+ "\bo" FONT_UP " " FONT_DOWN "\bw change the category, \boOK\bw takes it.\n"+ "\boOK\bw draws it under the brush (the outline),\n"+ "\boBack\bw erases.\n"+ "\boArrows\bw move the brush, \boshift+arrows\bw faster.\n"+ "\bo+\bw and \bo-\bw change its size, \boshift\bw with them its\n"+ "shape.\n"+ "Below the sim: what \boOK\bw and \boBack\bw hold, and the\n"+ "keys that do something right now."},+ {"Things react",+ "\btSAND\bw sinks in \btWATR\bw, and \btOIL\bw floats on it.\n"+ "\btFIRE\bw burns \btWOOD\bw, \btOIL\bw and \btGAS\bw.\n"+ "\btLAVA\bw melts \btICE\bw and boils \btWATR\bw.\n"+ "\btACID\bw eats most things (not \btGLAS\bw).\n"+ "\n"+ "Each material says what it does when you pick\n"+ "it in the materials (\botoolbox\bw).\n"+ "Try things together!"},+ {"Hot and cold",+ "\btHEAT\bw and \btCOOL\bw (in Tools) warm and chill\n"+ "what's under the brush while \boOK\bw is held.\n"+ "Heat \btICE\bw: it melts to \btWATR\bw, then boils to\n"+ "\btWTRV\bw (steam). Cool it to bring it back.\n"+ "\n"+ "Over something, the brush shows its name and\n"+ "temperature at the top right.\n"+ "\bovar\bw, Display: Heat shows every temperature."},+ {"Walls",+ "\btWALL\bw (in Walls) holds everything. Other walls\n"+ "let only air, liquids, powders or gases through.\n"+ "The wall with a red X erases walls.\n"+ "\n"+ "The screen's edges are solid: things stop there.\n"+ "In \bovar\bw, Settings, Edges: Void lets them fall out,\n"+ "Loop brings them back on the other side."},+ {"Electricity",+ "Draw \btMETL\bw, then touch it with \btSPRK\bw: the spark\n"+ "runs along the metal.\n"+ "\btBTRY\bw keeps sparking the metal it touches.\n"+ "\btPSCN\bw turns a \btSWCH\bw (switch) on, \btNSCN\bw off.\n"+ "\btLCRY\bw lights up, \btINST\bw carries a spark at once.\n"+ "\n"+ "They're in Electronics and Powered Materials."},+ {"Explosives",+ "\btGUN\bw (gunpowder), \btNITR\bw and \btC-4\bw blow up when\n"+ "\btFIRE\bw or \btSPRK\bw touches them.\n"+ "\btBOMB\bw blows up what it falls on.\n"+ "\n"+ "Explosions push the air: \bovar\bw, Display: Pressure\n"+ "shows it, red pushing, blue pulling.\n"+ "They're in Explosives."},+ {"Pause, look, keep",+ "\boalpha\bw pauses; \boshift+alpha\bw moves one frame.\n"+ "\bovar\bw opens the menu:\n"+ " Display changes the look (Fire, Heat, Fancy...),\n"+ " Save and Load keep four simulations,\n"+ " Settings has the original's options.\n"+ "\boHome\bw saves and quits: it's all here next time.\n"+ "\n"+ "Keys, in the menu, lists every key."},+};+#define HELP_PAGES (int)(sizeof help_pages / sizeof help_pages[0])++static const char keys_text[] =+ "\boArrows\bg move the brush (\boshift\bg: 4 at a time)\n"+ "\boOK\bg draws what OK holds (its border red)\n"+ "\boBack\bg draws what Back holds (blue; ERASE)\n"+ "\boshift+OK\bg a line from here (\bo" FONT_DEL "\bg: a box, then\n"+ " a fill); \boOK\bg draws it, \boBack\bg cancels\n"+ "\boshift+Back\bg the same, with what Back holds\n"+ "\botoolbox\bg the materials: \bo" FONT_LEFT " " FONT_RIGHT "\bg one (\boshift\bg: a row\n"+ " of them), \bo" FONT_UP " " FONT_DOWN "\bg the category, \boOK\bg for OK,\n"+ " \boshift+OK\bg for Back, \bo" FONT_DEL "\bg a favorite or not\n"+ "\bo+ -\bg brush size (\boshift\bg: its shape)\n"+ "\bo" FONT_DEL "\bg OK takes what's under the brush\n"+ "\boalpha\bg pause, \boshift+alpha\bg one frame\n"+ "\bovar\bg the menu: help, saves, display, settings\n"+ "\boHome\bg saves and quits\n"+ "\bgStickmen: draw \boSTKM\bg (in Special); the \boarrows\bg\n"+ "move it (\boshift\bg: STK2), \bodown\bg uses its element,\n"+ "\boBack\bg gives the brush back";+static const char credits_text[] =+ "\bl\bUNumPowder\bU\n"+ "\n"+ "\bwInspired by The Powder Toy, not affiliated with its\n"+ "developers.\n"+ "\n"+ "Elements, font and icons ported from The Powder Toy's\n"+ "source code (GPL-3.0) by Stanislaw K Skowronek, Simon\n"+ "Robertshaw and its contributors.\n"+ "\n"+ "Made by Mason Chen as part of NumPlay.\n"+ "\bghttps://powdertoy.co.uk";+#define TEXT_LINES 11+void text_open(int what) {+ ui.text = (uint8_t)what;+ ui.text_top = 0;+ ui.mode = MODE_TEXT;+}+void text_keys(void) {+ if (ui.text == TEXT_HELP) {+ if (key_repeat(K_RIGHT) || key_pressed(K_OK)) {+ if (ui.text_top + 1 < HELP_PAGES) ui.text_top++;+ else if (key_pressed(K_OK)) ui.mode = MODE_OPTIONS;+ }+ if (key_repeat(K_LEFT) && ui.text_top > 0) ui.text_top--;+ } else if (ui.text == TEXT_KEYS) {+ int lines = font_text_lines(keys_text);+ if (key_repeat(K_DOWN) && ui.text_top < lines - TEXT_LINES) ui.text_top++;+ if (key_repeat(K_UP) && ui.text_top > 0) ui.text_top--;+ if (key_pressed(K_OK)) ui.mode = MODE_OPTIONS;+ } else if (key_pressed(K_OK)) {+ ui.mode = MODE_OPTIONS;+ }+ if (key_pressed(K_BACK) || key_pressed(K_VAR)) ui.mode = MODE_OPTIONS;+}+#define TEXT_X (SIM_X + 6)+#define TEXT_Y 4+#define TEXT_W (SIM_W - 12)+#define TEXT_H 184+void text_draw(Overlay *o) {+ char title[48];+ const char *t;+ if (ui.text == TEXT_HELP) {+ int p = ui.text_top;+ strcpy(title, "How to play: ");+ strcat(title, help_pages[p][0]);+ t = help_pages[p][1];+ } else {+ strcpy(title, ui.text == TEXT_KEYS ? "Keys" : "Credits");+ t = ui.text == TEXT_KEYS ? keys_text : credits_text;+ }+ window_draw(o, TEXT_X, TEXT_Y, TEXT_W, TEXT_H, title);+ for (int k = 0; k < ui.text_top && *t && ui.text != TEXT_HELP; t++)+ if (*t == '\n') k++;+ /* (the lines shown, up to the window's bottom) */+ char buf[700];+ int n = 0, lines = 0;+ while (t[n] && n < (int)sizeof buf - 1) {+ if (t[n] == '\n' && ++lines >= TEXT_LINES) break;+ buf[n] = t[n], n++;+ }+ buf[n] = 0;+ ov_text(o, TEXT_X + 8, TEXT_Y + 27, buf, 0xFFFFFF, 255);+ ov_fill(o, TEXT_X + 1, TEXT_Y + TEXT_H - 18, TEXT_W - 2, 1, 0xC8C8C8, 255);+ if (ui.text == TEXT_HELP) {+ /* the pages: dots, the one shown white */+ char d[4];+ fmt_int(d, ui.text_top + 1);+ char s[24];+ strcpy(s, d), strcat(s, " / "), fmt_int(d, HELP_PAGES), strcat(s, d);+ ov_text(o, TEXT_X + TEXT_W - 8 - font_text_width(s), TEXT_Y + TEXT_H - 13, s, 0xC0C0C0, 255);+ for (int k = 0; k < HELP_PAGES; k++)+ ov_fill(o, TEXT_X + 8 + k * 9, TEXT_Y + TEXT_H - 10, 5, 5, k == ui.text_top ? 0xFFFFFF : 0x606060, 255);+ } else if (ui.text == TEXT_KEYS) {+ int all = font_text_lines(keys_text);+ if (all > TEXT_LINES)+ ov_text(o, TEXT_X + 8, TEXT_Y + TEXT_H - 13, ui.text_top + TEXT_LINES < all ? "\bg" FONT_DOWN " more below" : "\bg" FONT_UP " more above",+ 0xC0C0C0, 255);+ }+}diff --git a/games/numpowder/src/ui_save.c b/games/numpowder/src/ui_save.cnew file mode 100644index 00000000..456b4c0f--- /dev/null+++ b/games/numpowder/src/ui_save.c@@ -0,0 +1,274 @@+/* NumPowder: the save slots (the core's simsave), the interface's choices (numpowder.cfg), and a copy of them in+ * a Python script (as games/finalearth2/src/savecopy.c): installing apps from the NumWorks website keeps only+ * Python scripts, so the saves are also kept in numpowder_saves.py, each as a comment line "#>name:base64", and+ * come back from it when the files themselves are gone. The copy gives way to the saves: when the storage is+ * too full for both, there is no copy. */+#include "ui.h"+#include <string.h>+#include "simsave.h"++static const char *const slot_files[NSLOTS + 1] = {"numpowder.sav", "numpowder1.sav", "numpowder2.sav",+ "numpowder3.sav", "numpowder4.sav"};+#define CFG_NAME "numpowder.cfg"+#define COPY_NAME "numpowder_saves.py"+static const char *const kept[] = {"numpowder.cfg", "numpowder.sav", "numpowder1.sav", "numpowder2.sav",+ "numpowder3.sav", "numpowder4.sav"};+#define NKEPT (int)(sizeof kept / sizeof kept[0])++/* ---------------------------------------------------------------- the copy in a Python script */+static const char copy_head[] =+ "# NumPowder keeps a copy of your simulations here, so that\n"+ "# reinstalling it doesn't erase them. If you delete this file,\n"+ "# the game writes it again: your saves stay either way.\n";+static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";++static void save_copy(void) {+ /* (its size first, then written in place: the files read again, as writing it may have moved them) */+ uint32_t total = 1 + (sizeof copy_head - 1) + 1, len;+ int n = 0;+ for (int k = 0; k < NKEPT; k++)+ if (plat_load(kept[k], &len) && len) total += 2 + (uint32_t)strlen(kept[k]) + 1 + (len + 2) / 3 * 4 + 1, n++;+ plat_remove(COPY_NAME); /* (the old copy's room counts for the new one) */+ if (!n) return;+ uint8_t *o = plat_reserve(COPY_NAME, total), *p = o;+ if (!o) return;+ *p++ = 0; /* (the script's status byte: not imported) */+ memcpy(p, copy_head, sizeof copy_head - 1), p += sizeof copy_head - 1;+ for (int k = 0; k < NKEPT; k++) {+ const uint8_t *d = plat_load(kept[k], &len);+ if (!d || !len) continue;+ uint32_t nl = (uint32_t)strlen(kept[k]);+ *p++ = '#', *p++ = '>';+ memcpy(p, kept[k], nl), p += nl;+ *p++ = ':';+ for (uint32_t i = 0; i < len; i += 3, p += 4) {+ /* (written out: GCC 15.2 for the calculator got a loop over the four wrong, see NumPlay's+ * launcher/src/storage.c) */+ uint32_t left = len - i, v = (uint32_t)d[i] << 16 | (left > 1 ? d[i + 1] << 8 : 0) | (left > 2 ? d[i + 2] : 0);+ p[0] = (uint8_t)b64[v >> 18 & 63];+ p[1] = (uint8_t)b64[v >> 12 & 63];+ p[2] = left > 1 ? (uint8_t)b64[v >> 6 & 63] : '=';+ p[3] = left > 2 ? (uint8_t)b64[v & 63] : '=';+ }+ *p++ = '\n';+ }+ *p++ = 0;+ plat_reserved(COPY_NAME, (uint32_t)(p - o));+}++static int b64_value(uint8_t c) {+ for (int i = 0; i < 64; i++)+ if ((uint8_t)b64[i] == c) return i;+ return -1;+}+/* where kept[k]'s line starts in the copy (just after its tag) and its length, or NULL */+static const uint8_t *copy_line(int k, uint32_t *len) {+ uint32_t n, nl = (uint32_t)strlen(kept[k]);+ const uint8_t *c = plat_load(COPY_NAME, &n);+ if (!c) return NULL;+ for (uint32_t i = 0; i + nl + 3 <= n; i++)+ if (c[i] == '#' && c[i + 1] == '>' && !memcmp(c + i + 2, kept[k], nl) && c[i + 2 + nl] == ':') {+ const uint8_t *l = c + i + 3 + nl;+ uint32_t m = 0;+ while (l + m < c + n && l[m] != '\n' && l[m]) m++;+ *len = m;+ return l;+ }+ return NULL;+}+void saves_restore(void) {+ for (int k = 0; k < NKEPT; k++) {+ uint32_t have, len;+ if (plat_load(kept[k], &have)) continue;+ const uint8_t *l = copy_line(k, &len);+ if (!l || !len || len % 4) continue;+ uint32_t size = len / 4 * 3 - (l[len - 1] == '=') - (l[len - 2] == '=');+ /* decoded straight into the file's room, then the copy read again (making the file may have moved it) */+ uint8_t *out = plat_reserve(kept[k], size);+ if (!out) continue;+ l = copy_line(k, &len);+ bool ok = l != NULL && len / 4 * 3 - (l[len - 1] == '=') - (l[len - 2] == '=') == size;+ uint32_t o = 0;+ for (uint32_t i = 0; ok && i < len; i += 4) {+ int v0 = l[i] == '=' ? 0 : b64_value(l[i]), v1 = l[i + 1] == '=' ? 0 : b64_value(l[i + 1]);+ int v2 = l[i + 2] == '=' ? 0 : b64_value(l[i + 2]), v3 = l[i + 3] == '=' ? 0 : b64_value(l[i + 3]);+ if (v0 < 0 || v1 < 0 || v2 < 0 || v3 < 0) ok = false;+ uint32_t w = (uint32_t)(v0 << 18 | v1 << 12 | v2 << 6 | v3);+ if (o < size) out[o++] = (uint8_t)(w >> 16);+ if (o < size) out[o++] = (uint8_t)(w >> 8);+ if (o < size) out[o++] = (uint8_t)w;+ }+ if (ok && o == size) plat_reserved(kept[k], size);+ else plat_remove(kept[k]);+ }+}++/* ---------------------------------------------------------------- the interface's choices */+#define CFG_VERSION 1+enum { CF_HDISP_AUTO = 1, CF_PAUSED = 2 }; /* Dynamic Heat Display's range; the simulation paused */+typedef struct {+ uint8_t version, section, shape, slot;+ uint8_t heat, aheat, ngrav, water, air, gravity, edge, deco, gfield, debug, nfav, flags; /* (flags: CF_*) */+ int16_t rx, ry, cx, cy;+ int32_t tool[2];+ uint32_t render_mode, display_mode, colour_mode;+ int32_t fav[NFAV];+} Config;++void config_save(void) {+ Config c;+ memset(&c, 0, sizeof c);+ c.version = CFG_VERSION, c.section = ui.section, c.shape = brush.shape, c.slot = ui.slot;+ c.heat = settings.heat, c.aheat = settings.ambient_heat, c.ngrav = settings.newtonian_gravity;+ c.water = settings.water_equalization, c.air = settings.air_mode, c.gravity = settings.gravity_mode;+ c.edge = settings.edge_mode, c.deco = ren.decorations, c.gfield = ren.grav_field, c.debug = ui.debug;+ c.rx = (int16_t)brush.rx, c.ry = (int16_t)brush.ry, c.cx = (int16_t)ui.cx, c.cy = (int16_t)ui.cy;+ c.tool[0] = ui.tool[0], c.tool[1] = ui.tool[1];+ c.render_mode = ren.render_mode, c.display_mode = ren.display_mode, c.colour_mode = ren.colour_mode;+ c.nfav = ui.nfav;+ c.flags = (uint8_t)((ren.hdisp_auto ? CF_HDISP_AUTO : 0) | (sys_pause ? CF_PAUSED : 0));+ for (int k = 0; k < ui.nfav; k++) c.fav[k] = ui.fav[k];+ plat_save(CFG_NAME, &c, sizeof c);+}++static bool tool_ok(int tool) {+ if (tool & TOOL_WALLS) return (tool & 0xFF) < UI_WALLCOUNT && !(tool & ~(TOOL_WALLS | 0xFF));+ if (tool & TOOL_SIMTOOLS) return (tool & 0xFF) < TOOL_COUNT && !(tool & ~(TOOL_SIMTOOLS | 0xFF));+ if (tool & TOOL_UI) return tool == TOOL_SAMPLE;+ return IsElementOrNone(TYP(tool)) && (TYP(tool) == PT_LIFE ? ID(tool) < NGOL : ID(tool) == 0);+}+void config_load(void) {+ uint32_t len;+ const uint8_t *d = plat_load(CFG_NAME, &len);+ if (!d || len != sizeof(Config)) return;+ Config c;+ memcpy(&c, d, sizeof c);+ if (c.version != CFG_VERSION) return;+ ui.section = c.section < SC_TOTAL ? c.section : SC_POWDERS;+ brush.shape = c.shape < NUM_BRUSHES ? c.shape : BRUSH_CIRCLE;+ ui.slot = c.slot <= NSLOTS ? c.slot : 0;+ settings.heat = c.heat, settings.ambient_heat = c.aheat, settings.newtonian_gravity = c.ngrav;+ settings.water_equalization = c.water;+ settings.air_mode = c.air < NUM_AIRMODES ? c.air : AIR_ON;+ settings.gravity_mode = c.gravity < NUM_GRAVMODES ? c.gravity : GRAV_VERTICAL;+ settings.edge_mode = c.edge < NUM_EDGEMODES ? c.edge : EDGE_SOLID;+ ren.decorations = c.deco, ren.grav_field = c.gfield, ui.debug = c.debug;+ if (c.rx >= 0 && c.rx <= 50 && c.ry >= 0 && c.ry <= 50) brush.rx = c.rx, brush.ry = c.ry;+ if (c.cx >= 0 && c.cx < XRES && c.cy >= 0 && c.cy < YRES) ui.cx = c.cx, ui.cy = c.cy;+ for (int s = 0; s < 2; s++)+ if (tool_ok(c.tool[s])) ui.tool[s] = c.tool[s];+ render_apply(c.render_mode, c.display_mode, c.colour_mode);+ ren.hdisp_auto = (c.flags & CF_HDISP_AUTO) != 0;+ sys_pause = (c.flags & CF_PAUSED) != 0; /* (paused or not, kept across Home and starting again) */+ ui.nfav = 0;+ for (int k = 0; k < c.nfav && k < NFAV; k++)+ if (tool_ok(c.fav[k])) ui.fav[ui.nfav++] = c.fav[k];+ sim_settings_changed();+}++/* ---------------------------------------------------------------- the slots */+bool slot_used(int slot, int *nparts) {+ uint32_t len;+ const uint8_t *d = plat_load(slot_files[slot], &len);+ int n = d && len ? simsave_count(d, len) : -1;+ if (nparts) *nparts = n;+ return n >= 0;+}++int save_slot(int slot) {+ uint32_t n = simsave_size();+ if (!n) {+ config_save();+ save_copy();+ ui_message("Saving isn't ready yet");+ return SAVE_UNAVAILABLE;+ }+ plat_remove(COPY_NAME); /* (the copy gives way to the save) */+ uint8_t *o = plat_reserve(slot_files[slot], n);+ bool ok = false;+ if (o) {+ uint32_t w = simsave_write(o, n);+ if (w) plat_reserved(slot_files[slot], w), ok = true;+ else plat_remove(slot_files[slot]);+ }+ config_save();+ save_copy();+ ui_message(ok ? (slot ? "Saved" : "Autosaved") : "No room to save: delete some files");+ return ok ? SAVE_OK : SAVE_NOROOM;+}++bool load_slot(int slot) {+ uint32_t len;+ const uint8_t *d = plat_load(slot_files[slot], &len);+ if (!d) {+ ui_message("Nothing saved there");+ return false;+ }+ if (!simsave_read(d, len)) {+ ui_message("That save couldn't be read");+ return false;+ }+ render_clear_accumulation();+ ui.slot = (uint8_t)slot;+ ui_message("Loaded");+ return true;+}++/* ---------------------------------------------------------------- the slots' window */+void saves_open(bool saving) {+ ui.saving = saving;+ ui.prev_mode = MODE_OPTIONS;+ ui.mode = MODE_SAVES;+}+static int slot_sel;+void saves_keys(void) {+ if (key_pressed(K_BACK)) {+ ui.mode = MODE_OPTIONS;+ return;+ }+ if (key_repeat(K_UP)) slot_sel = (slot_sel + NSLOTS) % (NSLOTS + 1);+ if (key_repeat(K_DOWN)) slot_sel = (slot_sel + 1) % (NSLOTS + 1);+ if (key_pressed(K_OK)) {+ ui.slot = (uint8_t)slot_sel;+ if (ui.saving) {+ if (slot_sel && slot_used(slot_sel, NULL)) {+ ui.prev_mode = MODE_SAVES;+ confirm_open(CONFIRM_OVERWRITE);+ } else {+ save_slot(slot_sel);+ ui.mode = MODE_SIM;+ }+ } else if (slot_used(slot_sel, NULL)) {+ ui.prev_mode = MODE_SAVES;+ confirm_open(CONFIRM_LOAD);+ } else {+ ui_message("Nothing saved there");+ }+ }+}+void saves_draw(Overlay *o) {+ int w = 200, h = 24 + (NSLOTS + 1) * 18 + 4, x = SIM_X + (SIM_W - w) / 2, y = (SIM_H - h) / 2;+ window_draw(o, x, y, w, h, ui.saving ? "Save the simulation" : "Load a simulation");+ for (int s = 0; s <= NSLOTS; s++) {+ int ry = y + 24 + s * 18;+ int nparts;+ bool used = slot_used(s, &nparts);+ char t[40], info[24] = "empty";+ if (used) {+ fmt_int(info, nparts);+ strcat(info, nparts == 1 ? " particle" : " particles");+ }+ if (s) {+ strcpy(t, "Slot ");+ char d[4];+ fmt_int(d, s);+ strcat(t, d);+ } else {+ strcpy(t, "Autosave \bg(Home)");+ }+ ov_rect(o, x + 6, ry, w - 12, 16, 0xC8C8C8, 255);+ ov_text(o, x + 10, ry + 4, t, 0xFFFFFF, 255);+ ov_text(o, x + w - 10 - font_text_width(info), ry + 4, info, used ? 0x20D8FF : 0x808080, 255);+ if (s == slot_sel) ov_frame(o, x + 6, ry, w - 12, 16, 2, 0xFFFF00);+ }+}diff --git a/games/numpowder/src/walls.c b/games/numpowder/src/walls.cnew file mode 100644index 00000000..84e583ce--- /dev/null+++ b/games/numpowder/src/walls.c@@ -0,0 +1,141 @@+/* NumPowder: The Powder Toy's walls: their types (SimulationData.cpp's LoadWalls) and drawing them (Editing.cpp's+ * CreateWalls, CreateWallLine, CreateWallBox, FloodWalls). What they do is in the simulation (sim.c, sim_move.c,+ * air.c, gravity.c). Wall cells are WCELL particles wide. */+#include "simpriv.h"++const WallType walltypes[UI_WALLCOUNT] = {+ {0x808080, 0x000000, 0, "ERASE", "DEFAULT_WL_ERASE", "Erases walls."},+ {0xC0C0C0, 0x101010, 0, "CONDUCTIVE WALL", "DEFAULT_WL_CNDTW", "Blocks everything. Conductive."},+ {0x808080, 0x808080, 0, "EWALL", "DEFAULT_WL_EWALL", "E-Wall. Becomes transparent when electricity is connected."},+ {0xFF8080, 0xFF2008, 1, "DETECTOR", "DEFAULT_WL_DTECT", "Detector. Generates electricity when a particle is inside."},+ {0x808080, 0x000000, 0, "STREAMLINE", "DEFAULT_WL_STRM", "Streamline. Creates a line that follows air movement."},+ {0x8080FF, 0x000000, 1, "FAN", "DEFAULT_WL_FAN", "Fan. Accelerates air. Use the line tool to set direction and strength."},+ {0xC0C0C0, 0x101010, 2, "LIQUID WALL", "DEFAULT_WL_LIQD", "Allows liquids, blocks all other particles. Conductive."},+ {0x808080, 0x000000, 1, "ABSORB WALL", "DEFAULT_WL_ABSRB", "Absorbs particles but lets air currents through."},+ {0x808080, 0x000000, 3, "WALL", "DEFAULT_WL_WALL", "Basic wall, blocks everything."},+ {0x3C3C3C, 0x000000, 1, "AIRONLY WALL", "DEFAULT_WL_AIR", "Allows air, but blocks all particles."},+ {0x575757, 0x000000, 1, "POWDER WALL", "DEFAULT_WL_POWDR", "Allows powders, blocks all other particles."},+ {0xFFFF22, 0x101010, 2, "CONDUCTOR", "DEFAULT_WL_CNDTR", "Conductor. Allows all particles to pass through and conducts electricity."},+ {0x242424, 0x101010, 0, "EHOLE", "DEFAULT_WL_EHOLE", "E-Hole. absorbs particles, releases them when powered."},+ {0x579777, 0x000000, 1, "GAS WALL", "DEFAULT_WL_GAS", "Allows gases, blocks all other particles."},+ {0xFFEE00, 0xAA9900, 4, "GRAVITY WALL", "DEFAULT_WL_GRVTY", "Gravity wall. Newtonian Gravity has no effect inside a box drawn with this."},+ {0xFFAA00, 0xAA5500, 4, "ENERGY WALL", "DEFAULT_WL_ENRGY", "Allows energy particles, blocks all other particles."},+ {0xDCDCDC, 0x000000, 1, "AIRBLOCK WALL", "DEFAULT_WL_NOAIR", "Allows all particles, but blocks air."},+ {0x808080, 0x000000, 0, "ERASEALL", "DEFAULT_WL_ERASEA", "Erases walls, particles, and signs."},+ {0x800080, 0x000000, 0, "STASIS WALL", "DEFAULT_WL_STASIS", "Freezes particles inside the wall in place until powered."},+};++/* the walls in a square of wall cells around x, y (particles): the brush's radius, or rx, ry */+int CreateWalls(int x, int y, int rx, int ry, int wall, bool withBrush) {+ if (withBrush) {+ rx = brush.rx;+ ry = brush.ry;+ }+ ry = ry / WCELL;+ rx = rx / WCELL;+ x = x / WCELL;+ y = y / WCELL;+ x -= rx;+ y -= ry;+ for (int wallX = x; wallX <= x + rx + rx; wallX++)+ for (int wallY = y; wallY <= y + ry + ry; wallY++)+ if (wallX >= 0 && wallX < XWCELLS && wallY >= 0 && wallY < YWCELLS) {+ if (wall == WL_FAN) {+ fvx[wallY * WCELL / ACELL][wallX * WCELL / ACELL] = 0.0f;+ fvy[wallY * WCELL / ACELL][wallX * WCELL / ACELL] = 0.0f;+ } else if (wall == WL_STREAM) {+ wallX = x + rx;+ wallY = y + ry;+ /* streamlines can't be drawn next to each other */+ for (int tempY = wallY - 1; tempY < wallY + 2; tempY++)+ for (int tempX = wallX - 1; tempX < wallX + 2; tempX++)+ if (tempX >= 0 && tempX < XWCELLS && tempY >= 0 && tempY < YWCELLS && bmap[tempY][tempX] == WL_STREAM) return 1;+ }+ if (wall == WL_GRAV || bmap[wallY][wallX] == WL_GRAV) gravWallChanged = true;+ if (wall == WL_ERASEALL) {+ for (int i = 0; i < WCELL; i++)+ for (int j = 0; j < WCELL; j++) delete_part(wallX * WCELL + i, wallY * WCELL + j);+ bmap[wallY][wallX] = 0;+ } else {+ bmap[wallY][wallX] = (unsigned char)wall;+ }+ }+ return 1;+}++void CreateWallLine(int x1, int y1, int x2, int y2, int rx, int ry, int wall, bool withBrush) {+ int x, y, dx, dy, sy;+ bool reverseXY = abs(y2 - y1) > abs(x2 - x1);+ float e = 0.0f, de;+ if (reverseXY) {+ y = x1, x1 = y1, y1 = y;+ y = x2, x2 = y2, y2 = y;+ }+ if (x1 > x2) {+ y = x1, x1 = x2, x2 = y;+ y = y1, y1 = y2, y2 = y;+ }+ dx = x2 - x1;+ dy = abs(y2 - y1);+ de = dx ? dy / (float)dx : 0.0f;+ y = y1;+ sy = (y1 < y2) ? 1 : -1;+ for (x = x1; x <= x2; x++) {+ if (reverseXY) CreateWalls(y, x, rx, ry, wall, withBrush);+ else CreateWalls(x, y, rx, ry, wall, withBrush);+ e += de;+ if (e >= 0.5f) {+ y += sy;+ if ((y1 < y2) ? (y <= y2) : (y >= y2)) {+ if (reverseXY) CreateWalls(y, x, rx, ry, wall, withBrush);+ else CreateWalls(x, y, rx, ry, wall, withBrush);+ }+ e -= 1.0f;+ }+ }+}++void CreateWallBox(int x1, int y1, int x2, int y2, int wall) {+ int i, j;+ if (x1 > x2) i = x2, x2 = x1, x1 = i;+ if (y1 > y2) j = y2, y2 = y1, y1 = j;+ for (j = y1; j <= y2; j++)+ for (i = x1; i <= x2; i++) CreateWalls(i, j, 0, 0, wall, false);+}++/* fills the cells of wall bm (or none) connected to x, y (particles) with wall */+int FloodWalls(int x, int y, int wall, int bm) {+ int x1, x2, dy = WCELL;+ if (bm == -1) {+ if (wall == WL_ERASE || wall == WL_ERASEALL) {+ bm = bmap[y / WCELL][x / WCELL];+ if (!bm) return 0;+ } else {+ bm = 0;+ }+ }+ if (bmap[y / WCELL][x / WCELL] != bm) return 1;+ /* go left as far as possible */+ x1 = x2 = x;+ while (x1 >= WCELL) {+ if (bmap[y / WCELL][(x1 - 1) / WCELL] != bm) break;+ x1--;+ }+ while (x2 < XRES - WCELL) {+ if (bmap[y / WCELL][(x2 + 1) / WCELL] != bm) break;+ x2++;+ }+ /* fill span */+ for (x = x1; x <= x2; x++)+ if (!CreateWalls(x, y, 0, 0, wall, false)) return 0;+ /* fill children */+ if (y >= WCELL)+ for (x = x1; x <= x2; x++)+ if (bmap[(y - dy) / WCELL][x / WCELL] == bm)+ if (!FloodWalls(x, y - dy, wall, bm)) return 0;+ if (y < YRES - WCELL)+ for (x = x1; x <= x2; x++)+ if (bmap[(y + dy) / WCELL][x / WCELL] == bm)+ if (!FloodWalls(x, y + dy, wall, bm)) return 0;+ return 1;+}diff --git a/games/numpowder/tests/play.c b/games/numpowder/tests/play.cnew file mode 100644index 00000000..c3b26eff--- /dev/null+++ b/games/numpowder/tests/play.c@@ -0,0 +1,240 @@+/* Plays NumPowder on a computer, with scripted keys, and saves frames.+ *+ * play [--frames N] [--keys "10-40:right,50:ok,..."] [--shots 30,60] [--out DIR] [--saves DIR]+ * [--scene NAME]... [--rect TYPE:x0,y0,x1,y1]... [--wall WALL:x0,y0,x1,y1]... [--display N]+ * [--tools LEFT,RIGHT] [--cursor X,Y] [--brush R] [--paused] [--intro] [--npart N] [--debug]+ * [--seed N] [--time]+ *+ * Keys: left right up down ok back home toolbox var shift alpha plus minus backspace, and the typing keys as+ * tkN. "a-b:key" holds the key from frame a to b, "a:key" for one frame. Screenshots are DIR/shot_<frame>.ppm+ * (and the last frame's). Scenes: sand, water, fire, lava, walls, elec, gases, glow, stkm, explode, air, all (one+ * of every element, in rows). --rect fills with an element (its name, or its number), --wall with a wall's+ * number. --display picks a render preset (render.h's PRESET_*). --intro starts with the intro text, as the+ * calculator does. --time prints how long the drawing took. */+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <strings.h>+#include <sys/stat.h>+#include <time.h>+#include <math.h>+#include "../src/ui.h"++extern uint32_t host_keys, host_time;+extern int host_text_key;+void host_shot(const char *path);+void host_save_dir(const char *d);+bool game_frame(void);+void game_init(void);+int host_npart;++typedef struct { int a, b; uint32_t k; int tk; } Hold;+static Hold holds[1024];+static int nholds;++static uint32_t key_bit(const char *s) {+ if (!strncmp(s, "tk", 2)) return 0;+ static const struct { const char *n; uint32_t k; } keys[] = {+ {"left", K_LEFT}, {"right", K_RIGHT}, {"up", K_UP}, {"down", K_DOWN}, {"ok", K_OK}, {"back", K_BACK},+ {"home", K_HOME}, {"toolbox", K_TOOLBOX}, {"var", K_VAR}, {"shift", K_SHIFT}, {"alpha", K_ALPHA},+ {"plus", K_PLUS}, {"minus", K_MINUS}, {"backspace", K_BACKSPACE}};+ for (size_t i = 0; i < sizeof keys / sizeof keys[0]; i++)+ if (!strcmp(s, keys[i].n)) return keys[i].k;+ fprintf(stderr, "unknown key %s\n", s);+ return 0;+}++static int element_by_name(const char *s) {+ if (s[0] >= '0' && s[0] <= '9') return atoi(s);+ for (int t = 0; t < PT_COUNT; t++)+ if (elements[t].Name && !strcasecmp(elements[t].Name, s)) return t;+ fprintf(stderr, "unknown element %s\n", s);+ return 0;+}++static void fill(int t, int x0, int y0, int x1, int y1) {+ for (int y = y0; y <= y1; y++)+ for (int x = x0; x <= x1; x++)+ if (x >= 0 && y >= 0 && x < XRES && y < YRES) create_part(-1, x, y, t, -1);+}+static void wall(int w, int x0, int y0, int x1, int y1) {+ for (int y = y0; y <= y1; y++)+ for (int x = x0; x <= x1; x++)+ if (x >= 0 && y >= 0 && x < XRES && y < YRES) bmap[y / WCELL][x / WCELL] = (unsigned char)w;+}++static void scene(const char *name) {+ if (!strcmp(name, "sand")) {+ fill(PT_SAND, 30, 5, 45, 20);+ fill(PT_METL, 10, 50, 89, 52);+ fill(PT_SALT, 60, 10, 70, 18);+ } else if (!strcmp(name, "water")) {+ wall(WL_WALL, 4, 40, 95, 43);+ fill(PT_WATR, 10, 10, 40, 30);+ fill(PT_OIL, 60, 15, 80, 25);+ } else if (!strcmp(name, "fire")) {+ fill(PT_WOOD, 20, 40, 79, 50);+ fill(PT_FIRE, 30, 35, 70, 39);+ fill(PT_GAS, 40, 10, 60, 20);+ } else if (!strcmp(name, "lava")) {+ fill(PT_LAVA, 30, 20, 60, 30);+ fill(PT_WATR, 10, 45, 89, 55);+ fill(PT_GLAS, 5, 56, 94, 58);+ } else if (!strcmp(name, "walls")) {+ for (int w = 1; w < UI_WALLCOUNT; w++) {+ int x = 4 + ((w - 1) % 9) * 10, y = 6 + ((w - 1) / 9) * 14;+ wall(w, x, y, x + 7, y + 7);+ }+ fill(PT_WATR, 10, 40, 30, 50);+ } else if (!strcmp(name, "elec")) {+ fill(PT_METL, 10, 30, 89, 31);+ fill(PT_BTRY, 8, 28, 9, 33);+ fill(PT_LCRY, 40, 34, 60, 40);+ fill(PT_SPRK, 11, 30, 12, 30);+ } else if (!strcmp(name, "gases")) {+ fill(PT_PLSM, 10, 10, 30, 20);+ fill(PT_SMKE, 40, 10, 60, 20);+ fill(PT_NEUT, 70, 10, 90, 20);+ fill(PT_PHOT, 10, 40, 30, 50);+ fill(PT_CFLM, 40, 40, 60, 50);+ fill(PT_THDR, 75, 45, 76, 46);+ } else if (!strcmp(name, "glow")) {+ fill(PT_GLOW, 10, 10, 30, 30);+ fill(PT_DEUT, 40, 10, 60, 30);+ fill(PT_ACID, 70, 10, 90, 30);+ fill(PT_LAVA, 10, 40, 30, 55);+ fill(PT_GEL, 40, 40, 60, 55);+ fill(PT_BRAY, 70, 40, 90, 41);+ fill(PT_EMBR, 70, 50, 90, 55);+ } else if (!strcmp(name, "stkm")) {+ wall(WL_WALL, 4, 54, 95, 57);+ fill(PT_DMND, 70, 44, 75, 53);+ create_part(-2, 30, 45, PT_STKM, 0);+ } else if (!strcmp(name, "explode")) {+ fill(PT_PLEX, 40, 40, 60, 50);+ fill(PT_FIRE, 50, 38, 51, 39);+ } else if (!strcmp(name, "air")) {+ /* air to show: pressure up at the left and down at the right, a swirl in the middle */+ for (int y = 0; y < YACELLS; y++)+ for (int x = 0; x < XACELLS; x++) {+ float dx = x - XACELLS / 2.0f, dy = y - YACELLS / 2.0f;+ pv[y][x] = (x < XACELLS / 2 ? 1 : -1) * 8.0f * (1 - fabsf(dy) / YACELLS);+ vx[y][x] = -dy * 0.6f, vy[y][x] = dx * 0.6f;+ hv[y][x] = 273.15f + 22 + x * 60;+ }+ } else if (!strcmp(name, "all")) {+ /* every element in the menus, one block each, in rows */+ int k = 0;+ for (int t = 1; t < PT_COUNT; t++) {+ if (!elements[t].Enabled || !elements[t].MenuVisible) continue;+ int x = (k % 25) * 4, y = (k / 25) * 8 + 2;+ fill(t, x, y, x + 2, y + 2);+ k++;+ }+ } else {+ fprintf(stderr, "unknown scene %s\n", name);+ }+}++int main(int argc, char **argv) {+ const char *out = "build/play", *saves = "build/play/saves", *shots = "";+ int frames = 120, display = -1, brush_r = -1, seed = 1;+ bool paused = false, intro = false, debug = false, timing = false;+ const char *scenes[16], *rects[32], *walls_[32], *tools = NULL, *cursor = NULL;+ int nscenes = 0, nrects = 0, nwalls = 0;+ for (int i = 1; i < argc; i++) {+ if (!strcmp(argv[i], "--frames") && i + 1 < argc) frames = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--out") && i + 1 < argc) out = argv[++i];+ else if (!strcmp(argv[i], "--saves") && i + 1 < argc) saves = argv[++i];+ else if (!strcmp(argv[i], "--shots") && i + 1 < argc) shots = argv[++i];+ else if (!strcmp(argv[i], "--scene") && i + 1 < argc && nscenes < 16) scenes[nscenes++] = argv[++i];+ else if (!strcmp(argv[i], "--rect") && i + 1 < argc && nrects < 32) rects[nrects++] = argv[++i];+ else if (!strcmp(argv[i], "--wall") && i + 1 < argc && nwalls < 32) walls_[nwalls++] = argv[++i];+ else if (!strcmp(argv[i], "--display") && i + 1 < argc) display = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--tools") && i + 1 < argc) tools = argv[++i];+ else if (!strcmp(argv[i], "--cursor") && i + 1 < argc) cursor = argv[++i];+ else if (!strcmp(argv[i], "--brush") && i + 1 < argc) brush_r = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--npart") && i + 1 < argc) host_npart = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--seed") && i + 1 < argc) seed = atoi(argv[++i]);+ else if (!strcmp(argv[i], "--paused")) paused = true;+ else if (!strcmp(argv[i], "--intro")) intro = true;+ else if (!strcmp(argv[i], "--debug")) debug = true;+ else if (!strcmp(argv[i], "--time")) timing = true;+ else if (!strcmp(argv[i], "--keys") && i + 1 < argc) {+ char *s = strdup(argv[++i]);+ for (char *t = strtok(s, ","); t && nholds < 1024; t = strtok(NULL, ",")) {+ int a, b;+ char k[16];+ if (sscanf(t, "%d-%d:%15s", &a, &b, k) == 3) holds[nholds++] = (Hold){a, b, key_bit(k), -1};+ else if (sscanf(t, "%d:%15s", &a, k) == 2) holds[nholds++] = (Hold){a, a, key_bit(k), -1};+ else continue;+ if (!strncmp(k, "tk", 2)) holds[nholds - 1].tk = atoi(k + 2);+ }+ } else {+ fprintf(stderr, "unknown option %s\n", argv[i]);+ return 2;+ }+ }+ mkdir(out, 0755);+ mkdir(saves, 0755);+ host_save_dir(saves);+ game_init();+ rng_seed((unsigned)seed);+ if (!intro) ui.intro = 0;+ if (paused) sys_pause = true;+ if (debug) ui.debug = true;+ if (display >= 0 && display < PRESET_COUNT)+ render_apply_preset(display);+ if (brush_r >= 0) brush.rx = brush.ry = brush_r;+ if (cursor) sscanf(cursor, "%d,%d", &ui.cx, &ui.cy);+ if (tools) {+ char l[32], r[32];+ if (sscanf(tools, "%31[^,],%31s", l, r) == 2) ui.tool[0] = element_by_name(l), ui.tool[1] = element_by_name(r);+ }+ for (int k = 0; k < nscenes; k++) scene(scenes[k]);+ for (int k = 0; k < nrects; k++) {+ char name[32];+ int x0, y0, x1, y1;+ if (sscanf(rects[k], "%31[^:]:%d,%d,%d,%d", name, &x0, &y0, &x1, &y1) == 5) fill(element_by_name(name), x0, y0, x1, y1);+ }+ for (int k = 0; k < nwalls; k++) {+ int w, x0, y0, x1, y1;+ if (sscanf(walls_[k], "%d:%d,%d,%d,%d", &w, &x0, &y0, &x1, &y1) == 5) wall(w, x0, y0, x1, y1);+ }+ double draw_total = 0;+ for (int f = 0; f < frames; f++) {+ host_keys = 0;+ host_text_key = -1;+ for (int i = 0; i < nholds; i++)+ if (f >= holds[i].a && f <= holds[i].b) {+ host_keys |= holds[i].k;+ if (holds[i].tk >= 0) host_text_key = holds[i].tk;+ }+ clock_t c0 = clock();+ bool go = game_frame();+ draw_total += (double)(clock() - c0) / CLOCKS_PER_SEC;+ host_time += 33;+ char tag[16], list[1024];+ snprintf(tag, sizeof tag, ",%d,", f);+ snprintf(list, sizeof list, ",%s,", shots);+ if (strstr(list, tag) || f == frames - 1 || !go) {+ char path[512];+ snprintf(path, sizeof path, "%s/shot_%d.ppm", out, f);+ host_shot(path);+ }+ if (!go) {+ printf("quit at frame %d\n", f);+ break;+ }+ }+ if (timing) {+ float g = 0;+ for (int y = 0; y < YACELLS; y++)+ for (int x = 0; x < XACELLS; x++) g = fmaxf(g, fabsf(gravx[y][x]) + fabsf(gravy[y][x]));+ printf("Newtonian gravity %s, field lines %s, strongest field %.3f\n", ngrav_enable ? "on" : "off", ren.grav_field ? "on" : "off", g);+ }+ extern bool ov_overflowed;+ if (ov_overflowed) printf("the overlay's list overflowed\n");+ if (timing) printf("%d frames, %.2f ms a frame on this computer (sanitizers on), %d particles\n", frames, draw_total * 1000 / frames, NUM_PARTS);+ return 0;+}diff --git a/games/numpowder/tests/simtest.c b/games/numpowder/tests/simtest.cnew file mode 100644index 00000000..9d215c09--- /dev/null+++ b/games/numpowder/tests/simtest.c@@ -0,0 +1,677 @@+/* NumPowder: the simulation checked on a computer (make test, with the sanitizers): scenes whose outcome The Powder+ * Toy is known for, the save's round trip, and long runs of a full grid of every element. */+#include <stdio.h>+#include <stdlib.h>+#include <time.h>+#include "simpriv.h"+#include "simsave.h"++int host_npart = 3625; /* what the calculator gives on custom firmware (133652 bytes of RAM) */+static int fails, checks;+#define CHECK(cond, ...) \+ do { \+ checks++; \+ if (!(cond)) { \+ printf(" FAIL %s:%d: ", __FILE__, __LINE__); \+ printf(__VA_ARGS__); \+ printf("\n"); \+ fails++; \+ } \+ } while (0)++/* ---------------------------------------------------------------- helpers */+static void reset(void) {+ sim_clear();+ sim_default_settings();+ sim_settings_changed();+ rng_state[0] = 0x9E3779B97F4A7C15ull, rng_state[1] = 614;+ temp_dither = 0x2545F491;+}+static void run(int frames) {+ for (int f = 0; f < frames; f++) sim_step();+}+static int put(int x, int y, int t) { return create_part(-1, x, y, t, 0); }+static void fill(int x0, int y0, int x1, int y1, int t) {+ for (int y = y0; y <= y1; y++)+ for (int x = x0; x <= x1; x++) put(x, y, t);+}+static void wallbox(int x0, int y0, int x1, int y1, int wall) { CreateWallBox(x0, y0, x1, y1, wall); }+static int count(int t) {+ int n = 0;+ for (int i = 0; i < parts_active; i++) n += parts[i].type == t;+ return n;+}+static int type_at(int x, int y) { return TYP(PMAPAT(x, y)); }+static int topmost(int x, int t) { /* the highest row with t in column x, YRES if none */+ for (int y = 0; y < YRES; y++)+ if (type_at(x, y) == t) return y;+ return YRES;+}+/* the maps agree with the particles; ids, counts and positions are sane */+static bool consistent(const char *what) {+ int n = 0;+ for (int i = 0; i < parts_active; i++) {+ Particle *p = &parts[i];+ if (!p->type) continue;+ n++;+ if (p->type >= PT_COUNT) {+ printf(" %s: particle %d of type %d\n", what, i, p->type);+ return false;+ }+ }+ for (int y = 0; y < YRES; y++)+ for (int x = 0; x < XRES; x++) {+ int id = pmap_id[y][x] - 1;+ if (id >= 0) {+ Particle *p = &parts[id];+ if (!p->type || (elements[p->type].Properties & TYPE_ENERGY)) {+ printf(" %s: pmap at %d,%d holds %d (type %d)\n", what, x, y, id, p->type);+ return false;+ }+ }+ id = photons_id[y][x] - 1;+ if (id >= 0 && (!parts[id].type || !(elements[parts[id].type].Properties & TYPE_ENERGY))) {+ printf(" %s: photons at %d,%d holds %d (type %d)\n", what, x, y, id, parts[id].type);+ return false;+ }+ }+ if (n != NUM_PARTS) {+ printf(" %s: %d particles, NUM_PARTS %d\n", what, n, NUM_PARTS);+ return false;+ }+ return true;+}++/* ---------------------------------------------------------------- powders and liquids */+static void test_sand_pile(void) {+ puts("sand piles");+ reset();+ wallbox(10, 56, 89, 57, WL_WALL);+ fill(45, 10, 54, 29, PT_SAND); /* 200 grains */+ run(400);+ CHECK(count(PT_SAND) == 200, "sand count %d", count(PT_SAND));+ /* a pile: the middle highest, falling off to the sides, no grain floating */+ int mid = topmost(50, PT_SAND), side = topmost(40, PT_SAND);+ CHECK(mid < 56 && mid < side, "pile top %d, side %d", mid, side);+ int width = 0;+ for (int x = 0; x < XRES; x++) width += type_at(x, 55) == PT_SAND;+ CHECK(width > 12 && width < 60, "pile base %d wide", width);+ bool floating = false;+ for (int y = 0; y < 55; y++)+ for (int x = 0; x < XRES; x++)+ if (type_at(x, y) == PT_SAND && !type_at(x, y + 1)) floating = true;+ CHECK(!floating, "a grain floats");+ /* the slope: TPT's sand piles at about 45 degrees (a grain slides when the two below it diagonally are free) */+ int h = 56 - mid;+ CHECK(h >= 4 && h <= width, "height %d for a base of %d", h, width);+ CHECK(consistent("sand"), "maps");+}++static void test_water_level(void) {+ puts("water levels in a U-tube");+ reset();+ /* a U: two arms 8 particles wide joined at the bottom */+ wallbox(20, 56, 61, 57, WL_WALL); /* floor */+ wallbox(20, 10, 21, 55, WL_WALL); /* left wall */+ wallbox(60, 10, 61, 55, WL_WALL); /* right wall */+ wallbox(30, 10, 51, 47, WL_WALL); /* the middle, leaving a passage below */+ fill(22, 12, 29, 47, PT_WATR); /* the left arm full */+ int n = count(PT_WATR);+ run(3000);+ CHECK(count(PT_WATR) == n, "water count %d of %d", count(PT_WATR), n);+ int left = topmost(25, PT_WATR), right = topmost(56, PT_WATR);+ CHECK(abs(left - right) <= 2, "levels left %d right %d", left, right);+ CHECK(consistent("water"), "maps");+}++/* ---------------------------------------------------------------- heat and transitions */+static void test_transitions(void) {+ puts("lava cools to stone; water boils and freezes");+ reset();+ int l = put(50, 30, PT_LAVA);+ p_set_temp(&parts[l], 900.0f); /* below 973 K: LAVA (no ctype) -> STNE */+ int w1 = put(30, 30, PT_WATR), w2 = put(70, 30, PT_WATR);+ p_set_temp(&parts[w1], 380.0f); /* above 373 K: steam */+ p_set_temp(&parts[w2], 268.0f); /* below 273.15 K: ice */+ wallbox(20, 50, 80, 51, WL_WALL);+ run(60);+ CHECK(parts[l].type == PT_STNE, "lava is %d", parts[l].type);+ CHECK(parts[w1].type == PT_WTRV, "hot water is %d", parts[w1].type);+ CHECK(parts[w2].type == PT_ICEI && parts[w2].ctype == PT_WATR, "cold water is %d (%d)", parts[w2].type, parts[w2].ctype);+ /* (alone: water wanders along a floor, and would boil on the stone the lava left) */+ reset();+ int w3 = put(40, 20, PT_WATR);+ p_set_temp(&parts[w3], 360.0f); /* stays water */+ wallbox(20, 50, 80, 51, WL_WALL);+ run(60);+ CHECK(parts[w3].type == PT_WATR, "warm water is %d", parts[w3].type);+ /* a block of lava in cold metal: the metal takes its heat, the lava turns to stone */+ reset();+ wallbox(10, 56, 89, 57, WL_WALL);+ fill(40, 40, 59, 55, PT_METL);+ fill(47, 46, 52, 49, PT_LAVA); /* (made inside the metal: replacing) */+ for (int y = 46; y <= 49; y++)+ for (int x = 47; x <= 52; x++) {+ int i = pmap_id[y][x] - 1;+ if (i >= 0) create_part(i, x, y, PT_LAVA, 0), parts[i].ctype = PT_STNE, p_set_temp(&parts[i], 1500.0f);+ }+ int lava = count(PT_LAVA);+ run(800);+ CHECK(lava == 24 && count(PT_LAVA) == 0 && count(PT_STNE) == 24, "lava %d -> %d, stone %d", lava, count(PT_LAVA), count(PT_STNE));+ /* heat conducts along metal */+ reset();+ fill(10, 30, 89, 30, PT_METL);+ int hot = pmap_id[30][10] - 1, far = pmap_id[30][40] - 1;+ p_set_temp(&parts[hot], 2000.0f);+ float before = p_temp(&parts[far]);+ for (int f = 0; f < 600; f++) {+ p_set_temp(&parts[hot], 2000.0f);+ sim_step();+ }+ CHECK(p_temp(&parts[far]) > before + 20, "30 particles away: %.2f K from %.2f", p_temp(&parts[far]), before);+}++/* ---------------------------------------------------------------- electronics */+static void test_sparks(void) {+ puts("sparks through metal, PSCN and NSCN, INST");+ reset();+ fill(20, 30, 79, 30, PT_METL);+ create_part(-2, 20, 30, PT_SPRK, 0); /* the brush sparks a conductor */+ CHECK(parts[pmap_id[30][20] - 1].type == PT_SPRK, "first spark");+ int reached = -1;+ for (int f = 1; f <= 200 && reached < 0; f++) {+ sim_step();+ if (type_at(79, 30) == PT_SPRK) reached = f;+ }+ /* SPRK reaches 2 particles a frame along a line (its range), so 60 particles in about 30 frames */+ CHECK(reached > 0 && reached <= 60, "the spark reached the end at frame %d", reached);+ run(10);+ /* PSCN -> NSCN conducts, NSCN -> PSCN doesn't */+ reset();+ /* (a spark reaches 2 particles away: the chains are longer than that) */+ put(30, 30, PT_PSCN), fill(31, 30, 34, 30, PT_NSCN), put(35, 30, PT_METL);+ put(60, 30, PT_NSCN), fill(61, 30, 64, 30, PT_PSCN), put(65, 30, PT_METL);+ create_part(-2, 30, 30, PT_SPRK, 0);+ create_part(-2, 60, 30, PT_SPRK, 0);+ bool metalA = false, metalB = false;+ for (int f = 0; f < 12; f++) {+ sim_step();+ metalA |= type_at(35, 30) == PT_SPRK;+ metalB |= type_at(65, 30) == PT_SPRK || type_at(61, 30) == PT_SPRK;+ }+ CHECK(metalA, "PSCN -> NSCN -> METL");+ CHECK(!metalB, "NSCN -> PSCN conducted");+ /* PSCN turns SWCH on, NSCN off */+ reset();+ put(30, 30, PT_PSCN), put(31, 30, PT_SWCH);+ create_part(-2, 30, 30, PT_SPRK, 0);+ run(3);+ CHECK(parts[pmap_id[30][31] - 1].life == 10, "SWCH life %d", parts[pmap_id[30][31] - 1].life);+ /* INST conducts at once: through a T junction, not across a one-particle crossing */+ reset();+ fill(10, 30, 89, 30, PT_INST);+ fill(50, 31, 50, 50, PT_INST); /* a T below */+ fill(70, 10, 70, 29, PT_INST), fill(70, 31, 70, 50, PT_INST); /* a crossing */+ create_part(-2, 10, 30, PT_SPRK, 0); /* the brush floods it */+ CHECK(count(PT_SPRK) == 80 + 20, "INST sparked at once: %d of 100", count(PT_SPRK));+ run(30);+ CHECK(count(PT_INST) == 140, "back to INST: %d", count(PT_INST));+ /* a battery lights a line of metal through to NSCN... and a spark-powered wall */+ reset();+ put(30, 30, PT_BTRY), fill(31, 30, 40, 30, PT_METL);+ run(20);+ CHECK(count(PT_SPRK) > 0, "BTRY sparks");+ CHECK(consistent("sparks"), "maps");+}++/* ---------------------------------------------------------------- chemistry, fire, explosives */+static void test_acid_fire_c4(void) {+ puts("acid dissolves; fire burns wood out; C-4 explodes with pressure");+ reset();+ wallbox(10, 56, 89, 57, WL_WALL);+ fill(30, 46, 69, 55, PT_DUST);+ int dust = count(PT_DUST);+ fill(40, 30, 59, 40, PT_ACID);+ run(400);+ CHECK(count(PT_DUST) < dust / 2, "dust left %d of %d", count(PT_DUST), dust);+ reset();+ fill(30, 30, 69, 40, PT_WOOD);+ int wood = count(PT_WOOD);+ fill(29, 30, 29, 40, PT_FIRE);+ bool spread = false;+ for (int f = 0; f < 4000; f++) {+ sim_step();+ if (count(PT_WOOD) < wood * 3 / 4) spread = true;+ }+ CHECK(spread, "fire didn't spread: wood %d of %d", count(PT_WOOD), wood);+ CHECK(count(PT_FIRE) == 0, "fire still burning: %d", count(PT_FIRE));+ reset();+ wallbox(10, 56, 89, 57, WL_WALL);+ fill(40, 40, 59, 55, PT_PLEX);+ run(20);+ CHECK(count(PT_PLEX) == 320, "C-4 went off on its own");+ for (int f = 0; f < 5; f++) pv[44 / ACELL][50 / ACELL] = 10.0f, sim_step(); /* pressure (as the AIR tool) */+ float pmax = 0; /* (the blast's pressure, the most it reaches) */+ for (int f = 0; f < 60; f++) {+ sim_step();+ for (int y = 0; y < YACELLS; y++)+ for (int x = 0; x < XACELLS; x++) pmax = fmaxf(pmax, fabsf(pv[y][x]));+ }+ CHECK(count(PT_PLEX) == 0, "C-4 left %d", count(PT_PLEX));+ CHECK(pmax > 5.0f, "the blast's pressure %.2f", pmax);+ CHECK(consistent("explosives"), "maps");+}++/* ---------------------------------------------------------------- light and walls */+static void test_light_walls(void) {+ puts("photons pass through glass; walls block");+ reset();+ fill(50, 20, 53, 40, PT_GLAS);+ for (int y = 25; y <= 35; y++) {+ int i = create_part(-3, 20, y, PT_PHOT, 0);+ p_set_vx(&parts[i], 3), p_set_vy(&parts[i], 0);+ }+ run(18);+ int beyond = 0;+ for (int i = 0; i < parts_active; i++)+ if (parts[i].type == PT_PHOT && p_x(&parts[i]) > 54) beyond++;+ CHECK(beyond >= 8, "%d photons went through the glass", beyond);+ /* a photon into metal reflects */+ reset();+ fill(50, 20, 52, 40, PT_METL);+ int ph = create_part(-3, 30, 30, PT_PHOT, 0);+ p_set_vx(&parts[ph], 3), p_set_vy(&parts[ph], 0);+ run(20);+ CHECK(parts[ph].type == PT_PHOT && p_vx(&parts[ph]) < 0, "the photon came back: type %d vx %.2f", parts[ph].type, p_vx(&parts[ph]));+ /* walls: sand stops on a wall, water passes a liquid wall, sand doesn't */+ reset();+ wallbox(10, 40, 49, 41, WL_WALL);+ wallbox(50, 40, 89, 41, WL_ALLOWLIQUID);+ wallbox(10, 56, 89, 57, WL_WALL), wallbox(10, 42, 11, 55, WL_WALL), wallbox(88, 42, 89, 55, WL_WALL);+ fill(20, 20, 29, 25, PT_SAND), fill(60, 20, 69, 25, PT_SAND), fill(75, 20, 84, 25, PT_WATR);+ run(300);+ int below = 0, sandBelow = 0;+ for (int y = 42; y < YRES; y++)+ for (int x = 0; x < XRES; x++) below += type_at(x, y) == PT_WATR, sandBelow += type_at(x, y) == PT_SAND;+ CHECK(below >= 50, "water through the liquid wall: %d of 60", below);+ CHECK(sandBelow == 0, "sand through a wall: %d", sandBelow);+ /* an absorb wall eats what falls in */+ reset();+ wallbox(10, 50, 89, 51, WL_DESTROYALL);+ fill(40, 20, 49, 29, PT_SAND);+ run(200);+ CHECK(count(PT_SAND) == 0, "the absorb wall left %d", count(PT_SAND));+ /* walls block air: pressure stays inside a box */+ reset();+ wallbox(36, 20, 63, 21, WL_WALL), wallbox(36, 42, 63, 43, WL_WALL);+ wallbox(36, 20, 37, 43, WL_WALL), wallbox(62, 20, 63, 43, WL_WALL);+ for (int k = 0; k < 4; k++) pv[32 / ACELL][48 / ACELL + k - 1] = 50;+ run(100);+ CHECK(pv[32 / ACELL][48 / ACELL] > 3 && fabsf(pv[10 / ACELL][20 / ACELL]) < 0.5f, "inside %.1f, outside %.1f",+ pv[32 / ACELL][48 / ACELL], pv[10 / ACELL][20 / ACELL]);+ CHECK(consistent("walls"), "maps");+}++/* ---------------------------------------------------------------- Game of Life */+static bool life_at(int x, int y) { return type_at(x, y) == PT_LIFE; }+static void test_life(void) {+ puts("Game of Life: blinker, glider");+ reset();+ put(49, 30, PT_LIFE), put(50, 30, PT_LIFE), put(51, 30, PT_LIFE); /* a blinker (GOL, v 0) */+ run(1);+ CHECK(life_at(50, 29) && life_at(50, 30) && life_at(50, 31) && !life_at(49, 30) && !life_at(51, 30), "blinker vertical");+ run(1);+ CHECK(life_at(49, 30) && life_at(50, 30) && life_at(51, 30) && !life_at(50, 29) && !life_at(50, 31), "blinker horizontal");+ CHECK(count(PT_LIFE) == 3, "blinker cells %d", count(PT_LIFE));+ reset();+ /* a glider going down and right: .#. / ..# / ### */+ put(31, 20, PT_LIFE), put(32, 21, PT_LIFE), put(30, 22, PT_LIFE), put(31, 22, PT_LIFE), put(32, 22, PT_LIFE);+ run(8);+ CHECK(count(PT_LIFE) == 5, "glider cells %d", count(PT_LIFE));+ CHECK(life_at(33, 22) && life_at(34, 23) && life_at(32, 24) && life_at(33, 24) && life_at(34, 24), "glider moved 2,2");+ /* another rule: HLIF (B36/S23) by its number */+ reset();+ create_part(-1, 50, 30, PT_LIFE, 1);+ CHECK(parts[pmap_id[30][50] - 1].ctype == 1, "HLIF ctype");+ char rule[24];+ SerialiseGOLRule(builtinGol[1].ruleset, rule);+ CHECK(!strcmp(rule, "B36/S23") && ParseGOLString("B36/S23") == builtinGol[1].ruleset, "rule %s", rule);+ CHECK(ParseGOLString("B37/S3458/4") == builtinGol[19].ruleset, "LOTE");+}++/* ---------------------------------------------------------------- what the audit found (P1.2, P1.3, P1.4, P1.7, P2.2) */+static void test_audit(void) {+ puts("velocities decay, LIGH's and PHOT's numbers, HEAT on PUMP, whole degrees");+ /* a slow particle's velocity times Loss decays to 0 (rounded to the nearest it stayed at 10/256 for ever) */+ reset();+ settings.gravity_mode = GRAV_OFF, settings.air_mode = AIR_OFF;+ sim_settings_changed();+ int s = put(20, 30, PT_SAND);+ parts[s].vx = 64; /* 0.25 a frame */+ run(300);+ float x1 = p_x(&parts[s]);+ run(100);+ CHECK(parts[s].vx == 0 && parts[s].vy == 0 && p_x(&parts[s]) == x1 && x1 > 23 && x1 < 29,+ "sand slid to %.2f, then %.2f, at %.4f", x1, p_x(&parts[s]), p_vx(&parts[s]));++ /* LIGH's powderful is an int (LIGH.cpp): its heat into the air is a whole number of kelvins */+ reset();+ settings.ambient_heat = true;+ sim_settings_changed();+ int l = put(50, 30, PT_LIGH);+ parts[l].life = 0, parts[l].tmp2 = 0;+ p_set_temp(&parts[l], 3010.0f);+ hv[30 / ACELL][50 / ACELL] = 300.0f;+ int powderful = (int)(p_temp(&parts[l]) * 0.65f);+ elements[PT_LIGH].Update(l, 50, 30, 8, 8);+ float dh = hv[30 / ACELL][50 / ACELL] - 300.0f;+ CHECK(powderful % 50 && dh == (float)(powderful / 50), "air heated by %.3f (powderful %d)", dh, powderful);++ /* PHOT turning ISOZ into PHOT: the new one's angle is any whole degree (an int angle was a whole radian) */+ int made = 0, off = 0;+ for (unsigned seed = 1; seed < 6000 && made < 12; seed++) {+ reset();+ int ph = create_part(-3, 50, 30, PT_PHOT, 0), iz = put(51, 30, PT_ISOZ);+ rng_seed(seed);+ elements[PT_PHOT].Update(ph, 50, 30, 8, 8);+ if (parts[iz].type != PT_PHOT || (!parts[iz].vx && !parts[iz].vy)) continue;+ made++;+ float a = atan2f(p_vy(&parts[iz]), p_vx(&parts[iz]));+ if (a < 0) a += 2 * NP_PI;+ off += fabsf(a - roundf(a)) > 0.05f;+ }+ CHECK(made >= 8 && off > 0, "%d photons made, %d not at a whole radian", made, off);++ /* HEAT on PUMP: 0.1 K a time, kept on average (dithered) */+ reset();+ int pu = put(50, 30, PT_PUMP);+ p_set_temp(&parts[pu], 300.0f);+ Brush b = brush;+ brush.rx = brush.ry = 0;+ for (int k = 0; k < 100; k++) sim_tool_points(TOOL_SIMTOOLS + TOOL_HEAT, 50, 30, 50, 30, false);+ brush = b;+ CHECK(fabsf(p_temp(&parts[pu]) - 310.0f) < 2.0f, "PUMP heated to %.2f K", p_temp(&parts[pu]));++ /* whole degrees Celsius are kept exactly, and the ends */+ Particle q;+ p_set_temp(&q, 295.15f);+ float t22 = p_temp(&q);+ p_set_temp(&q, elements[PT_WATR].DefaultProperties.temp);+ float tw = p_temp(&q);+ p_set_temp(&q, MAX_TEMP);+ float tmax = p_temp(&q);+ p_set_temp(&q, MIN_TEMP);+ float tmin = p_temp(&q);+ CHECK(t22 == 295.15f && tw == 293.15f && tmax == MAX_TEMP && tmin == MIN_TEMP, "22 C: %.4f, water %.4f, %.2f, %.2f",+ t22, tw, tmax, tmin);+}++/* ---------------------------------------------------------------- saves */+static uint8_t save_a[1 << 16], save_b[1 << 16];+static void mix(uint32_t *h, const void *p, size_t n) {+ for (size_t k = 0; k < n; k++) *h = (*h ^ ((const uint8_t *)p)[k]) * 16777619u;+}+static uint32_t state_hash(void) {+ uint32_t h = 2166136261u;+ for (int i = 0; i < parts_active; i++)+ if (parts[i].type) mix(&h, &i, sizeof i), mix(&h, &parts[i], sizeof(Particle));+ mix(&h, pv, sizeof pv), mix(&h, vx, sizeof vx), mix(&h, vy, sizeof vy), mix(&h, hv, sizeof hv);+ mix(&h, bmap, sizeof bmap), mix(&h, emap, sizeof emap), mix(&h, rng_state, sizeof rng_state);+ return h;+}+static uint32_t full_hash(void) {+ uint32_t h = state_hash();+ mix(&h, gravx, sizeof gravx), mix(&h, gravy, sizeof gravy), mix(&h, &temp_dither, sizeof temp_dither);+ mix(&h, &NUM_PARTS, sizeof NUM_PARTS), mix(&h, &parts_active, sizeof parts_active);+ return h;+}+static uint32_t every_hash[2]; /* test_every_element's, after its long run and after the brim */+static void busy_scene(void) {+ reset();+ wallbox(4, 58, 95, 59, WL_WALL);+ fill(10, 40, 30, 57, PT_WATR), fill(35, 30, 45, 40, PT_SAND), fill(50, 50, 60, 57, PT_WOOD);+ fill(49, 45, 61, 45, PT_FIRE), fill(70, 20, 80, 30, PT_GAS), fill(65, 50, 90, 52, PT_METL);+ put(65, 49, PT_BTRY), fill(84, 40, 88, 44, PT_PLNT), fill(20, 10, 22, 12, PT_LIFE);+ int ph = create_part(-3, 15, 15, PT_PHOT, 0);+ p_set_vx(&parts[ph], 2), p_set_vy(&parts[ph], 1);+ put(15, 30, PT_STKM); /* (over the water: away from the fire and the singularity, it lives) */+ fill(86, 10, 90, 14, PT_VIRS), fill(5, 20, 8, 22, PT_SEED);+ settings.ambient_heat = true;+ settings.newtonian_gravity = true;+ sim_settings_changed();+ put(40, 15, PT_SING), put(60, 15, PT_GRVT);+ run(120);+}+/* a save, written to buf; its size */+static uint32_t save_to(uint8_t *buf, uint32_t room) {+ uint32_t n = simsave_size();+ if (n > room) return 0;+ return simsave_write(buf, n) == n ? n : 0;+}+static int soap_links(void) {+ int n = 0;+ for (int i = 0; i < parts_active; i++)+ if (parts[i].type == PT_SOAP && (parts[i].ctype & 2)) {+ int j = parts[i].tmp;+ n += j >= 0 && j < parts_active && parts[j].type == PT_SOAP && (parts[j].ctype & 4) && parts[j].tmp2 == i;+ }+ return n;+}+static void test_saves(void) {+ puts("saves round-trip");+ busy_scene();+ uint32_t h0 = state_hash();+ uint32_t n = simsave_size();+ CHECK(n > 0 && n < sizeof save_a, "save of %u bytes", n);+ CHECK(simsave_write(save_a, n) == n, "written");+ CHECK(simsave_write(save_b, n - 1) == 0, "too small a room");+ CHECK(state_hash() == h0, "saving changes nothing");+ CHECK(simsave_count(save_a, n) == NUM_PARTS, "count %d of %d", simsave_count(save_a, n), NUM_PARTS);+ int stkm = count(PT_STKM), parts0 = NUM_PARTS;+ CHECK(stkm == 1, "the stickman is there to save (%d)", stkm);+ player.rocketBoots = true;+ n = save_to(save_a, sizeof save_a);+ uint32_t busy = n;+ run(50);+ CHECK(simsave_read(save_a, n), "read");+ CHECK(consistent("loaded"), "maps after loading");+ CHECK(NUM_PARTS == parts0 && count(PT_STKM) == stkm && player.rocketBoots, "%d particles of %d, stickman %d, boots %d", NUM_PARTS, parts0, count(PT_STKM), player.rocketBoots);+ /* saved again, the same (but for the stickman's SPAWN: loading a stickman makes one where it is, as the+ * original's Load does through create_part, and the one saved is then left out; from then on the same) */+ uint32_t n2 = save_to(save_b, sizeof save_b);+ CHECK(simsave_read(save_b, n2), "read the second save");+ static uint8_t save_c[1 << 16];+ uint32_t n3 = save_to(save_c, sizeof save_c);+ CHECK(n3 == n2 && !memcmp(save_b, save_c, n2), "saved again: %u bytes of %u, the same %d", n3, n2, n3 == n2 && !memcmp(save_b, save_c, n2));+ CHECK(n2 + 8 > n && n2 < n + 8, "the first save again: %u bytes of %u", n2, n);+ /* a save loaded twice goes on the same way */+ CHECK(simsave_read(save_a, n), "read the first save");+ run(200);+ uint32_t a = state_hash();+ CHECK(simsave_read(save_a, n), "read again");+ run(200);+ CHECK(state_hash() == a, "200 frames on from the same save are the same");+ /* SOAP keeps its links (bubbles are made by pressure and last a few frames), PIPE what it carries */+ reset();+ wallbox(4, 58, 95, 59, WL_WALL);+ fill(30, 30, 45, 40, PT_SOAP);+ for (int y = 30 / ACELL; y <= 40 / ACELL; y++)+ for (int x = 30 / ACELL; x <= 45 / ACELL; x++) pv[y][x] = 2;+ run(8);+ int links = soap_links();+ n = save_to(save_a, sizeof save_a);+ CHECK(simsave_read(save_a, n), "SOAP read");+ CHECK(links > 20 && soap_links() == links, "SOAP links %d of %d", soap_links(), links);+ n2 = save_to(save_b, sizeof save_b);+ CHECK(n2 == n && !memcmp(save_a, save_b, n), "SOAP saved again the same");+ /* pipes with water and photons in them (all 30 bits of wavelengths: the top byte of tmp4) */+ reset();+ fill(20, 50, 70, 50, PT_PIPE);+ run(3);+ for (int x = 20; x <= 70; x += 2) {+ int pp = PMAPAT(x, 50), q = create_part(-3, x, 45, x % 4 ? PT_WATR : PT_PHOT, -1);+ if (TYP(pp) != PT_PIPE || q < 0) continue;+ parts[q].ctype = x % 4 ? 0 : 0x3FFFFFFF;+ Element_PIPE_transfer_part_to_pipe(&parts[q], &parts[ID(pp)]);+ kill_part(q);+ }+ run(3);+ int pipe = 0, photons = 0;+ for (int i = 0; i < parts_active; i++)+ if (parts[i].type == PT_PIPE && TYP(parts[i].ctype)) pipe++, photons += TYP(parts[i].ctype) == PT_PHOT && tmp4_get(i) == 0x3FFFFFFF;+ n = save_to(save_a, sizeof save_a);+ CHECK(simsave_read(save_a, n), "PIPE read");+ int pipe2 = 0, photons2 = 0;+ for (int i = 0; i < parts_active; i++)+ if (parts[i].type == PT_PIPE && TYP(parts[i].ctype)) pipe2++, photons2 += TYP(parts[i].ctype) == PT_PHOT && tmp4_get(i) == 0x3FFFFFFF;+ CHECK(pipe > 20 && pipe2 == pipe && photons > 5 && photons2 == photons, "pipes carrying %d of %d, photons %d of %d", pipe2, pipe, photons2, photons);+ n2 = save_to(save_b, sizeof save_b);+ CHECK(n2 == n && !memcmp(save_a, save_b, n), "PIPE saved again the same");+ /* a damaged save is refused and changes nothing; a garbled one doesn't break anything */+ uint32_t h = state_hash();+ CHECK(!simsave_read(save_a, n / 2), "a cut save refused");+ CHECK(state_hash() == h, "unchanged by a bad save");+ memcpy(save_b, save_a, n);+ save_b[0] = 'X';+ CHECK(!simsave_read(save_b, n), "a bad magic refused");+ int garbled = 0;+ for (int k = 0; k < 300; k++) {+ memcpy(save_b, save_a, n);+ for (int j = 0; j < 1 + k % 4; j++) save_b[5 + rng_between(0, (int)n - 6)] ^= (uint8_t)rng_between(1, 255);+ if (simsave_read(save_b, n)) {+ garbled++;+ run(3);+ if (!consistent("garbled")) break;+ }+ }+ printf(" (%d of 300 garbled saves loaded)\n", garbled);+ /* sand drawn is about a byte a grain, settled too */+ reset();+ fill(10, 20, 89, 49, PT_SAND);+ wallbox(4, 50, 95, 51, WL_WALL);+ uint32_t drawn = simsave_size();+ CHECK(drawn < (uint32_t)NUM_PARTS + 600, "%d grains drawn in %u bytes", NUM_PARTS, drawn);+ run(150);+ uint32_t s = simsave_size();+ int grains = NUM_PARTS;+ CHECK(s < (uint32_t)NUM_PARTS * 2 + 600, "%d grains settled in %u bytes", NUM_PARTS, s);+ reset();+ wallbox(4, 58, 95, 59, WL_WALL), wallbox(4, 30, 5, 57, WL_WALL), wallbox(94, 30, 95, 57, WL_WALL);+ fill(6, 40, 93, 57, PT_WATR);+ run(150);+ uint32_t water = simsave_size();+ printf(" (busy scene: %u bytes, %d particles; sand: %u bytes drawn, %u settled, %d grains; water: %u bytes, %d)\n", busy, parts0, drawn, s,+ grains, water, NUM_PARTS);+}++/* ---------------------------------------------------------------- every element, a full grid, a long run */+static void test_every_element(void) {+ puts("every element on a full grid, a long run");+ reset();+ int t = 1;+ for (int y = BORDER; y < YRES - BORDER; y += 4)+ for (int x = BORDER; x < XRES - BORDER; x += 4) {+ while (t < PT_COUNT && !elements[t].Enabled) t++;+ if (t >= PT_COUNT) t = 1;+ for (int j = 0; j < 3; j++)+ for (int i = 0; i < 3; i++) put(x + i, y + j, t);+ t++;+ }+ /* walls of every kind along the bottom */+ for (int w = 1; w < UI_WALLCOUNT; w++)+ if (w != WL_ERASEALL) CreateWalls(BORDER + w * 4, YRES - BORDER - 2, 1, 1, w, false);+ CHECK(consistent("placed"), "maps");+ int frames = 3000;+ for (int f = 0; f < frames; f++) {+ if (f % 500 == 0) {+ settings.ambient_heat = f % 1000 == 0;+ settings.newtonian_gravity = f % 1500 == 0;+ settings.gravity_mode = (uint8_t)(f / 500 % 4);+ settings.edge_mode = (uint8_t)(f / 500 % 3);+ settings.water_equalization = f % 1000 != 0;+ sim_settings_changed();+ }+ sim_step();+ if (f % 250 == 0 && !consistent("running")) {+ CHECK(false, "maps at frame %d", f);+ break;+ }+ }+ CHECK(consistent("after"), "maps");+ every_hash[0] = full_hash();+ printf(" (%d particles after %d frames)\n", NUM_PARTS, frames);+ /* filled to the brim: all particles, every cell */+ reset();+ for (int y = BORDER; y < YRES - BORDER; y++)+ for (int x = BORDER; x < XRES - BORDER; x++) put(x, y, 1 + (x * 7 + y * 13) % (PT_COUNT - 1));+ run(1000);+ CHECK(consistent("brim"), "maps");+ every_hash[1] = full_hash();+ printf(" (brim: %d particles, %d the most)\n", NUM_PARTS, npart_max);+}++/* ---------------------------------------------------------------- the same simulation after the speed work+ * The speed tests' scenes (sim.c's sim_scene 1 to 6, main.c's TEST_SCENE 1 and 2) and the full grid of every element+ * (test_every_element), run for a long time: the state's hash must be the reference's (expect[]). The speed work kept+ * the hashes the code had before it; the audit's fixes (dithered velocities, the temperatures' encoding, LIGH, PHOT,+ * WARP, VIRS, MORT...) changed the simulation on purpose and made these. A change that means to change the+ * simulation updates them (make test prints the new ones). */+static void test_scenes_unchanged(void) {+ puts("the speed tests' scenes, a long run: the reference simulation");+ static const uint32_t expect[11] = {0, 0x9b1d32c0, 0xf1995947, 0xa45ef928, 0x96ba526e, 0xae6a35fc, 0x892c76fd, 0x7e5748cd, 0x528dc52b, 0x47e98ea7, 0x11c96084};+ uint32_t got[11] = {0};+ for (int n = 1; n <= 8; n++) {+ reset();+ currentTick = 0, CGOL = 0;+ if (n <= 6) {+ sim_scene(n);+ } else {+ /* main.c's TEST_SCENE: 7 still elements, 8 with fire, plasma and lava */+ static const uint8_t still[] = {PT_STNE, PT_GLAS, PT_METL, PT_WOOD, PT_BRCK, PT_DMND, PT_IRON, PT_CNCT};+ static const uint8_t hot[] = {PT_SAND, PT_WATR, PT_STNE, PT_OIL, PT_GLAS, PT_LAVA, PT_FIRE, PT_PLSM, PT_METL, PT_SALT};+ for (int y = 4; y < YRES - 4; y++)+ for (int x = 2; x < XRES - 2; x++) {+ int k = x / 10 + y / 16 * 3;+ create_part(-1, x, y, n == 7 ? still[k % sizeof still] : hot[k % sizeof hot], -1);+ }+ }+ run(400);+ got[n] = full_hash();+ }+ got[9] = every_hash[0], got[10] = every_hash[1];+ for (int n = 1; n <= 10; n++) CHECK(got[n] == expect[n], "scene %d: hash %08x, %08x before", n, got[n], expect[n]);+ printf(" (hashes: 0");+ for (int n = 1; n <= 10; n++) printf(", 0x%08x", got[n]);+ printf(")\n");+}++/* ---------------------------------------------------------------- speed on the computer (a rough guide) */+static void test_speed(void) {+ reset();+ wallbox(4, 58, 95, 59, WL_WALL);+ fill(5, 20, 94, 57, PT_WATR);+ fill(20, 5, 80, 19, PT_SAND);+ clock_t c = clock();+ run(300);+ double ms = (double)(clock() - c) * 1000.0 / CLOCKS_PER_SEC / 300;+ printf("speed: %d particles, %.2f ms a frame on this computer (with the sanitizers)\n", NUM_PARTS, ms);+}++int main(int argc, char **argv) {+ sim_init();+ printf("NumPowder simtest: %d particles of room\n", npart_max);+ test_sand_pile();+ test_water_level();+ test_transitions();+ test_sparks();+ test_acid_fire_c4();+ test_light_walls();+ test_life();+ test_audit();+ test_saves();+ test_every_element();+ test_scenes_unchanged();+ if (argc > 1 && !strcmp(argv[1], "speed")) test_speed();+ printf("%d checks, %d failed\n", checks, fails);+ return fails != 0;+}diff --git a/games/numpowder/tools/gen_elements.py b/games/numpowder/tools/gen_elements.pynew file mode 100644index 00000000..f8e5c126--- /dev/null+++ b/games/numpowder/tools/gen_elements.py@@ -0,0 +1,256 @@+#!/usr/bin/env python3+"""NumPowder: the element table, from The Powder Toy's element files.++Each of The Powder Toy's src/simulation/elements/XXXX.cpp sets an element's+properties in its Element::Element_XXXX() function; their numbers come from+the list in elements/meson.build. This writes:++- src/elements.h: the elements' numbers (PT_*) and the Element struct;+- src/elements_data.c: the table, each property as the original writes it+ (the C compiler works out expressions such as 0.04f * CFDS), and the+ element's functions, declared weak: one not ported yet is NULL.++Usage: gen_elements.py [the Powder Toy's source folder]+"""+import os+import re+import sys++TPT = sys.argv[1] if len(sys.argv) > 1 else os.environ.get(+ "TPT_SRC", os.path.expanduser("~/Documents/Assets/gamesrc/powdertoy"))+ELEM = os.path.join(TPT, "src", "simulation", "elements")+OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "src")++names = re.findall(r"'([A-Z0-9_]+)'", open(os.path.join(ELEM, "meson.build")).read().split("]")[0])++# the properties, their C type in the table and their default (Element::Element())+PROPS = [+ ("Identifier", "const char *", '""'), ("Name", "const char *", '""'), ("Colour", "uint32_t", "0xFFFFFF"),+ ("MenuVisible", "uint8_t", "0"), ("MenuSection", "uint8_t", "SC_SPECIAL"), ("Enabled", "uint8_t", "0"),+ ("Advection", "float", "0"), ("AirDrag", "float", "0"), ("AirLoss", "float", "1"), ("Loss", "float", "1"),+ ("Collision", "float", "0"), ("Gravity", "float", "0"), ("NewtonianGravity", "float", "1"),+ ("Diffusion", "float", "0"), ("HotAir", "float", "0"), ("Falldown", "int8_t", "0"),+ ("Flammable", "int16_t", "0"), ("Explosive", "int16_t", "0"), ("Meltable", "int16_t", "0"),+ ("Hardness", "int16_t", "30"), ("PhotonReflectWavelengths", "uint32_t", "0x3FFFFFFF"),+ ("Weight", "int16_t", "50"), ("HeatConduct", "uint8_t", "128"), ("HeatCapacity", "float", "1"),+ ("Description", "const char *", '""'), ("Properties", "uint32_t", "0"), ("CarriesTypeIn", "uint32_t", "0"),+ ("LowPressure", "float", "IPL"), ("LowPressureTransition", "int16_t", "NT"),+ ("HighPressure", "float", "IPH"), ("HighPressureTransition", "int16_t", "NT"),+ ("LowTemperature", "float", "ITL"), ("LowTemperatureTransition", "int16_t", "NT"),+ ("HighTemperature", "float", "ITH"), ("HighTemperatureTransition", "int16_t", "NT"),+]+DEFAULTS = [("temp", "float", "R_TEMP + 273.15f"), ("life", "int", "0"), ("ctype", "int", "0"), ("tmp", "int", "0"),+ ("tmp2", "int", "0"), ("tmp3", "int", "0"), ("tmp4", "int", "0")]+FUNCS = {"Update": "update", "Graphics": "graphics", "Create": "create", "CreateAllowed": "create_allowed",+ "ChangeType": "change_type", "CtypeDraw": "ctype_draw"}+PROTOS = {"Update": "int %s(UPDATE_FUNC_ARGS)", "Graphics": "int %s(GRAPHICS_FUNC_ARGS)",+ "Create": "void %s(ELEMENT_CREATE_FUNC_ARGS)", "CreateAllowed": "bool %s(ELEMENT_CREATE_ALLOWED_FUNC_ARGS)",+ "ChangeType": "void %s(ELEMENT_CHANGETYPE_FUNC_ARGS)", "CtypeDraw": "bool %s(CTYPEDRAW_FUNC_ARGS)"}+++def c_expr(v):+ v = v.strip()+ v = re.sub(r"(0x[0-9A-Fa-f]+)_rgb", r"\1", v)+ v = v.replace("UINT32_C(", "(uint32_t)(")+ v = re.sub(r"\bString\(", "(", v)+ v = re.sub(r"(\d)U\b", r"\1u", v)+ return v+++def body_of(name, text):+ m = re.search(r"void\s+Element::Element_%s\s*\(\s*\)\s*\{" % name, text)+ if not m:+ raise SystemExit("no Element_%s()" % name)+ i, depth = m.end(), 1+ while depth:+ depth += {"{": 1, "}": -1}.get(text[i], 0)+ i += 1+ return text[m.end():i - 1]+++def strip_comments(s):+ s = re.sub(r"/\*.*?\*/", "", s, flags=re.S)+ return re.sub(r"//[^\n]*", "", s)+++elements, used_funcs = [], {}+for n in names:+ text = open(os.path.join(ELEM, n + ".cpp"), encoding="utf-8").read()+ body = strip_comments(body_of(n, text))+ props, defaults, funcs = {}, {}, {}+ for stmt in body.split(";"):+ stmt = " ".join(stmt.split())+ m = re.match(r"^([A-Za-z]+(?:\.[a-z0-9]+)?) = (.*)$", stmt)+ if not m:+ continue+ key, val = m.groups()+ if key.startswith("DefaultProperties."):+ defaults[key.split(".")[1]] = c_expr(val)+ elif key in FUNCS:+ f = val.lstrip("&").strip()+ if f in ("nullptr", "NULL"):+ continue+ if f.startswith("Element::"):+ cname = f.split("::")[1] # shared: Element::ctypeDrawVInTmp+ elif f.startswith("Element_"):+ cname = f # another element's: Element_FIRE_update+ else:+ cname = "el_%s_%s" % (n, f) # the file's own: update -> el_SAND_update+ funcs[key] = cname+ used_funcs[cname] = key+ elif key == "IconGenerator":+ continue+ else:+ props[key] = c_expr(val)+ elements.append((n, props, defaults, funcs))++# --------------------------------------------------------------------------- elements.h+h = ["/* NumPowder: The Powder Toy's elements, their numbers and properties (generated by tools/gen_elements.py",+ " * from the original's element files: do not edit). */",+ "#ifndef NP_ELEMENTS_H", "#define NP_ELEMENTS_H", "#include \"simdefs.h\"", "",+ "enum {"]+for i, (n, _, _, _) in enumerate(elements):+ h.append(" PT_%s = %d," % (n, i))+h += [" PT_COUNT = %d" % len(elements), "};", "",+ "typedef struct {"]+for k, t, _ in PROPS:+ h.append(" %s %s;" % (t, k))+h.append(" struct { float temp; int life, ctype, tmp, tmp2, tmp3, tmp4; } DefaultProperties;")+for k in FUNCS:+ h.append(" " + PROTOS[k].replace("%s", "(*%s)") % k + ";")+h += ["} Element;", "extern const Element elements[PT_NUM];", "", "#endif", ""]++# --------------------------------------------------------------------------- elements_data.c+c = ["/* NumPowder: The Powder Toy's element table (generated by tools/gen_elements.py: do not edit). Each element's",+ " * functions are weak: one not ported yet is NULL. */",+ "#include \"sim.h\"", ""]+for f, k in sorted(used_funcs.items()):+ c.append("%s __attribute__((weak));" % (PROTOS[k] % f))+c += ["", "const Element elements[PT_NUM] = {"]+for n, props, defaults, funcs in elements:+ c.append(" [PT_%s] = {" % n)+ for k, t, d in PROPS:+ v = props.get(k, d)+ c.append(" .%s = %s," % (k, v))+ dv = ", ".join(".%s = %s" % (k, defaults.get(k, d)) for k, _, d in DEFAULTS)+ c.append(" .DefaultProperties = {%s}," % dv)+ for k in FUNCS:+ if k in funcs:+ c.append(" .%s = %s," % (k, funcs[k]))+ c.append(" },")+c += ["};", ""]++# --------------------------------------------------------------------------- canmove_data.c+# SimulationData::init_can_move, worked out here from the elements' Properties and Weight (read as data: a list+# of flags joined by |, an integer)+FLAGS = {"TYPE_PART": 0x1, "TYPE_LIQUID": 0x2, "TYPE_SOLID": 0x4, "TYPE_GAS": 0x8, "TYPE_ENERGY": 0x10,+ "PROP_CONDUCTS": 0x20, "PROP_PHOTPASS": 0x40, "PROP_NEUTPENETRATE": 0x80, "PROP_NEUTABSORB": 0x100,+ "PROP_NEUTPASS": 0x200, "PROP_DEADLY": 0x400, "PROP_HOT_GLOW": 0x800, "PROP_LIFE": 0x1000,+ "PROP_RADIOACTIVE": 0x2000, "PROP_LIFE_DEC": 0x4000, "PROP_LIFE_KILL": 0x8000,+ "PROP_LIFE_KILL_DEC": 0x10000, "PROP_SPARKSETTLE": 0x20000, "PROP_NOAMBHEAT": 0x40000,+ "PROP_NOCTYPEDRAW": 0x100000}+++def flags_of(v):+ r = 0+ for tok in v.replace("(", " ").replace(")", " ").split("|"):+ tok = tok.strip()+ if tok in FLAGS:+ r |= FLAGS[tok]+ elif re.fullmatch(r"(0x[0-9A-Fa-f]+|\d+)u?", tok):+ r |= int(tok.rstrip("u"), 0)+ else:+ raise SystemExit("can't read Properties %r" % v)+ return r+++def int_of(v):+ v = v.strip()+ if not re.fullmatch(r"-?\d+", v):+ raise SystemExit("can't read Weight %r" % v)+ return int(v)+++N = len(elements)+num = {n: i for i, (n, _, _, _) in enumerate(elements)}+props = [flags_of(p.get("Properties", "TYPE_SOLID")) for _, p, _, _ in elements]+weight = [int_of(p.get("Weight", "50")) for _, p, _, _ in elements]+cm = [[1] * N for _ in range(N)]+for d in range(N):+ cm[0][d] = 0+PHOT, NEUT = num["PHOT"], num["NEUT"]+for d in range(1, N):+ cm[PHOT][d] = 2+for m in range(1, N):+ for d in range(1, N):+ if weight[m] <= weight[d] or d == num["GEL"]:+ cm[m][d] = 0+ if m == NEUT and props[d] & FLAGS["PROP_NEUTPASS"]:+ cm[m][d] = 2+ if m == NEUT and props[d] & FLAGS["PROP_NEUTABSORB"]:+ cm[m][d] = 1+ if m == NEUT and props[d] & FLAGS["PROP_NEUTPENETRATE"]:+ cm[m][d] = 1+ if d == NEUT and props[m] & FLAGS["PROP_NEUTPENETRATE"]:+ cm[m][d] = 0+ if props[m] & FLAGS["TYPE_ENERGY"] and props[d] & FLAGS["TYPE_ENERGY"]:+ cm[m][d] = 2+for d in range(N):+ stkm_move = 0+ if props[d] & (FLAGS["TYPE_LIQUID"] | FLAGS["TYPE_GAS"]):+ stkm_move = 2+ if not d or d in (num["PRTO"], num["SPAWN"], num["SPAWN2"]):+ stkm_move = 2+ for s_ in ("STKM", "STKM2", "FIGH"):+ cm[num[s_]][d] = stkm_move+ cm[num["SPRK"]][d] = 0+for m in range(1, N):+ for d_ in ("BHOL", "NBHL"):+ cm[m][num[d_]] = 1+ for d_ in ("STKM", "STKM2", "FIGH"):+ cm[m][num[d_]] = 0+ cm[m][num["INVIS"]] = 3+ cm[m][num["CNCT"]] = 0+ cm[m][num["PVOD"]] = 3+ cm[m][num["VOID"]] = 3+ cm[m][num["EMBR"]] = 0+ cm[num["EMBR"]][m] = 0+ if props[m] & FLAGS["TYPE_ENERGY"]:+ cm[m][num["VIBR"]] = 1+ cm[m][num["BVBR"]] = 1+ if props[m] & FLAGS["TYPE_PART"]:+ cm[m][num["SAWD"]] = 0+for d in range(N):+ if props[d] & FLAGS["PROP_PHOTPASS"]:+ cm[PHOT][d] = 2+ if d not in [num[k] for k in ("DMND", "INSL", "VOID", "PVOD", "VIBR", "BVBR", "PRTI", "PRTO")]:+ cm[num["PROT"]][d] = 2+ cm[num["GRVT"]][d] = 2+for a, b, v in [("DEST", "DMND", 0), ("DEST", "CLNE", 0), ("DEST", "PCLN", 0), ("DEST", "BCLN", 0), ("DEST", "PBCN", 0),+ ("DEST", "ROCK", 0), ("NEUT", "INVIS", 2), ("ELEC", "LCRY", 2), ("ELEC", "EXOT", 2), ("ELEC", "GLOW", 2),+ ("PHOT", "LCRY", 3), ("PHOT", "GPMP", 3), ("PHOT", "BIZR", 2), ("ELEC", "BIZR", 2), ("PHOT", "BIZRG", 2),+ ("ELEC", "BIZRG", 2), ("PHOT", "BIZRS", 2), ("ELEC", "BIZRS", 2), ("BIZR", "FILT", 2), ("BIZRG", "FILT", 2),+ ("ANAR", "WHOL", 1), ("ANAR", "NWHL", 1), ("ELEC", "DEUT", 1), ("THDR", "THDR", 2), ("EMBR", "EMBR", 2),+ ("TRON", "SWCH", 3), ("ELEC", "RSST", 2), ("ELEC", "RSSS", 2)]:+ cm[num[a]][num[b]] = v+stride = (N + 3) // 4+m_ = ["/* NumPowder: The Powder Toy's can_move table (SimulationData::init_can_move), 2 bits a pair (generated by",+ " * tools/gen_elements.py: do not edit). can_move[moving][destination]: 0 bounce, 1 swap, 2 same place, 3 varies */",+ "#include \"simpriv.h\"", "",+ "const uint8_t can_move_table[PT_COUNT][CANMOVE_STRIDE] = {"]+for m in range(N):+ row = []+ for k in range(stride):+ b = 0+ for q in range(4):+ d = k * 4 + q+ if d < N:+ b |= cm[m][d] << (2 * q)+ row.append("0x%02X" % b)+ m_.append(" {" + ",".join(row) + "},")+m_ += ["};", ""]+open(os.path.join(OUT, "canmove_data.c"), "w").write("\n".join(m_))++open(os.path.join(OUT, "elements.h"), "w").write("\n".join(h))+open(os.path.join(OUT, "elements_data.c"), "w").write("\n".join(c))+print("gen_elements.py: %d elements, %d functions to port" % (len(elements), len(used_funcs)))diff --git a/games/numpowder/tools/gen_font.py b/games/numpowder/tools/gen_font.pynew file mode 100644index 00000000..1e6d8596--- /dev/null+++ b/games/numpowder/tools/gen_font.py@@ -0,0 +1,102 @@+#!/usr/bin/env python3+"""NumPowder: The Powder Toy's font, from its resources/font.bz2.++The original's font (src/graphics/FontReader.cpp) is a list of glyphs, each a+24-bit code point and an 8-bit width, then 12 rows of `width` pixels, two bits+of alpha each (0..3), four to a byte, low bits first, row by row. Its glyphs+U+E000 and on are the interface's icons (menu sections, tools, render modes).++This keeps the glyphs the interface uses, in the same format, in+src/font_data.c, indexed by NumPowder's one-byte text code (font.h):+ 0x20..0x7E ASCII+ 0x7F U+00B0, the degree sign+ 0x80..0xEE U+E000..U+E06E, the icons+ 0xEF U+00B7, the middle dot+ 0xF0..0xF4 the keypad's symbols, drawn here in the font's style (the original has none):+ left, right, up and down triangles (the arrow keys), and the delete key's symbol+and U+FFFD for anything else.++Usage: gen_font.py [the Powder Toy's source folder]+"""+import bz2+import os+import sys++TPT = sys.argv[1] if len(sys.argv) > 1 else os.environ.get(+ "TPT_SRC", os.path.expanduser("~/Documents/Assets/gamesrc/powdertoy"))+OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "src", "font_data.c")++data = bz2.decompress(open(os.path.join(TPT, "resources", "font.bz2"), "rb").read())+glyphs = {}+i = 0+while i < len(data):+ cp = data[i] | data[i + 1] << 8 | data[i + 2] << 16+ w = data[i + 3]+ glyphs[cp] = (w, data[i + 4:i + 4 + 3 * w])+ i += 4 + 3 * w++# the keypad's symbols: rows of the glyph from its top (row 0 is 2 pixels above the text's y: capitals take rows 2 to+# 8), '#' a full pixel; a column of spacing after each, as the font's own glyphs+KEYPAD = [+ # left: the arrow key+ ["", "", " #", " ##", " ###", " ####", " ###", " ##", " #"],+ # right+ ["", "", "#", "##", "###", "####", "###", "##", "#"],+ # up+ ["", "", "", "", " #", " ###", " #####", "#######"],+ # down+ ["", "", "", "", "#######", " #####", " ###", " #"],+ # the delete key (backspace)+ ["", "", " #######", " # #", "# # # #", "# # #", "# # # #", " # #", " #######"],+]+++def keypad_glyph(rows):+ w = max(len(r) for r in rows) + 1+ px = []+ for y in range(12):+ r = rows[y] if y < len(rows) else ""+ px += [3 if x < len(r) and r[x] == "#" else 0 for x in range(w)]+ b = bytearray(3 * w)+ for k, a in enumerate(px):+ b[k // 4] |= a << (2 * (k % 4))+ return w, bytes(b)+++for k, rows in enumerate(KEYPAD):+ glyphs[0x110000 + k] = keypad_glyph(rows)++codes = list(range(0x20, 0x7F)) + [0xB0] + list(range(0xE000, 0xE06F)) + [0xB7] + \+ [0x110000 + k for k in range(len(KEYPAD))] + [0xFFFD]+missing = [hex(c) for c in codes if c not in glyphs]+if missing:+ raise SystemExit("no glyph for " + ", ".join(missing))++widths, offsets, bits = [], [], bytearray()+for c in codes:+ w, b = glyphs[c]+ widths.append(w)+ offsets.append(len(bits))+ bits += b++out = []+out.append("/* NumPowder: The Powder Toy's font (resources/font.bz2), the glyphs the interface uses (generated by\n"+ " * tools/gen_font.py: do not edit). Each glyph is 12 rows of its width in pixels, 2 bits of alpha each, four to\n"+ " * a byte, low bits first (FontReader.cpp). Indexed as font.h's text codes: ASCII from 0x20, 0x7F the degree\n"+ " * sign, 0x80 to 0xEE the icons U+E000 to U+E06E, 0xEF the middle dot, 0xF0 to 0xF4 the keypad's symbols (left, right,\n"+ " * up, down, delete: drawn by gen_font.py), then U+FFFD. */")+out.append('#include "font.h"\n')+out.append("const uint8_t font_widths[FONT_GLYPHS] = {")+for k in range(0, len(widths), 24):+ out.append(" " + ", ".join(str(w) for w in widths[k:k + 24]) + ",")+out.append("};")+out.append("const uint16_t font_offsets[FONT_GLYPHS] = {")+for k in range(0, len(offsets), 16):+ out.append(" " + ", ".join(str(o) for o in offsets[k:k + 16]) + ",")+out.append("};")+out.append("const uint8_t font_bits[%d] = {" % len(bits))+for k in range(0, len(bits), 20):+ out.append(" " + ", ".join("0x%02X" % v for v in bits[k:k + 20]) + ",")+out.append("};")+open(OUT, "w").write("\n".join(out) + "\n")+print("wrote %s: %d glyphs, %d bytes" % (OUT, len(codes), len(bits)))diff --git a/tests/test_games.py b/tests/test_games.pyindex f832bb9e..d8521eab 100644--- a/tests/test_games.py+++ b/tests/test_games.py@@ -117,6 +117,9 @@ GAMES = {presses((2500, "ok"), (4500, "ok"), (5500, "ok"), (6500, "ok")) + every(18000, 22000, 600, "right", 400),25000,presses((2500, "ok"), (4500, "ok")) + every(9000, 11000, 600, "left", 400), 14000),+ # the intro, then OK draws for a while (the autosave on Home); next time it comes back and more is drawn+ "numpowder": ("NumPowder.nwa", "numpowder.sav", presses((2000, "ok"), (3000, "ok", 1500)), 6000,+ presses((2000, "ok"), (2500, "right", 600), (3200, "ok", 800)), 5000),# Press OK to Play: the first scenario, its first goal closed, the city runs; then Continue"finalearth2": ("FinalEarth2.nwa", "finalearth2.sav", presses((2000, "ok"), (3000, "ok")), 9000,presses((2000, "ok")), 6000),@@ -147,7 +150,8 @@ SEEDS = {# NumWorks installer keeps): before the second session, as after installing# the app again, only the scripts are left, and the save must come backCOPIES = {"championisland": "champion_saves.py", "numblocks": "numblocks_saves.py", "celeste": "celeste_saves.py",- "hollowknight": "hollowknight_saves.py", "finalearth2": "finalearth2_saves.py"}+ "hollowknight": "hollowknight_saves.py", "finalearth2": "finalearth2_saves.py",+ "numpowder": "numpowder_saves.py"}CHECKS = {# the island remembers where Lucky was; after the reinstall, from the copy"championisland": (lambda v: v[:3] == b"CI1" and b"PLAYER_LOC" in v,) * 2,@@ -158,6 +162,8 @@ CHECKS = {"chess": (lambda v: v == SEEDS["chess"],) * 2, # read back and kept# a city saved ("FE2S", version 1); after the reinstall, from the copy, it goes on and is saved again"finalearth2": (lambda v: v[:4] == b"FE2S" and v[4] == 1,) * 2,+ # a simulation saved ("NPWD"); after the reinstall, from the copy, it goes on and is saved again+ "numpowder": (lambda v: v[:4] == b"NPWD",) * 2,# a game saved ("HKSV", then the play time at 152); after the reinstall, from the copy, it goes on"hollowknight": (lambda v: v[:4] == b"HKSV" and struct.unpack_from("<f", v, 152)[0] > 0,lambda v: v[:4] == b"HKSV" and struct.unpack_from("<f", v, 152)[0] > 10),diff --git a/tools/release.py b/tools/release.pyindex 0b05e830..c7f3d4ee 100644--- a/tools/release.py+++ b/tools/release.py@@ -29,6 +29,8 @@ ALONE = {"NumPlay: install it on its own"),"championisland": ("Champion Island", "the Doodle Champion Island Games. Too big to share the calculator with ""NumPlay: install it on its own"),+ "numpowder": ("NumPowder", "The Powder Toy on the calculator: sand, water, fire, acid, electricity and nearly 200 "+ "elements. Too big to share the calculator with NumPlay: install it on its own"),"finalearth2": ("The Final Earth 2", "build a city on floating islands in space, every scenario and free play map. ""Too big to share the calculator with NumPlay: install it on its own"),}