diff src/scenario.c @ 0:c84446dfb3f5

initial add
author paulo@localhost
date Fri, 13 Mar 2009 00:39:12 -0700
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/scenario.c	Fri Mar 13 00:39:12 2009 -0700
     1.3 @@ -0,0 +1,339 @@
     1.4 +/* Scenario code for LOCKJAW, an implementation of the Soviet Mind Game
     1.5 +
     1.6 +Copyright (C) 2008 Damian Yerrick <tepples+lj@spamcop.net>
     1.7 +
     1.8 +This work is free software; you can redistribute it and/or modify
     1.9 +it under the terms of the GNU General Public License as published by
    1.10 +the Free Software Foundation; either version 2 of the License, or
    1.11 +(at your option) any later version.
    1.12 +
    1.13 +This program is distributed in the hope that it will be useful,
    1.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 +GNU General Public License for more details.
    1.17 +
    1.18 +You should have received a copy of the GNU General Public License
    1.19 +along with this program; if not, write to the Free Software
    1.20 +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +Original game concept and design by Alexey Pajitnov.
    1.23 +The Software is not sponsored or endorsed by Alexey Pajitnov, Elorg,
    1.24 +or The Tetris Company LLC.
    1.25 +
    1.26 +*/
    1.27 +
    1.28 +#include "scenario.h"
    1.29 +#include "options.h"
    1.30 +#include <string.h>
    1.31 +
    1.32 +#define END_OF_PRESET {OPTIONS_MENU_LEN}
    1.33 +
    1.34 +const Preset predefPresets[] = {
    1.35 +  {"Guideline", {
    1.36 +    {OPTIONS_WIDTH, 10},
    1.37 +    {OPTIONS_HEIGHT, 20},
    1.38 +    {OPTIONS_ENTRY_DELAY, 0},
    1.39 +    {OPTIONS_PIECE_SET, LJRAND_4BLK},
    1.40 +    {OPTIONS_RANDOMIZER, LJRAND_BAG},
    1.41 +    {OPTIONS_HOLD_PIECE, LJHOLD_EMPTY},
    1.42 +    {OPTIONS_ROTATION_SYSTEM, LJROT_SRS},
    1.43 +    {OPTIONS_FLOOR_KICKS, 6},
    1.44 +    {OPTIONS_LOCKDOWN, LJLOCK_MOVE},
    1.45 +    {OPTIONS_LOCK_DELAY, 30},
    1.46 +    {OPTIONS_BOTTOM_BLOCKS, 0},
    1.47 +    {OPTIONS_LINE_DELAY, 30},
    1.48 +    {OPTIONS_CLEAR_GRAVITY, LJGRAV_NAIVE},
    1.49 +    {OPTIONS_GLUING, 0},
    1.50 +    {OPTIONS_SCORING, LJSCORE_TDS},
    1.51 +    {OPTIONS_DROP_SCORING, LJDROP_1S_2H},
    1.52 +    {OPTIONS_T_SPIN, LJTS_TDS},
    1.53 +    END_OF_PRESET
    1.54 +  }},
    1.55 +
    1.56 +  {"Classic", {
    1.57 +    {OPTIONS_GIMMICK, LJGM_ATYPE},
    1.58 +    {OPTIONS_WIDTH, 10},
    1.59 +    {OPTIONS_HEIGHT, 20},
    1.60 +    {OPTIONS_ENTER_ABOVE, 0},
    1.61 +    {OPTIONS_ENTRY_DELAY, 10},
    1.62 +    {OPTIONS_SPEED_CURVE, LJSPD_NES},
    1.63 +    {OPTIONS_PIECE_SET, LJRAND_4BLK},
    1.64 +    {OPTIONS_RANDOMIZER, LJRAND_PURE},
    1.65 +    {OPTIONS_HOLD_PIECE, LJHOLD_NONE},
    1.66 +    {OPTIONS_ROTATION_SYSTEM, LJROT_NES},
    1.67 +    {OPTIONS_FLOOR_KICKS, 0},
    1.68 +    {OPTIONS_LOCKDOWN, LJLOCK_NOW},
    1.69 +    {OPTIONS_LOCK_DELAY, 0},
    1.70 +    {OPTIONS_BOTTOM_BLOCKS, 0},
    1.71 +    {OPTIONS_LINE_DELAY, 30},
    1.72 +    {OPTIONS_CLEAR_GRAVITY, LJGRAV_NAIVE},
    1.73 +    {OPTIONS_GLUING, 0},
    1.74 +    {OPTIONS_SCORING, LJSCORE_NES},
    1.75 +    {OPTIONS_DROP_SCORING, LJDROP_NES},
    1.76 +    {OPTIONS_GARBAGE, LJGARBAGE_NONE},
    1.77 +    {OPTIONS_SIDEWAYS_DELAY, 15},
    1.78 +    {OPTIONS_SIDEWAYS_SPEED, 6},
    1.79 +    {OPTIONS_SOFT_DROP_SPEED, 2},
    1.80 +    {OPTIONS_INITIAL_SIDEWAYS, 1},
    1.81 +    {OPTIONS_IRS, 0},
    1.82 +    {OPTIONS_NEXT_PIECES, 1},
    1.83 +    END_OF_PRESET
    1.84 +  }},
    1.85 +
    1.86 +  /* http://www.tetrisconcept.com/forum/viewtopic.php?t=892 */
    1.87 +  {"Master", {
    1.88 +    {OPTIONS_GIMMICK, LJGM_ATYPE},
    1.89 +    {OPTIONS_WIDTH, 10},
    1.90 +    {OPTIONS_HEIGHT, 20},
    1.91 +    {OPTIONS_ENTER_ABOVE, 0},
    1.92 +    {OPTIONS_SPEED_CURVE, LJSPD_TGM},
    1.93 +    {OPTIONS_ENTRY_DELAY, 30},
    1.94 +    {OPTIONS_PIECE_SET, LJRAND_4BLK},
    1.95 +    {OPTIONS_RANDOMIZER, LJRAND_HIST_6},
    1.96 +    {OPTIONS_HOLD_PIECE, LJHOLD_NONE},
    1.97 +    {OPTIONS_ROTATION_SYSTEM, LJROT_ARIKA},
    1.98 +    {OPTIONS_FLOOR_KICKS, 0},
    1.99 +    {OPTIONS_LOCKDOWN, LJLOCK_STEP},
   1.100 +    {OPTIONS_LOCK_DELAY, 30},
   1.101 +    {OPTIONS_BOTTOM_BLOCKS, 0},
   1.102 +    {OPTIONS_LINE_DELAY, 0},
   1.103 +    {OPTIONS_CLEAR_GRAVITY, LJGRAV_NAIVE},
   1.104 +    {OPTIONS_GLUING, LJGLUING_STICKY},
   1.105 +    {OPTIONS_GARBAGE, LJGARBAGE_NONE},
   1.106 +    {OPTIONS_SIDEWAYS_DELAY, 16},
   1.107 +    {OPTIONS_SIDEWAYS_SPEED, 1},
   1.108 +    {OPTIONS_INITIAL_SIDEWAYS, 0},
   1.109 +    {OPTIONS_IRS, 1},
   1.110 +    {OPTIONS_SOFT_DROP_SPEED, 1},
   1.111 +    {OPTIONS_SOFT_DROP, LJZANGI_LOCK},
   1.112 +    {OPTIONS_HARD_DROP, LJZANGI_SLIDE},
   1.113 +    {OPTIONS_NEXT_PIECES, 1},
   1.114 +    END_OF_PRESET
   1.115 +  }},
   1.116 +
   1.117 +  /* http://www.tetrisconcept.com/forum/viewtopic.php?t=892 */
   1.118 +  {"T.A. Death", {
   1.119 +    {OPTIONS_GIMMICK, LJGM_ATYPE},
   1.120 +    {OPTIONS_SPEED_CURVE, LJSPD_DEATH},
   1.121 +    {OPTIONS_WIDTH, 10},
   1.122 +    {OPTIONS_HEIGHT, 20},
   1.123 +    {OPTIONS_ENTER_ABOVE, 0},
   1.124 +    {OPTIONS_ENTRY_DELAY, 30},
   1.125 +    {OPTIONS_PIECE_SET, LJRAND_4BLK},
   1.126 +    {OPTIONS_RANDOMIZER, LJRAND_HIST_6},
   1.127 +    {OPTIONS_HOLD_PIECE, LJHOLD_NONE},
   1.128 +    {OPTIONS_ROTATION_SYSTEM, LJROT_ARIKA},
   1.129 +    {OPTIONS_FLOOR_KICKS, 0},
   1.130 +    {OPTIONS_LOCKDOWN, LJLOCK_STEP},
   1.131 +    {OPTIONS_LOCK_DELAY, 30},
   1.132 +    {OPTIONS_BOTTOM_BLOCKS, 0},
   1.133 +    {OPTIONS_LINE_DELAY, 0},
   1.134 +    {OPTIONS_CLEAR_GRAVITY, LJGRAV_NAIVE},
   1.135 +    {OPTIONS_GLUING, LJGLUING_STICKY},
   1.136 +    {OPTIONS_GARBAGE, LJGARBAGE_NONE},
   1.137 +    {OPTIONS_SIDEWAYS_DELAY, 16},
   1.138 +    {OPTIONS_SIDEWAYS_SPEED, 1},
   1.139 +    {OPTIONS_INITIAL_SIDEWAYS, 0},
   1.140 +    {OPTIONS_IRS, 1},
   1.141 +    {OPTIONS_NEXT_PIECES, 1},
   1.142 +    END_OF_PRESET
   1.143 +  }},
   1.144 +
   1.145 +  {"Square", {
   1.146 +    {OPTIONS_GIMMICK, LJGM_ATYPE},
   1.147 +    {OPTIONS_WIDTH, 10},
   1.148 +    {OPTIONS_HEIGHT, 20},
   1.149 +    {OPTIONS_ENTER_ABOVE, 1},
   1.150 +    {OPTIONS_ENTRY_DELAY, 30},
   1.151 +    {OPTIONS_SPEED_CURVE, LJSPD_EXP},
   1.152 +    {OPTIONS_PIECE_SET, LJRAND_4BLK},
   1.153 +    {OPTIONS_RANDOMIZER, LJRAND_PURE},
   1.154 +    {OPTIONS_HOLD_PIECE, LJHOLD_TNT},
   1.155 +    {OPTIONS_ROTATION_SYSTEM, LJROT_SRS},
   1.156 +    {OPTIONS_FLOOR_KICKS, 6},
   1.157 +    {OPTIONS_LOCKDOWN, LJLOCK_STEP},
   1.158 +    {OPTIONS_LOCK_DELAY, 30},
   1.159 +    {OPTIONS_BOTTOM_BLOCKS, 0},
   1.160 +    {OPTIONS_LINE_DELAY, 40},
   1.161 +    {OPTIONS_CLEAR_GRAVITY, LJGRAV_NAIVE},
   1.162 +    {OPTIONS_GLUING, LJGLUING_SQUARE},
   1.163 +    {OPTIONS_SCORING, LJSCORE_TNT64},
   1.164 +    {OPTIONS_DROP_SCORING, LJDROP_NOSCORE},
   1.165 +    {OPTIONS_T_SPIN, LJTS_TNT},
   1.166 +    {OPTIONS_GARBAGE, LJGARBAGE_NONE},
   1.167 +    {OPTIONS_SIDEWAYS_DELAY, 11},
   1.168 +    {OPTIONS_SIDEWAYS_SPEED, 5},
   1.169 +    {OPTIONS_SOFT_DROP_SPEED, 2},
   1.170 +    {OPTIONS_SOFT_DROP, LJZANGI_SLIDE},
   1.171 +    {OPTIONS_HARD_DROP, LJZANGI_SLIDE},
   1.172 +    {OPTIONS_INITIAL_SIDEWAYS, 0},
   1.173 +    {OPTIONS_IRS, 0},
   1.174 +    {OPTIONS_NEXT_PIECES, 3},
   1.175 +    END_OF_PRESET
   1.176 +  }},
   1.177 +
   1.178 +  /* http://www.tetrisconcept.com/forum/viewtopic.php?t=549 */
   1.179 +  {"40 Lines", {
   1.180 +    {OPTIONS_GIMMICK, LJGM_BTYPE},
   1.181 +    {OPTIONS_WIDTH, 10},
   1.182 +    {OPTIONS_PIECE_SET, LJRAND_4BLK},
   1.183 +    {OPTIONS_BOTTOM_BLOCKS, 0},
   1.184 +    {OPTIONS_CLEAR_GRAVITY, LJGRAV_NAIVE},
   1.185 +    {OPTIONS_GARBAGE, 0},
   1.186 +    END_OF_PRESET
   1.187 +  }},
   1.188 +
   1.189 +  /* http://www.tetrisconcept.com/forum/viewtopic.php?t=549 */
   1.190 +  {"180 Seconds", {
   1.191 +    {OPTIONS_GIMMICK, LJGM_ULTRA},
   1.192 +    {OPTIONS_WIDTH, 10},
   1.193 +    {OPTIONS_PIECE_SET, LJRAND_4BLK},
   1.194 +    {OPTIONS_HOLD_PIECE, LJHOLD_EMPTY},
   1.195 +    {OPTIONS_BOTTOM_BLOCKS, 0},
   1.196 +    {OPTIONS_CLEAR_GRAVITY, LJGRAV_NAIVE},
   1.197 +    {OPTIONS_GLUING, 0},
   1.198 +    {OPTIONS_SCORING, LJSCORE_LJ},
   1.199 +    {OPTIONS_DROP_SCORING, 0},
   1.200 +    {OPTIONS_T_SPIN, 0},
   1.201 +    {OPTIONS_GARBAGE, 0},
   1.202 +    END_OF_PRESET
   1.203 +  }},
   1.204 +
   1.205 +  /* http://www.tetrisconcept.com/forum/viewtopic.php?t=892 */
   1.206 +  {"Death 300", {
   1.207 +    {OPTIONS_GIMMICK, LJGM_ULTRA},
   1.208 +    {OPTIONS_SPEED_CURVE, LJSPD_DEATH300},
   1.209 +    {OPTIONS_WIDTH, 10},
   1.210 +    {OPTIONS_HEIGHT, 20},
   1.211 +    {OPTIONS_ENTER_ABOVE, 0},
   1.212 +    {OPTIONS_ENTRY_DELAY, 30},
   1.213 +    {OPTIONS_PIECE_SET, LJRAND_4BLK},
   1.214 +    {OPTIONS_RANDOMIZER, LJRAND_HIST_6},
   1.215 +    {OPTIONS_HOLD_PIECE, LJHOLD_EMPTY},
   1.216 +    {OPTIONS_ROTATION_SYSTEM, LJROT_ARIKA},
   1.217 +    {OPTIONS_FLOOR_KICKS, 0},
   1.218 +    {OPTIONS_LOCKDOWN, LJLOCK_STEP},
   1.219 +    {OPTIONS_LOCK_DELAY, 30},
   1.220 +    {OPTIONS_BOTTOM_BLOCKS, 0},
   1.221 +    {OPTIONS_LINE_DELAY, 0},
   1.222 +    {OPTIONS_CLEAR_GRAVITY, LJGRAV_NAIVE},
   1.223 +    {OPTIONS_GLUING, LJGLUING_STICKY},
   1.224 +    {OPTIONS_GARBAGE, LJGARBAGE_NONE},
   1.225 +    {OPTIONS_SIDEWAYS_DELAY, 16},
   1.226 +    {OPTIONS_SIDEWAYS_SPEED, 1},
   1.227 +    {OPTIONS_INITIAL_SIDEWAYS, 0},
   1.228 +    {OPTIONS_IRS, 1},
   1.229 +    {OPTIONS_NEXT_PIECES, 1},
   1.230 +    END_OF_PRESET
   1.231 +  }},
   1.232 +
   1.233 +  {"M-Roll", {
   1.234 +    {OPTIONS_GIMMICK, LJGM_BTYPE},
   1.235 +    {OPTIONS_SPEED_CURVE, LJSPD_DEATH300},
   1.236 +    {OPTIONS_WIDTH, 10},
   1.237 +    {OPTIONS_HEIGHT, 20},
   1.238 +    {OPTIONS_ENTER_ABOVE, 0},
   1.239 +    {OPTIONS_ENTRY_DELAY, 30},
   1.240 +    {OPTIONS_PIECE_SET, LJRAND_4BLK},
   1.241 +    {OPTIONS_RANDOMIZER, LJRAND_HIST_6},
   1.242 +    {OPTIONS_HOLD_PIECE, LJHOLD_EMPTY},
   1.243 +    {OPTIONS_ROTATION_SYSTEM, LJROT_ARIKA},
   1.244 +    {OPTIONS_FLOOR_KICKS, 0},
   1.245 +    {OPTIONS_LOCKDOWN, LJLOCK_STEP},
   1.246 +    {OPTIONS_LOCK_DELAY, 30},
   1.247 +    {OPTIONS_BOTTOM_BLOCKS, 0},
   1.248 +    {OPTIONS_LINE_DELAY, 0},
   1.249 +    {OPTIONS_CLEAR_GRAVITY, LJGRAV_NAIVE},
   1.250 +    {OPTIONS_GLUING, LJGLUING_STICKY},
   1.251 +    {OPTIONS_GARBAGE, LJGARBAGE_NONE},
   1.252 +    {OPTIONS_SIDEWAYS_DELAY, 16},
   1.253 +    {OPTIONS_SIDEWAYS_SPEED, 1},
   1.254 +    {OPTIONS_INITIAL_SIDEWAYS, 0},
   1.255 +    {OPTIONS_IRS, 1},
   1.256 +    {OPTIONS_NEXT_PIECES, 1},
   1.257 +    {OPTIONS_HIDE_PF, 1},
   1.258 +    END_OF_PRESET
   1.259 +  }},
   1.260 +
   1.261 +  /* http://www.tetrisconcept.com/forum/viewtopic.php?t=549 */
   1.262 +  {"Cascade", {
   1.263 +    {OPTIONS_GIMMICK, LJGM_BTYPE},
   1.264 +    {OPTIONS_WIDTH, 10},
   1.265 +    {OPTIONS_PIECE_SET, LJRAND_4BLK},
   1.266 +    {OPTIONS_HOLD_PIECE, LJHOLD_EMPTY},
   1.267 +    {OPTIONS_CLEAR_GRAVITY, LJGRAV_CASCADE},
   1.268 +    {OPTIONS_GARBAGE, 0},
   1.269 +    END_OF_PRESET
   1.270 +  }},
   1.271 +
   1.272 +  /* http://www.tetrisconcept.com/forum/viewtopic.php?t=777 */
   1.273 +  {"Baboo!", {
   1.274 +    {OPTIONS_GIMMICK, LJGM_BABY},
   1.275 +    {OPTIONS_WIDTH, 10},
   1.276 +    {OPTIONS_PIECE_SET, LJRAND_4BLK},
   1.277 +    {OPTIONS_SPEED_CURVE, LJSPD_ZERO},
   1.278 +    {OPTIONS_BOTTOM_BLOCKS, 0},
   1.279 +    {OPTIONS_CLEAR_GRAVITY, LJGRAV_NAIVE},
   1.280 +    {OPTIONS_GLUING, 0},
   1.281 +    {OPTIONS_SCORING, LJSCORE_LJ},
   1.282 +    {OPTIONS_DROP_SCORING, 0},
   1.283 +    {OPTIONS_T_SPIN, LJTS_TDS},
   1.284 +    {OPTIONS_GARBAGE, 0}
   1.285 +  }},
   1.286 +
   1.287 +};
   1.288 +
   1.289 +const Preset *loadedPresets = predefPresets;
   1.290 +size_t nLoadedPresets = sizeof(predefPresets)/sizeof(predefPresets[0]);
   1.291 +
   1.292 +static unsigned char presetBuffer[OPTIONS_MENU_LEN];
   1.293 +
   1.294 +void presetStart(void) {
   1.295 +  memset(&presetBuffer, 255, sizeof(presetBuffer));
   1.296 +}
   1.297 +
   1.298 +void presetAdd(size_t which) {
   1.299 +  if (which >= nLoadedPresets) {
   1.300 +    return;
   1.301 +  }
   1.302 +  const PresetRule *r = loadedPresets[which].rules;
   1.303 +  for (size_t i = 0;
   1.304 +       i < PRESET_MAX_RULES
   1.305 +       && r[i].line < OPTIONS_MENU_LEN;
   1.306 +       ++i) {
   1.307 +    presetBuffer[r[i].line] = r[i].value;
   1.308 +  }
   1.309 +}
   1.310 +
   1.311 +void presetFinish(struct LJView *v) {
   1.312 +  unpackCommonOptions(v, presetBuffer);
   1.313 +}
   1.314 +
   1.315 +#if 0
   1.316 +void loadPresetsFromText(FILE *fp) {
   1.317 +  Preset *presets = NULL;
   1.318 +
   1.319 +  size_t capacity = 0, n = 0;
   1.320 +  
   1.321 +  {
   1.322 +    // allocate memory for this preset
   1.323 +    if (capacity <= n) {
   1.324 +      if (capacity < 32) {
   1.325 +        capacity += 16;
   1.326 +      } else {
   1.327 +        capacity += capacity / 2;
   1.328 +      }
   1.329 +      Preset *newPresets = realloc(presets,
   1.330 +                                   capacity * sizeof(preset));
   1.331 +      // if we can't allocate memory, screw it
   1.332 +      if (!newPresets) {
   1.333 +        break;
   1.334 +      }
   1.335 +    }
   1.336 +  }
   1.337 +  
   1.338 +  loadedPresets = presets;
   1.339 +  nLoadedPresets = n;
   1.340 +}
   1.341 +#endif
   1.342 +