ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/cfperl.xs
(Generate patch)

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.397 by root, Tue Jan 25 22:39:54 2011 UTC vs.
Revision 1.400 by root, Sat Apr 23 04:46:27 2011 UTC

29#include <cstdarg> 29#include <cstdarg>
30#include <typeinfo> 30#include <typeinfo>
31 31
32#include "global.h" 32#include "global.h"
33#include "rmg.h" 33#include "rmg.h"
34#include "noise.h"
34#include "evthread.h" 35#include "evthread.h"
35#include "sproto.h" 36#include "sproto.h"
36 37
37#include <unistd.h> 38#include <unistd.h>
38#if _POSIX_MEMLOCK 39#if _POSIX_MEMLOCK
1557 1558
1558 for_all_objects (op) 1559 for_all_objects (op)
1559 op->reattach (); 1560 op->reattach ();
1560} 1561}
1561 1562
1562# support function for map-world.ext
1563void _quantise (SV *data_sv, SV *plt_sv)
1564 CODE:
1565{
1566 if (!SvROK (plt_sv) || SvTYPE (SvRV (plt_sv)) != SVt_PVAV)
1567 croak ("_quantise called with invalid agruments");
1568
1569 plt_sv = SvRV (plt_sv);
1570 SV **plt = AvARRAY (plt_sv);
1571 int plt_count = AvFILL (plt_sv) + 1;
1572
1573 STRLEN len;
1574 char *data = SvPVbyte (data_sv, len);
1575 char *dst = data;
1576
1577 while (len >= 3)
1578 {
1579 for (SV **val_sv = plt + plt_count; val_sv-- > plt; )
1580 {
1581 char *val = SvPVX (*val_sv);
1582
1583 if (val [0] == data [0]
1584 && val [1] == data [1]
1585 && val [2] == data [2])
1586 {
1587 *dst++ = val [3];
1588 goto next;
1589 }
1590 }
1591
1592 croak ("_quantise: color not found in palette: #%02x%02x%02x, at offset %d %d",
1593 (uint8_t)data [0], (uint8_t)data [1], (uint8_t)data [2],
1594 dst - SvPVX (data_sv), len);
1595
1596 next:
1597 data += 3;
1598 len -= 3;
1599 }
1600
1601 SvCUR_set (data_sv, dst - SvPVX (data_sv));
1602}
1603
1604void init_anim () 1563void init_anim ()
1605 1564
1606void init_globals () 1565void init_globals ()
1607 1566
1608void init_attackmess () 1567void init_attackmess ()
2391 if (pl->ob && pl->ob->map == THIS) 2350 if (pl->ob && pl->ob->map == THIS)
2392 PUSHs (sv_2mortal (to_sv (pl->ob))); 2351 PUSHs (sv_2mortal (to_sv (pl->ob)));
2393 } 2352 }
2394 2353
2395void 2354void
2355maptile::add_quadland (int mx, int my, int mz, SV *biome_map, SV *biome_plt)
2356 CODE:
2357{
2358 static frac_gen<vec2d> frac;
2359
2360 if (!SvROK (biome_plt) || SvTYPE (SvRV (biome_plt)) != SVt_PVAV)
2361 croak ("maptile::add_quadland: biome_plt must be arrayref");
2362
2363 biome_plt = SvRV (biome_plt);
2364
2365 const uint8_t *bmap = (const uint8_t *)SvPVbyte_nolen (biome_map);
2366
2367 for (int x = 0; x < THIS->width; ++x)
2368 for (int y = 0; y < THIS->height; ++y)
2369 {
2370 for (object *op = THIS->at (x, y).bot; op; op = op->above)
2371 if (op->flag [FLAG_IS_FLOOR])
2372 goto skip;
2373
2374 {
2375 float fx = mx * THIS->width + x;
2376 float fy = my * THIS->height + y;
2377
2378 int temp = clamp (int (32 * frac.fBm (vec2d (fx * 0.001, fy * 0.001), 2) ) - 8, 0, 15);
2379 int rain = clamp (int (16 * frac.ridgedmultifractal (vec2d (fx * 0.01, fy * 0.01), 3, 1.03, 2)) - 8, 0, 15);
2380
2381 rain = lerp (rain, 0, 15, 0, temp);
2382 printf ("rain %d\n", temp);//D
2383
2384 int biome = bmap [rain * 16 + temp];
2385
2386 //printf ("%2d %2d => %s\n", temp, rain, SvPV_nolen (AvARRAY ((AV *)biome_plt)[biome]));//D
2387#if 1
2388 if (SV **elem = av_fetch ((AV *)biome_plt, bmap [rain * 16 + temp], 0))
2389 {
2390 object *ob = get_archetype (cfSvPVutf8_nolen (*elem));
2391 ob->flag [FLAG_NO_MAP_SAVE] = true;
2392 THIS->insert (ob, x, y, 0, INS_ABOVE_FLOOR_ONLY);
2393
2394 if (ob->randomitems && !ob->above)
2395 {
2396 ob->create_treasure (ob->randomitems);
2397
2398 for (object *op = ob->above; op; op = op->above)
2399 op->flag [FLAG_NO_MAP_SAVE] = true;
2400 }
2401 }
2402#endif
2403 }
2404 skip: ;
2405 }
2406}
2407
2408void
2396maptile::add_underlay (SV *data, int offset, int stride, SV *palette) 2409maptile::add_underlay (SV *data, int offset, int stride, SV *palette)
2397 CODE: 2410 CODE:
2398{ 2411{
2399 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV) 2412 if (!SvROK (palette) || SvTYPE (SvRV (palette)) != SVt_PVAV)
2400 croak ("maptile::add_underlay: palette must be arrayref"); 2413 croak ("maptile::add_underlay: palette must be arrayref");
2430 op->flag [FLAG_NO_MAP_SAVE] = true; 2443 op->flag [FLAG_NO_MAP_SAVE] = true;
2431 // TODO: if this is a pickable object, then the item 2444 // TODO: if this is a pickable object, then the item
2432 // will at a bit weird - saving inside the player 2445 // will at a bit weird - saving inside the player
2433 // will clear the flag, but when the player drops 2446 // will clear the flag, but when the player drops
2434 // it without logging out, it keeps the flag. 2447 // it without logging out, it keeps the flag.
2435 // nobody ahs reported this, but this can be rather 2448 // nobody has reported this, but this can be rather
2436 // annoying on persistent maps. 2449 // annoying on persistent maps.
2437 } 2450 }
2438 } 2451 }
2439 } 2452 }
2440 } 2453 }
2441
2442 skip: ; 2454 skip: ;
2443 } 2455 }
2444} 2456}
2445 2457
2446void 2458void
2477 for (int x = 0; x < THIS->width; ++x) 2489 for (int x = 0; x < THIS->width; ++x)
2478 for (int y = 0; y < THIS->height; ++y) 2490 for (int y = 0; y < THIS->height; ++y)
2479 { 2491 {
2480 region *rgn = THIS->region (x, y); 2492 region *rgn = THIS->region (x, y);
2481 2493
2482 //fprintf (stderr, "%d,%d %f %p\n", x, y, rgn->treasure_density,rgn->treasure);//D
2483 if (object *op = THIS->at (x, y).top) 2494 if (object *op = THIS->at (x, y).top)
2484 if (rgn->treasure && rndm () < rgn->treasure_density) 2495 if (rgn->treasure && rndm () < rgn->treasure_density)
2485 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty); 2496 create_treasure (rgn->treasure, op, GT_ENVIRONMENT, THIS->difficulty);
2486 } 2497 }
2487 2498

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines