;;; -*- Common Lisp -*- #| Copyright (c) 2007,2008 Gustavo Henrique Milar� This file is part of The Feebs War. The Feebs War is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The Feebs War is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with The Feebs War. If not, see . |# ;;; Usefull for creating a feeb ;;; These are optimized so someone can use them without ;;; complaining that they slow down your feeb !!! (in-package :the-feebs-war) (declaim (optimize (speed 3) (safety 0)) (inline left-of right-of behind forward-dx forward-dy left-dx left-dy right-dx right-dy behind-dx behind-dy relative-facing wallp chance) ((function ((integer 0 3)) (integer 0 3)) left-of right-of behind relative-facing) ((function ((integer 0 3)) (integer -1 1)) forward-dx forward-dy left-dx left-dy right-dx right-dy behind-dx behind-dy) ((function (rational) boolean) chance)) ;;; Directional arithmetic. (defun right-of (facing) (mod (+ facing 3) 4)) (defun left-of (facing) (mod (+ facing 1) 4)) (defun behind (facing) (mod (+ facing 2) 4)) (defun relative-facing (my-facing other-facing) (mod (- my-facing other-facing) 4)) (defun forward-dy (facing) (if (oddp facing) 0 (rem (1- facing) 4))) (defun forward-dx (facing) (if (oddp facing) (rem (- 2 facing) 4) 0)) (defun left-dy (facing) (forward-dy (left-of facing))) (defun left-dx (facing) (forward-dx (left-of facing))) (defun right-dy (facing) (forward-dy (right-of facing))) (defun right-dx (facing) (forward-dx (right-of facing))) (defun behind-dy (facing) (forward-dy (behind facing))) (defun behind-dx (facing) (forward-dx (behind facing))) ;;; Tests (defun wallp (thing) (the boolean (eq :rock (car thing)))) (defun chance (ratio) (< (random (denominator ratio)) (numerator ratio))) #| ;;; Handling the vision, vision-left and vision-right objects (defmacro with-visible-elements ((count line-of-sight) ((vis vision) &body vis-body) ((vis-l vision-left) &body vis-l-body) ((vis-r vision-right) &body vis-r-body) &body finalize) (let ((v (gensym)) (vl (gensym)) (vr (gensym))) `(do* ((,count 1 (1+ ,count)) (,v (svref ,vision ,count)) (,vl (svref ,vision ,count)) (,vr (svref ,vision ,count))) ((= ,count line-of-sight) ,@finalize) (declare (list ,v ,vl ,vr) (fixnum ,count)) (dolist (,vis ,v) ,@vis-body) (dolist (,vis-l ,vl) ,@vis-l-body) (dolist (,vis-r ,vr) ,@vis-r-body)))) |#